StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | use strato_widgets::{ |
| 2 | Widget, Column, Row, Text, Flex, Grid, GridUnit, |
| 3 | layout::{CrossAxisAlignment, MainAxisAlignment}, |
| 4 | }; |
| 5 | use crate::components::{ |
| 6 | stats_card::StatsCard, |
| 7 | activity_list::ActivityList, |
| 8 | animated_chart::AnimatedChart, |
| 9 | }; |
| 10 | use crate::theme::{AppTheme, SPACING_LG, SPACING_MD}; |
| 11 | use strato_core::types::Color; |
| 12 | |
| 13 | pub struct DashboardView; |
| 14 | |
| 15 | impl DashboardView { |
| 16 | pub fn build() -> Box<dyn Widget> { |
| 17 | let theme = AppTheme::dark(); |
| 18 | |
| 19 | Box::new(Column::new() |
| 20 | .spacing(SPACING_LG) |
| 21 | .cross_axis_alignment(CrossAxisAlignment::Stretch) |
| 22 | .children(vec![ |
| 23 | // Page Title |
| 24 | Box::new(Text::new("Dashboard Overview") |
| 25 | .font_size(32.0) |
| 26 | .color(theme.text_primary)) as Box<dyn Widget>, |
| 27 | |
| 28 | // Stats Grid (New Layout System) |
| 29 | Box::new(Grid::new() |
| 30 | .rows(vec![GridUnit::Auto]) |
| 31 | .columns(vec![ |
| 32 | GridUnit::Fraction(1.0), |
| 33 | GridUnit::Fraction(1.0), |
| 34 | GridUnit::Fraction(1.0), |
| 35 | GridUnit::Fraction(1.0), |
| 36 | ]) |
| 37 | .row_gap(SPACING_MD) |
| 38 | .col_gap(SPACING_MD) |
| 39 | .children(vec![ |
| 40 | Box::new(StatsCard::new("Total Revenue", "$45,231.89", "+20.1%", true).build()), |
| 41 | Box::new(StatsCard::new("Active Users", "2,350", "+15.2%", true).build()), |
| 42 | Box::new(StatsCard::new("Bounce Rate", "42.3%", "-5.4%", true).build()), |
| 43 | Box::new(StatsCard::new("Server Uptime", "99.9%", "+0.1%", true).build()), |
| 44 | ]) |
| 45 | ) as Box<dyn Widget>, |
| 46 | |
| 47 | // Main Content Area (Charts & Lists) |
| 48 | Box::new(Flex::new( |
| 49 | Box::new(Row::new() |
| 50 | .spacing(SPACING_MD) |
| 51 | .cross_axis_alignment(CrossAxisAlignment::Start) // Top align |
| 52 | .children(vec![ |
| 53 | // Left Column (Activity List) |
| 54 | Box::new(Flex::new( |
| 55 | Box::new(ActivityList::new().build()) // Box required for Flex::new |
| 56 | ).flex(2.0)) as Box<dyn Widget>, |
| 57 | |
| 58 | // Right Column (Animated Chart) |
| 59 | Box::new(Flex::new( |
| 60 | Box::new(strato_widgets::Container::new() |
| 61 | .background(theme.bg_secondary) |
| 62 | .padding(SPACING_MD) |
| 63 | .border_radius(crate::theme::BORDER_RADIUS_MD) |
| 64 | .height(400.0) // Fixed height for chart area |
| 65 | .child( |
| 66 | Column::new() |
| 67 | .spacing(SPACING_MD) |
| 68 | .children(vec![ |
| 69 | Box::new(Text::new("Growth Analytics") |
| 70 | .font_size(20.0) |
| 71 | .color(theme.text_primary)) as Box<dyn Widget>, |
| 72 | |
| 73 | Box::new(AnimatedChart::new(vec![ |
| 74 | 65.0, 40.0, 100.0, 85.0, 45.0, 92.0, |
| 75 | 55.0, 70.0, 30.0, 60.0, 95.0, 80.0 |
| 76 | ]).color(Color::rgb(0.4, 0.7, 1.0))) as Box<dyn Widget> |
| 77 | ]) |
| 78 | ) |
| 79 | ) |
| 80 | ).flex(3.0)) as Box<dyn Widget>, |
| 81 | ]) |
| 82 | ) |
| 83 | ).flex(1.0)) as Box<dyn Widget>, |
| 84 | ]) |
| 85 | ) |
| 86 | } |
| 87 | } |
| 88 |