vizia_core/views/
stack.rs

1use crate::prelude::*;
2
3/// A view which arranges its children into a vertical stack (column).
4///
5///
6pub struct VStack {}
7
8impl VStack {
9    /// Creates a new [VStack].
10    pub fn new<F>(cx: &mut Context, content: F) -> Handle<Self>
11    where
12        F: FnOnce(&mut Context),
13    {
14        Self {}
15            .build(cx, |cx| {
16                (content)(cx);
17            })
18            .role(Role::GenericContainer)
19    }
20}
21
22impl View for VStack {
23    fn element(&self) -> Option<&'static str> {
24        Some("vstack")
25    }
26}
27
28/// A view which arranges its children into a horizontal stack (row).
29pub struct HStack {}
30
31impl HStack {
32    /// Creates a new [HStack].
33    pub fn new<F>(cx: &mut Context, content: F) -> Handle<Self>
34    where
35        F: FnOnce(&mut Context),
36    {
37        Self {}
38            .build(cx, |cx| {
39                (content)(cx);
40            })
41            .layout_type(LayoutType::Row)
42            .role(Role::GenericContainer)
43    }
44}
45
46impl View for HStack {
47    fn element(&self) -> Option<&'static str> {
48        Some("hstack")
49    }
50}
51
52/// A view which overlays its children on top of each other.
53pub struct ZStack {}
54
55impl ZStack {
56    /// Creates a new [ZStack].
57    pub fn new<F>(cx: &mut Context, content: F) -> Handle<Self>
58    where
59        F: FnOnce(&mut Context),
60    {
61        Self {}.build(cx, |cx| {
62            (content)(cx);
63        })
64    }
65}
66
67impl View for ZStack {
68    fn element(&self) -> Option<&'static str> {
69        Some("zstack")
70    }
71}