antoyo / relm

Idiomatic, GTK+-based, GUI library, inspired by Elm, written in Rust
MIT License
2.43k stars 78 forks source link

How to close a widget #214

Closed MGlolenstine closed 4 years ago

MGlolenstine commented 4 years ago

I have a class Popup, that opens a popup, which has a gtk::Window(gtk::WindowType::Popup) for a parent. But whenever I run it using

#[allow(unused)]
fn show_modal(pt: PopupType){
    Popup::run(pt);
}

it never stops, or at least it never continues onward from that Popup::run(pt); line. Stuff after that line doesn't get executed and the function never returns.

I'm currently closing it like this

let window = self.window.clone();
button1.connect_clicked(move |_c| {
    glib::clone!(@strong window => move || {
        cbf();
        window.close();
    })();
});

I'm not sure if that only closes the window and leaves other stuff running or if it closes everything.

What would the correct way to close a popup be in this case?

antoyo commented 4 years ago

That's normal because run() creates a new inner gtk+ event loop. You should call .destroy() on your popup to end this, I believe.

MGlolenstine commented 4 years ago

Destroy still doesn't kill the event loop. The window does close, but with the same problem as above.

antoyo commented 4 years ago

The doc says to either destroy or send a response. Maybe try to send a response. Or maybe ask the gtk+ people. I don't remember how that works.

MGlolenstine commented 4 years ago

Ok, thanks for your help!

MGlolenstine commented 4 years ago
    window.destroy();
    gtk::main_quit();

Did the trick!

Thanks!