tawasuyu

tawasuyu/llimphi

Sovereign retained-mode GPU UI framework in Rust (wgpu+vello+taffy+parley), Elm loop, 40+ widgets.

Rust 229TOML 101Markdown 82Shell 24052 Sutichaykuna

⎇ main widgets/toolbar/examples/toolbar_demo.rs Rust · 117 siq'ikuna · 3.6 KB Ñawpa willay Pi imata llamkarqan ch'uya

chore: refresco desde el monorepo — vello 0.9 / wgpu 29, 120 miembros d251eb32b · Sergio ·

1//! Demo interactiva del toolbar: grupo de navegación + toggles de vista +
2//! acciones (una deshabilitada). El texto de abajo refleja el último click.
3//!
4//! `cargo run -p llimphi-widget-toolbar --example toolbar_demo --release`
5
6use llimphi_icons::{icon_view, Icon};
7use llimphi_theme::Theme;
8use llimphi_ui::llimphi_layout::taffy::{
9    prelude::{length, percent, FlexDirection, Size, Style},
10    AlignItems,
11};
12use llimphi_ui::{run, App, Handle, View};
13use llimphi_widget_toolbar::{toolbar_view, ToolbarGroup, ToolbarItem, ToolbarPalette};
14
15struct Demo;
16
17struct Model {
18    vista: usize,
19    dual: bool,
20    ultimo: String,
21}
22
23#[derive(Clone)]
24enum Msg {
25    Subir,
26    Vista(usize),
27    Dual,
28    Nueva,
29}
30
31impl App for Demo {
32    type Model = Model;
33    type Msg = Msg;
34
35    fn title() -> &'static str {
36        "toolbar · demo"
37    }
38
39    fn init(_handle: &Handle<Self::Msg>) -> Self::Model {
40        Model { vista: 0, dual: false, ultimo: "(sin acciones)".into() }
41    }
42
43    fn update(model: Self::Model, msg: Self::Msg, _h: &Handle<Self::Msg>) -> Self::Model {
44        let mut m = model;
45        match msg {
46            Msg::Subir => m.ultimo = "subir".into(),
47            Msg::Vista(v) => {
48                m.vista = v;
49                m.ultimo = format!("vista {v}");
50            }
51            Msg::Dual => {
52                m.dual = !m.dual;
53                m.ultimo = format!("dual: {}", m.dual);
54            }
55            Msg::Nueva => m.ultimo = "nueva carpeta".into(),
56        }
57        m
58    }
59
60    fn view(model: &Self::Model) -> View<Self::Msg> {
61        let theme = Theme::dark();
62        let pal = ToolbarPalette::from_theme(&theme);
63        let vistas = [Icon::Rows, Icon::Table, Icon::Grid, Icon::Image];
64        let barra = toolbar_view(
65            vec![
66                ToolbarGroup::new(vec![ToolbarItem::new(
67                    |_s, c| icon_view(Icon::ChevronUp, c, 1.7),
68                    Msg::Subir,
69                )
70                .with_label("subir")]),
71                ToolbarGroup::new(
72                    vistas
73                        .iter()
74                        .enumerate()
75                        .map(|(i, ic)| {
76                            let ic = *ic;
77                            ToolbarItem::new(move |_s, c| icon_view(ic, c, 1.7), Msg::Vista(i))
78                                .active(model.vista == i)
79                        })
80                        .collect(),
81                ),
82                ToolbarGroup::new(vec![
83                    ToolbarItem::new(|_s, c| icon_view(Icon::Columns, c, 1.7), Msg::Dual)
84                        .active(model.dual),
85                    ToolbarItem::new(|_s, c| icon_view(Icon::Plus, c, 1.7), Msg::Nueva)
86                        .with_label("carpeta")
87                        .enabled(false),
88                ]),
89            ],
90            36.0,
91            &pal,
92        );
93        let estado = View::new(Style {
94            size: Size { width: percent(1.0_f32), height: length(30.0_f32) },
95            align_items: Some(AlignItems::CENTER),
96            padding: llimphi_ui::llimphi_layout::taffy::Rect {
97                left: length(12.0_f32),
98                right: length(12.0_f32),
99                top: length(0.0_f32),
100                bottom: length(0.0_f32),
101            },
102            ..Default::default()
103        })
104        .text(format!("último: {}", model.ultimo), 13.0, theme.fg_text);
105        View::new(Style {
106            flex_direction: FlexDirection::Column,
107            size: Size { width: percent(1.0_f32), height: percent(1.0_f32) },
108            ..Default::default()
109        })
110        .fill(theme.bg_app)
111        .children(vec![barra, estado])
112    }
113}
114
115fn main() {
116    run::<Demo>();
117}