diff --git a/crates/tek_core/src/engine.rs b/crates/tek_core/src/engine.rs index 29d146ff..6fdb692b 100644 --- a/crates/tek_core/src/engine.rs +++ b/crates/tek_core/src/engine.rs @@ -10,7 +10,7 @@ pub trait Engine: Send + Sync + Sized { /// Render target type Output: Output; /// Unit of length - type Unit: Number; + type Unit: Coordinate; /// Rectangle without offset type Size: Size + From<[Self::Unit;2]> + Debug + Copy; /// Rectangle with offset diff --git a/crates/tek_core/src/lib.rs b/crates/tek_core/src/lib.rs index 41744473..d02aca7e 100644 --- a/crates/tek_core/src/lib.rs +++ b/crates/tek_core/src/lib.rs @@ -54,35 +54,3 @@ pub type Usually = Result>; /// Standard optional result type. pub type Perhaps = Result, Box>; - -/// Standard numeric type. -pub trait Number: Send + Sync + Copy - + Add - + Sub - + Mul - + Div - + Ord + PartialEq + Eq - + Debug + Display + Default - + From + Into - + Into -{ - fn minus (self, other: Self) -> Self { - if self >= other { - self - other - } else { - 0.into() - } - } -} - -impl Number for T where - T: Send + Sync + Copy - + Add - + Sub - + Mul - + Div - + Ord + PartialEq + Eq - + Debug + Display + Default - + From + Into - + Into -{} diff --git a/crates/tek_core/src/space.rs b/crates/tek_core/src/space.rs index 6e94f5be..7bf26ce3 100644 --- a/crates/tek_core/src/space.rs +++ b/crates/tek_core/src/space.rs @@ -1,5 +1,37 @@ use crate::*; +/// Standard numeric type. +pub trait Coordinate: Send + Sync + Copy + + Add + + Sub + + Mul + + Div + + Ord + PartialEq + Eq + + Debug + Display + Default + + From + Into + + Into +{ + fn minus (self, other: Self) -> Self { + if self >= other { + self - other + } else { + 0.into() + } + } +} + +impl Coordinate for T where + T: Send + Sync + Copy + + Add + + Sub + + Mul + + Div + + Ord + PartialEq + Eq + + Debug + Display + Default + + From + Into + + Into +{} + pub struct FixedAxis { pub start: T, pub point: Option, @@ -39,7 +71,7 @@ impl_axis_common!(ScaledAxis usize); // TODO: return impl Point and impl Size instead of [N;x] // to disambiguate between usage of 2-"tuple"s -pub trait Size { +pub trait Size { fn x (&self) -> N; fn y (&self) -> N; #[inline] fn w (&self) -> N { self.x() } @@ -56,17 +88,17 @@ pub trait Size { } } -impl Size for (N, N) { +impl Size for (N, N) { fn x (&self) -> N { self.0 } fn y (&self) -> N { self.1 } } -impl Size for [N;2] { +impl Size for [N;2] { fn x (&self) -> N { self[0] } fn y (&self) -> N { self[1] } } -pub trait Area: Copy { +pub trait Area: Copy { fn x (&self) -> N; fn y (&self) -> N; fn w (&self) -> N; @@ -117,14 +149,14 @@ pub trait Area: Copy { } } -impl Area for (N, N, N, N) { +impl Area for (N, N, N, N) { #[inline] fn x (&self) -> N { self.0 } #[inline] fn y (&self) -> N { self.1 } #[inline] fn w (&self) -> N { self.2 } #[inline] fn h (&self) -> N { self.3 } } -impl Area for [N;4] { +impl Area for [N;4] { #[inline] fn x (&self) -> N { self[0] } #[inline] fn y (&self) -> N { self[1] } #[inline] fn w (&self) -> N { self[2] } @@ -338,7 +370,7 @@ impl Align { } } -fn align + From<[N;4]>> (align: &Align, outer: R, inner: R) -> Option { +fn align + From<[N;4]>> (align: &Align, outer: R, inner: R) -> Option { if outer.w() < inner.w() || outer.h() < inner.h() { None } else { @@ -381,7 +413,7 @@ impl> Widget for Align { } /// Enforce fixed size of drawing area -pub enum Fixed { +pub enum Fixed { /// Enforce fixed width X(U, T), /// Enforce fixed height @@ -389,7 +421,7 @@ pub enum Fixed { /// Enforce fixed width and height XY(U, U, T), } -impl Fixed { +impl Fixed { pub fn inner (&self) -> &T { match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } } @@ -417,7 +449,7 @@ impl> Widget for Fixed { } /// Enforce minimum size of drawing area -pub enum Min { +pub enum Min { /// Enforce minimum width X(U, T), /// Enforce minimum height @@ -425,7 +457,7 @@ pub enum Min { /// Enforce minimum width and height XY(U, U, T), } -impl Min { +impl Min { pub fn inner (&self) -> &T { match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } } @@ -448,7 +480,7 @@ impl> Widget for Min { } /// Enforce maximum size of drawing area -pub enum Max { +pub enum Max { /// Enforce maximum width X(U, T), /// Enforce maximum height @@ -457,7 +489,7 @@ pub enum Max { XY(U, U, T), } -impl Max { +impl Max { fn inner (&self) -> &T { match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } } @@ -480,7 +512,7 @@ impl> Widget for Max { } /// Expand drawing area -pub enum Grow { +pub enum Grow { /// Increase width X(N, T), /// Increase height @@ -489,7 +521,7 @@ pub enum Grow { XY(N, N, T) } -impl Grow { +impl Grow { fn inner (&self) -> &T { match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } } @@ -512,7 +544,7 @@ impl> Widget for Grow { } /// Shrink drawing area -pub enum Shrink { +pub enum Shrink { /// Decrease width X(N, T), /// Decrease height @@ -521,7 +553,7 @@ pub enum Shrink { XY(N, N, T), } -impl Shrink { +impl Shrink { fn inner (&self) -> &T { match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } } @@ -553,7 +585,7 @@ impl> Widget for Shrink { } /// Shrink from each side -pub enum Inset { +pub enum Inset { /// Decrease width X(N, T), /// Decrease height @@ -562,14 +594,14 @@ pub enum Inset { XY(N, N, T), } -impl Inset { +impl Inset { pub fn inner (&self) -> &T { match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } } } /// Grow on each side -pub enum Outset { +pub enum Outset { /// Increase width X(N, T), /// Increase height @@ -578,7 +610,7 @@ pub enum Outset { XY(N, N, T), } -impl Outset { +impl Outset { pub fn inner (&self) -> &T { match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } } @@ -623,7 +655,7 @@ impl> Widget for Outset { } /// Move origin point of drawing area -pub enum Push { +pub enum Push { /// Move origin to the right X(N, T), /// Move origin downwards @@ -632,7 +664,7 @@ pub enum Push { XY(N, N, T), } -impl Push { +impl Push { pub fn inner (&self) -> &T { match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } } @@ -661,7 +693,7 @@ impl> Widget for Push { } /// Move origin point of drawing area -pub enum Pull { +pub enum Pull { /// Move origin to the right X(N, T), /// Move origin downwards @@ -670,7 +702,7 @@ pub enum Pull { XY(N, N, T), } -impl Pull { +impl Pull { pub fn inner (&self) -> &T { match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } }