summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorGilles Roudière <gilles.roudiere@gmail.com>2021-09-06 13:40:56 +0200
committerGitHub <noreply@github.com>2021-09-06 13:40:56 +0200
commitd9b07faad2da7845b3a48115ac479900ab049f41 (patch)
treee2c468fa539a285f90d7208d15d09982508b8942 /scene/gui
parente5c6c773e99e3f9aae4ac8a804f392416c871285 (diff)
parent3aa2a7fc180fc3f0cc4d9624b4ae6824f88f4222 (diff)
Merge pull request #30623 from Awkor/disable-container-child-editing
Prevent editing properties managed by parent container
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/control.cpp29
-rw-r--r--scene/gui/control.h3
2 files changed, 32 insertions, 0 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 4ac6a58d36..81411d5844 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -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"
@@ -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();
@@ -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 {
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 0faa617f8d..9cec5d6e8d 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -230,6 +230,9 @@ private:
} 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);