diff --git a/doc/classes/FlowContainer.xml b/doc/classes/FlowContainer.xml index 14e84b40e63..e70e76f1918 100644 --- a/doc/classes/FlowContainer.xml +++ b/doc/classes/FlowContainer.xml @@ -21,6 +21,10 @@ The alignment of the container's children (must be one of [constant ALIGNMENT_BEGIN], [constant ALIGNMENT_CENTER], or [constant ALIGNMENT_END]). + + If [code]true[/code], reverses fill direction. Horizontal [FlowContainer]s will fill rows bottom to top, vertical [FlowContainer]s will fill columns right to left. + When using a vertical [FlowContainer] with a right to left [member Control.layout_direction], columns will fill left to right instead. + If [code]true[/code], the [FlowContainer] will arrange its children vertically, rather than horizontally. Can't be changed when using [HFlowContainer] and [VFlowContainer]. diff --git a/scene/gui/flow_container.cpp b/scene/gui/flow_container.cpp index 5b5f8e5f2df..9f79da2905b 100644 --- a/scene/gui/flow_container.cpp +++ b/scene/gui/flow_container.cpp @@ -198,7 +198,10 @@ void FlowContainer::_resort() { } Rect2 child_rect = Rect2(ofs, child_size); - if (rtl) { + if (reverse_fill && !vertical) { + child_rect.position.y = get_rect().size.y - child_rect.position.y - child_rect.size.height; + } + if ((rtl && !vertical) || ((rtl != reverse_fill) && vertical)) { child_rect.position.x = get_rect().size.x - child_rect.position.x - child_rect.size.width; } @@ -322,6 +325,18 @@ bool FlowContainer::is_vertical() const { return vertical; } +void FlowContainer::set_reverse_fill(bool p_reverse_fill) { + if (reverse_fill == p_reverse_fill) { + return; + } + reverse_fill = p_reverse_fill; + _resort(); +} + +bool FlowContainer::is_reverse_fill() const { + return reverse_fill; +} + FlowContainer::FlowContainer(bool p_vertical) { vertical = p_vertical; } @@ -333,6 +348,8 @@ void FlowContainer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_alignment"), &FlowContainer::get_alignment); ClassDB::bind_method(D_METHOD("set_vertical", "vertical"), &FlowContainer::set_vertical); ClassDB::bind_method(D_METHOD("is_vertical"), &FlowContainer::is_vertical); + ClassDB::bind_method(D_METHOD("set_reverse_fill", "reverse_fill"), &FlowContainer::set_reverse_fill); + ClassDB::bind_method(D_METHOD("is_reverse_fill"), &FlowContainer::is_reverse_fill); BIND_ENUM_CONSTANT(ALIGNMENT_BEGIN); BIND_ENUM_CONSTANT(ALIGNMENT_CENTER); @@ -340,6 +357,7 @@ void FlowContainer::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "alignment", PROPERTY_HINT_ENUM, "Begin,Center,End"), "set_alignment", "get_alignment"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "vertical"), "set_vertical", "is_vertical"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "reverse_fill"), "set_reverse_fill", "is_reverse_fill"); BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, FlowContainer, h_separation); BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, FlowContainer, v_separation); diff --git a/scene/gui/flow_container.h b/scene/gui/flow_container.h index 1c06c828150..90da73aaab8 100644 --- a/scene/gui/flow_container.h +++ b/scene/gui/flow_container.h @@ -48,6 +48,7 @@ private: int cached_line_count = 0; bool vertical = false; + bool reverse_fill = false; AlignmentMode alignment = ALIGNMENT_BEGIN; struct ThemeCache { @@ -73,6 +74,9 @@ public: void set_vertical(bool p_vertical); bool is_vertical() const; + void set_reverse_fill(bool p_reverse_fill); + bool is_reverse_fill() const; + virtual Size2 get_minimum_size() const override; virtual Vector get_allowed_size_flags_horizontal() const override;