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

Replace BoxConstraints and update Layout function #701

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

jaredoconnell
Copy link
Contributor

This pull request works towards implementing changes proposed in #37

It does so by replacing BoxConstraints with a generic type that has a vertical and horizontal component. The Layout function has the BoxConstraints parameter replaced with available_space and requested_fill. available_space is like the Size type; it uses the new generic type with f64 as the type on the axes. requested_fill takes the place of the min size in BoxConstraints, and will have more future uses with Intrinsic sizing. When set to Exact, the widgets should behave the way they did when they previously got BoxConstraints with the min equaling the max. I did not find any instances where min wasn't set to either 0 by 0 or the max.

I chose BiAxial for the name for the generic 2D type that is used for the layout parameters. I think it is descriptive while not colliding with the names of other types. Size was proposed in #37, but it collided with the Size type in several libraries, including Kurbo. And for the uses that were proposed, including requested_fill, I felt like a more generic name made sense. If the community doesn't like the name, I'm open to changing it.

This code is ready for high-level review, including discussions on whether or not this is the way forward, as well as naming and file structure.

This design is a major step forward towards implementing Taffy integration.
The code still has at least one bug (like in the Flex example). I need to fix the linter errors, validate the tests, and fix the ordering of the code in the new files. But the examples should work mostly.

Copy link
Contributor

@PoignardAzur PoignardAzur left a comment

Choose a reason for hiding this comment

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

General note: it feels like you could have kept the diff a lot smaller by keeping the BoxConstraints type and changing its internals.

As it is it feels like a lot of diff lines are just replacing one thing by another semantically equivalent other thing, which makes the whole PR harder to review.


Overall, I'm wondering whether this code actually moves us closer to Taffy integration. I guess the ContentFill enum is closer to taffy's AvailableSpace, but is that necessary?

From the perspective of what I'd like Masonry's layout to look like long term, this isn't it. I've described my thought process a few times for the direction I wanted layout to move towards, and this PR is at best orthogonal to that direction.

(My thoughts on the subject are scattered in a few places, though. I'll go into more details on Zulip.)

That doesn't mean we can't accept it, just that a lot of its changes would be almost completely erased by the now imminent layout refactor.

Comment on lines 106 to 107
extern crate core;

Copy link
Contributor

Choose a reason for hiding this comment

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

Is that supposed to be here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My IDE must have added it. Removed.

Comment on lines 218 to 225
let input_size = match root.size_policy {
WindowSizePolicy::User => window_size, // Note: this was "tight"
WindowSizePolicy::Content => BiAxial::UNBOUNDED,
};
let content_fill = BiAxial {
horizontal: Exact,
vertical: Exact,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

The combo of "unbounded input size" with "exact content fill" doesn't make sense to me. Does it work in practice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's an illegal combination. I hit it when testing size_policy. But the current code does not deal with unbounded dimensions well.

It makes me think that I should merge all layout parameters into one type to validate that the combinations of parameters are valid.

Comment on lines +370 to +376
let child_fill = if self.must_fill {
BiAxial::new(ContentFill::Exact, ContentFill::Exact)
} else {
// TODO: Somehow allow specifying which axis should overflow.
// once that happens, we can specify the major axis as Max, and the minor as Constrain.
BiAxial::new(ContentFill::Constrain, ContentFill::Constrain)
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Be aware that in the future we're likely to remove the must_fill field. Having a scroll area that somehow "must" be filled doesn't really make sense.

@PoignardAzur
Copy link
Contributor

PoignardAzur commented Oct 23, 2024

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.

2 participants