-
Notifications
You must be signed in to change notification settings - Fork 111
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
Grid/refactor coordinate handling #301
Grid/refactor coordinate handling #301
Conversation
I agree with your assessment of the options. Panicking is bad, and NonZero is a giant pain for anyone writing this out by hand (or serializing it). |
Excellent. This has now been implemented :) |
9eb1b5c
to
a57c752
Compare
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.
This improves "correct" usage, so I really like these changes.
src/compute/grid/implicit_grid.rs
Outdated
@@ -28,12 +28,12 @@ pub(crate) fn compute_grid_size_estimate<'a>( | |||
// Compute *track* count estimates for each axis from: | |||
// - The explicit track counts | |||
// - The origin-zero coordinate min and max grid line variables | |||
let negative_implicit_inline_tracks = col_min.unsigned_abs(); | |||
let negative_implicit_inline_tracks = col_min.0.unsigned_abs(); |
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.
This diff is an indication that we should be using Deref / DerefMut impls on these newtypes IMO.
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'm a bit wary of implementing Deref
/DerefMut
for the coordinate newtypes as a large part of the purpose of the types is to make sure that they are not used in the wrong context and I feel like this would weaken that protection. I've taken an alternative approach of:
- Adding methods to
OriginZeroLine
. They still use.0
internally, but these.0
's are now constrained to the impls for that type (i.e they're allself.0
). - Just using
OriginZeroLine
directly in more places (avoiding the need to access the inner value entirely).
Does that seem acceptable to you?
I've also uncovered a couple of bugs in the process of this, which all seemed to affect grid items that are auto-placed into negative grid tracks. These now have gentests. At some point I would like to go through and convert all the placement unit tests to gentests, but that's definitely for a separate PR.
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.
Generally in favor of this! Two requests:
- Deref / DerefMut on the newtypes: there's a ton of .0 churn in this diff that makes it unclear.
- Change log.
…nd convert to Auto internally if zero is specified
Co-authored-by: Andreas Weibye <[email protected]>
Co-authored-by: Andreas Weibye <[email protected]>
d29da94
to
7408fdc
Compare
47279cd
to
4a64cd9
Compare
b8dc8ea
to
77728d3
Compare
Release notes updated. User-facing changes in this PR are pretty minor, but there is one small one so I've included it. |
Objective
The handling of grid line coordinates was previously incorrect in a few corner cases (such as specifying
-1 span 3
). This PR fixes those bugs. It also introduces 2 newtypesGridLine(NonZeroI16)
andOriginZeroLine(i16)
to represent the coordinate systemsFeedback wanted
What is the best way to expose grid lines to users.
The publicly exposed
GridPlacement
type is now an alias forGenericGridPlacement<GridLine>
(so users who are using the raw types rather than the style helpers must pass aGridLine
for theLine
variant.Currently:
GridLine
is a wrapper aroundNonZeroI16
(zero is invalid)line()
style helper acceptsi16
, but returnsGridPlacement::Auto
if zero is passed.I'm thinking it might be better if:
GridLine
is a wrapper aroundi16
line()
to indicate that zero is invalid (and point to MDN docs on grid lines)line()
returnsGridPlacement::Line(GridLine(0))
if zero is passed.GridPlacement::Line(GridLine(0))
gets converted toGridPlacement::Auto
internally.The reason I'm thinking this is that I reckon we'll probably want some kind of debug tooling to introspect styles at some point, and for that we'll need to represent exactly what the user specified (and then indicate it's invalid).
Other alternatives:
NonZeroI16
(but this is incredibly verbose)line()
panic if passed zero (but I think we ought to avoid panics wherever possible).