Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to reverse FlowContainer fill direction (HFlow bottom-to-top, VFlow right-to-left) #74195

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/classes/FlowContainer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<member name="alignment" type="int" setter="set_alignment" getter="get_alignment" enum="FlowContainer.AlignmentMode" default="0">
The alignment of the container's children (must be one of [constant ALIGNMENT_BEGIN], [constant ALIGNMENT_CENTER], or [constant ALIGNMENT_END]).
</member>
<member name="reverse_fill" type="bool" setter="set_reverse_fill" getter="is_reverse_fill" default="false">
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.
</member>
<member name="vertical" type="bool" setter="set_vertical" getter="is_vertical" default="false">
If [code]true[/code], the [FlowContainer] will arrange its children vertically, rather than horizontally.
Can't be changed when using [HFlowContainer] and [VFlowContainer].
Expand Down
20 changes: 19 additions & 1 deletion scene/gui/flow_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
TheSecondReal0 marked this conversation as resolved.
Show resolved Hide resolved
_resort();
}

bool FlowContainer::is_reverse_fill() const {
return reverse_fill;
}

FlowContainer::FlowContainer(bool p_vertical) {
vertical = p_vertical;
}
Expand All @@ -333,13 +348,16 @@ 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);
BIND_ENUM_CONSTANT(ALIGNMENT_END);

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);
Expand Down
4 changes: 4 additions & 0 deletions scene/gui/flow_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class FlowContainer : public Container {
int cached_line_count = 0;

bool vertical = false;
bool reverse_fill = false;
AlignmentMode alignment = ALIGNMENT_BEGIN;

struct ThemeCache {
Expand All @@ -73,6 +74,9 @@ class FlowContainer : public Container {
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<int> get_allowed_size_flags_horizontal() const override;
Expand Down
Loading