slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.54k stars 600 forks source link

Panic in accesskit when using dialog box #6015

Open oswald2 opened 2 months ago

oswald2 commented 2 months ago

Version: slint 1.7.2 Language: Rust OS: Ubuntu 24.04

When opening a dialog box, main panics with:

thread 'main' panicked at /home/oswald/.cargo/registry/src/index.crates.io-6f17d22bba15001f/accesskit_consumer-0.24.0/src/tree.rs:272:13:
Tried to initialize the accessibility tree without a root tree. TreeUpdate::tree must be Some.
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: accesskit_consumer::tree::Tree::new
   3: accesskit_atspi_common::adapter::Adapter::with_wrapped_action_handler
   4: <i_slint_backend_winit::winitwindowadapter::WinitWindowAdapter as i_slint_core::window::WindowAdapterInternal>::handle_focus_change
   5: i_slint_core::window::WindowInner::set_focus_item
   6: wyrdoscope::ui::event_dialog::display_new_time_event_dialog::slint_generatedNewEventDialog::NewEventDialog::new

This worked with the 1.6.x versions of slint (recently upgraded to 1.7.2).

The dialog is defined like this:

pub fn display_new_time_event_dialog<F>(
    time: &DateTime<Local>,
    name: &str,
    comment: &str,
    set_time_editable: bool,
    on_ok: F,
) where
    F: 'static + Fn(&DateTime<Local>, &str, &str),
{
    slint::slint! {

        import { LineEdit , TextEdit, StandardButton} from "std-widgets.slint";
        export component NewEventDialog inherits Dialog {
            forward-focus: time_edit;
            in-out property <string> time;
            in-out property <string> name;
            in-out property <string> comment;
            in property <bool> time-editable;

            VerticalLayout {
                spacing: 4px;

                Text {
                    text: "Time:";
                }

                time_edit := LineEdit {
                    text <=> time;
                    enabled: time-editable;
                    width: 300px;
                }

                Text {
                    text: "Name:";
                }

                name_edit := LineEdit {
                    text <=> name;
                    enabled: true;
                    width: 300px;
                }

                Text {
                    text: "Comment:";
                }

                TextEdit {
                    text <=> comment;
                    enabled: true;
                    width: 300px;
                    height: 300px;
                }
            }

            StandardButton {
                kind: cancel;
            }

            StandardButton {
                kind: ok;
            }

        }
    }

    let dialog = NewEventDialog::new().unwrap();
    let weak_dialog = dialog.as_weak();
    let weak_dialog2 = weak_dialog.clone();

    dialog.set_time(format_time(time).into());
    dialog.set_time_editable(set_time_editable);
    dialog.set_name(name.into());
    dialog.set_comment(comment.into());

    dialog.on_ok_clicked(move || {
        let dialog = weak_dialog.unwrap();
        let _ = dialog.hide();
        on_ok(&dialog.get_time(), &dialog.get_name(), &dialog.get_comment());
    });

    dialog.on_cancel_clicked(move || {
        let dialog = weak_dialog2.unwrap();
        let _ = dialog.hide();
    });

    let _ = dialog.run();
}

Anything I am doing wrong here, or is this a bug?

tronical commented 2 months ago

This is definitely a bug :(