1use gpui::{div, px, App, IntoElement, ParentElement, RenderOnce, Styled, Window};
4
5use crate::alignment::HorizontalAlignment;
6use crate::modifier::Modifier;
7
8#[derive(IntoElement)]
22pub struct VStack {
23 spacing: f32,
24 alignment: HorizontalAlignment,
25 children: Vec<gpui::AnyElement>,
26}
27
28impl VStack {
29 pub fn new() -> Self {
31 Self {
32 spacing: 8.0,
33 alignment: HorizontalAlignment::Center, children: Vec::new(),
35 }
36 }
37
38 pub fn spacing(mut self, spacing: f32) -> Self {
40 self.spacing = spacing;
41 self
42 }
43
44 pub fn alignment(mut self, alignment: HorizontalAlignment) -> Self {
46 self.alignment = alignment;
47 self
48 }
49
50 impl_child_methods!();
51}
52
53impl Default for VStack {
54 fn default() -> Self {
55 Self::new()
56 }
57}
58
59impl Modifier for VStack {}
60
61impl RenderOnce for VStack {
62 fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
63 let container = div().flex().flex_col().gap(px(self.spacing));
64 self.alignment
65 .apply_as_items(container)
66 .children(self.children)
67 }
68}