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

Adds the ability to disable/enable window interactions #6694

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

TheColorRed
Copy link
Contributor

@TheColorRed TheColorRed commented Oct 31, 2024

This allows the user to enable/disable interactions with the window. This is useful for displaying a dialog box that. This is useful in conjunction with always-on-top and PR #6675.

Example Slint:

mod dialog {
    slint::slint! {
        export component MyDialog inherits Window {
          skip-taskbar: true;

          width: 200px;
          height: 200px;
        }
    }
}

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

  export component AppWindow inherits Window {
    callback show-dialog;

    min-width: 200px;
    min-height: 200px;

    Button {
      text: "Click me!";
      clicked => {
        root.show-dialog();
        // root.disabled = true;
      }
    }
  }
}

Example Rust (Might be overkill 😃)

use std::sync::Arc;

pub fn main() -> Result<(), slint::PlatformError> {
    let app_window = AppWindow::new()?;
    let app = Arc::new(app_window);

    let window_ref = app.clone();
    app.clone().on_show_dialog(move || {
        let dialog = dialog::MyDialog::new().unwrap();
        window_ref.clone().window().set_disabled(true);
        let window_ref = window_ref.clone();
        dialog.window().on_close_requested(move || {
            window_ref.clone().window().set_disabled(false);
            slint::CloseRequestResponse::HideWindow
        });

        let _ = dialog.show();
    });

    app.clone().run()?;
    Ok(())
}

@TheColorRed TheColorRed marked this pull request as ready for review November 1, 2024 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant