1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
//! Complex UI Demo - Multi-Panel Application Showcase
//!
//! This example demonstrates a sophisticated multi-panel UI with:
//! - Multi-column layout with navigation sidebar
//! - Dashboard with data cards and statistics
//! - Forms with various input types
//! - Nested containers and layouts
//! - Mixed interactive widgets (buttons, text inputs, etc.)
//!
//! This showcases the full power of the Astrelis UI system with proper
//! composition, nesting, and layout management.
use astrelis_core::logging;
use astrelis_core::profiling::{ProfilingBackend, init_profiling, new_frame};
use astrelis_render::{Color, GraphicsContext, RenderWindow, RenderWindowBuilder, wgpu};
use astrelis_ui::UiSystem;
use astrelis_winit::{
FrameTime, WindowId,
app::{App, AppCtx, run_app},
event::{Event, EventBatch, HandleStatus},
window::{WindowDescriptor, WinitPhysicalSize},
};
struct ComplexUiApp {
window: RenderWindow,
window_id: WindowId,
ui: UiSystem,
stats: AppStats,
}
#[derive(Clone, Copy)]
struct AppStats {
active_users: u32,
total_revenue: f32,
tasks_completed: u32,
success_rate: f32,
}
impl Default for AppStats {
fn default() -> Self {
Self {
active_users: 1247,
total_revenue: 45678.9,
tasks_completed: 328,
success_rate: 94.5,
}
}
}
fn main() {
logging::init();
init_profiling(ProfilingBackend::PuffinHttp);
run_app(|ctx| {
let graphics_ctx =
GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
let window = ctx
.create_window(WindowDescriptor {
title: "Complex UI Demo - Multi-Panel Showcase".to_string(),
size: Some(WinitPhysicalSize::new(1600.0, 900.0)),
..Default::default()
})
.expect("Failed to create window");
let window = RenderWindowBuilder::new()
.color_format(wgpu::TextureFormat::Bgra8UnormSrgb)
.with_depth_default()
.build(window, graphics_ctx.clone())
.expect("Failed to create render window");
let window_id = window.id();
let size = window.physical_size();
let mut ui = UiSystem::from_window(graphics_ctx.clone(), &window);
ui.set_viewport(window.viewport());
let stats = AppStats::default();
// Build initial UI
build_complex_ui(&mut ui, size.width as f32, size.height as f32, stats);
println!("\n═══════════════════════════════════════════════════════");
println!(" 📊 COMPLEX UI DEMO - Multi-Panel Application");
println!("═══════════════════════════════════════════════════════");
println!("\n FEATURES:");
println!(" • Multi-column layout with sidebar navigation");
println!(" • Real-time dashboard with statistics cards");
println!(" • Interactive forms with text inputs");
println!(" • Activity feed with recent events");
println!(" • Nested containers and flexbox layouts");
println!("\n This showcases full UI composition capabilities!");
println!(" Resize the window to see responsive layout updates.");
println!("═══════════════════════════════════════════════════════\n");
tracing::info!("Complex UI demo initialized");
Box::new(ComplexUiApp {
window,
window_id,
ui,
stats,
})
});
}
fn build_complex_ui(ui: &mut UiSystem, width: f32, height: f32, stats: AppStats) {
let theme = ui.theme().clone();
let colors = &theme.colors;
ui.build(|root| {
// Main container - full screen
root.container()
.width(width)
.height(height)
.background_color(colors.background)
.child(|root| {
// Horizontal layout - sidebar + main content
root.row()
.child(|root| {
// Left sidebar - navigation
root.container()
.width(250.0)
.background_color(colors.background)
.border_color(colors.border)
.border_width(1.0)
.padding(20.0)
.child(|root| {
root.column()
.gap(20.0)
.child(|root| {
// Logo/Title area
root.container()
.padding(10.0)
.child(|root| {
root.text("Astrelis")
.size(28.0)
.color(colors.info)
.bold()
.build()
})
.build()
})
.child(|root| {
// Navigation menu
root.column()
.gap(8.0)
.child(|root| {
root.button("Dashboard")
.background_color(colors.primary)
.padding(12.0)
.font_size(14.0)
.min_width(200.0)
.build()
})
.child(|root| {
root.button("Analytics")
.background_color(colors.surface)
.padding(12.0)
.font_size(14.0)
.min_width(200.0)
.build()
})
.child(|root| {
root.button("Settings")
.background_color(colors.surface)
.padding(12.0)
.font_size(14.0)
.min_width(200.0)
.build()
})
.child(|root| {
root.button("Users")
.background_color(colors.surface)
.padding(12.0)
.font_size(14.0)
.min_width(200.0)
.build()
})
.build()
})
.child(|root| {
// Footer in sidebar
root.container()
.margin(20.0)
.child(|root| {
root.text("Version 0.1.0")
.size(11.0)
.color(colors.text_disabled)
.build()
})
.build()
})
.build()
})
.build()
})
.child(|root| {
// Main content area
root.container()
.background_color(colors.background)
.padding(30.0)
.child(|root| {
root.column()
.gap(25.0)
.child(|root| {
// Header
root.container()
.child(|root| {
root.column()
.gap(8.0)
.child(|root| {
root.text("Dashboard Overview")
.size(32.0)
.color(colors.text_primary)
.bold()
.build()
})
.child(|root| {
root.text("Real-time application metrics and controls")
.size(14.0)
.color(colors.text_secondary)
.build()
})
.build()
})
.build()
})
.child(|root| {
// Statistics cards row
root.row()
.gap(20.0)
.child(|root| {
build_stat_card(root, &theme, "Active Users",
&format!("{}", stats.active_users),
Color::from_rgb_u8(100, 200, 150))
})
.child(|root| {
build_stat_card(root, &theme, "Revenue",
&format!("${:.2}", stats.total_revenue),
Color::from_rgb_u8(100, 180, 255))
})
.child(|root| {
build_stat_card(root, &theme, "Tasks",
&format!("{}", stats.tasks_completed),
Color::from_rgb_u8(255, 180, 100))
})
.child(|root| {
build_stat_card(root, &theme, "Success Rate",
&format!("{:.1}%", stats.success_rate),
Color::from_rgb_u8(200, 100, 255))
})
.build()
})
.child(|root| {
// Two-column content area
root.row()
.gap(20.0)
.child(|root| {
// Left column - Form
root.container()
.background_color(colors.surface)
.border_radius(12.0)
.padding(20.0)
.min_width(400.0)
.child(|root| {
root.column()
.gap(15.0)
.child(|root| {
root.text("Create New Task")
.size(20.0)
.color(colors.text_primary)
.bold()
.build()
})
.child(|root| {
root.text("Task Name")
.size(12.0)
.color(colors.text_secondary)
.build()
})
.child(|root| {
root.text_input("Enter task name...")
.padding(10.0)
.min_width(350.0)
.build()
})
.child(|root| {
root.text("Description")
.size(12.0)
.color(colors.text_secondary)
.build()
})
.child(|root| {
root.text_input("Enter description...")
.padding(10.0)
.min_width(350.0)
.build()
})
.child(|root| {
// Form buttons
root.row()
.gap(10.0)
.child(|root| {
root.button("Create Task")
.background_color(colors.success)
.padding(12.0)
.font_size(14.0)
.build()
})
.child(|root| {
root.button("Cancel")
.background_color(colors.surface)
.padding(12.0)
.font_size(14.0)
.build()
})
.build()
})
.build()
})
.build()
})
.child(|root| {
// Right column - Recent activity list
root.container()
.background_color(colors.surface)
.border_radius(12.0)
.padding(20.0)
.child(|root| {
root.column()
.gap(12.0)
.child(|root| {
root.text("Recent Activity")
.size(20.0)
.color(colors.text_primary)
.bold()
.build()
})
.child(|root| {
build_activity_item(root, &theme, "User logged in", "2 minutes ago")
})
.child(|root| {
build_activity_item(root, &theme, "Task completed", "15 minutes ago")
})
.child(|root| {
build_activity_item(root, &theme, "New user registered", "1 hour ago")
})
.child(|root| {
build_activity_item(root, &theme, "System backup completed", "3 hours ago")
})
.child(|root| {
build_activity_item(root, &theme, "Database optimized", "6 hours ago")
})
.build()
})
.build()
})
.build()
})
.build()
})
.build()
})
.build()
})
.build();
});
}
fn build_stat_card(
root: &mut astrelis_ui::UiBuilder,
theme: &astrelis_ui::Theme,
title: &str,
value: &str,
color: Color,
) -> astrelis_ui::NodeId {
let colors = &theme.colors;
root.container()
.background_color(colors.surface)
.border_radius(10.0)
.padding(20.0)
.min_width(150.0)
.child(|root| {
root.column()
.gap(10.0)
.child(|root| {
root.text(title)
.size(12.0)
.color(colors.text_secondary)
.build()
})
.child(|root| root.text(value).size(26.0).color(color).bold().build())
.build()
})
.build()
}
fn build_activity_item(
root: &mut astrelis_ui::UiBuilder,
theme: &astrelis_ui::Theme,
title: &str,
time: &str,
) -> astrelis_ui::NodeId {
let colors = &theme.colors;
root.container()
.background_color(colors.surface)
.border_radius(6.0)
.padding(12.0)
.child(|root| {
root.column()
.gap(4.0)
.child(|root| {
root.text(title)
.size(14.0)
.color(colors.text_primary)
.build()
})
.child(|root| {
root.text(time)
.size(11.0)
.color(colors.text_secondary)
.build()
})
.build()
})
.build()
}
impl App for ComplexUiApp {
fn update(&mut self, _ctx: &mut AppCtx, _time: &FrameTime) {
new_frame();
self.ui.update(0.016);
}
fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
if window_id != self.window_id {
return;
}
// Handle window resize
events.dispatch(|event| {
if let Event::WindowResized(size) = event {
self.window.resized(*size);
self.ui.set_viewport(self.window.viewport());
build_complex_ui(
&mut self.ui,
size.width as f32,
size.height as f32,
self.stats,
);
return HandleStatus::consumed();
}
HandleStatus::ignored()
});
// Handle UI events
self.ui.handle_events(events);
// Begin frame and render with depth buffer for proper z-ordering
let bg = self.ui.theme().colors.background;
let Some(frame) = self.window.begin_frame() else {
return; // Surface not available
};
{
let mut pass = frame
.render_pass()
.clear_color(bg)
.with_window_depth()
.clear_depth(0.0)
.label("UI")
.build();
self.ui.render(pass.wgpu_pass());
}
// Frame auto-submits on drop
}
}