From 564b9e5a96722447a622ae99d59b895a4e8547bc Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Thu, 21 Dec 2023 15:41:34 -0800 Subject: [PATCH] Added comments to multi-window Also made it open a second window before startup --- Cargo.lock | 4 ++-- examples/multi-window.rs | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 81fb15b..59a3572 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/examples/multi-window.rs b/examples/multi-window.rs index 1687610..e1b73d7 100644 --- a/examples/multi-window.rs +++ b/examples/multi-window.rs @@ -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, @@ -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,