1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Merge pull request #101598 from MewPurPur/quick-open-pt1

Tweak Quick Open theming
This commit is contained in:
Rémi Verschelde
2025-02-10 10:49:06 +01:00
2 changed files with 55 additions and 63 deletions

View File

@@ -220,14 +220,15 @@ QuickOpenResultContainer::QuickOpenResultContainer() {
list = memnew(VBoxContainer); list = memnew(VBoxContainer);
list->set_h_size_flags(Control::SIZE_EXPAND_FILL); list->set_h_size_flags(Control::SIZE_EXPAND_FILL);
list->add_theme_constant_override(SNAME("separation"), 0);
list->hide(); list->hide();
scroll_container->add_child(list); scroll_container->add_child(list);
grid = memnew(HFlowContainer); grid = memnew(HFlowContainer);
grid->set_h_size_flags(Control::SIZE_EXPAND_FILL); grid->set_h_size_flags(Control::SIZE_EXPAND_FILL);
grid->set_v_size_flags(Control::SIZE_EXPAND_FILL); grid->set_v_size_flags(Control::SIZE_EXPAND_FILL);
grid->add_theme_constant_override("v_separation", 18); grid->add_theme_constant_override(SNAME("v_separation"), 0);
grid->add_theme_constant_override("h_separation", 4); grid->add_theme_constant_override(SNAME("h_separation"), 0);
grid->hide(); grid->hide();
scroll_container->add_child(grid); scroll_container->add_child(grid);
@@ -899,7 +900,7 @@ void QuickOpenResultItem::_notification(int p_what) {
} break; } break;
case NOTIFICATION_THEME_CHANGED: { case NOTIFICATION_THEME_CHANGED: {
selected_stylebox = get_theme_stylebox("selected", "Tree"); selected_stylebox = get_theme_stylebox("selected", "Tree");
hovering_stylebox = get_theme_stylebox(SceneStringName(hover), "Tree"); hovering_stylebox = get_theme_stylebox(SNAME("hovered"), "Tree");
highlighted_font_color = get_theme_color("font_focus_color", EditorStringName(Editor)); highlighted_font_color = get_theme_color("font_focus_color", EditorStringName(Editor));
} break; } break;
case NOTIFICATION_DRAW: { case NOTIFICATION_DRAW: {
@@ -932,43 +933,40 @@ static Vector2i _get_name_interval(const Vector2i &p_interval, int p_dir_index)
QuickOpenResultListItem::QuickOpenResultListItem() { QuickOpenResultListItem::QuickOpenResultListItem() {
set_h_size_flags(Control::SIZE_EXPAND_FILL); set_h_size_flags(Control::SIZE_EXPAND_FILL);
add_theme_constant_override("separation", 4 * EDSCALE); add_theme_constant_override("margin_left", 6 * EDSCALE);
add_theme_constant_override("margin_right", 6 * EDSCALE);
{ hbc = memnew(HBoxContainer);
image_container = memnew(MarginContainer); hbc->add_theme_constant_override(SNAME("separation"), 4 * EDSCALE);
image_container->add_theme_constant_override("margin_top", 2 * EDSCALE); add_child(hbc);
image_container->add_theme_constant_override("margin_bottom", 2 * EDSCALE);
image_container->add_theme_constant_override("margin_left", CONTAINER_MARGIN * EDSCALE);
image_container->add_theme_constant_override("margin_right", 0);
add_child(image_container);
thumbnail = memnew(TextureRect); const int max_size = 36 * EDSCALE;
thumbnail->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
thumbnail->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
thumbnail->set_expand_mode(TextureRect::EXPAND_IGNORE_SIZE);
thumbnail->set_stretch_mode(TextureRect::StretchMode::STRETCH_SCALE);
image_container->add_child(thumbnail);
}
{ thumbnail = memnew(TextureRect);
text_container = memnew(VBoxContainer); thumbnail->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
text_container->add_theme_constant_override("separation", -6 * EDSCALE); thumbnail->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
text_container->set_h_size_flags(Control::SIZE_EXPAND_FILL); thumbnail->set_expand_mode(TextureRect::EXPAND_IGNORE_SIZE);
text_container->set_v_size_flags(Control::SIZE_FILL); thumbnail->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED);
add_child(text_container); thumbnail->set_custom_minimum_size(Size2i(max_size, max_size));
hbc->add_child(thumbnail);
name = memnew(HighlightedLabel); text_container = memnew(VBoxContainer);
name->set_h_size_flags(Control::SIZE_EXPAND_FILL); text_container->add_theme_constant_override(SNAME("separation"), -7 * EDSCALE);
name->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS); text_container->set_h_size_flags(Control::SIZE_EXPAND_FILL);
name->set_horizontal_alignment(HorizontalAlignment::HORIZONTAL_ALIGNMENT_LEFT); text_container->set_v_size_flags(Control::SIZE_FILL);
text_container->add_child(name); hbc->add_child(text_container);
path = memnew(HighlightedLabel); name = memnew(HighlightedLabel);
path->set_h_size_flags(Control::SIZE_EXPAND_FILL); name->set_h_size_flags(Control::SIZE_EXPAND_FILL);
path->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS); name->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
path->add_theme_font_size_override(SceneStringName(font_size), 12 * EDSCALE); name->set_horizontal_alignment(HorizontalAlignment::HORIZONTAL_ALIGNMENT_LEFT);
text_container->add_child(path); text_container->add_child(name);
}
path = memnew(HighlightedLabel);
path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
path->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
path->add_theme_font_size_override(SceneStringName(font_size), 12 * EDSCALE);
text_container->add_child(path);
} }
void QuickOpenResultListItem::set_content(const QuickOpenResultCandidate &p_candidate, bool p_highlight) { void QuickOpenResultListItem::set_content(const QuickOpenResultCandidate &p_candidate, bool p_highlight) {
@@ -986,21 +984,6 @@ void QuickOpenResultListItem::set_content(const QuickOpenResultCandidate &p_cand
} }
} }
} }
const int max_size = 32 * EDSCALE;
bool uses_icon = p_candidate.thumbnail->get_width() < max_size;
if (uses_icon) {
thumbnail->set_custom_minimum_size(p_candidate.thumbnail->get_size());
int margin_needed = (max_size - p_candidate.thumbnail->get_width()) / 2;
image_container->add_theme_constant_override("margin_left", CONTAINER_MARGIN + margin_needed);
image_container->add_theme_constant_override("margin_right", margin_needed);
} else {
thumbnail->set_custom_minimum_size(Size2i(max_size, max_size));
image_container->add_theme_constant_override("margin_left", CONTAINER_MARGIN);
image_container->add_theme_constant_override("margin_right", 0);
}
} }
void QuickOpenResultListItem::reset() { void QuickOpenResultListItem::reset() {
@@ -1030,22 +1013,31 @@ void QuickOpenResultListItem::_notification(int p_what) {
//--------------- Grid Item //--------------- Grid Item
QuickOpenResultGridItem::QuickOpenResultGridItem() { QuickOpenResultGridItem::QuickOpenResultGridItem() {
set_h_size_flags(Control::SIZE_FILL); set_custom_minimum_size(Size2i(120 * EDSCALE, 0));
set_v_size_flags(Control::SIZE_EXPAND_FILL); add_theme_constant_override("margin_top", 6 * EDSCALE);
add_theme_constant_override("separation", -2 * EDSCALE); add_theme_constant_override("margin_left", 2 * EDSCALE);
add_theme_constant_override("margin_right", 2 * EDSCALE);
vbc = memnew(VBoxContainer);
vbc->set_h_size_flags(Control::SIZE_FILL);
vbc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
vbc->add_theme_constant_override(SNAME("separation"), 0);
add_child(vbc);
const int max_size = 64 * EDSCALE;
thumbnail = memnew(TextureRect); thumbnail = memnew(TextureRect);
thumbnail->set_h_size_flags(Control::SIZE_SHRINK_CENTER); thumbnail->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
thumbnail->set_v_size_flags(Control::SIZE_SHRINK_CENTER); thumbnail->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
thumbnail->set_custom_minimum_size(Size2i(120 * EDSCALE, 64 * EDSCALE)); thumbnail->set_custom_minimum_size(Size2i(max_size, max_size));
add_child(thumbnail); vbc->add_child(thumbnail);
name = memnew(HighlightedLabel); name = memnew(HighlightedLabel);
name->set_h_size_flags(Control::SIZE_EXPAND_FILL); name->set_h_size_flags(Control::SIZE_EXPAND_FILL);
name->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS); name->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
name->set_horizontal_alignment(HorizontalAlignment::HORIZONTAL_ALIGNMENT_CENTER); name->set_horizontal_alignment(HorizontalAlignment::HORIZONTAL_ALIGNMENT_CENTER);
name->add_theme_font_size_override(SceneStringName(font_size), 13 * EDSCALE); name->add_theme_font_size_override(SceneStringName(font_size), 13 * EDSCALE);
add_child(name); vbc->add_child(name);
} }
void QuickOpenResultGridItem::set_content(const QuickOpenResultCandidate &p_candidate, bool p_highlight) { void QuickOpenResultGridItem::set_content(const QuickOpenResultCandidate &p_candidate, bool p_highlight) {

View File

@@ -33,6 +33,7 @@
#include "core/templates/oa_hash_map.h" #include "core/templates/oa_hash_map.h"
#include "scene/gui/dialogs.h" #include "scene/gui/dialogs.h"
#include "scene/gui/margin_container.h"
class Button; class Button;
class CenterContainer; class CenterContainer;
@@ -176,8 +177,8 @@ private:
static void _bind_methods(); static void _bind_methods();
}; };
class QuickOpenResultGridItem : public VBoxContainer { class QuickOpenResultGridItem : public MarginContainer {
GDCLASS(QuickOpenResultGridItem, VBoxContainer) GDCLASS(QuickOpenResultGridItem, MarginContainer)
public: public:
QuickOpenResultGridItem(); QuickOpenResultGridItem();
@@ -188,12 +189,13 @@ public:
void remove_highlight(); void remove_highlight();
private: private:
VBoxContainer *vbc = nullptr;
TextureRect *thumbnail = nullptr; TextureRect *thumbnail = nullptr;
HighlightedLabel *name = nullptr; HighlightedLabel *name = nullptr;
}; };
class QuickOpenResultListItem : public HBoxContainer { class QuickOpenResultListItem : public MarginContainer {
GDCLASS(QuickOpenResultListItem, HBoxContainer) GDCLASS(QuickOpenResultListItem, MarginContainer)
public: public:
QuickOpenResultListItem(); QuickOpenResultListItem();
@@ -207,9 +209,7 @@ protected:
void _notification(int p_what); void _notification(int p_what);
private: private:
static const int CONTAINER_MARGIN = 8; HBoxContainer *hbc = nullptr;
MarginContainer *image_container = nullptr;
VBoxContainer *text_container = nullptr; VBoxContainer *text_container = nullptr;
TextureRect *thumbnail = nullptr; TextureRect *thumbnail = nullptr;