wip: refactor(tui): 44 errors
Some checks failed
/ build (push) Has been cancelled

This commit is contained in:
same mf who else 2026-02-15 07:07:08 +02:00
parent b7b1055fbc
commit 4fa5d74fa2
26 changed files with 1550 additions and 1548 deletions

View file

@ -49,7 +49,7 @@ impl<N: Coord> WH<N> {
}
}
impl<N: Coord> XYWH<N> {
fn zero (&self) -> Self {
fn zero () -> Self {
Self(0.into(), 0.into(), 0.into(), 0.into())
}
fn x2 (&self) -> N {
@ -250,8 +250,13 @@ impl<O: Out> Measure<O> {
}
}
impl<O: Out> From<[O::Unit; 2]> for Measure<O> {
fn from ([x, y]: [O::Unit; 2]) -> Self { Self::new(x, y) }
/// FIXME don't convert to u16 specifically
impl<O: Out> HasWH<O::Unit> for Measure<O> {
fn w (&self) -> O::Unit { (self.x.load(Relaxed) as u16).into() }
fn h (&self) -> O::Unit { (self.y.load(Relaxed) as u16).into() }
}
impl<O: Out> From<WH<O::Unit>> for Measure<O> {
fn from (WH(x, y): WH<O::Unit>) -> Self { Self::new(x, y) }
}
impl<O: Out> Layout<O> for () {
@ -460,10 +465,10 @@ layout_op_xy!(1 opt: Expand);
impl<O: Out, T: Layout<O>> Layout<O> for Expand<O::Unit, T> {
fn layout_w (&self, to: XYWH<O::Unit>) -> O::Unit {
self.inner().w(to).plus(self.dx().unwrap_or_default())
self.inner().layout_w(to).plus(self.dx().unwrap_or_default())
}
fn layout_h (&self, to: XYWH<O::Unit>) -> O::Unit {
self.inner().w(to).plus(self.dy().unwrap_or_default())
self.inner().layout_w(to).plus(self.dy().unwrap_or_default())
}
}
@ -703,8 +708,8 @@ impl<'a, O, A, B, I, F, G> Layout<O> for Map<O, A, B, I, F, G> where
fn layout (&self, area: XYWH<O::Unit>) -> XYWH<O::Unit> {
let Self { get_iter, get_item, .. } = self;
let mut index = 0;
let [mut min_x, mut min_y] = area.center();
let [mut max_x, mut max_y] = area.center();
let XY(mut min_x, mut min_y) = area.centered();
let XY(mut max_x, mut max_y) = area.center();
for item in get_iter() {
let XYWH(x, y, w, h) = get_item(item, index).layout(area);
min_x = min_x.min(x);

View file

@ -6,7 +6,7 @@ use crate::*;
/// let xy: XY<u16> = XY(0, 0);
/// ```
#[cfg_attr(test, derive(Arbitrary))]
#[derive(Copy, Clone)] pub struct XY<C: Coord>(pub C, pub C);
#[derive(Copy, Clone, Default)] pub struct XY<C: Coord>(pub C, pub C);
/// A size (Width, Height).
///
@ -14,7 +14,7 @@ use crate::*;
/// let wh: WH<u16> = WH(0, 0);
/// ```
#[cfg_attr(test, derive(Arbitrary))]
#[derive(Copy, Clone)] pub struct WH<C: Coord>(pub C, pub C);
#[derive(Copy, Clone, Default)] pub struct WH<C: Coord>(pub C, pub C);
/// Point with size.
///
@ -25,7 +25,7 @@ use crate::*;
/// * [ ] TODO: anchor field (determines at which corner/side is X0 Y0)
///
#[cfg_attr(test, derive(Arbitrary))]
#[derive(Copy, Clone)] pub struct XYWH<C: Coord>(pub C, pub C, pub C, pub C);
#[derive(Copy, Clone, Default)] pub struct XYWH<C: Coord>(pub C, pub C, pub C, pub C);
/// A cardinal direction.
///
@ -53,7 +53,7 @@ use crate::*;
/// let measure = Measure::default();
/// ```
#[derive(Default)] pub struct Measure<O: Out> {
__: PhantomData<O>,
pub __: PhantomData<O>,
pub x: Arc<AtomicUsize>,
pub y: Arc<AtomicUsize>,
}

View file

@ -41,6 +41,32 @@ pub trait Out: Send + Sync + Sized {
}
}
/// A numeric type that can be used as coordinate.
///
/// FIXME: Replace this ad-hoc trait with `num` crate.
pub trait Coord: Send + Sync + Copy
+ Add<Self, Output=Self>
+ Sub<Self, Output=Self>
+ Mul<Self, Output=Self>
+ Div<Self, Output=Self>
+ Ord + PartialEq + Eq
+ Debug + Display + Default
+ From<u16> + Into<u16>
+ Into<usize>
+ Into<f64>
{
fn plus (self, other: Self) -> Self;
fn minus (self, other: Self) -> Self {
if self >= other { self - other } else { 0.into() }
}
fn atomic (self) -> AtomicUsize {
AtomicUsize::new(self.into())
}
fn zero () -> Self {
0.into()
}
}
/// Drawable with dynamic dispatch.
pub trait Draw<O: Out> {
fn draw (&self, to: &mut O);
@ -93,32 +119,6 @@ pub trait HasContent<O: Out> {
// TODO DOCUMENTME
pub trait Content<O: Out>: Draw<O> + Layout<O> {}
/// A numeric type that can be used as coordinate.
///
/// FIXME: Replace this ad-hoc trait with `num` crate.
pub trait Coord: Send + Sync + Copy
+ Add<Self, Output=Self>
+ Sub<Self, Output=Self>
+ Mul<Self, Output=Self>
+ Div<Self, Output=Self>
+ Ord + PartialEq + Eq
+ Debug + Display + Default
+ From<u16> + Into<u16>
+ Into<usize>
+ Into<f64>
{
fn plus (self, other: Self) -> Self;
fn minus (self, other: Self) -> Self {
if self >= other { self - other } else { 0.into() }
}
fn atomic (self) -> AtomicUsize {
AtomicUsize::new(self.into())
}
fn zero () -> Self {
0.into()
}
}
// Something that has an origin point (X, Y).
pub trait HasXY<N: Coord> {
fn x (&self) -> N;