pub fn empty() -> ViewExpand description
Create an EmptyView.
Examples found in repository?
examples/inbox.rs (line 85)
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
examples/sugar.rs (line 23)
4fn main() {
5 let show_detail = true;
6 let items = vec![String::from("alpha"), String::from("beta")];
7
8 let sugared = swiftui! {
9 VStack(spacing: 8.0) {
10 Text("Title").text_style(.large_title)
11 if show_detail {
12 Text("the details")
13 }
14 ForEach(items) { item in
15 Text(item)
16 }
17 }
18 };
19
20 let by_hand = vstack_spacing(
21 &[
22 text("Title").text_style(views::TextStyle::LargeTitle),
23 conditional(show_detail, text("the details"), empty()),
24 for_each_items(&items, |item| text(item)),
25 ],
26 8.0,
27 );
28
29 let a = views::dump_value_to_depth(&sugared.into_handle(), 6);
30 let b = views::dump_value_to_depth(&by_hand.into_handle(), 6);
31 eprintln!("macro == hand-written? {}", a == b);
32 if a != b {
33 for (x, y) in a.lines().zip(b.lines()) {
34 if x != y {
35 eprintln!(" macro: {}\n hand : {}", x.trim(), y.trim());
36 break;
37 }
38 }
39 }
40}