diff --git a/crates/yakui-widgets/src/shorthand.rs b/crates/yakui-widgets/src/shorthand.rs index 2fcf5b6c..bfcbb68f 100644 --- a/crates/yakui-widgets/src/shorthand.rs +++ b/crates/yakui-widgets/src/shorthand.rs @@ -15,8 +15,8 @@ use crate::widgets::{ ConstrainedBoxResponse, CountGrid, Divider, DividerResponse, Draggable, DraggableResponse, Flexible, FlexibleResponse, Image, ImageResponse, List, ListResponse, MaxWidth, MaxWidthResponse, NineSlice, Offset, OffsetResponse, Opaque, OpaqueResponse, Pad, PadResponse, - Reflow, ReflowResponse, Scrollable, ScrollableResponse, Slider, SliderResponse, Spacer, State, - StateResponse, Text, TextBox, TextBoxResponse, TextResponse, + Reflow, ReflowResponse, Scrollable, ScrollableResponse, Slider, SliderResponse, Spacer, Stack, + StackResponse, State, StateResponse, Text, TextBox, TextBoxResponse, TextResponse, }; /// See [List]. @@ -192,6 +192,11 @@ pub fn max_width(max_width: f32, children: impl FnOnce()) -> Response Response { + Stack::new().show(children) +} + pub fn use_state(default: F) -> Response> where F: FnOnce() -> T + 'static, diff --git a/crates/yakui-widgets/src/widgets/mod.rs b/crates/yakui-widgets/src/widgets/mod.rs index bbe1ae2b..2e75a8b7 100644 --- a/crates/yakui-widgets/src/widgets/mod.rs +++ b/crates/yakui-widgets/src/widgets/mod.rs @@ -26,6 +26,7 @@ mod round_rect; mod scrollable; mod slider; mod spacer; +mod stack; mod state; mod text; mod textbox; @@ -60,6 +61,7 @@ pub use self::round_rect::*; pub use self::scrollable::*; pub use self::slider::*; pub use self::spacer::*; +pub use self::stack::*; pub use self::state::*; pub use self::text::*; pub use self::textbox::*; diff --git a/crates/yakui-widgets/src/widgets/stack.rs b/crates/yakui-widgets/src/widgets/stack.rs new file mode 100644 index 00000000..360e7388 --- /dev/null +++ b/crates/yakui-widgets/src/widgets/stack.rs @@ -0,0 +1,62 @@ +use yakui_core::{widget::Widget, Response}; + +use crate::util::widget_children; + +/** +A [Stack] widget. This widget does nothing interesting on its own, but +when used "inside" other layouts, such as [List](crate::widgets::List), +it will stacks its own children, rather than following the layout of its own parent. +This internal layouting is just using yakui's default layout algorithm. + +Responds with [StackResponse]. + +Shorthand: +```rust +# let _handle = yakui_widgets::DocTest::start(); +yakui::column(|| { + yakui::label("on top"); + yakui::stack(|| { + // this would compose, by being stacked, + // to appear like "hello world", barring issues from spacing, + // as opposed to continuing the columnar layout setup above. + yakui::text(12.0, "hello"); + yakui::text(12.0, " world"); + }); + yakui::label("on bottom"); +}); +``` +*/ +#[derive(Debug, Default)] +#[non_exhaustive] +pub struct Stack {} + +impl Stack { + /// Creates a new [Stack]. + pub fn new() -> Self { + Self {} + } + + /// Shows the [Stack] along with its children. + pub fn show(self, children: F) -> Response { + widget_children::(children, self) + } +} + +#[derive(Debug)] +pub struct StackWidget; + +pub type StackResponse = (); + +impl Widget for StackWidget { + type Props<'a> = Stack; + + type Response = StackResponse; + + fn new() -> Self { + Self + } + + fn update(&mut self, _props: Self::Props<'_>) -> Self::Response { + // nothing here + } +}