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/header.rs
1use strato_widgets::{
2 Widget, Row, Container, Text, Button, InputType, TextInput,
3 text::FontWeight,
4 layout::{CrossAxisAlignment, MainAxisAlignment},
5};
6use crate::theme::{AppTheme, BORDER_RADIUS_MD, SPACING_MD, SPACING_SM};
7 
8pub struct Header {
9 theme: AppTheme,
10}
11 
12impl Header {
13 pub fn new() -> Self {
14 Self {
15 theme: AppTheme::dark(),
16 }
17 }
18 
19 pub fn build(self) -> Box<dyn Widget> {
20 let theme = self.theme;
21 
22 Box::new(Container::new()
23 .background(theme.bg_secondary)
24 .padding(SPACING_MD)
25 .child(
26 Row::new()
27 .main_axis_alignment(MainAxisAlignment::SpaceBetween)
28 .cross_axis_alignment(CrossAxisAlignment::Center)
29 .children(vec![
30 // Search Bar
31 Box::new(Container::new()
32 .width(300.0)
33 .child(
34 TextInput::new()
35 .placeholder("Search anything...")
36 )
37 ) as Box<dyn Widget>,
38 
39 // Right Actions
40 Box::new(Row::new()
41 .spacing(SPACING_SM)
42 .children(vec![
43 Box::new(Button::new("Notifications").outline()) as Box<dyn Widget>,
44 Box::new(Container::new()
45 .width(40.0)
46 .height(40.0)
47 .background(theme.accent)
48 .border_radius(20.0) // Circle
49 .child(
50 Text::new("JD")
51 .color(theme.text_primary)
52 .font_weight(FontWeight::Bold)
53 .align(strato_widgets::text::TextAlign::Center)
54 )
55 ) as Box<dyn Widget>,
56 ])
57 ) as Box<dyn Widget>,
58 ])
59 )
60 )
61 }
62}
63