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.55k stars 601 forks source link

Multi-window support ? #4031

Closed shanliu closed 11 months ago

shanliu commented 11 months ago

How to create multiple windows in the desktop environment?

ogoffart commented 11 months ago

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 https://github.com/slint-ui/slint/issues/3217 )

In the future we plan to support multiple component from the same file:
https://github.com/slint-ui/slint/issues/784

shanliu commented 11 months ago

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!

dorukotiv commented 9 months ago

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 commented 9 months ago

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()