slint/examples/todo/rust/main.rs
Olivier Goffart 8361ef4019 Start code egeneration for the two ways binding
This is only meant to include the cases in which the property are optimized.
Does not work yet for the dynamic component
2020-09-24 14:37:16 +02:00

42 lines
1.5 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 */
use std::rc::Rc;
#[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 todo_model = Rc::new(sixtyfps::VecModel::<TodoItem>::from(vec![
TodoItem { checked: true, title: "Implement the .60 file".into() },
TodoItem { checked: true, title: "Do the rust part".into() },
TodoItem { checked: false, title: "Make the C++ code".into() },
TodoItem { checked: false, title: "???".into() },
TodoItem { checked: false, title: "Profit".into() },
]));
let main_window = MainWindow::new();
main_window.as_ref().on_todo_added({
let todo_model = todo_model.clone();
move |text| todo_model.push(TodoItem { checked: true, title: text })
});
main_window.as_ref().set_todo_model(Some(todo_model));
main_window.run();
}