docs(out): docstrings
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
same mf who else 2026-02-14 20:27:52 +02:00
parent 18bd982a95
commit 997610f23e

View file

@ -1,97 +1,128 @@
use crate::*;
/// A point (X, Y).
///
/// ```
/// let xy: XY<u16> = XY(0, 0);
/// ```
pub struct XY<C: Coord>(pub C, pub C);
/// A size (Width, Height).
///
/// ```
/// let wh: WH<u16> = WH(0, 0);
/// ```
pub struct WH<C: Coord>(pub C, pub C);
/// Point with size.
///
/// TODO: anchor field (determines at which corner/side is X0 Y0)
/// ```
/// let xywh: XYWH<u16> = XYWH(0, 0, 0, 0);
/// ```
///
/// * [ ] TODO: anchor field (determines at which corner/side is X0 Y0)
///
pub struct XYWH<C: Coord>(pub C, pub C, pub C, pub C);
/// A cardinal direction.
///
/// ```
/// let direction = Direction::Above;
/// ```
#[derive(Copy, Clone, PartialEq, Debug)] #[cfg_attr(test, derive(Arbitrary))]
pub enum Direction {
North, South, East, West, Above, Below
}
/// 9th of area to place.
///
/// ```
/// let alignment = Align::Center;
/// ```
#[derive(Debug, Copy, Clone, Default)]
pub enum Alignment {
#[default] Center, X, Y, NW, N, NE, E, SE, S, SW, W
}
/// A widget that tracks its rendered width and height
/// A widget that tracks its rendered width and height.
///
/// ```
/// let measure = Measure::default();
/// ```
#[derive(Default)] pub struct Measure<O: Out> {
__: PhantomData<O>,
pub x: Arc<AtomicUsize>,
pub y: Arc<AtomicUsize>,
}
// TODO DOCUMENTME
pub struct Bounded<O: Out, D>(pub O::Area, pub D);
/// Draws items from an iterator.
pub struct Map<O, A, B, I, F, G>
where
I: Iterator<Item = A> + Send + Sync,
F: Fn() -> I + Send + Sync,
{
__: PhantomData<(O, B)>,
/// Function that returns iterator over stacked components
get_iter: F,
/// Function that returns each stacked component
get_item: G,
}
// TODO DOCUMENTME
pub struct Lazy<O, T, F>(
pub F,
pub PhantomData<(O, T)>
);
// TODO DOCUMENTME
pub struct Thunk<O: Out, F: Fn(&mut O)>(
pub PhantomData<O>,
pub F
);
// TODO DOCUMENTME
#[derive(Debug, Default)] pub struct Memo<T, U> {
pub value: T,
pub view: Arc<RwLock<U>>
}
/// Show an item only when a condition is true.
///
/// ```
/// let when = When(true, "Yes");
/// ```
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
/// Show one item if a condition is true and another if the condition is false.
///
/// ```
/// let either = Either(true, "Yes", "No");
/// ```
pub struct Either<E: Out, A, B>(pub bool, pub A, pub B, pub PhantomData<E>);
/// Increment X and/or Y coordinate.
///
/// ```
/// let pushed = Push::XY(2, 2, "Hello");
/// ```
pub enum Push<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
/// Decrement X and/or Y coordinate.
///
/// ```
/// let pulled = Pull::XY(2, 2, "Hello");
/// ```
pub enum Pull<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
/// Set the content to fill the container.
///
/// ```
/// let filled = Fill::XY("Hello");
/// ```
pub enum Fill<A> { X(A), Y(A), XY(A) }
/// Set fixed size for content.
///
/// ```
/// let fixed = Fixed::XY(3, 5, "Hello"); // 3x5
/// ```
pub enum Fixed<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
/// Set the maximum width and/or height of the content.
///
/// ```
/// let maximum = Min::XY(3, 5, "Hello"); // 3x1
/// ```
pub enum Max<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
/// Set the minimum width and/or height of the content.
///
/// ```
/// let minimam = Min::XY(3, 5, "Hello"); // 5x5
/// ```
pub enum Min<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
/// Decrease the width and/or height of the content.
///
/// ```
/// let shrunk = Shrink::XY(2, 0, "Hello"); // 1x1
/// ```
pub enum Shrink<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
/// Increaase the width and/or height of the content.
///
/// ```
/// let expanded = Expand::XY(5, 3, "HELLO"); // 15x3
/// ```
pub enum Expand<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
/// Align position of inner area to middle, side, or corner of outer area.
@ -130,8 +161,52 @@ 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), }
/// TODO DOCUMENTME
///
/// ```
/// let bounded = Bounded(XYWH(0, 0, 0, 0), "");
/// ```
pub struct Bounded<O: Out, D>(pub O::Area, pub D);
/// Draws items from an iterator.
///
/// ```
/// let map = Map(||[].iter(), |_|{});
/// ```
pub struct Map<O, A, B, I, F, G>
where
I: Iterator<Item = A> + Send + Sync,
F: Fn() -> I + Send + Sync,
{
/// Function that returns iterator over stacked components
pub get_iter: F,
/// Function that returns each stacked component
pub get_item: G,
pub __: PhantomData<(O, B)>,
}
// TODO DOCUMENTME
pub struct Lazy<O, T, F>(
pub F,
pub PhantomData<(O, T)>
);
// TODO DOCUMENTME
pub struct Thunk<O: Out, F: Fn(&mut O)>(
pub PhantomData<O>,
pub F
);
// TODO DOCUMENTME
#[derive(Debug, Default)] pub struct Memo<T, U> {
pub value: T,
pub view: Arc<RwLock<U>>
}
/// A binary split or layer.
pub struct Bsp<Head, Tail>(
/// Direction of split
pub(crate) Direction,
/// First element.
pub(crate) Head,