MCPcopy Create free account
hub / github.com/algoscienceacademy/RustUI / rebuild_ui

Method rebuild_ui

examples/todo_app.rs:27–87  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

25 }
26
27 fn rebuild_ui(&mut self) {
28 let todos = self.todos.clone();
29
30 let mut main_view = View::new()
31 .with_layout(Layout::Column);
32
33 // Apply platform-specific styling
34 {
35 let style = main_view.style_mut().modify();
36 style.gap = 10.0;
37
38 #[cfg(target_os = "ios")]
39 {
40 style.padding = 20.0; // Account for iOS safe area
41 }
42
43 #[cfg(target_os = "android")]
44 {
45 style.padding = 16.0; // Material Design spacing
46 }
47
48 #[cfg(target_arch = "wasm32")]
49 {
50 style.padding = 12.0; // Web spacing
51 }
52 }
53
54 // Create platform-specific title
55 let mut title = Text::new("RustUI Todo App");
56 {
57 let style = title.style_mut().modify();
58 style.font_size = match std::env::var("PLATFORM").unwrap_or_default().as_str() {
59 "ios" => 34.0,
60 "android" => 28.0,
61 "web" => 24.0,
62 _ => 24.0,
63 };
64 style.text_align = TextAlign::Center;
65 }
66 main_view = main_view.child(title);
67
68 // Add new todo button
69 let mut add_button = Button::new("Add Todo");
70 {
71 let style = add_button.style_mut();
72 style.padding = 10.0;
73 style.background = Color::rgb(0.2, 0.6, 1.0);
74 }
75
76 let todos_ref = todos.clone();
77 add_button = add_button.on_click(move || {
78 if let Ok(mut todos) = todos_ref.lock() {
79 todos.push(Todo::default());
80 }
81 });
82
83 main_view = main_view.child(add_button);
84 main_view = main_view.child(self.build_todo_list());

Callers 1

newMethod · 0.45

Calls 7

with_layoutMethod · 0.80
modifyMethod · 0.80
on_clickMethod · 0.80
pushMethod · 0.80
style_mutMethod · 0.45
childMethod · 0.45
build_todo_listMethod · 0.45

Tested by

no test coverage detected