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

Multi-window support ? #4031

Closed
shanliu opened this issue Nov 29, 2023 · 4 comments
Closed

Multi-window support ? #4031

shanliu opened this issue Nov 29, 2023 · 4 comments

Comments

@shanliu
Copy link

shanliu commented Nov 29, 2023

How to create multiple windows in the desktop environment?

@ogoffart
Copy link
Member

If this is about several instance of the same windows, you can just use MyWindow::new() several time and call .show() on multiple window.

If you need several window of different kind, you currently need to use the slint! macro several time. The problem is that they are all independent from eachother and don't share the datastructure and all. (and it is also not possible with slint-build yet #3217 )

In the future we plan to support multiple component from the same file:
#784

@shanliu
Copy link
Author

shanliu commented Nov 30, 2023

If this is about several instance of the same windows, you can just use MyWindow::new() several time and call .show() on multiple window.

If you need several window of different kind, you currently need to use the slint! macro several time. The problem is that they are all independent from eachother and don't share the datastructure and all. (and it is also not possible with slint-build yet #3217 )

In the future we plan to support multiple component from the same file: #784

thx!

@shanliu shanliu closed this as completed Nov 30, 2023
@dorukotiv
Copy link

dorukotiv commented Jan 31, 2024

If this is about several instance of the same windows, you can just use MyWindow::new() several time and call .show() on multiple window.

If you need several window of different kind, you currently need to use the slint! macro several time. The problem is that they are all independent from eachother and don't share the datastructure and all. (and it is also not possible with slint-build yet #3217 )

In the future we plan to support multiple component from the same file: #784

can a window communicate to another window through the Rust code?

@shanliu
Copy link
Author

shanliu commented Feb 6, 2024

If this is about several instance of the same windows, you can just use MyWindow::new() several time and call .show() on multiple window.
If you need several window of different kind, you currently need to use the slint! macro several time. The problem is that they are all independent from eachother and don't share the datastructure and all. (and it is also not possible with slint-build yet #3217 )
In the future we plan to support multiple component from the same file: #784

can a window communicate to another window through the Rust code?

  let (tx, rx) = mpsc::channel::<String>();

    let ui = win1::AppWindow::new()?;

    let ui_handle = ui.as_weak();
    thread::spawn(move || {
        for received in rx {
            let _ = ui_handle.upgrade_in_event_loop(move |ui| {
                ui.set_msg(format!("data:{}", received).into());
            });
        }
    });

    // let ser_mgr = ServerState::default();
    let ui_handle = ui.as_weak();
    ui.on_request_increase_value(move || {
        let ui = ui_handle.unwrap();
        if ui.get_status().as_str() == "close" {
            ui.set_msg("is close".into());
            ui.set_status("run".into());
        } else {
            ui.set_msg("is run".into());
            ui.set_status("close".into());
        }
    });
    let sub = win2::SubWindow::new()?;

    sub.on_push_msg(move |data| {
        tx.send(data.to_string()).unwrap();
    });
    let ui_handle = ui.as_weak();
    ui.on_open_window(move || {
        let ui = ui_handle.unwrap();
        if !sub.window().is_visible() {
            sub.show().unwrap();
            ui.set_button("close win".into());
        } else {
            sub.hide().unwrap();
            ui.set_button("open win".into());
        }
    });
    ui.run()

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

No branches or pull requests

3 participants