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