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/modern_dashboard/src/components/stats_card.rs
1use strato_widgets::{
2 Widget, Column, Container, Text, Flex,
3 text::FontWeight,
4};
5use strato_core::types::Color;
6use crate::theme::{AppTheme, BORDER_RADIUS_MD, SPACING_MD, SPACING_SM};
7 
8pub struct StatsCard {
9 title: String,
10 value: String,
11 trend: String,
12 is_positive: bool,
13 theme: AppTheme,
14}
15 
16impl StatsCard {
17 pub fn new(title: &str, value: &str, trend: &str, is_positive: bool) -> Self {
18 Self {
19 title: title.to_string(),
20 value: value.to_string(),
21 trend: trend.to_string(),
22 is_positive,
23 theme: AppTheme::dark(),
24 }
25 }
26 
27 pub fn build(self) -> impl Widget {
28 let theme = self.theme;
29 let trend_color = if self.is_positive { theme.success } else { theme.error };
30 
31 // Wrap in Flex(1.0) so it expands in a Row
32 Flex::new(
33 Box::new(Container::new()
34 .background(theme.bg_secondary)
35 .border_radius(BORDER_RADIUS_MD)
36 .padding(SPACING_MD)
37 .child(
38 Column::new()
39 .spacing(SPACING_SM)
40 .children(vec![
41 Box::new(Text::new(&self.title)
42 .color(theme.text_secondary)
43 .font_size(14.0)) as Box<dyn Widget>,
44 
45 Box::new(Text::new(&self.value)
46 .color(theme.text_primary)
47 .font_size(28.0)
48 .font_weight(FontWeight::Bold)) as Box<dyn Widget>,
49 
50 Box::new(Text::new(&self.trend)
51 .color(trend_color)
52 .font_size(12.0)) as Box<dyn Widget>,
53 ])
54 )
55 )
56 ).flex(1.0)
57 }
58}
59