Added comments to multi-window

Also made it open a second window before startup
This commit is contained in:
Jonathan Johnson 2023-12-21 15:41:34 -08:00
parent f1a2a711ff
commit 564b9e5a96
No known key found for this signature in database
GPG key ID: A66D6A34D6620579
2 changed files with 15 additions and 2 deletions

4
Cargo.lock generated
View file

@ -106,7 +106,7 @@ dependencies = [
[[package]]
name = "appit"
version = "0.1.1"
source = "git+https://github.com/khonsulabs/appit#1e162ed8df4470522d6dbfb1567b54df74ba911f"
source = "git+https://github.com/khonsulabs/appit#8ca300682c83d1bd6c698bc13ba7011b4be0ca8c"
dependencies = [
"winit",
]
@ -1179,7 +1179,7 @@ checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
[[package]]
name = "kludgine"
version = "0.6.1"
source = "git+https://github.com/khonsulabs/kludgine#76a378ca124b2f965049e65aada1b0e839b37aff"
source = "git+https://github.com/khonsulabs/kludgine#8327335a103ad4ba09093aa201c007d43b4a48d9"
dependencies = [
"ahash",
"alot",

View file

@ -3,11 +3,15 @@ use gooey::widget::MakeWidget;
use gooey::{Application, Open, PendingApp, Run};
fn main() -> gooey::Result {
// To open multiple applications, we need a handle to the application. This
// starts with the `PendingApp` type.
let app = PendingApp::default();
let open_windows = Dynamic::new(0_usize);
let counter = Dynamic::new(0_usize);
// We're going to open two windows as part of the app startup process.
// First, the "main" window that displays some stats about the open windows.
(&open_windows, &counter)
.map_each(|(open, counter)| {
format!(
@ -17,11 +21,19 @@ fn main() -> gooey::Result {
.and(open_window_button(&app, &open_windows, &counter))
.into_rows()
.centered()
// The other examples call run() on the widget/window. Since we're
// opening two windows at the app's startup,
.open(&app)?;
// And now let's open our first "clone" window -- the window that clicking
// the open button on any of the windows will create.
open_another_window(&app, &open_windows, &counter);
// Run the application
app.run()
}
/// Returns a button that invokes `open_another_window` when clicked.
fn open_window_button(
app: &impl Application,
open_windows: &Dynamic<usize>,
@ -35,6 +47,7 @@ fn open_window_button(
})
}
/// Opens another window that contains a button that opens another window.
fn open_another_window(
app: &impl Application,
open_windows: &Dynamic<usize>,