Skip to content

Conversation

PoignardAzur
Copy link
Contributor

Add Stack view.
Include test screenshots.

Stack is a non-flexible container widget, for cases where a Flex is not needed.

Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this fix #607?

It's not clear to me why this is only used in a single example - do so many of our examples and other code make use of "advanced" flex features?
If so, it's not all that clear what the purpose of this type actually is.

(That isn't entirely clear to me anyway, to be honest).

Code looks good other than my comments

Comment on lines +25 to +26
/// All the children of this widget will be laid out with the same constraints,
/// then placed one after the other depending on the set alignment.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these same constraints? It's really helpful for a mental model if this is explained, even if we expect it to change later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's parent_box_constraints.loosen(), which is essentially "same maximum sized at the parent, no minimum size".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

harness.edit_root_widget(|mut stack| {
Stack::set_cross_axis_alignment(&mut stack, CrossAxisAlignment::Fill);
});
assert_render_snapshot!(harness, "stack_row_cross_axis_fill");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this test meaningfully shows a fill (because e.g. the label is always left aligned).

Maybe (at least for the vertical ones) giving the labels internally centre alignment would work? OTOH, if we ever got a safety rail for that case, we'd run into issues...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I should give them a border.

@PoignardAzur
Copy link
Contributor Author

So my ideal plan for this would be to track down flex uses in examples which don't set must_fill_main_axis or have flex children: those are the ones we can replace with stack.

After that, I'd want to straight up remove the must_fill_main_axis parameter, which is non-standard, unintuitive, and makes the flex code more complex. That way, Flex and Stack would actually fill distinct niches.

Does this fix #607?

Weeell, I don't know. I'd argue not.

This is still more complex than an hypothetical "simplest container you can write" widget: it has axis-independent code, which makes the whole code really hard to read until you internalize what "minor" and "major" mean (every time I spend more than six months without looking at the flex code, I have a learning period the next time I see it where I have to get used to those idioms again).

It also deals alignment and spreading extra space, whereas a "simplest possible container" widget would just align everything top-left.

@DJMcNab
Copy link
Member

DJMcNab commented Aug 15, 2025

So my ideal plan for this would be to track down flex uses in examples which don't set must_fill_main_axis or have flex children: those are the ones we can replace with stack.
After that, I'd want to straight up remove the must_fill_main_axis parameter, which is non-standard, unintuitive, and makes the flex code more complex. That way, Flex and Stack would actually fill distinct niches.

How this will work is a little bit unclear to me still. Since the Stack widget supports distributing its spacing, it seems like it also sometimes fills the main axis? I'm probably misunderstanding something fundamental here.

Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of this discussion blocks this PR landing.

I'd really like to see the test items have a border here, and I'm approving conditional on that.

@PoignardAzur PoignardAzur marked this pull request as draft August 15, 2025 09:34
@PoignardAzur
Copy link
Contributor Author

Since the Stack widget supports distributing its spacing, it seems like it also sometimes fills the main axis? I'm probably misunderstanding something fundamental here.

Right, so, the Stack widget distributes its spacing when it needs to fill the minimum constraint.

Ideally, I'd like to remove min constraints for Masonry entirely, and remove extra space code from Stack.

Though we could also remove the MainAxisAlignment param, assume that alignment is always at the start, and remove most of that code.

None of this discussion blocks this PR landing.

I know I've asked you to expedite the process before, but I'm actually okay with delaying this PR a little. It's not critical for anything, and those questions are worth exploring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants