diff --git a/output/src/out_impls.rs b/output/src/out_impls.rs index c8c3189..99dfdc6 100644 --- a/output/src/out_impls.rs +++ b/output/src/out_impls.rs @@ -43,14 +43,18 @@ impl HasWH for O { impl WH { fn clip_w (&self, w: N) -> [N;2] { [self.w().min(w), self.h()] } fn clip_h (&self, h: N) -> [N;2] { [self.w(), self.h().min(h)] } - fn to_area_pos (&self) -> [N;4] { let [x, y] = self.wh(); [x, y, 0.into(), 0.into()] } - fn to_area_size (&self) -> [N;4] { let [w, h] = self.wh(); [0.into(), 0.into(), w, h] } fn expect_min (&self, w: N, h: N) -> Usually<&Self> { if self.w() < w || self.h() < h { return Err(format!("min {w}x{h}").into()) } Ok(self) } } impl XYWH { + fn with_w (&self, w: N) -> XYWH { Self(self.x(), self.y(), w, self.h()) } + fn with_h (&self, h: N) -> XYWH { Self(self.x(), self.y(), self.w(), h) } + fn lrtb (&self) -> XYWH { Self(self.x(), self.x2(), self.y(), self.y2()) } + fn clipped_w (&self, w: N) -> XYWH { Self(self.x(), self.y(), self.w().min(w), self.h()) } + fn clipped_h (&self, h: N) -> XYWH { Self(self.x(), self.y(), self.w(), self.h().min(h)) } + fn clipped (&self, wh: impl HasWH) -> XYWH { Self(self.x(), self.y(), wh.w(), wh.h()) } /// Iterate over every covered X coordinate. fn iter_x (&self) -> impl Iterator where N: std::iter::Step { self.x()..(self.x()+self.w()) @@ -59,22 +63,11 @@ impl XYWH { fn iter_y (&self) -> impl Iterator where N: std::iter::Step { self.y()..(self.y()+self.h()) } - fn from_position (pos: impl HasWH) -> Self { - let [x, y] = pos.wh(); - Self(x, y, 0.into(), 0.into()) - } - fn from_size (size: impl HasWH) -> Self { - let [w, h] = size.wh(); - Self(0.into(), 0.into(), w, h) - } - fn lrtb (&self) -> [N;4] { - Self(self.x(), self.x2(), self.y(), self.y2()) - } fn center (&self) -> XY { - Self(self.x().plus(self.w()/2.into()), self.y().plus(self.h()/2.into())) + XY(self.x().plus(self.w()/2.into()), self.y().plus(self.h()/2.into())) } fn centered (&self) -> XY { - Self(self.x().minus(self.w()/2.into()), self.y().minus(self.h()/2.into())) + XY(self.x().minus(self.w()/2.into()), self.y().minus(self.h()/2.into())) } fn centered_x (&self, n: N) -> XYWH { let [x, y, w, h] = self.xywh(); @@ -88,22 +81,8 @@ impl XYWH { let [x, y, w, h] = self.xywh(); Self((x.plus(w / 2.into())).minus(n / 2.into()), (y.plus(h / 2.into())).minus(m / 2.into()), n, m) } - fn clipped (&self, wh: impl HasWH) -> XYWH { - Self(self.x(), self.y(), wh.w(), wh.h()) - } - fn clipped_h (&self, h: N) -> XYWH { - Self(self.x(), self.y(), self.w(), self.h().min(h)) - } - fn clipped_w (&self, w: N) -> XYWH { - [self.x(), self.y(), self.w().min(w), self.h()] - } - fn with_w (&self, w: N) -> XYWH { - [self.x(), self.y(), w, self.h()] - } - fn with_h (&self, h: N) -> XYWH { - [self.x(), self.y(), self.w(), h] - } } + impl + Layout> Content for T {} impl<'a, O: Out> AsRef + 'a> for dyn Content + 'a { @@ -114,10 +93,6 @@ impl<'a, O: Out> AsRef + 'a> for dyn Content + 'a { fn as_ref (&self) -> &(dyn Layout + 'a) { self } } -pub trait HasContent { - fn content (&self) -> impl Content; -} - impl Draw for () { fn draw (&self, _: &mut O) {} } diff --git a/output/src/out_structs.rs b/output/src/out_structs.rs index 9f1d74e..0149443 100644 --- a/output/src/out_structs.rs +++ b/output/src/out_structs.rs @@ -48,14 +48,14 @@ where // TODO DOCUMENTME pub struct Lazy( - F, - PhantomData<(O, T)> + pub F, + pub PhantomData<(O, T)> ); // TODO DOCUMENTME pub struct Thunk( - PhantomData, - F + pub PhantomData, + pub F ); // TODO DOCUMENTME @@ -65,7 +65,7 @@ pub struct Thunk( } /// Show an item only when a condition is true. -pub struct When(bool, T, PhantomData); +pub struct When(pub bool, pub T, pub PhantomData); /// Show one item if a condition is true and another if the condition is false pub struct Either(pub bool, pub A, pub B, pub PhantomData); @@ -125,7 +125,7 @@ pub enum Expand { X(U, A), Y(U, A), XY(U, U, A), } /// test(area, &Align::sw(two_by_four()), [10, 28, 4, 2]); /// test(area, &Align::w(two_by_four()), [10, 19, 4, 2]); /// ``` -pub struct Align(Alignment, T); +pub struct Align(pub Alignment, pub T); // TODO DOCUMENTME pub enum Pad { X(U, A), Y(U, A), XY(U, U, A), } diff --git a/output/src/out_traits.rs b/output/src/out_traits.rs index 726fc04..10196cb 100644 --- a/output/src/out_traits.rs +++ b/output/src/out_traits.rs @@ -90,6 +90,10 @@ pub trait Layout { fn layout (&self, to: O::Area) -> O::Area { [self.x(to), self.y(to), self.w(to), self.h(to)].into() } } +pub trait HasContent { + fn content (&self) -> impl Content; +} + // TODO DOCUMENTME pub trait Content: Draw + Layout {} @@ -143,6 +147,6 @@ pub trait HasXYWH: HasXY + HasWH { // TODO DOCUMENTME pub trait HasSize { fn size (&self) -> &Measure; - fn width (&self) -> usize { self.size().w() } - fn height (&self) -> usize { self.size().h() } + fn width (&self) -> O::Unit { self.size().w() } + fn height (&self) -> O::Unit { self.size().h() } }