summaryrefslogtreecommitdiff
path: root/src/geom
diff options
context:
space:
mode:
Diffstat (limited to 'src/geom')
-rw-r--r--src/geom/gridu.rs73
-rw-r--r--src/geom/mod.rs2
2 files changed, 75 insertions, 0 deletions
diff --git a/src/geom/gridu.rs b/src/geom/gridu.rs
new file mode 100644
index 00000000..70fc17e4
--- /dev/null
+++ b/src/geom/gridu.rs
@@ -0,0 +1,73 @@
+use super::*;
+
+/// An enum with the length that a grid cell may have.
+#[derive(Copy, Clone, PartialEq, Hash)]
+pub enum TrackSizing {
+ /// A length stated in absolute values and fractions of the parent's size.
+ Linear(Linear),
+ /// A length that is the fraction of the remaining free space in the parent.
+ Fractional(Fractional),
+ /// The cell will fit its contents.
+ Auto,
+}
+
+impl TrackSizing {
+ pub fn is_zero(&self) -> bool {
+ match self {
+ Self::Linear(l) => l.is_zero(),
+ Self::Fractional(f) => f.is_zero(),
+ Self::Auto => false,
+ }
+ }
+
+ pub fn preliminary_length(&self, resolve: Length) -> Length {
+ match self {
+ Self::Linear(l) => l.resolve(resolve),
+ _ => resolve,
+ }
+ }
+}
+
+impl Display for TrackSizing {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ match self {
+ Self::Linear(x) => <Linear as Display>::fmt(x, f),
+ Self::Fractional(x) => <Fractional as Display>::fmt(x, f),
+ Self::Auto => write!(f, "auto"),
+ }
+ }
+}
+
+impl Debug for TrackSizing {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ match self {
+ Self::Linear(x) => <Linear as Debug>::fmt(x, f),
+ Self::Fractional(x) => <Fractional as Debug>::fmt(x, f),
+ Self::Auto => write!(f, "auto"),
+ }
+ }
+}
+
+impl From<Length> for TrackSizing {
+ fn from(abs: Length) -> Self {
+ Self::Linear(abs.into())
+ }
+}
+
+impl From<Relative> for TrackSizing {
+ fn from(rel: Relative) -> Self {
+ Self::Linear(rel.into())
+ }
+}
+
+impl From<Linear> for TrackSizing {
+ fn from(lin: Linear) -> Self {
+ Self::Linear(lin)
+ }
+}
+
+impl From<Fractional> for TrackSizing {
+ fn from(fr: Fractional) -> Self {
+ Self::Fractional(fr)
+ }
+}
diff --git a/src/geom/mod.rs b/src/geom/mod.rs
index ce8a7276..fdc3980e 100644
--- a/src/geom/mod.rs
+++ b/src/geom/mod.rs
@@ -7,6 +7,7 @@ mod angle;
mod dir;
mod fr;
mod gen;
+mod gridu;
mod length;
mod linear;
mod path;
@@ -21,6 +22,7 @@ pub use angle::*;
pub use dir::*;
pub use fr::*;
pub use gen::*;
+pub use gridu::*;
pub use length::*;
pub use linear::*;
pub use path::*;