summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-07-06 13:26:39 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-07-06 13:30:24 -0300
commitfd9b4ba6e6ce42080c728a11031a12f90cfbfb1d (patch)
tree553b13f16487b703be99657209f8b9e266a5624c /scene/gui
parent2d95c510fc57f5b6d6cbacc73994b701e651873b (diff)
-Ability for controls to grow the left/top when anchored. This makes anchoring controls to the right/bottom easier when they are resized.
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/control.cpp56
-rw-r--r--scene/gui/control.h14
2 files changed, 68 insertions, 2 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 45485b768e..51461e9c41 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -1219,10 +1219,26 @@ void Control::_size_changed() {
Point2 new_pos_cache = Point2(margin_pos[0], margin_pos[1]).floor();
Size2 new_size_cache = Point2(margin_pos[2], margin_pos[3]).floor() - new_pos_cache;
+
Size2 minimum_size = get_combined_minimum_size();
- new_size_cache.x = MAX(minimum_size.x, new_size_cache.x);
- new_size_cache.y = MAX(minimum_size.y, new_size_cache.y);
+ if (data.h_grow == GROW_DIRECTION_BEGIN) {
+ if (minimum_size.width > new_size_cache.width) {
+ new_pos_cache.x = new_pos_cache.x + new_size_cache.width - minimum_size.width;
+ new_size_cache.width = minimum_size.width;
+ }
+ } else {
+ new_size_cache.width = MAX(minimum_size.width, new_size_cache.width);
+ }
+
+ if (data.v_grow == GROW_DIRECTION_BEGIN) {
+ if (minimum_size.height > new_size_cache.height) {
+ new_pos_cache.y = new_pos_cache.y + new_size_cache.height - minimum_size.height;
+ new_size_cache.height = minimum_size.height;
+ }
+ } else {
+ new_size_cache.height = MAX(minimum_size.height, new_size_cache.height);
+ }
bool pos_changed = new_pos_cache != data.pos_cache;
bool size_changed = new_size_cache != data.size_cache;
@@ -2300,6 +2316,27 @@ bool Control::is_clipping_contents() {
return data.clip_contents;
}
+void Control::set_h_grow_direction(GrowDirection p_direction) {
+
+ data.h_grow = p_direction;
+ _size_changed();
+}
+
+Control::GrowDirection Control::get_h_grow_direction() const {
+
+ return data.h_grow;
+}
+
+void Control::set_v_grow_direction(GrowDirection p_direction) {
+
+ data.v_grow = p_direction;
+ _size_changed();
+}
+Control::GrowDirection Control::get_v_grow_direction() const {
+
+ return data.v_grow;
+}
+
void Control::_bind_methods() {
//ClassDB::bind_method(D_METHOD("_window_resize_event"),&Control::_window_resize_event);
@@ -2388,6 +2425,12 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_parent_control:Control"), &Control::get_parent_control);
+ ClassDB::bind_method(D_METHOD("set_h_grow_direction", "direction"), &Control::set_h_grow_direction);
+ ClassDB::bind_method(D_METHOD("get_h_grow_direction"), &Control::get_h_grow_direction);
+
+ ClassDB::bind_method(D_METHOD("set_v_grow_direction", "direction"), &Control::set_v_grow_direction);
+ ClassDB::bind_method(D_METHOD("get_v_grow_direction"), &Control::get_v_grow_direction);
+
ClassDB::bind_method(D_METHOD("set_tooltip", "tooltip"), &Control::set_tooltip);
ClassDB::bind_method(D_METHOD("get_tooltip", "atpos"), &Control::get_tooltip, DEFVAL(Point2()));
ClassDB::bind_method(D_METHOD("_get_tooltip"), &Control::_get_tooltip);
@@ -2438,6 +2481,10 @@ void Control::_bind_methods() {
ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "margin_right", PROPERTY_HINT_RANGE, "-4096,4096"), "set_margin", "get_margin", MARGIN_RIGHT);
ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "margin_bottom", PROPERTY_HINT_RANGE, "-4096,4096"), "set_margin", "get_margin", MARGIN_BOTTOM);
+ ADD_GROUP("Grow Direction", "grow_");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "grow_horizontal", PROPERTY_HINT_ENUM, "Begin,End"), "set_h_grow_direction", "get_h_grow_direction");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "grow_vertical", PROPERTY_HINT_ENUM, "Begin,End"), "set_v_grow_direction", "get_v_grow_direction");
+
ADD_GROUP("Rect", "rect_");
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_position", "get_position");
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_size", "get_size");
@@ -2507,6 +2554,9 @@ void Control::_bind_methods() {
BIND_CONSTANT(MOUSE_FILTER_PASS);
BIND_CONSTANT(MOUSE_FILTER_IGNORE);
+ BIND_CONSTANT(GROW_DIRECTION_BEGIN);
+ BIND_CONSTANT(GROW_DIRECTION_END);
+
ADD_SIGNAL(MethodInfo("resized"));
ADD_SIGNAL(MethodInfo("gui_input", PropertyInfo(Variant::OBJECT, "ev", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
ADD_SIGNAL(MethodInfo("mouse_entered"));
@@ -2543,6 +2593,8 @@ Control::Control() {
data.modal_frame = 0;
data.block_minimum_size_adjust = false;
data.disable_visibility_clip = false;
+ data.h_grow = GROW_DIRECTION_END;
+ data.v_grow = GROW_DIRECTION_END;
data.clip_contents = false;
for (int i = 0; i < 4; i++) {
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 5834d1550a..f55010a354 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -57,6 +57,11 @@ public:
ANCHOR_CENTER,
};
+ enum GrowDirection {
+ GROW_DIRECTION_BEGIN,
+ GROW_DIRECTION_END
+ };
+
enum FocusMode {
FOCUS_NONE,
FOCUS_CLICK,
@@ -117,6 +122,8 @@ private:
float margin[4];
AnchorType anchor[4];
FocusMode focus_mode;
+ GrowDirection h_grow;
+ GrowDirection v_grow;
float rotation;
Vector2 scale;
@@ -273,6 +280,12 @@ public:
void set_begin(const Point2 &p_point); // helper
void set_end(const Point2 &p_point); // helper
+ void set_h_grow_direction(GrowDirection p_direction);
+ GrowDirection get_h_grow_direction() const;
+
+ void set_v_grow_direction(GrowDirection p_direction);
+ GrowDirection get_v_grow_direction() const;
+
float get_margin(Margin p_margin) const;
Point2 get_begin() const;
Point2 get_end() const;
@@ -409,5 +422,6 @@ VARIANT_ENUM_CAST(Control::FocusMode);
VARIANT_ENUM_CAST(Control::SizeFlags);
VARIANT_ENUM_CAST(Control::CursorShape);
VARIANT_ENUM_CAST(Control::MouseFilter);
+VARIANT_ENUM_CAST(Control::GrowDirection);
#endif