From 997610f23e87733d2b813d9e47eed89d0ac615af Mon Sep 17 00:00:00 2001 From: same mf who else Date: Sat, 14 Feb 2026 20:27:52 +0200 Subject: [PATCH] docs(out): docstrings --- output/src/out_structs.rs | 149 ++++++++++++++++++++++++++++---------- 1 file changed, 112 insertions(+), 37 deletions(-) diff --git a/output/src/out_structs.rs b/output/src/out_structs.rs index 0149443..22b6465 100644 --- a/output/src/out_structs.rs +++ b/output/src/out_structs.rs @@ -1,97 +1,128 @@ use crate::*; /// A point (X, Y). +/// +/// ``` +/// let xy: XY = XY(0, 0); +/// ``` pub struct XY(pub C, pub C); /// A size (Width, Height). +/// +/// ``` +/// let wh: WH = WH(0, 0); +/// ``` pub struct WH(pub C, pub C); /// Point with size. /// -/// TODO: anchor field (determines at which corner/side is X0 Y0) +/// ``` +/// let xywh: XYWH = XYWH(0, 0, 0, 0); +/// ``` +/// +/// * [ ] TODO: anchor field (determines at which corner/side is X0 Y0) +/// pub struct XYWH(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 { __: PhantomData, pub x: Arc, pub y: Arc, } -// TODO DOCUMENTME -pub struct Bounded(pub O::Area, pub D); - -/// Draws items from an iterator. -pub struct Map -where - I: Iterator + 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( - pub F, - pub PhantomData<(O, T)> -); - -// TODO DOCUMENTME -pub struct Thunk( - pub PhantomData, - pub F -); - -// TODO DOCUMENTME -#[derive(Debug, Default)] pub struct Memo { - pub value: T, - pub view: Arc> -} - /// Show an item only when a condition is true. +/// +/// ``` +/// let when = When(true, "Yes"); +/// ``` pub struct When(pub bool, pub T, pub PhantomData); -/// 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(pub bool, pub A, pub B, pub PhantomData); /// Increment X and/or Y coordinate. +/// +/// ``` +/// let pushed = Push::XY(2, 2, "Hello"); +/// ``` pub enum Push { 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 { 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 { X(A), Y(A), XY(A) } /// Set fixed size for content. +/// +/// ``` +/// let fixed = Fixed::XY(3, 5, "Hello"); // 3x5 +/// ``` pub enum Fixed { 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 { 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 { 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 { 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 { 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(pub Alignment, pub T); // TODO DOCUMENTME pub enum Pad { X(U, A), Y(U, A), XY(U, U, A), } +/// TODO DOCUMENTME +/// +/// ``` +/// let bounded = Bounded(XYWH(0, 0, 0, 0), ""); +/// ``` +pub struct Bounded(pub O::Area, pub D); + +/// Draws items from an iterator. +/// +/// ``` +/// let map = Map(||[].iter(), |_|{}); +/// ``` +pub struct Map +where + I: Iterator + 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( + pub F, + pub PhantomData<(O, T)> +); + +// TODO DOCUMENTME +pub struct Thunk( + pub PhantomData, + pub F +); + +// TODO DOCUMENTME +#[derive(Debug, Default)] pub struct Memo { + pub value: T, + pub view: Arc> +} + /// A binary split or layer. pub struct Bsp( + /// Direction of split pub(crate) Direction, /// First element. pub(crate) Head,