Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Todo demo: implement the dialog as a separate window #2094

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions examples/todo/rust/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,43 @@ pub fn main() {
}
});

slint::slint! {
import { StandardButton } from "std-widgets.slint";

component ConfirmDialog inherits Dialog {
confirm_popup_text := Text {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
confirm_popup_text := Text {
Text {

text: "Some items are not done, are you sure you wish to quit?";
wrap: word-wrap;
}

StandardButton { kind: yes; }
StandardButton { kind: no; }
}
}
let confirm_dialog = ConfirmDialog::new();

let weak_window = main_window.as_weak();
main_window.on_popup_confirmed(move || {
let window = weak_window.unwrap();
window.hide();
let weak_confirm_dialog = confirm_dialog.as_weak();
confirm_dialog.on_yes_clicked(move || {
weak_window.unwrap().hide();
weak_confirm_dialog.unwrap().hide();
});
let weak_confirm_dialog = confirm_dialog.as_weak();
confirm_dialog.on_no_clicked(move || {
weak_confirm_dialog.unwrap().hide();
});

{
let weak_window = main_window.as_weak();
main_window.window().on_close_requested({
let todo_model = todo_model.clone();
main_window.window().on_close_requested(move || {
let window = weak_window.unwrap();

move || {
if todo_model.iter().any(|t| !t.checked) {
window.invoke_show_confirm_popup();
confirm_dialog.show();
slint::CloseRequestResponse::KeepWindowShown
} else {
slint::CloseRequestResponse::HideWindow
}
});
}
}
});

main_window.on_apply_sorting_and_filtering({
let weak_window = main_window.as_weak();
Expand Down