wip: refactor(output): 53 more errors...

This commit is contained in:
same mf who else 2026-02-14 20:20:37 +02:00
parent f033f9ff54
commit 18bd982a95
3 changed files with 21 additions and 42 deletions

View file

@ -43,14 +43,18 @@ impl<O: Out> HasWH<O::Unit> for O {
impl<N: Coord> WH<N> {
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<N: Coord> XYWH<N> {
fn with_w (&self, w: N) -> XYWH<N> { Self(self.x(), self.y(), w, self.h()) }
fn with_h (&self, h: N) -> XYWH<N> { Self(self.x(), self.y(), self.w(), h) }
fn lrtb (&self) -> XYWH<N> { Self(self.x(), self.x2(), self.y(), self.y2()) }
fn clipped_w (&self, w: N) -> XYWH<N> { Self(self.x(), self.y(), self.w().min(w), self.h()) }
fn clipped_h (&self, h: N) -> XYWH<N> { Self(self.x(), self.y(), self.w(), self.h().min(h)) }
fn clipped (&self, wh: impl HasWH<N>) -> XYWH<N> { Self(self.x(), self.y(), wh.w(), wh.h()) }
/// Iterate over every covered X coordinate.
fn iter_x (&self) -> impl Iterator<Item = N> where N: std::iter::Step {
self.x()..(self.x()+self.w())
@ -59,22 +63,11 @@ impl<N: Coord> XYWH<N> {
fn iter_y (&self) -> impl Iterator<Item = N> where N: std::iter::Step {
self.y()..(self.y()+self.h())
}
fn from_position (pos: impl HasWH<N>) -> Self {
let [x, y] = pos.wh();
Self(x, y, 0.into(), 0.into())
}
fn from_size (size: impl HasWH<N>) -> 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<N> {
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<N> {
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<N> {
let [x, y, w, h] = self.xywh();
@ -88,22 +81,8 @@ impl<N: Coord> XYWH<N> {
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<N>) -> XYWH<N> {
Self(self.x(), self.y(), wh.w(), wh.h())
}
fn clipped_h (&self, h: N) -> XYWH<N> {
Self(self.x(), self.y(), self.w(), self.h().min(h))
}
fn clipped_w (&self, w: N) -> XYWH<N> {
[self.x(), self.y(), self.w().min(w), self.h()]
}
fn with_w (&self, w: N) -> XYWH<N> {
[self.x(), self.y(), w, self.h()]
}
fn with_h (&self, h: N) -> XYWH<N> {
[self.x(), self.y(), self.w(), h]
}
}
impl<O: Out, T: Draw<O> + Layout<O>> Content<O> for T {}
impl<'a, O: Out> AsRef<dyn Draw<O> + 'a> for dyn Content<O> + 'a {
@ -114,10 +93,6 @@ impl<'a, O: Out> AsRef<dyn Layout<O> + 'a> for dyn Content<O> + 'a {
fn as_ref (&self) -> &(dyn Layout<O> + 'a) { self }
}
pub trait HasContent<O: Out> {
fn content (&self) -> impl Content<O>;
}
impl<O: Out> Draw<O> for () {
fn draw (&self, _: &mut O) {}
}

View file

@ -48,14 +48,14 @@ where
// TODO DOCUMENTME
pub struct Lazy<O, T, F>(
F,
PhantomData<(O, T)>
pub F,
pub PhantomData<(O, T)>
);
// TODO DOCUMENTME
pub struct Thunk<O: Out, F: Fn(&mut O)>(
PhantomData<O>,
F
pub PhantomData<O>,
pub F
);
// TODO DOCUMENTME
@ -65,7 +65,7 @@ pub struct Thunk<O: Out, F: Fn(&mut O)>(
}
/// Show an item only when a condition is true.
pub struct When<O, T>(bool, T, PhantomData<O>);
pub struct When<O, T>(pub bool, pub T, pub PhantomData<O>);
/// Show one item if a condition is true and another if the condition is false
pub struct Either<E: Out, A, B>(pub bool, pub A, pub B, pub PhantomData<E>);
@ -125,7 +125,7 @@ pub enum Expand<U, A> { 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<T>(Alignment, T);
pub struct Align<T>(pub Alignment, pub T);
// TODO DOCUMENTME
pub enum Pad<U, A> { X(U, A), Y(U, A), XY(U, U, A), }

View file

@ -90,6 +90,10 @@ pub trait Layout<O: Out> {
fn layout (&self, to: O::Area) -> O::Area { [self.x(to), self.y(to), self.w(to), self.h(to)].into() }
}
pub trait HasContent<O: Out> {
fn content (&self) -> impl Content<O>;
}
// TODO DOCUMENTME
pub trait Content<O: Out>: Draw<O> + Layout<O> {}
@ -143,6 +147,6 @@ pub trait HasXYWH<N: Coord>: HasXY<N> + HasWH<N> {
// TODO DOCUMENTME
pub trait HasSize<O: Out> {
fn size (&self) -> &Measure<O>;
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() }
}