From 63a4549f29229c09d3deb873364b5b7718ba63ef Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Wed, 29 Nov 2023 15:42:06 -0800 Subject: [PATCH] Tested buttons in buttons --- examples/buttonception.rs | 60 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 examples/buttonception.rs diff --git a/examples/buttonception.rs b/examples/buttonception.rs new file mode 100644 index 0000000..6b5e297 --- /dev/null +++ b/examples/buttonception.rs @@ -0,0 +1,60 @@ +//! This example shows off how buttons are able to use any widget, including +//! buttons, as their "label". The widget hierarchy constructed for this example +//! is: +//! +//! ```text +//! ┏ Align +//! ┃ ┏ Stack +//! ┃ ┃ ┏ Button +//! ┃ ┃ ┃ ┏ Stack +//! ┃ ┃ ┃ ┃ ┏ "Yo dawg!" +//! ┃ ┃ ┃ ┃ ┣ Button +//! ┃ ┃ ┃ ┃ ┃ ┏ Stack +//! ┃ ┃ ┃ ┃ ┃ ┃ ┏ "I heard you like buttons" +//! ┃ ┃ ┃ ┃ ┃ ┃ ┣ Button +//! ┃ ┃ ┃ ┃ ┃ ┃ ┃ ╺ "So I put buttons in your buttons" +//! ┃ ┃ ┣ clicked_button Label +//! ``` + +use gooey::value::Dynamic; +use gooey::widget::MakeWidget; +use gooey::widgets::button::{ButtonHoverBackground, ButtonHoverForeground}; +use gooey::Run; +use kludgine::Color; + +fn main() -> gooey::Result { + let clicked_button = Dynamic::<&'static str>::default(); + + let inner_button = "So I put buttons in your buttons" + .into_button() + .on_click({ + let clicked_button = clicked_button.clone(); + move |()| clicked_button.set("inner button clicked") + }) + .with(&ButtonHoverBackground, Color::RED) + .with(&ButtonHoverForeground, Color::WHITE); + + let middle_button = "I heard you like buttons" + .and(inner_button) + .into_rows() + .into_button() + .on_click({ + let clicked_button = clicked_button.clone(); + move |()| clicked_button.set("middle button clicked") + }); + + let outer_button = "Yo dawg!" + .and(middle_button) + .into_rows() + .into_button() + .on_click({ + let clicked_button = clicked_button.clone(); + move |()| clicked_button.set("outer button clicked") + }); + + outer_button + .and(clicked_button) + .into_rows() + .centered() + .run() +}