Skip to content

Commit

Permalink
More fill modes for containers, closes #9504
Browse files Browse the repository at this point in the history
  • Loading branch information
reduz committed Jul 6, 2017
1 parent bd9d98c commit 7c679dd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
18 changes: 15 additions & 3 deletions scene/gui/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,25 @@ void Container::fit_child_in_rect(Control *p_child, const Rect2 &p_rect) {
Rect2 r = p_rect;

if (!(p_child->get_h_size_flags() & SIZE_FILL)) {
r.size.x = minsize.x;
r.position.x += Math::floor((p_rect.size.x - minsize.x) / 2);
r.size.x = minsize.width;
if (p_child->get_h_size_flags() & SIZE_SHRINK_END) {
r.position.x += p_rect.size.width - minsize.width;
} else if (p_child->get_h_size_flags() & SIZE_SHRINK_CENTER) {
r.position.x += Math::floor((p_rect.size.x - minsize.width) / 2);
} else {
r.position.x += 0;
}
}

if (!(p_child->get_v_size_flags() & SIZE_FILL)) {
r.size.y = minsize.y;
r.position.y += Math::floor((p_rect.size.y - minsize.y) / 2);
if (p_child->get_v_size_flags() & SIZE_SHRINK_END) {
r.position.y += p_rect.size.height - minsize.height;
} else if (p_child->get_v_size_flags() & SIZE_SHRINK_CENTER) {
r.position.y += Math::floor((p_rect.size.y - minsize.height) / 2);
} else {
r.position.y += 0;
}
}

for (int i = 0; i < 4; i++)
Expand Down
6 changes: 4 additions & 2 deletions scene/gui/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2534,8 +2534,8 @@ void Control::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_filter", PROPERTY_HINT_ENUM, "Stop,Pass,Ignore"), "set_mouse_filter", "get_mouse_filter");

ADD_GROUP("Size Flags", "size_flags_");
ADD_PROPERTYNO(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill,Expand"), "set_h_size_flags", "get_h_size_flags");
ADD_PROPERTYNO(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill,Expand"), "set_v_size_flags", "get_v_size_flags");
ADD_PROPERTYNO(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_h_size_flags", "get_h_size_flags");
ADD_PROPERTYNO(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_v_size_flags", "get_v_size_flags");
ADD_PROPERTYNO(PropertyInfo(Variant::INT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "1,128,0.01"), "set_stretch_ratio", "get_stretch_ratio");
ADD_GROUP("Theme", "");
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme");
Expand Down Expand Up @@ -2577,6 +2577,8 @@ void Control::_bind_methods() {
BIND_CONSTANT(SIZE_EXPAND);
BIND_CONSTANT(SIZE_FILL);
BIND_CONSTANT(SIZE_EXPAND_FILL);
BIND_CONSTANT(SIZE_SHRINK_CENTER);
BIND_CONSTANT(SIZE_SHRINK_END);

BIND_CONSTANT(MOUSE_FILTER_STOP);
BIND_CONSTANT(MOUSE_FILTER_PASS);
Expand Down
4 changes: 3 additions & 1 deletion scene/gui/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ class Control : public CanvasItem {

SIZE_FILL = 1,
SIZE_EXPAND = 2,
SIZE_EXPAND_FILL = SIZE_EXPAND | SIZE_FILL
SIZE_EXPAND_FILL = SIZE_EXPAND | SIZE_FILL,
SIZE_SHRINK_CENTER = 4, //ignored by expand or fill
SIZE_SHRINK_END = 8, //ignored by expand or fil

};

Expand Down

0 comments on commit 7c679dd

Please sign in to comment.