Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ColorPicker load/save swatches button interactions #101960

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 deletions scene/gui/color_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1770,13 +1770,6 @@ void ColorPicker::_pick_finished() {
}

void ColorPicker::_update_menu_items() {
if (!options_menu) {
options_menu = memnew(PopupMenu);
add_child(options_menu, false, INTERNAL_MODE_FRONT);
options_menu->force_parent_owned();
options_menu->connect("id_pressed", callable_mp(this, &ColorPicker::_options_menu_cbk));
}

options_menu->clear();
options_menu->reset_size();

Expand All @@ -1802,16 +1795,6 @@ void ColorPicker::_update_menu_items() {
}
}

void ColorPicker::_update_menu() {
_update_menu_items();
Rect2 gt = menu_btn->get_screen_rect();
menu_btn->reset_size();
int min_size = menu_btn->get_minimum_size().width;
Vector2 popup_pos = gt.get_end() - Vector2(min_size, 0);
options_menu->set_position(popup_pos);
options_menu->popup();
}

void ColorPicker::_options_menu_cbk(int p_which) {
if (!file_dialog) {
file_dialog = memnew(FileDialog);
Expand Down Expand Up @@ -2369,13 +2352,15 @@ ColorPicker::ColorPicker() {
btn_preset->connect(SceneStringName(toggled), callable_mp(this, &ColorPicker::_show_hide_preset).bind(btn_preset, preset_container));
palette_box->add_child(btn_preset);

menu_btn = memnew(Button);
menu_btn = memnew(MenuButton);
menu_btn->set_flat(true);
menu_btn->set_tooltip_text(ETR("Show all options available."));
menu_btn->set_focus_mode(FOCUS_NONE);
menu_btn->connect(SceneStringName(pressed), callable_mp(this, &ColorPicker::_update_menu));
menu_btn->connect("about_to_popup", callable_mp(this, &ColorPicker::_update_menu_items));
palette_box->add_child(menu_btn);

options_menu = menu_btn->get_popup();
options_menu->connect(SceneStringName(id_pressed), callable_mp(this, &ColorPicker::_options_menu_cbk));

palette_name = memnew(Label);
palette_name->hide();
palette_name->set_mouse_filter(MOUSE_FILTER_PASS);
Expand Down
3 changes: 1 addition & 2 deletions scene/gui/color_picker.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class ColorPicker : public VBoxContainer {
TextureRect *picker_texture_rect = nullptr;
Color picker_color;
FileDialog *file_dialog = nullptr;
Button *menu_btn = nullptr;
MenuButton *menu_btn = nullptr;
PopupMenu *options_menu = nullptr;

MarginContainer *internal_margin = nullptr;
Expand Down Expand Up @@ -305,7 +305,6 @@ class ColorPicker : public VBoxContainer {
void _target_gui_input(const Ref<InputEvent> &p_event);
void _pick_finished();
void _update_menu_items();
void _update_menu();
void _options_menu_cbk(int p_which);

// Legacy color picking.
Expand Down