summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-09-27 22:15:00 +0200
committerGitHub <noreply@github.com>2017-09-27 22:15:00 +0200
commitda144fed4c49133a93b3b83cfc665352c0af351a (patch)
treee3ee2e13f9c0664e2c9fa8474fbf7ae9a1fbb5c1 /scene/gui
parent78423320d78235a5b2fde05e7816f79de729f317 (diff)
parentbd8a5fba30510558ce34f6a863567d668524f5b3 (diff)
Merge pull request #11617 from groud/fix_bad_display
Fixes bad display
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/control.cpp100
-rw-r--r--scene/gui/popup.cpp2
2 files changed, 66 insertions, 36 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index d22357ce99..91c5263bf5 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -1472,102 +1472,132 @@ void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin) {
}
void Control::set_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode, int p_margin) {
- if (!is_inside_tree())
- return;
-
- Point2 new_pos;
+ // Calculate the size if the node is not resized
Size2 min_size = get_minimum_size();
Size2 new_size = get_size();
- Size2 parent_size = get_parent_area_size();
+ if (p_resize_mode == PRESET_MODE_MINSIZE || p_resize_mode == PRESET_MODE_KEEP_HEIGHT) {
+ new_size.x = min_size.x;
+ }
+ if (p_resize_mode == PRESET_MODE_MINSIZE || p_resize_mode == PRESET_MODE_KEEP_WIDTH) {
+ new_size.y = min_size.y;
+ }
+
+ float pw = _get_parent_range(0);
+ float ph = _get_parent_range(1);
- // Width
+ //Left
switch (p_preset) {
+ case PRESET_TOP_LEFT:
+ case PRESET_BOTTOM_LEFT:
+ case PRESET_CENTER_LEFT:
case PRESET_TOP_WIDE:
case PRESET_BOTTOM_WIDE:
+ case PRESET_LEFT_WIDE:
case PRESET_HCENTER_WIDE:
case PRESET_WIDE:
- new_size.x = parent_size.x - 2 * p_margin;
+ data.margin[0] = pw * (0.0 - data.anchor[0]) + p_margin;
break;
- default:
- if (p_resize_mode == PRESET_MODE_MINSIZE || p_resize_mode == PRESET_MODE_KEEP_HEIGHT) {
- new_size.x = min_size.x;
- }
+
+ case PRESET_CENTER_TOP:
+ case PRESET_CENTER_BOTTOM:
+ case PRESET_CENTER:
+ case PRESET_VCENTER_WIDE:
+ data.margin[0] = pw * (0.5 - data.anchor[0]) - new_size.x / 2;
+ break;
+
+ case PRESET_TOP_RIGHT:
+ case PRESET_BOTTOM_RIGHT:
+ case PRESET_CENTER_RIGHT:
+ case PRESET_RIGHT_WIDE:
+ data.margin[0] = pw * (1.0 - data.anchor[0]) - new_size.x - p_margin;
break;
}
- // Height
+ // Top
switch (p_preset) {
+ case PRESET_TOP_LEFT:
+ case PRESET_TOP_RIGHT:
+ case PRESET_CENTER_TOP:
case PRESET_LEFT_WIDE:
case PRESET_RIGHT_WIDE:
+ case PRESET_TOP_WIDE:
case PRESET_VCENTER_WIDE:
case PRESET_WIDE:
- new_size.y = parent_size.y - 2 * p_margin;
+ data.margin[1] = ph * (0.0 - data.anchor[1]) + p_margin;
break;
- default:
- if (p_resize_mode == PRESET_MODE_MINSIZE || p_resize_mode == PRESET_MODE_KEEP_WIDTH) {
- new_size.y = min_size.y;
- }
+
+ case PRESET_CENTER_LEFT:
+ case PRESET_CENTER_RIGHT:
+ case PRESET_CENTER:
+ case PRESET_HCENTER_WIDE:
+ data.margin[1] = ph * (0.5 - data.anchor[1]) - new_size.y / 2;
+ break;
+
+ case PRESET_BOTTOM_LEFT:
+ case PRESET_BOTTOM_RIGHT:
+ case PRESET_CENTER_BOTTOM:
+ case PRESET_BOTTOM_WIDE:
+ data.margin[1] = ph * (1.0 - data.anchor[1]) - new_size.y - p_margin;
break;
}
- // x pos
+ // Right
switch (p_preset) {
case PRESET_TOP_LEFT:
case PRESET_BOTTOM_LEFT:
case PRESET_CENTER_LEFT:
- case PRESET_TOP_WIDE:
- case PRESET_BOTTOM_WIDE:
case PRESET_LEFT_WIDE:
- case PRESET_HCENTER_WIDE:
- case PRESET_WIDE:
- new_pos.x = p_margin;
+ data.margin[2] = pw * (0.0 - data.anchor[2]) + new_size.x + p_margin;
break;
case PRESET_CENTER_TOP:
case PRESET_CENTER_BOTTOM:
case PRESET_CENTER:
case PRESET_VCENTER_WIDE:
- new_pos.x = (parent_size.x - new_size.x) / 2.0;
+ data.margin[2] = pw * (0.5 - data.anchor[2]) + new_size.x / 2;
break;
case PRESET_TOP_RIGHT:
case PRESET_BOTTOM_RIGHT:
case PRESET_CENTER_RIGHT:
+ case PRESET_TOP_WIDE:
case PRESET_RIGHT_WIDE:
- new_pos.x = parent_size.x - new_size.x - p_margin;
+ case PRESET_BOTTOM_WIDE:
+ case PRESET_HCENTER_WIDE:
+ case PRESET_WIDE:
+ data.margin[2] = pw * (1.0 - data.anchor[2]) - p_margin;
break;
}
- // y pos
+ // Bottom
switch (p_preset) {
case PRESET_TOP_LEFT:
case PRESET_TOP_RIGHT:
case PRESET_CENTER_TOP:
- case PRESET_LEFT_WIDE:
- case PRESET_RIGHT_WIDE:
case PRESET_TOP_WIDE:
- case PRESET_VCENTER_WIDE:
- case PRESET_WIDE:
- new_pos.y = p_margin;
+ data.margin[3] = ph * (0.0 - data.anchor[3]) + new_size.y + p_margin;
break;
case PRESET_CENTER_LEFT:
case PRESET_CENTER_RIGHT:
case PRESET_CENTER:
case PRESET_HCENTER_WIDE:
- new_pos.y = (parent_size.y - new_size.y) / 2.0;
+ data.margin[3] = ph * (0.5 - data.anchor[3]) + new_size.y / 2;
break;
case PRESET_BOTTOM_LEFT:
case PRESET_BOTTOM_RIGHT:
case PRESET_CENTER_BOTTOM:
+ case PRESET_LEFT_WIDE:
+ case PRESET_RIGHT_WIDE:
case PRESET_BOTTOM_WIDE:
- new_pos.y = parent_size.y - new_size.y - p_margin;
+ case PRESET_VCENTER_WIDE:
+ case PRESET_WIDE:
+ data.margin[3] = ph * (1.0 - data.anchor[3]) - p_margin;
break;
}
- set_position(new_pos);
- set_size(new_size);
+ _size_changed();
}
void Control::set_anchors_and_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode, int p_margin) {
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index 1460fba89a..2110298950 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -265,7 +265,7 @@ void PopupPanel::set_child_rect(Control *p_child) {
ERR_FAIL_NULL(p_child);
Ref<StyleBox> p = get_stylebox("panel");
- p_child->set_anchors_and_margins_preset(Control::PRESET_WIDE);
+ p_child->set_anchors_preset(Control::PRESET_WIDE);
p_child->set_margin(MARGIN_LEFT, p->get_margin(MARGIN_LEFT));
p_child->set_margin(MARGIN_RIGHT, -p->get_margin(MARGIN_RIGHT));
p_child->set_margin(MARGIN_TOP, p->get_margin(MARGIN_TOP));