Skip to content

Commit

Permalink
Update controls after project settings changed.
Browse files Browse the repository at this point in the history
In `canvas_item_editor_plugin`: Call `update_viewport()` in
`_project_setting_changed` to redraw viewport after project
settings changed.

In `control`: Add a new private function `_project_setting_changed`
to update the size and redraw the control. Connect/Disconnet this
function to "settings_changed" of `ProjectSettings` when the control
enters/exits the canvas.
  • Loading branch information
EAinsley committed Jun 29, 2024
1 parent 811ce36 commit 17d2acd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3967,6 +3967,7 @@ void CanvasItemEditor::_update_editor_settings() {

void CanvasItemEditor::_project_settings_changed() {
EditorNode::get_singleton()->get_scene_root()->set_snap_controls_to_pixels(GLOBAL_GET("gui/common/snap_controls_to_pixels"));
update_viewport();
}

void CanvasItemEditor::_notification(int p_what) {
Expand Down
15 changes: 15 additions & 0 deletions scene/gui/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,11 @@ void Control::_size_changed() {
}
}

void Control::_project_settings_changed() {
update_minimum_size();
_size_changed();
}

void Control::_clear_size_warning() {
data.size_warning = false;
}
Expand Down Expand Up @@ -3259,6 +3264,10 @@ void Control::_notification(int p_notification) {
data.RI = viewport->_gui_add_root_control(this);

get_parent()->connect(SNAME("child_order_changed"), callable_mp(get_viewport(), &Viewport::gui_set_root_order_dirty), CONNECT_REFERENCE_COUNTED);

if (Engine::get_singleton()->is_editor_hint()) {
ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &Control::_project_settings_changed));
}
}

data.parent_canvas_item = get_parent_item();
Expand Down Expand Up @@ -3290,6 +3299,12 @@ void Control::_notification(int p_notification) {
get_parent()->disconnect(SNAME("child_order_changed"), callable_mp(get_viewport(), &Viewport::gui_set_root_order_dirty));
}

if (Engine::get_singleton()->is_editor_hint()) {
if (!Object::cast_to<Control>(get_parent())) {
ProjectSettings::get_singleton()->disconnect("settings_changed", callable_mp(this, &Control::_project_settings_changed));
}
}

data.parent_canvas_item = nullptr;
data.is_rtl_dirty = true;
} break;
Expand Down
1 change: 1 addition & 0 deletions scene/gui/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ class Control : public CanvasItem {
void _update_minimum_size_cache();
void _update_minimum_size();
void _size_changed();
void _project_settings_changed();

void _top_level_changed() override {} // Controls don't need to do anything, only other CanvasItems.
void _top_level_changed_on_parent() override;
Expand Down

0 comments on commit 17d2acd

Please sign in to comment.