Skip to content

Commit

Permalink
Add span method to Line<OriginZeroLine>
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Jan 2, 2023
1 parent cfec1b8 commit 4a64cd9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/compute/grid/types/coordinates.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! Taffy uses two coordinate systems to refer to grid lines (the gaps/gutters between rows/columns):
use super::super::types::TrackCounts;
use crate::geometry::Line;
use core::cmp::{max, Ordering};
use core::ops::{Add, AddAssign, Sub};
use std::cmp::Ordering;

/// Represents a grid line position in "CSS Grid Line" coordinates
///
Expand Down Expand Up @@ -115,6 +116,13 @@ impl OriginZeroLine {
}
}

impl Line<OriginZeroLine> {
/// The number of tracks between the start and end lines
pub(crate) fn span(self) -> u16 {
max(self.end.0 - self.start.0, 0) as u16
}
}

/// A trait for the different coordinates used to define grid lines.
pub trait GridCoordinate: Copy {}
impl GridCoordinate for GridLine {}
Expand Down
5 changes: 2 additions & 3 deletions src/compute/grid/types/grid_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::prelude::LayoutTree;
use crate::resolve::MaybeResolve;
use crate::style::{AvailableSpace, LengthPercentageAuto, MaxTrackSizingFunction, MinTrackSizingFunction, Style};
use crate::style_helpers::*;
use core::cmp::max;
use core::ops::Range;

/// Represents a single grid item
Expand Down Expand Up @@ -111,8 +110,8 @@ impl GridItem {
/// Returns the number of tracks that this item spans in the specified axis
pub fn span(&self, axis: AbstractAxis) -> u16 {
match axis {
AbstractAxis::Block => max(self.row.end.0 - self.row.start.0, 0) as u16,
AbstractAxis::Inline => max(self.column.end.0 - self.column.start.0, 0) as u16,
AbstractAxis::Block => self.row.span(),
AbstractAxis::Inline => self.column.span(),
}
}

Expand Down

0 comments on commit 4a64cd9

Please sign in to comment.