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

Can't close a window with a custom button #464

Closed
ghost opened this issue Jan 16, 2020 · 0 comments · Fixed by #797
Closed

Can't close a window with a custom button #464

ghost opened this issue Jan 16, 2020 · 0 comments · Fixed by #797
Labels
shell/gtk concerns the GTK backend

Comments

@ghost
Copy link

ghost commented Jan 16, 2020

I'm running code which in simplified version looks like this

use std::{thread, time};
use druid::widget::{Button, Flex};
use druid::{AppLauncher, Widget, WindowDesc};

// Clicking a button should close the window

//// The close button close the window
//fn main () {
//    let window = WindowDesc::new(build_widget);
//    AppLauncher::with_window(window)
//        .use_simple_logger()
//        .launch(0_u32)
//        .expect("launch failed");
//
//    dbg!("GUI killed");
//}

// The close button makes the window hang
fn main () {
    dbg!("LAUNCH_GUI");

    let mut should_gui = true;
    loop {
        dbg!("LOOP ITERATION");
        if should_gui == true {
            dbg!("SHOW GUI");
            should_gui = false;

            let window = WindowDesc::new(build_widget);
            AppLauncher::with_window(window)
                .use_simple_logger()
                .launch(0_u32)
                .expect("launch failed");

            dbg!("GUI KILLED");
        }
        let sleep_time = time::Duration::from_millis(100);
        thread::sleep(sleep_time);
    }
}

fn build_widget() -> impl Widget<u32> {
    Flex::column()
        .with_child(
            Button::sized(
                "Close",
                |evt_ctx , data: _, _env| {
                    dbg!(&data);
                    //evt_ctx.window().close();
                    evt_ctx.submit_command(druid::commands::CLOSE_WINDOW, None);
                },
                80.0,
                20.0,
            ),
            0.0,
        )
}

I'm expecting the window is closed properly and the program keeps looping without GUI.

Instead, I'm getting a hanging window which can't be closed, see
druid-close-broken2

Also discussed here: https://xi.zulipchat.com/#narrow/stream/147926-druid/topic/evt_ctx.2Ewindow().2Eclose().20not.20working.3F

Software versions

gtk3-devel.x86_64 3.24.13-1.fc31
glib2-devel.x86_64 2.62.3-1.fc31

@ghost ghost changed the title Can't close a window when Can't close a window with a custom button Jan 16, 2020
@cmyr cmyr added the shell/gtk concerns the GTK backend label Jan 16, 2020
@cmyr cmyr closed this as completed in #797 Apr 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
shell/gtk concerns the GTK backend
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant