103 lines
3.6 KiB
Rust
103 lines
3.6 KiB
Rust
// slint::include_modules!();
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
use slint_ui::*;
|
|
extern crate testfrontend;
|
|
use std::rc::Rc;
|
|
|
|
/// Returns the current time formated as a string
|
|
fn current_time() -> slint::SharedString {
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
return chrono::Local::now().format("%H:%M:%S %d/%m/%Y").to_string().into();
|
|
#[cfg(target_arch = "wasm32")]
|
|
return "".into();
|
|
}
|
|
|
|
// use crate::slint_ui::TodoItem;
|
|
// use crate::slint_ui::MainWindow;
|
|
|
|
fn main() {
|
|
// fn main() -> Result<(), slint::PlatformError> {
|
|
// 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().unwrap();
|
|
|
|
main_window.set_todo_model(
|
|
[
|
|
TodoItem { checked: true, title: "Implement the .slint file".into() },
|
|
TodoItem { checked: true, title: "Do the Rust part".into() },
|
|
TodoItem { checked: false, title: "Make the C++ code".into() },
|
|
TodoItem { checked: false, title: "Write some JavaScript code".into() },
|
|
TodoItem { checked: false, title: "Test the application".into() },
|
|
TodoItem { checked: false, title: "Ship to customer".into() },
|
|
TodoItem { checked: false, title: "???".into() },
|
|
TodoItem { checked: false, title: "Profit".into() },
|
|
]
|
|
.into(),
|
|
);
|
|
// let todo_model = Rc::new(slint::VecModel::<TodoItem>::from(vec![
|
|
// TodoItem { checked: true, title: "Implement the .slint file".into() },
|
|
// TodoItem { checked: true, title: "Do the Rust part".into() },
|
|
// TodoItem { checked: false, title: "Make the C++ code".into() },
|
|
// TodoItem { checked: false, title: "Write some JavaScript code".into() },
|
|
// TodoItem { checked: false, title: "Test the application".into() },
|
|
// TodoItem { checked: false, title: "Ship to customer".into() },
|
|
// TodoItem { checked: false, title: "???".into() },
|
|
// TodoItem { checked: false, title: "Profit".into() },
|
|
// ]));
|
|
|
|
// let ui = AppWindow::new()?;
|
|
main_window.on_todo_added({
|
|
let todo_model = todo_model.clone();
|
|
move |text| todo_model.push(TodoItem { checked: false, title: text })
|
|
});
|
|
|
|
main_window.on_quit(move || {
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
std::process::exit(0);
|
|
});
|
|
|
|
let weak_window = main_window.as_weak();
|
|
// main_window.on_popup_confirmed(move || {
|
|
// let window = weak_window.unwrap();
|
|
// window.hide().unwrap();
|
|
// });
|
|
|
|
{
|
|
let weak_window = main_window.as_weak();
|
|
let todo_model = todo_model.clone();
|
|
// main_window.window().on_close_requested(move || {
|
|
// let window = weak_window.unwrap();
|
|
|
|
// // if todo_model.iter().any(|t| !t.checked) {
|
|
// // // window.invoke_show_confirm_popup();
|
|
// // slint::CloseRequestResponse::KeepWindowShown
|
|
// // } else {
|
|
// // slint::CloseRequestResponse::HideWindow
|
|
// // }
|
|
// });
|
|
}
|
|
|
|
|
|
// let ui_handle = main_window.as_weak();
|
|
// main_window.on_request_increase_value(move || {
|
|
// let ui = ui_handle.unwrap();
|
|
// ui.set_counter(main_window.get_counter() + 1);
|
|
// });
|
|
|
|
// main_window.run()
|
|
|
|
main_window.set_show_header(true);
|
|
main_window.set_todo_model(todo_model.into());
|
|
|
|
main_window.run().unwrap();
|
|
}
|
|
|
|
mod slint_ui {
|
|
pub use testfrontend::*;
|
|
// pub use ui_settings_profile_server_window::*;
|
|
// pub use ui_settings_profile_window::*;
|
|
} |