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

Fix panic when GridLine 0 is specified #671

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/style/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,6 @@ impl GridPlacement {
}

impl<T: GridCoordinate> Line<GenericGridPlacement<T>> {
#[inline]
/// Whether the track position is definite in this axis (or the item will need auto placement)
/// The track position is definite if least one of the start and end positions is a track index
pub fn is_definite(&self) -> bool {
matches!((self.start, self.end), (GenericGridPlacement::Line(_), _) | (_, GenericGridPlacement::Line(_)))
}

/// Resolves the span for an indefinite placement (a placement that does not consist of two `Track`s).
/// Panics if called on a definite placement
pub fn indefinite_span(&self) -> u16 {
Expand All @@ -154,6 +147,18 @@ impl<T: GridCoordinate> Line<GenericGridPlacement<T>> {
}

impl Line<GridPlacement> {
#[inline]
/// Whether the track position is definite in this axis (or the item will need auto placement)
/// The track position is definite if least one of the start and end positions is a NON-ZERO track index
/// (0 is an invalid line in GridLine coordinates, and falls back to "auto" which is indefinite)
pub fn is_definite(&self) -> bool {
match (self.start, self.end) {
(GenericGridPlacement::Line(line), _) if line.as_i16() != 0 => true,
(_, GenericGridPlacement::Line(line)) if line.as_i16() != 0 => true,
_ => false,
}
}

/// Apply a mapping function if the [`GridPlacement`] is a `Track`. Otherwise return `self` unmodified.
pub fn into_origin_zero(&self, explicit_track_count: u16) -> Line<OriginZeroGridPlacement> {
Line {
Expand All @@ -164,6 +169,13 @@ impl Line<GridPlacement> {
}

impl Line<OriginZeroGridPlacement> {
#[inline]
/// Whether the track position is definite in this axis (or the item will need auto placement)
/// The track position is definite if least one of the start and end positions is a track index
pub fn is_definite(&self) -> bool {
matches!((self.start, self.end), (GenericGridPlacement::Line(_), _) | (_, GenericGridPlacement::Line(_)))
}

/// If at least one of the of the start and end positions is a track index then the other end can be resolved
/// into a track index purely based on the information contained with the placement specification
pub fn resolve_definite_grid_lines(&self) -> Line<OriginZeroLine> {
Expand Down