1use floem::text::FONT_SYSTEM;
2use floem::views::Label;
3use floem::window::WindowConfig;
4use floem::Application;
5use floem::{
6 reactive::{RwSignal, SignalGet, SignalUpdate},
7 views::{ButtonClass, Decorators},
8 IntoView,
9};
10
11#[cfg(target_arch = "wasm32")]
12use wasm_bindgen::prelude::*;
13
14const FIRA_MONO: &[u8] = include_bytes!("../fonts/FiraMono-Medium.ttf");
15const FIRA_SANS: &[u8] = include_bytes!("../fonts/FiraSans-Medium.ttf");
16const DEJAVU_SERIF: &[u8] = include_bytes!("../fonts/DejaVuSerif.ttf");
17
18pub fn app_view() -> impl IntoView {
19 let counter = RwSignal::new(0);
21
22 (
24 Label::derived(move || format!("Value: {}", counter.get())),
26 (
28 "Increment".class(ButtonClass).on_click_stop(move |_| {
29 counter.update(|value| *value += 1);
30 }),
31 "Decrement".class(ButtonClass).on_click_stop(move |_| {
32 counter.update(|value| *value -= 1);
33 }),
34 ),
35 )
36 .style(|s| s.flex_col())
37}
38
39#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
40pub fn run() {
41 #[cfg(target_family = "wasm")]
42 console_error_panic_hook::set_once();
43
44 {
45 let mut font_system = FONT_SYSTEM.lock();
46 let font_db = font_system.db_mut();
47 font_db.load_font_data(Vec::from(FIRA_MONO));
48 font_db.load_font_data(Vec::from(FIRA_SANS));
49 font_db.load_font_data(Vec::from(DEJAVU_SERIF));
50 }
51
52 let window_config = WindowConfig::default().with_web_config(|w| w.canvas_id("the-canvas"));
53
54 Application::new()
55 .window(move |_| app_view(), Some(window_config))
56 .run()
57}