1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: MIT
3
4#[cfg(target_arch = "wasm32")]
5use wasm_bindgen::prelude::*;
6
7slint::include_modules!();
8
9#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
10pub fn main() {
11 // This provides better error messages in debug mode.
12 // It's disabled in release mode so it doesn't bloat up the file size.
13 #[cfg(all(debug_assertions, target_arch = "wasm32"))]
14 console_error_panic_hook::set_once();
15
16 let main_window = MainWindow::new().unwrap();
17 main_window.set_ink_levels(slint::VecModel::from_slice(&[
18 InkLevel { color: slint::Color::from_rgb_u8(0, 255, 255), level: 0.40 },
19 InkLevel { color: slint::Color::from_rgb_u8(255, 0, 255), level: 0.20 },
20 InkLevel { color: slint::Color::from_rgb_u8(255, 255, 0), level: 0.50 },
21 InkLevel { color: slint::Color::from_rgb_u8(0, 0, 0), level: 0.80 },
22 ]));
23
24 let main_weak = main_window.as_weak();
25 main_window.on_fax_number_erase(move || {
26 let main_window = main_weak.unwrap();
27 let mut fax_number = main_window.get_fax_number().to_string();
28 fax_number.pop();
29 main_window.set_fax_number(fax_number.into());
30 });
31
32 let main_weak = main_window.as_weak();
33 main_window.on_fax_send(move || {
34 let main_window = main_weak.upgrade().unwrap();
35 let fax_number = main_window.get_fax_number().to_string();
36 println!("Sending a fax to {}", fax_number);
37 main_window.set_fax_number(slint::SharedString::default());
38 });
39
40 main_window.on_quit(move || {
41 #[cfg(not(target_arch = "wasm32"))]
42 std::process::exit(0);
43 });
44
45 main_window.run().unwrap();
46}
47