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) {}
}