slint/examples/printerdemo_old/rust/main.rs
Simon Hausmann b27034efa5 Rename sixtyfps::IntoWeak into sixtyfps::ComponentHandle and remove Clone from generated components
`ComponentHandle` offers a richer API of common functions, such as
`show()`/`hide()` as well as the new `clone_strong()` - that should help
to prevent mistakely created strong reference that may cause leaks.

Fixes #188
2021-03-15 16:01:13 +01:00

52 lines
2 KiB
Rust

/* LICENSE BEGIN
This file is part of the SixtyFPS Project -- https://sixtyfps.io
Copyright (c) 2020 Olivier Goffart <olivier.goffart@sixtyfps.io>
Copyright (c) 2020 Simon Hausmann <simon.hausmann@sixtyfps.io>
SPDX-License-Identifier: GPL-3.0-only
This file is also available under commercial licensing terms.
Please contact info@sixtyfps.io for more information.
LICENSE END */
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
sixtyfps::include_modules!();
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
pub fn main() {
// This provides better error messages in debug mode.
// It's disabled in release mode so it doesn't bloat up the file size.
#[cfg(all(debug_assertions, target_arch = "wasm32"))]
console_error_panic_hook::set_once();
let main_window = MainWindow::new();
main_window.set_ink_levels(sixtyfps::VecModel::from_slice(&[
InkLevel { color: sixtyfps::Color::from_rgb_u8(0, 255, 255), level: 0.40 },
InkLevel { color: sixtyfps::Color::from_rgb_u8(255, 0, 255), level: 0.20 },
InkLevel { color: sixtyfps::Color::from_rgb_u8(255, 255, 0), level: 0.50 },
InkLevel { color: sixtyfps::Color::from_rgb_u8(0, 0, 0), level: 0.80 },
]));
let main_weak = main_window.as_weak();
main_window.on_fax_number_erase(move || {
let main_window = main_weak.unwrap();
let mut fax_number = main_window.get_fax_number().to_string();
fax_number.pop();
main_window.set_fax_number(fax_number.into());
});
let main_weak = main_window.as_weak();
main_window.on_fax_send(move || {
let main_window = main_weak.upgrade().unwrap();
let fax_number = main_window.get_fax_number().to_string();
println!("Sending a fax to {}", fax_number);
main_window.set_fax_number(sixtyfps::SharedString::default());
});
main_window.on_quit(move || {
#[cfg(not(target_arch = "wasm32"))]
std::process::exit(0);
});
main_window.run();
}