⎇ 30f83642887f3f0d5e5e6235e3de9700a5e30495
src/compute/grid/util/coordinates.rs
Historia
Quién tocó qué
crudo
1//! Taffy uses two coordinate systems to refer to grid lines (the gaps/gutters between rows/columns):
2//!
3//! "CSS Grid Line" coordinates are those used in grid-row/grid-column in the CSS grid spec:
4//! - The line at left hand (or top) edge of the explicit grid is line 1
5//! (and counts up from there)
6//! - The line at the right hand (or bottom) edge of the explicit grid in -1
7//! (and counts down from there)
8//! - 0 is not a valid index
9//!
10//! "OriginZero" coordinates are a normalized form:
11//! - The line at left hand (or top) edge of the explicit grid is line 0
12//! - The next line to the right (or down) is 1, and so on
13//! - The next line to the left (or up) is -1, and so on
14//!
15use core::cmp::Ordering;
16
17/// Convert from CSS Grid Line coordinates to our custom OriginZero coordinates
18pub(crate) fn css_grid_line_into_origin_zero_coords(grid_line: i16, explicit_track_count: u16) -> i16 {
19 let explicit_line_count = explicit_track_count + 1;
20 match grid_line.cmp(&0) {
21 Ordering::Greater => grid_line - 1,
22 Ordering::Less => grid_line + explicit_line_count as i16,
23 Ordering::Equal => panic!("Grid line of zero is invalid"),
24 }
25}
26
27#[allow(dead_code)]
28/// Convert from OriginZero coordinates to CSS Grid Line coordinates
29pub(crate) fn origin_zero_coords_into_css_grid_line(origin_zero_line: i16, explicit_track_count: u16) -> i16 {
30 let explicit_line_count = explicit_track_count + 1;
31 if origin_zero_line >= 0 {
32 origin_zero_line + 1
33 } else {
34 -(origin_zero_line + explicit_line_count as i16)
35 }
36}