From 6caadd57a9693cd9f39ac24781c49e23ea02b2e1 Mon Sep 17 00:00:00 2001 From: WhalesState Date: Fri, 17 Jan 2025 18:12:36 +0200 Subject: [PATCH] `ColorPicker` remove unused children and fix sample bugs. Remove an unused `VBoxContainer`. Remove 3 unused children from grid (Label, Slider, SpinBox). Ignore sample input when old color is not displayed. Fix current color overbright position. --- scene/gui/color_picker.cpp | 17 +++++++---------- scene/gui/color_picker.h | 4 ++-- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 349c4b22ee..6eb65a008c 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -1258,6 +1258,10 @@ void ColorPicker::_update_text_value() { } void ColorPicker::_sample_input(const Ref &p_event) { + if (!display_old_color) { + return; + } + const Ref mb = p_event; if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) { const Rect2 rect_old = Rect2(Point2(), Size2(sample->get_size().width * 0.5, sample->get_size().height * 0.95)); @@ -1310,7 +1314,7 @@ void ColorPicker::_sample_draw() { if (color.r > 1 || color.g > 1 || color.b > 1) { // Draw an indicator to denote that the new color is "overbright" and can't be displayed accurately in the preview. - sample->draw_texture(theme_cache.overbright_indicator, Point2(uv_edit->get_size().width * 0.5, 0)); + sample->draw_texture(theme_cache.overbright_indicator, Point2(display_old_color ? sample->get_size().width * 0.5 : 0, 0)); } } @@ -2269,17 +2273,10 @@ ColorPicker::ColorPicker() { mode_popup->set_item_checked(current_mode, true); mode_popup->set_item_checked(MODE_MAX + 1, true); mode_popup->connect(SceneStringName(id_pressed), callable_mp(this, &ColorPicker::_set_mode_popup_value)); - VBoxContainer *vbl = memnew(VBoxContainer); - real_vbox->add_child(vbl); - - VBoxContainer *vbr = memnew(VBoxContainer); - - real_vbox->add_child(vbr); - vbr->set_h_size_flags(SIZE_EXPAND_FILL); slider_gc = memnew(GridContainer); - vbr->add_child(slider_gc); + real_vbox->add_child(slider_gc); slider_gc->set_h_size_flags(SIZE_EXPAND_FILL); slider_gc->set_columns(3); @@ -2291,7 +2288,7 @@ ColorPicker::ColorPicker() { hex_hbc = memnew(HBoxContainer); hex_hbc->set_alignment(ALIGNMENT_BEGIN); - vbr->add_child(hex_hbc); + real_vbox->add_child(hex_hbc); hex_hbc->add_child(memnew(Label(ETR("Hex")))); diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index fc3df061c7..7a689cc773 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -38,6 +38,7 @@ class AspectRatioContainer; class ColorMode; class ColorPickerShape; +class FileDialog; class GridContainer; class HSlider; class Label; @@ -49,7 +50,6 @@ class PopupMenu; class SpinBox; class StyleBoxFlat; class TextureRect; -class FileDialog; class ColorPresetButton : public BaseButton { GDCLASS(ColorPresetButton, BaseButton); @@ -104,7 +104,7 @@ public: SHAPE_MAX }; - static const int SLIDER_COUNT = 4; + static const int SLIDER_COUNT = 3; private: enum class MenuOption {