pub struct Button { /* private fields */ }Expand description
A Button widget
Implementations§
Source§impl Button
impl Button
Sourcepub fn new(label: &str) -> Self
pub fn new(label: &str) -> Self
Constructs a new widget
Examples found in repository?
examples/simple.rs (line 10)
5fn mygui(vc: &ViewController) -> MainView {
6 let count = Rc::from(RefCell::from(0));
7 MainView::new(
8 &vc,
9 &[
10 &Button::new("Increment").foreground(Color::Blue).action({
11 let count = count.clone();
12 move |_| {
13 log("Increment clicked");
14 let mut c = count.borrow_mut();
15 *c += 1;
16 let t: Text = from_id("mytext").unwrap();
17 t.text(&format!("{}", c));
18 }
19 }),
20 &Text::new("0").id("mytext").center().bold(),
21 &Button::new("Decrement")
22 .foreground(Color::Red)
23 .action(move |_| {
24 log("Decrement clicked");
25 let mut c = count.borrow_mut();
26 *c -= 1;
27 let t: Text = from_id("mytext").unwrap();
28 t.text(&format!("{}", c));
29 }),
30 ],
31 )
32}Sourcepub fn action<F: 'static + FnMut(&Self)>(self, cb: F) -> Self
pub fn action<F: 'static + FnMut(&Self)>(self, cb: F) -> Self
Sets the action of the widget
Examples found in repository?
examples/simple.rs (lines 10-19)
5fn mygui(vc: &ViewController) -> MainView {
6 let count = Rc::from(RefCell::from(0));
7 MainView::new(
8 &vc,
9 &[
10 &Button::new("Increment").foreground(Color::Blue).action({
11 let count = count.clone();
12 move |_| {
13 log("Increment clicked");
14 let mut c = count.borrow_mut();
15 *c += 1;
16 let t: Text = from_id("mytext").unwrap();
17 t.text(&format!("{}", c));
18 }
19 }),
20 &Text::new("0").id("mytext").center().bold(),
21 &Button::new("Decrement")
22 .foreground(Color::Red)
23 .action(move |_| {
24 log("Decrement clicked");
25 let mut c = count.borrow_mut();
26 *c -= 1;
27 let t: Text = from_id("mytext").unwrap();
28 t.text(&format!("{}", c));
29 }),
30 ],
31 )
32}Sourcepub fn foreground(self, col: Color) -> Self
pub fn foreground(self, col: Color) -> Self
Sets the foreground color
Examples found in repository?
examples/simple.rs (line 10)
5fn mygui(vc: &ViewController) -> MainView {
6 let count = Rc::from(RefCell::from(0));
7 MainView::new(
8 &vc,
9 &[
10 &Button::new("Increment").foreground(Color::Blue).action({
11 let count = count.clone();
12 move |_| {
13 log("Increment clicked");
14 let mut c = count.borrow_mut();
15 *c += 1;
16 let t: Text = from_id("mytext").unwrap();
17 t.text(&format!("{}", c));
18 }
19 }),
20 &Text::new("0").id("mytext").center().bold(),
21 &Button::new("Decrement")
22 .foreground(Color::Red)
23 .action(move |_| {
24 log("Decrement clicked");
25 let mut c = count.borrow_mut();
26 *c -= 1;
27 let t: Text = from_id("mytext").unwrap();
28 t.text(&format!("{}", c));
29 }),
30 ],
31 )
32}Trait Implementations§
Source§impl WidgetExt for Button
impl WidgetExt for Button
Source§fn from_widget_ptr(ptr: *mut CWidget) -> Self
fn from_widget_ptr(ptr: *mut CWidget) -> Self
Constructs a new widget from a widget pointer
Source§fn underlying(&self) -> *mut c_void
fn underlying(&self) -> *mut c_void
Gets the underlying pointer (JNI jobject on android, UIView on iOS)
Source§fn background(self, col: Color) -> Selfwhere
Self: Sized,
fn background(self, col: Color) -> Selfwhere
Self: Sized,
Sets the background color
impl Send for Button
impl Sync for Button
Auto Trait Implementations§
impl Freeze for Button
impl RefUnwindSafe for Button
impl Unpin for Button
impl UnsafeUnpin for Button
impl UnwindSafe for Button
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more