1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
/// Creates a GTK button. /// /// # See Also /// - [widget Macro](macro.widget.html) /// - [ButtonBuilder in gtk-rs](https://gtk-rs.org/docs/gtk/struct.ButtonBuilder.html) /// - [Button in gtk-rs](https://gtk-rs.org/docs/gtk/struct.Button.html) /// /// # Examples /// /// Short example: /// ```rust,no_run /// # #[macro_use] /// # extern crate gstore; /// # use gstore::prelude::*; /// # use gtk::prelude::*; /// # slice! { CountState { count: i64 = 0 } CountAction { Clicked } } /// # fn reduce_count(action: CountAction, state: CountState) -> CountState { state } /// # store! { count: Count = crate::{CountState, CountAction, reduce_count} } /// # fn main() { /// # let store = Store::new(|a,s| s, vec![]); /// button!("Click Me!", |store| store.dispatch(Action::Count(CountAction::Clicked))); /// # } /// ``` /// /// Long example: /// ```rust,no_run /// # #[macro_use] /// # extern crate gstore; /// # use gstore::prelude::*; /// # use gtk::prelude::*; /// # slice! { CountState { count: i64 = 0 } CountAction { Clicked } } /// # fn reduce_count(action: CountAction, state: CountState) -> CountState { state } /// # store! { count: Count = crate::{CountState, CountAction, reduce_count} } /// # fn main() { /// # let store = Store::new(|a,s| s, vec![]); /// button! { /// properties { /// label: "Click Me!" /// } /// connections { /// (store) connect_clicked: move |_| store.dispatch(Action::Count(CountAction::Clicked)) /// } /// children [ /// image!("list-add-symbolic", gtk::IconSize::Button) /// ] /// }; /// # } /// ``` #[macro_export] macro_rules! button { ($text:expr, |$store:ident| $callback:expr) => {{ let widget = gtk::ButtonBuilder::new().visible(true).label($text).build(); { let $store = $store.clone(); widget.connect_clicked(move |_| $callback); } widget }}; ( $($text:tt)* ) => {{ let widget = gtk::ButtonBuilder::new().visible(true).build(); widget!(widget { $($text)* }); widget }} }