slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
16.94k stars 568 forks source link

Support for multiple windows #1377

Closed DBLouis closed 1 year ago

DBLouis commented 2 years ago

I could not find a way to instantiate multiple windows. Is this currently not possible?

tronical commented 2 years ago

It is possible, but it's a little tricky.

Suppose you have MyWindow1 := Window { ... } and MyWindow2 := Window { ... } and want to show them. To overcome #784 you could put say MyWindow2 into a helper crate, build it using build.rs and export it. Then in your main crate you can import MyWindow and then write something like this:

fn main() {
    let my_window_1 = MyWindow1::new();
    let my_window_2 = helper_create::MyWindow2::new();
    my_window_1.show();
    my_window_2.show();
    slint::run_event_loop();
}

I haven't tested this, but this might work as workaround until #784 is resolved.

ogoffart commented 1 year ago

Closing as the main issue is tracked in https://github.com/slint-ui/slint/issues/784

Davidc2525 commented 8 months ago

It is possible, but it's a little tricky.

Suppose you have MyWindow1 := Window { ... } and MyWindow2 := Window { ... } and want to show them. To overcome #784 you could put say MyWindow2 into a helper crate, build it using build.rs and export it. Then in your main crate you can import MyWindow and then write something like this:

fn main() {
    let my_window_1 = MyWindow1::new();
    let my_window_2 = helper_create::MyWindow2::new();
    my_window_1.show();
    my_window_2.show();
    slint::run_event_loop();
}

I haven't tested this, but this might work as workaround until #784 is resolved.

I don't know how to do it, can you leave an example?

Davidc2525 commented 8 months ago

It is possible, but it's a little tricky.

Suppose you have MyWindow1 := Window { ... } and MyWindow2 := Window { ... } and want to show them. To overcome #784 you could put say MyWindow2 into a helper crate, build it using build.rs and export it. Then in your main crate you can import MyWindow and then write something like this:

fn main() {
    let my_window_1 = MyWindow1::new();
    let my_window_2 = helper_create::MyWindow2::new();
    my_window_1.show();
    my_window_2.show();
    slint::run_event_loop();
}

I haven't tested this, but this might work as workaround until #784 is resolved.

I loved slint until I saw that you can create multiple windows, I tried the popupwindow and it turns out that if you open one popup inside another the app freezes