Seregon/StratoSDK

StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.

Rust/27.3 KB/No license
examples/complex_demo/src/main.rs
1use strato_core::inspector::{inspector, InspectorConfig};
2use strato_core::types::Color;
3use strato_platform::{application::Application, window::WindowBuilder};
4use strato_widgets::{
5 layout::{CrossAxisAlignment, MainAxisAlignment},
6 text::{FontWeight, TextAlign},
7 Button, ButtonStyle, Column, Container, InspectorOverlay, Row, Text, TextStyle, Widget,
8};
9 
10fn main() -> anyhow::Result<()> {
11 // Create application
12 let window_builder = WindowBuilder::new()
13 .with_title("Complex Demo")
14 .with_size(1024.0, 768.0)
15 .resizable(true);
16 
17 inspector().configure(InspectorConfig {
18 enabled: true,
19 ..Default::default()
20 });
21 
22 let mut app = Application::new("Complex Demo", window_builder);
23 
24 // Create UI structure
25 // Main container with background
26 let main_container = InspectorOverlay::new(
27 Container::new()
28 .background(Color::rgba(0.95, 0.95, 0.97, 1.0)) // Light gray background
29 .padding(20.0)
30 .child(
31 Column::new()
32 .spacing(20.0)
33 .main_axis_alignment(MainAxisAlignment::Start)
34 .cross_axis_alignment(CrossAxisAlignment::Stretch)
35 .children(vec![
36 // Header Section
37 create_header(),
38 // Content Section (Row with Sidebar and Main Content)
39 Box::new(Row::new().spacing(20.0).children(vec![
40 // Sidebar
41 create_sidebar(),
42 // Main Content Area
43 create_main_content(),
44 ])) as Box<dyn Widget>,
45 ]),
46 ),
47 );
48 
49 app.set_root(Box::new(main_container));
50 
51 println!("Starting Complex Demo...");
52 app.run()
53}
54 
55fn create_header() -> Box<dyn Widget> {
56 Box::new(
57 Container::new()
58 .background(Color::rgba(1.0, 1.0, 1.0, 1.0))
59 .padding(15.0)
60 .border_radius(8.0)
61 .child(
62 Row::new()
63 .main_axis_alignment(MainAxisAlignment::SpaceBetween)
64 .cross_axis_alignment(CrossAxisAlignment::Center)
65 .children(vec![
66 Box::new(
67 Text::new("StratoUI Dashboard")
68 .font_size(24.0)
69 .font_weight(FontWeight::Bold)
70 .color(Color::rgba(0.1, 0.1, 0.2, 1.0)),
71 ) as Box<dyn Widget>,
72 Box::new(Row::new().spacing(10.0).children(vec![
73 Box::new(Button::new("Settings").ghost()) as Box<dyn Widget>,
74 Box::new(Button::new("Profile").primary()) as Box<dyn Widget>,
75 ])) as Box<dyn Widget>,
76 ]),
77 ),
78 )
79}
80 
81fn create_sidebar() -> Box<dyn Widget> {
82 Box::new(
83 Container::new()
84 .width(200.0)
85 .background(Color::rgba(1.0, 1.0, 1.0, 1.0))
86 .padding(10.0)
87 .border_radius(8.0)
88 .child(
89 Column::new()
90 .spacing(5.0)
91 .cross_axis_alignment(CrossAxisAlignment::Stretch)
92 .children(vec![
93 Box::new(
94 Text::new("MENU")
95 .font_size(12.0)
96 .color(Color::rgba(0.5, 0.5, 0.5, 1.0)),
97 ) as Box<dyn Widget>,
98 Box::new(
99 Button::new("Dashboard")
100 .ghost()
101 .on_click(|| println!("Dashboard clicked")),
102 ) as Box<dyn Widget>,
103 Box::new(Button::new("Analytics").ghost()) as Box<dyn Widget>,
104 Box::new(Button::new("Reports").ghost()) as Box<dyn Widget>,
105 Box::new(Button::new("Users").ghost()) as Box<dyn Widget>,
106 Box::new(Container::new().height(20.0)) as Box<dyn Widget>, // Spacer
107 Box::new(
108 Text::new("SYSTEM")
109 .font_size(12.0)
110 .color(Color::rgba(0.5, 0.5, 0.5, 1.0)),
111 ) as Box<dyn Widget>,
112 Box::new(Button::new("Configuration").ghost()) as Box<dyn Widget>,
113 Box::new(Button::new("Logs").ghost()) as Box<dyn Widget>,
114 ]),
115 ),
116 )
117}
118 
119fn create_main_content() -> Box<dyn Widget> {
120 Box::new(Container::new()
121 .background(Color::rgba(1.0, 1.0, 1.0, 1.0))
122 .padding(20.0)
123 .border_radius(8.0)
124 .child(
125 Column::new()
126 .spacing(15.0)
127 .cross_axis_alignment(CrossAxisAlignment::Start)
128 .children(vec![
129 Box::new(
130 Text::new("Welcome back, User!")
131 .font_size(20.0)
132 .font_weight(FontWeight::SemiBold)
133 ) as Box<dyn Widget>,
134 Box::new(
135 Text::new("Here is an overview of your system status. This text demonstrates automatic wrapping and layout capabilities of the StratoUI framework. It should flow naturally within the container.")
136 .color(Color::rgba(0.3, 0.3, 0.3, 1.0))
137 .style(TextStyle {
138 line_height: 1.6,
139 ..TextStyle::default()
140 })
141 ) as Box<dyn Widget>,
142 Box::new(Container::new().height(20.0)) as Box<dyn Widget>, // Spacer
143 
144 // Cards Row
145 Box::new(
146 Row::new()
147 .spacing(15.0)
148 .children(vec![
149 create_card("Total Users", "1,234", Color::rgba(0.2, 0.6, 1.0, 0.1)),
150 create_card("Active Sessions", "56", Color::rgba(0.2, 0.8, 0.4, 0.1)),
151 create_card("Server Load", "42%", Color::rgba(1.0, 0.6, 0.2, 0.1)),
152 ])
153 ) as Box<dyn Widget>,
154 
155 Box::new(Container::new().height(20.0)) as Box<dyn Widget>, // Spacer
156 
157 // Typography Showcase
158 Box::new(Text::new("Typography & Spacing").font_size(18.0).font_weight(FontWeight::Medium)) as Box<dyn Widget>,
159 Box::new(
160 Text::new("Wide Spacing Example")
161 .style(TextStyle {
162 letter_spacing: 2.0,
163 ..TextStyle::default()
164 })
165 ) as Box<dyn Widget>,
166 Box::new(
167 Text::new("Tight Spacing Example")
168 .style(TextStyle {
169 letter_spacing: -0.5,
170 ..TextStyle::default()
171 })
172 ) as Box<dyn Widget>,
173 ])
174 ))
175}
176 
177fn create_card(title: &str, value: &str, bg_color: Color) -> Box<dyn Widget> {
178 Box::new(
179 Container::new()
180 .width(150.0)
181 .height(100.0)
182 .background(bg_color)
183 .border_radius(8.0)
184 .padding(15.0)
185 .child(
186 Column::new()
187 .main_axis_alignment(MainAxisAlignment::Center)
188 .cross_axis_alignment(CrossAxisAlignment::Start)
189 .children(vec![
190 Box::new(
191 Text::new(title)
192 .font_size(14.0)
193 .color(Color::rgba(0.4, 0.4, 0.4, 1.0)),
194 ) as Box<dyn Widget>,
195 Box::new(
196 Text::new(value)
197 .font_size(24.0)
198 .font_weight(FontWeight::Bold),
199 ) as Box<dyn Widget>,
200 ]),
201 ),
202 )
203}
204