euv_example/pages/data/
fn.rs1use super::*;
2
3pub(crate) fn mount_data_vlist_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
14 let palette: ThemePalette = tokens.get_palette();
15 let scroll_y: Signal<f32> = state.get_list_scroll_y();
16 let vlist: EuvVirtualList =
17 EuvVirtualList::new(DATA_VLIST_ROWS, DATA_VLIST_ROW_H, scroll_y, tokens)
18 .viewport_height(DATA_VLIST_VIEWPORT_H);
19 let vlist_down: EuvVirtualList = vlist.clone();
20 let list_node: NodeId = vlist.mount_with(move |idx: usize| {
21 let live: ThemeTokens = live_tokens_untracked(tokens);
22 let live_p: ThemePalette = live.get_palette();
23 let live_g: ThemeGeometry = live.get_geometry();
24 let row_label: String = format!("{DATA_ROW_PREFIX}{idx}");
25 let row_style: Style = style! {
26 Width(Length::Percent(100.0))
27 Height(Length::Px(DATA_VLIST_ROW_H))
28 Padding(Edges::symmetric(SPACE_XS, SPACE_MD))
29 AlignItems::Center
30 Border::new(live_g.get_border_width(), live_p.get_border())
31 };
32 let text_fifth_style: Style = style! {
33 Width(Length::Percent(100.0))
34 FontSize(13.0)
35 TextColor(live_p.get_foreground())
36 };
37 view! {
38 row {
39 style: row_style
40 text {
41 style: text_fifth_style
42 { row_label }
43 }
44 }
45 }
46 });
47 let on_scroll_down = move |_: &UiEvent| {
48 vlist_down.scroll_by(160.0);
49 };
50 let on_scroll_top = move |_: &UiEvent| {
51 let _: bool = scroll_y.set_if_changed(0.0);
52 };
53 let scroll_readout = move || -> String {
54 let pos_y: f32 = scroll_y.get();
55 let top_row: usize = (pos_y / DATA_VLIST_ROW_H).floor() as usize;
56 format!("scroll_y={pos_y:.0}px | top_row=#{top_row} / {DATA_VLIST_ROWS}")
57 };
58 let column_quaternary_style: Style = style! {
59 Width(Length::Percent(100.0))
60 Gap(SPACE_MD)
61 };
62 let text_quaternary_style: Style = style! {
63 Width(Length::Percent(100.0))
64 FontSize(12.0)
65 TextColor(palette.get_muted_foreground())
66 };
67 view! {
68 EuvCard {
69 title: DATA_VLIST_TITLE.to_string()
70 tokens: tokens
71 subtitle: DATA_VLIST_SUB
72 column {
73 style: column_quaternary_style
74 EuvActionRow {
75 EuvButton {
76 label: DATA_BTN_SCROLL_DOWN.to_string()
77 tokens: tokens
78 small()
79 on_click: on_scroll_down
80 }
81 EuvButton {
82 label: DATA_BTN_SCROLL_TOP.to_string()
83 tokens: tokens
84 outline()
85 small()
86 on_click: on_scroll_top
87 }
88 }
89 text {
90 style: text_quaternary_style
91 { scroll_readout }
92 }
93 { list_node }
94 }
95 }
96 }
97}
98
99pub(crate) fn mount_data_datatable_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
110 let palette: ThemePalette = tokens.get_palette();
111 let sort_asc: Signal<bool> = state.get_lab_table_sort_asc();
112 let selected_row: Signal<Option<usize>> = state.get_lab_table_selected();
113 let headers: Vec<String> = vec![
114 DATA_DTABLE_H_TARGET.to_string(),
115 DATA_DTABLE_H_FONT.to_string(),
116 DATA_DTABLE_H_STATUS.to_string(),
117 ];
118 let rows: Vec<Vec<String>> = vec![
119 vec![
120 LABEL_PLATFORM_ANDROID.to_string(),
121 DATA_DTABLE_R1_FONT.to_string(),
122 DATA_DTABLE_R1_STATUS.to_string(),
123 ],
124 vec![
125 DATA_DTABLE_R2_TARGET.to_string(),
126 DATA_DTABLE_R2_FONT.to_string(),
127 DATA_DTABLE_R2_STATUS.to_string(),
128 ],
129 vec![
130 LABEL_PLATFORM_MACOS.to_string(),
131 DATA_DTABLE_R3_FONT.to_string(),
132 DATA_DTABLE_R3_STATUS.to_string(),
133 ],
134 vec![
135 DATA_DTABLE_R4_TARGET.to_string(),
136 DATA_DTABLE_R4_FONT.to_string(),
137 DATA_DTABLE_R4_STATUS.to_string(),
138 ],
139 ];
140 let table_readout = move || -> String {
141 let dir: &str = if sort_asc.get() { "ASC" } else { "DESC" };
142 let sel: String = selected_row
143 .get()
144 .map(|idx: usize| format!("Row #{idx}"))
145 .unwrap_or_else(|| DATA_TREE_NONE.to_string());
146 format!("Sort: {dir} | Selected: {sel}")
147 };
148 let column_tertiary_style: Style = style! {
149 Width(Length::Percent(100.0))
150 Gap(SPACE_MD)
151 };
152 let text_tertiary_style: Style = style! {
153 Width(Length::Percent(100.0))
154 FontSize(12.0)
155 TextColor(palette.get_muted_foreground())
156 };
157 view! {
158 EuvCard {
159 title: DATA_DTABLE_TITLE.to_string()
160 tokens: tokens
161 subtitle: DATA_DTABLE_SUB
162 column {
163 style: column_tertiary_style
164 EuvDataTable {
165 headers: headers
166 rows: rows
167 tokens: tokens
168 filter: state.get_lab_table_filter()
169 sort_ascending: sort_asc
170 selected_row: selected_row
171 }
172 text {
173 style: text_tertiary_style
174 { table_readout }
175 }
176 }
177 }
178 }
179}
180
181pub(crate) fn mount_data_table_card(tokens: ThemeTokens) -> NodeId {
191 let headers: Vec<String> = vec![
192 DATA_TABLE_H_CRATE.to_string(),
193 DATA_TABLE_H_ROLE.to_string(),
194 DATA_TABLE_H_BUDGET.to_string(),
195 ];
196 let rows: Vec<Vec<String>> = vec![
197 vec![
198 DATA_TABLE_R1_CRATE.to_string(),
199 DATA_TABLE_R1_ROLE.to_string(),
200 DATA_TABLE_R1_BUDGET.to_string(),
201 ],
202 vec![
203 DATA_TABLE_R2_CRATE.to_string(),
204 DATA_TABLE_R2_ROLE.to_string(),
205 DATA_TABLE_R2_BUDGET.to_string(),
206 ],
207 vec![
208 DATA_TABLE_R3_CRATE.to_string(),
209 DATA_TABLE_R3_ROLE.to_string(),
210 DATA_TABLE_R3_BUDGET.to_string(),
211 ],
212 ];
213 view! {
214 EuvCard {
215 title: DATA_TABLE_TITLE.to_string()
216 tokens: tokens
217 subtitle: DATA_TABLE_SUB
218 EuvTable {
219 headers: headers
220 rows: rows
221 tokens: tokens
222 }
223 }
224 }
225}
226
227pub(crate) fn mount_data_tree_progress_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
238 let palette: ThemePalette = tokens.get_palette();
239 let tree_sel: Signal<Option<String>> = state.get_tree_selected();
240 let roots: Vec<EuvTreeNode> = vec![EuvTreeNode::new(
241 DATA_TREE_WORKSPACE.to_string(),
242 vec![
243 EuvTreeNode::new(
244 DATA_TREE_CORE.to_string(),
245 vec![
246 EuvTreeNode::new(DATA_TREE_RENDER.to_string(), Vec::new()),
247 EuvTreeNode::new(DATA_TREE_REACTIVE.to_string(), Vec::new()),
248 ],
249 ),
250 EuvTreeNode::new(DATA_TREE_UI.to_string(), Vec::new()),
251 EuvTreeNode::new(DATA_TREE_PERF.to_string(), Vec::new()),
252 ],
253 )];
254 let tree_readout = move || -> String {
255 let cur: String = tree_sel.get().unwrap_or_else(|| DATA_TREE_NONE.to_string());
256 format!("{DATA_TREE_SELECTED_PREFIX}: {cur}")
257 };
258 let progress_specs: [(&str, f32); 3] = [
259 (DATA_PROG_LAYOUT, 0.92),
260 (DATA_PROG_ATLAS, 0.64),
261 (DATA_PROG_VRAM, 0.84),
262 ];
263 let progress_rows: Vec<NodeId> = progress_specs
264 .iter()
265 .map(|(label_text, val): &(&str, f32)| {
266 let caption: String = (*label_text).to_string();
267 let pct: f32 = *val;
268 let column_secondary_style: Style = style! {
269 Width(Length::Percent(100.0))
270 Gap(SPACE_XS)
271 };
272 let text_secondary_style: Style = style! {
273 Width(Length::Percent(100.0))
274 FontSize(12.0)
275 TextColor(palette.get_muted_foreground())
276 };
277 view! {
278 column {
279 style: column_secondary_style
280 text {
281 style: text_secondary_style
282 { caption }
283 }
284 EuvProgress {
285 value: pct
286 tokens: tokens
287 }
288 }
289 }
290 })
291 .collect();
292 let column_style: Style = style! {
293 Width(Length::Percent(100.0))
294 Gap(SPACE_MD)
295 };
296 let text_style: Style = style! {
297 Width(Length::Percent(100.0))
298 FontSize(12.0)
299 TextColor(palette.get_muted_foreground())
300 };
301 view! {
302 EuvCard {
303 title: DATA_TREE_TITLE.to_string()
304 tokens: tokens
305 subtitle: DATA_TREE_SUB
306 column {
307 style: column_style
308 EuvTree {
309 roots: roots
310 tokens: tokens
311 selected: tree_sel
312 }
313 text {
314 style: text_style
315 { tree_readout }
316 }
317 ..progress_rows
318 }
319 }
320 }
321}
322
323pub fn mount_data_page(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
334 let top_cards: Vec<NodeId> = vec![
335 mount_data_vlist_card(state, tokens),
336 mount_data_datatable_card(state, tokens),
337 ];
338 let bottom_cards: Vec<NodeId> = vec![
339 mount_data_table_card(tokens),
340 mount_data_tree_progress_card(state, tokens),
341 ];
342 let top_grid: NodeId = mount_responsive_grid(top_cards, 2);
343 let bottom_grid: NodeId = mount_responsive_grid(bottom_cards, 2);
344 view! {
345 EuvPage {
346 title: DATA_TITLE.to_string()
347 subtitle: DATA_SUBTITLE.to_string()
348 tokens: tokens
349 EuvStatGrid {
350 EuvStatCard {
351 label: DATA_KPI_ROWS_LABEL.to_string()
352 value: DATA_KPI_ROWS_VAL.to_string()
353 caption: DATA_KPI_ROWS_CAP.to_string()
354 tokens: tokens
355 }
356 EuvStatCard {
357 label: DATA_KPI_COMPLEXITY_LABEL.to_string()
358 value: DATA_KPI_COMPLEXITY_VAL.to_string()
359 caption: DATA_KPI_COMPLEXITY_CAP.to_string()
360 tokens: tokens
361 }
362 EuvStatCard {
363 label: DATA_KPI_TREE_LABEL.to_string()
364 value: DATA_KPI_TREE_VAL.to_string()
365 caption: DATA_KPI_TREE_CAP.to_string()
366 tokens: tokens
367 }
368 }
369 { top_grid }
370 { bottom_grid }
371 }
372 }
373}