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

Prevent editing properties managed by parent container #30623

Merged
merged 1 commit into from
Sep 6, 2021
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
29 changes: 29 additions & 0 deletions scene/gui/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "control.h"

#include "container.h"
#include "core/config/project_settings.h"
#include "core/math/geometry_2d.h"
#include "core/object/message_queue.h"
Expand Down Expand Up @@ -168,6 +169,20 @@ Size2 Control::_edit_get_minimum_size() const {
}
#endif

String Control::properties_managed_by_container[] = {
"offset_left",
"offset_top",
"offset_right",
"offset_bottom",
"anchor_left",
"anchor_top",
"anchor_right",
"anchor_bottom",
"rect_position",
"rect_scale",
"rect_size"
};

void Control::accept_event() {
if (is_inside_tree()) {
get_viewport()->_gui_accept_event();
Expand Down Expand Up @@ -442,6 +457,20 @@ void Control::_validate_property(PropertyInfo &property) const {

property.hint_string = hint_string;
}
if (!Object::cast_to<Container>(get_parent())) {
return;
}
// Disable the property if it's managed by the parent container.
bool property_is_managed_by_container = false;
for (unsigned i = 0; i < properties_managed_by_container_count; i++) {
property_is_managed_by_container = properties_managed_by_container[i] == property.name;
if (property_is_managed_by_container) {
break;
}
}
if (property_is_managed_by_container) {
property.usage |= PROPERTY_USAGE_READ_ONLY;
}
}

Control *Control::get_parent_control() const {
Expand Down
3 changes: 3 additions & 0 deletions scene/gui/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ class Control : public CanvasItem {

} data;

static constexpr unsigned properties_managed_by_container_count = 11;
static String properties_managed_by_container[properties_managed_by_container_count];

// used internally
Control *_find_control_at_pos(CanvasItem *p_node, const Point2 &p_pos, const Transform2D &p_xform, Transform2D &r_inv_xform);

Expand Down