-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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 FlowContainer #56104
Add FlowContainer #56104
Conversation
For the record, this is being discussed in godotengine/godot-proposals#3558. |
ef7ab31
to
e788083
Compare
e788083
to
3ec02c0
Compare
This would be really useful for a project I'm working on. The project is an android launcher, I could use this to order apps like a word cloud. I've wanted to do this for a while but didn't because of how difficult it would be with the current control nodes, this would be great for that. Just my 2 cents. |
This would massively simplify one of my extant projects (a graphical roguelike). Think Diablo 3/NWN 1/Baldur's Gate inventory, with a grid of slots... |
A FlowContainer is definitely something we have been wanting for a long time. However, I think the current implementation won't be very usable in practice. While it works as an independent node as you display in your video, I am pretty sure that, as soon as your container will be put in another container, it will break. Mainly because it won't be able to compute a correct minimum size. Supporting floating layouts is a more complex task than it seems, as they require computing a minimum width that depends on a given height (or the other way around, if you adjust the width the minimum height can change). This is something that is not yet supported at all by Godot's layout system. It should be done someday but it's a significant amount of work. |
3ec02c0
to
f74fb52
Compare
Removed an overlooked print_line debug loop. |
Although it shouldn't block the PR from being merged, I think we should drop the H/V variants and just have |
That's not really the reason for their existence. It does make the tree much clearer without the need to go into each node's properties. I think that consistency here is for the better, until we decide to drop H/V prefixes everywhere (there was a proposal to do so, maybe even a PR). |
Toggling visibility of a child in FlowContainer results in a crash:
If a child is invisible, it won't be added to |
The size flags could be handled better. This is HFlowContainer: For the OK button, Horizontal Fill should actually stretch it to all available space instead of using only minsize. Shrink Center and Shrink End could change the horizontal alignment. And actually, if they affected vertical alignment too, the To better illustrate what I have in mind: Vertical Shrink Center (same as CENTER line alignment) Vertical Shrink End (same as BOTTOM line alignment) The Expand flag would be unused. You can't really push controls in a FlowContainer, no? Looking at the code, it shouldn't be difficult to implement. Although @pycbouh knows more about flags, so he could comment whether what I propose makes sense. |
416be9e
to
cd551e8
Compare
Wouldn't it be useful to enable this behavior explicitly with expand so that you can do this with not just the last child in a row/column, but also with intermediate ones? In the same row you have "OK" other children could be positioned in the same way, in theory, but without an explicit expand we wouldn't be able to tell them to take the remaining space from the row. Unless shrink center and shrink end do that implicitly, but then you still might want to use stretch ratios and do something fancy there with multiple items, no? And in that case, even shrink begin (no flags) would want to be able to "expand" to reclaim a piece of that space. |
cd551e8
to
bb116aa
Compare
I tested the flags and they seem fine, except the "perpendicular" size shouldn't need expand. E.g. in HBoxContainer, if your control has Fill enabled, it takes whole height. But in HFlowContainer you need to enable Expand. It shouldn't be like that, as it's inconsistent. Verticall Fill in HFlowContainer should make the control take all available height without Expand. The "parallel" behavior (i.e. horizontal flags in HFlowContainer) is correct. |
bb116aa
to
5fe5e8d
Compare
@KoBeWi Changed it accordingly. |
5fe5e8d
to
f567804
Compare
Fixed, now it should finally work as expected :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested different layouts. Size flags, stretch ratio, expanding etc. all work as expected.
@groud HFlowContainer is like a Label with autowrap enabled, but lays controls instead of text. It uses all available width and if it doesn't have enough, it will grow its minimum size. VFlowContainer is analogous, but vertically. The container system is robust enough to support this without problems. So unless you can find a (non-corner) case where this really breaks, the PR is good to go.
f567804
to
40ee2b8
Compare
@Geometror will any of these containers enable one to layout things from the end (bottom-right) to overcome this hack: https://twitter.com/pawel_lampe/status/1373370799319617537 ? |
You can do it with the existing |
yeah, but I don't know how many columns I need beforehand. Thus |
FlowContainer from this PR also supports layout direction, but there's no bottom-to-top option. |
Thanks! |
We discussed in length this PR on Rocket.Chat yesterday, as I wanted to figure out why this FlowContainer seems to work correctly, while, theoretically, it should not. I'll express my doubts here so that they are documented, in case we face issues later on. To compute its children position and size, a Container relies on its children size flags and their minimum size returned by
where In this All of this to explain that, to compute the minimum size of a FlowContainer (returned by For example, something like this:
would cause MyControl to grow to infinity as soon as it is put into a Container. Thus relying on the actual size to compute a minimum size is quite a bad thing in general. In the case of this PR, I don't know why such behavior does not happen, and why the size stays stable. I suppose it might come from the fact that only one component (out of x and y) is impacted, causing the values to stabilize. Or something else, I don't know. Also, as a side note, we also have a similar behavior with the Label node with the "auto wrap" mode, and it works there too. I don't know if we are going to have problems there too, but we should likely keep an eye on issues that could arise. |
This PR adds a H/VFlowContainer node, which arranges and wraps control nodes like line of text. This container type can be very useful for menu bands, palettes, etc., so it has some internal use cases (e.g. the color picker presets for which I had to use a GridContainer which had some problems with resizing requiring a rather hacky solution).
Implements godotengine/godot-proposals#2893
Might provide a solution/alternative in some cases to godotengine/godot-proposals#2907
Features:
Demonstration:
EDIT: New improved version:
Note: This PR adds a separate HFlowContainer and VFlowContainer node for consistency. Whether to merge these container variants is another topic and requires additional discussion.