https://github.com/lapce/floem
- 布局系统使用 Taffy 实现 Flexbox
- 响应式设计启发自 leptos_reactive
响应性“信号”允许您以最小的努力保持UI最新,同时保持非常高的性能。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| use floem::reactive::create_signal; use floem::view::View; use floem::views::{h_stack, label, v_stack, Decorators}; use floem::widgets::button;
fn app_view() -> impl View { let (counter, set_counter) = create_signal(0);
v_stack(( label(move || format!("Value: {}", counter.get())), h_stack(( button(|| "Increment").on_click_stop(move |_| { set_counter.update(|value| *value += 1); }), button(|| "Decrement").on_click_stop(move |_| { set_counter.update(|value| *value -= 1); }), )), )) }
fn main() { floem::launch(app_view); }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| use floem::{ peniko::Color, view::View, views::{container, stack, Decorators}, widgets::button, };
fn main() { println!("Hello, world!");
floem::launch(app_view_0); }
fn app_view_0() -> impl View { button(|| "Hello") .on_click_stop(|_| println!("button clicked")) .style(|s| { s.absolute() .width(100) .height(50) .margin_left(50) .margin_top(50) }) }
fn app_view_1() -> impl View { container({ button(|| "按钮") .on_click_stop(|_| { println!("button clicked!"); }) .style(|s| s.width(100).height(100)) }) .style(|s| s.background(Color::GRAY).height(200).width(200)) }
fn app_view_2() -> impl View { stack(( button(|| "Button1"), button(|| "Button2"), )) }
|