godot icon indicating copy to clipboard operation
godot copied to clipboard

Add FlowContainer wrap options for center alignment.

Open Koyper opened this issue 2 years ago • 20 comments

Fixes inability to wrap a partially filled, last row or column so that the last items preserve the grid pattern of the previous filled rows or columns.

Adds a last_wrap_alignment property to set a wrap alignment option that determine the wrapping behavior of the last unfilled row or column.

For example, a common desired behavior of a centered flow container of tiles, is for the last row to fill in from the left, rather than per the current default behavior of filling in centered.

The PR includes LAST_WRAP_ALIGNMENT_INHERIT, LAST_WRAP_ALIGNMENT_BEGIN, LAST_WRAP_ALIGNMENT_CENTER, and LAST_WRAP_ALIGNMENT_END options, and also works when the flow container has vertical enabled.

The default last_wrap_alignment is LAST_WRAP_ALIGNMENT_INHERIT which preserves backward compatiblity.

https://user-images.githubusercontent.com/33969780/215350978-4da3cad6-fc8f-4617-942b-a688f015d0ea.mov

Koyper avatar Jan 29 '23 17:01 Koyper

@Calinou

Can you advise on what's triggering the format complaint in the static check?

Koyper avatar Jan 29 '23 19:01 Koyper

It was an errant TAB :( - all good now...

Koyper avatar Jan 29 '23 21:01 Koyper

It was an errant TAB :( - all good now...

To avoid this in the future, I recommend configuring your editor to trim trailing whitespace by default :slightly_smiling_face:

Calinou avatar Jan 29 '23 21:01 Calinou

Found the setting! Thanks!

Koyper avatar Jan 29 '23 21:01 Koyper

Could you amend the commit message? It currently says "Doc fix." which is not an accurate description for what this PR does (see PR workflow).

akien-mga avatar Jan 30 '23 13:01 akien-mga

Commit message amended...

Koyper avatar Jan 30 '23 17:01 Koyper

Thanks for that tip, I'll use that elsewhere! Your code was perfect, just had to add the notify_property_list_changed().

Koyper avatar Jan 31 '23 22:01 Koyper

The implementation looks good. The feature has no proposal though.

I hadn't known about the proper process - is a proposal in this case required?

Koyper avatar May 22 '23 17:05 Koyper

is a proposal in this case required?

Yes: https://github.com/godotengine/godot-proposals

Calinou avatar May 23 '23 12:05 Calinou

There is a linux doc complaint that looks incorrect, because the default value is indeed 1 for the new property. Nothing changed in the docs - how should this be handled?

Koyper avatar May 23 '23 12:05 Koyper

Run --doctool and just push the result. Doc strings outside description should not be edited manually.

KoBeWi avatar May 23 '23 13:05 KoBeWi

How often do you want to align the whole grid one way, but the last row of items another way?

If you are using FlowContainer as a grid, then all the time. You would want to maintain a grid arrangement, regardless of alignment. You could think of this enhancement as adding a center-aligned grid container with auto-flow.

A common example is browsing a collection of image tiles or icons.

I think that it's a rare instance where you would ever want to break the grid and have the last row or column mis-aligned with the prior row or column. If there wasn't a backward-compatibility issue, I would opt to have the center align option default to filling in from the left per this enhancement.

Koyper avatar May 27 '23 17:05 Koyper

Why is it limited to the central alignment only? IMO it makes more sense to allow it with any alignment and default to some INHERIT option that aligns the last row according to the alignment option.

This could be done, but I think it would be rare to want that behavior, per my prior comment on preserving a grid arrangement regardless of alignment choice.

Koyper avatar May 27 '23 17:05 Koyper

That said, I'm not entirely sure how useful this is as it can be implemented with an extra container.

You would have to move children in and out of an extra container or use a GridContainer to get the behavior of this enhancement. The issue is there is no script access to alignment_ofs, which a separate container or script needs to respond to to maintain the grid alignment with the prior row or column.

			switch (alignment) {
				case ALIGNMENT_CENTER: {
					if (current_line_idx != 0 && center_wrap != CENTER_WRAP_CENTER && !line_data.is_filled) {
						if (center_wrap == CENTER_WRAP_END) {
							alignment_ofs = line_data.stretch_avail - (lines_data[current_line_idx - 1].stretch_avail * 0.5);
						} else { // Is CENTER_WRAP_BEGIN
							alignment_ofs = lines_data[current_line_idx - 1].stretch_avail * 0.5;
						}
					} else {
						alignment_ofs = line_data.stretch_avail * 0.5;
					}
				} break;
				case ALIGNMENT_END: {
					alignment_ofs = line_data.stretch_avail;
				} break;
				default:
					break;
			}

Koyper avatar May 27 '23 18:05 Koyper

Please use the "Edit" button instead of multiposting.

You would have to move children in and out of an extra container

No, the way you can set it up is to have a parent container and a FlowContainer with a left-side alignment. The in the FlowContainer you would use size flags to position it within the parent container however you want. You would need to give your FlowContainer a min size, but that's already the case here.

Of course, that may not work exactly as you desire if you want FlowContainer to be resizable at runtime. Then this double-alignment system makes sense as a solution. But then I don't see why it must be limited to the center alignment only. It won't change the implementation much, it would just remove an artificial limitation from the new option.

YuriSizov avatar May 27 '23 18:05 YuriSizov

Please use the "Edit" button instead of multiposting.

Roger about multiposting...

Of course, that may not work exactly as you desire if you want FlowContainer to be resizable at runtime. Then this double-alignment system makes sense as a solution. But then I don't see why it must be limited to the center alignment only. It won't change the implementation much, it would just remove an artificial limitation from the new option.

Yes, I presume requiring resizing at runtime. I concede the point and will remove the limitation, which is sensible and simplifies the docs...

Koyper avatar May 27 '23 21:05 Koyper

Okay, this push makes the last wrap alignment work with any AlignmentMode, and defaults to LAST_WRAP_ALIGNMENT_INHERIT, which continues to preserve backward-compatibility.

I admit I was slightly skeptical of the usefulness for the other alignment modes, but after playing with it, I found it cool and I'm certain there will be many good uses for it.

Koyper avatar Jun 01 '23 19:06 Koyper

Sorry for kicking this around. Let's make sure we merge it once 4.3 dev cycle starts (I still would like to review though).

YuriSizov avatar Oct 27 '23 15:10 YuriSizov

Can this be merged now into 4.3?

Koyper avatar Apr 29 '24 13:04 Koyper

It's marked for 4.3 so it just awaiting final decision and merger

AThousandShips avatar May 01 '24 15:05 AThousandShips

Thanks!

akien-mga avatar May 07 '24 07:05 akien-mga