yakui_widgets/widgets/stack.rs
1use yakui_core::{widget::Widget, Response};
2
3use crate::util::widget_children;
4
5/**
6A [Stack] widget. This widget does nothing interesting on its own, but
7when used "inside" other layouts, such as [List](crate::widgets::List),
8it will stacks its own children, rather than following the layout of its own parent.
9This internal layouting is just using yakui's default layout algorithm.
10
11Responds with [StackResponse].
12
13Shorthand:
14```rust
15# let _handle = yakui_widgets::DocTest::start();
16yakui::column(|| {
17 yakui::label("on top");
18 yakui::stack(|| {
19 // this would compose, by being stacked,
20 // to appear like "hello world", barring issues from spacing,
21 // as opposed to continuing the columnar layout setup above.
22 yakui::text(12.0, "hello");
23 yakui::text(12.0, " world");
24 });
25 yakui::label("on bottom");
26});
27```
28*/
29#[derive(Debug, Default)]
30#[non_exhaustive]
31pub struct Stack {}
32
33impl Stack {
34 /// Creates a new [Stack].
35 pub fn new() -> Self {
36 Self {}
37 }
38
39 /// Shows the [Stack] along with its children.
40 pub fn show<F: FnOnce()>(self, children: F) -> Response<StackResponse> {
41 widget_children::<StackWidget, F>(children, self)
42 }
43}
44
45#[derive(Debug)]
46pub struct StackWidget;
47
48pub type StackResponse = ();
49
50impl Widget for StackWidget {
51 type Props<'a> = Stack;
52
53 type Response = StackResponse;
54
55 fn new() -> Self {
56 Self
57 }
58
59 fn update(&mut self, _props: Self::Props<'_>) -> Self::Response {
60 // nothing here
61 }
62}