Skip to main content

vstack_aligned

Function vstack_aligned 

Source
pub fn vstack_aligned(children: &[View], alignment: HorizontalAlignment) -> View
Expand description

VStack(alignment:) { … } — how children line up across the stack’s width.

Examples found in repository?
examples/inbox.rs (lines 87-93)
77fn row(i: usize) -> View {
78    let m = &MESSAGES[i];
79    hstack_spacing(
80        &[
81            // An unread dot, or the space where one would be.
82            view_if!(
83                m.unread,
84                circle_shape().fill_system(SystemColor::Blue).frame(8.0, 8.0),
85                empty().frame(8.0, 8.0)
86            ),
87            vstack_aligned(
88                &[
89                    text(m.from).bold(),
90                    text(m.subject).font_size(12.0).fg_system(SystemColor::Gray),
91                ],
92                HorizontalAlignment::Leading,
93            ),
94            spacer(),
95        ],
96        8.0,
97    )
98    .padding_edges(EdgeSet::Vertical, Some(4.0))
99    .a11y_label(&format!("{}, {}", m.from, m.subject))
100    .a11y_hint(if m.unread { "Unread" } else { "Read" })
101}
More examples
Hide additional examples
examples/dashboard.rs (lines 62-70)
54fn body() -> View {
55    vstack_aligned_spacing(
56        &[
57            text("System").text_style(TextStyle::LargeTitle).bold(),
58            grid(&[grid_row(&[tile(0), tile(1), tile(2)])]),
59            divider(),
60            // A gauge over the busiest reading, which is a different control
61            // from the rings and reads the same state.
62            vstack_aligned(
63                &[
64                    text("Busiest").font_size(12.0).fg_system(SystemColor::Gray),
65                    gauge(reading(1), 0.0, 1.0, text("Memory"))
66                        .gauge_style(views::GaugeStyle::AccessoryLinearCapacityGaugeStyle)
67                        .tint_system(SystemColor::Orange),
68                ],
69                HorizontalAlignment::Leading,
70            ),
71            spacer(),
72            button("Refresh", refresh)
73                .button_style(views::ButtonStyle::BorderedProminent)
74                .keyboard_shortcut(KeyboardShortcut::DefaultAction),
75        ],
76        HorizontalAlignment::Leading,
77        Some(16.0),
78    )
79    .padding(20.0)
80    // Animate whatever changed, rather than snapping to the new reading.
81    .animation(LOAD[0].load(Ordering::Relaxed) as i64)
82}
examples/settings.rs (lines 58-65)
43fn body() -> View {
44    let s = settings();
45
46    form![
47        section![header: text("Account");
48            hstack![
49                text("Name"),
50                spacer(),
51                textfield_bound("Your name", &s.name).text_field_style(
52                    views::TextFieldStyle::RoundedBorderTextFieldStyle,
53                ),
54            ],
55            toggle_bound("Notifications", &s.notify),
56        ],
57        section![header: text("Playback");
58            vstack_aligned(&[
59                hstack![
60                    text("Volume"),
61                    spacer(),
62                    text!("{:.0}%", s.volume.get() * 100.0).fg_system(SystemColor::Gray),
63                ],
64                slider_bound(&s.volume, 0.0, 1.0),
65            ], HorizontalAlignment::Leading),
66            stepper_bound("Refresh every", &s.refresh, 1.0, 60.0, 1.0),
67        ],
68        section![header: text("Appearance");
69            picker_bound!(
70                "Theme",
71                &s.theme,
72                text(THEMES[0]).tag_int(0),
73                text(THEMES[1]).tag_int(1),
74                text(THEMES[2]).tag_int(2),
75            )
76            .picker_style(PickerStyle::InlinePickerStyle),
77        ],
78        section![
79            button("About", show_about)
80                .a11y_hint("Opens a panel describing this app"),
81        ],
82    ]
83    .form_style(FormStyle::GroupedFormStyle)
84    .sheet_bound(&s.about, about_panel())
85}