Skip to main content

Button

Struct Button 

Source
pub struct Button { /* private fields */ }
Expand description

A Button widget

Implementations§

Source§

impl Button

Source

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}
Source

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}
Source

pub fn filled(self) -> Self

Set the button to be filled

Source

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 Clone for Button

Source§

fn clone(&self) -> Button

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl WidgetExt for Button

Source§

fn inner(&self) -> *mut CWidget

Gets the inner wrapper
Source§

fn from_widget_ptr(ptr: *mut CWidget) -> Self

Constructs a new widget from a widget pointer
Source§

fn underlying(&self) -> *mut c_void

Gets the underlying pointer (JNI jobject on android, UIView on iOS)
Source§

fn id(self, id: &'static str) -> Self
where Self: 'static + Sync + Sized + Clone + Send,

Adds the widget to the widget map, and assigns it an id
Source§

fn background(self, col: Color) -> Self
where Self: Sized,

Sets the background color
Source§

impl Send for Button

Source§

impl Sync for Button

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.