(&mut self)
| 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()); |
no test coverage detected