[][src]Struct druid::widget::Button

pub struct Button<T> { /* fields omitted */ }

A button with a text label.

Implementations

impl<T: Data> Button<T>[src]

pub fn new(text: impl Into<LabelText<T>>) -> Button<T>[src]

Create a new button with a text label.

Use the .on_click method to provide a closure to be called when the button is clicked.

Examples

use druid::widget::Button;

let button = Button::new("Increment").on_click(|_ctx, data: &mut u32, _env| {
    *data += 1;
});

pub fn from_label(label: Label<T>) -> Button<T>[src]

Create a new button with the provided Label.

Use the .on_click method to provide a closure to be called when the button is clicked.

Examples

use druid::Color;
use druid::widget::{Button, Label};

let button = Button::from_label(Label::new("Increment").with_text_color(Color::grey(0.5))).on_click(|_ctx, data: &mut u32, _env| {
    *data += 1;
});

pub fn dynamic(text: impl Fn(&T, &Env) -> String + 'static) -> Self[src]

Construct a new dynamic button.

The contents of this button are generated from the data using a closure.

This is provided as a convenience; a closure can also be passed to new, but due to limitations of the implementation of that method, the types in the closure need to be annotated, which is not true for this method.

Examples

The following are equivalent.

use druid::Env;
use druid::widget::Button;
let button1: Button<u32> = Button::new(|data: &u32, _: &Env| format!("total is {}", data));
let button2: Button<u32> = Button::dynamic(|data, _| format!("total is {}", data));

pub fn on_click(
    self,
    f: impl Fn(&mut EventCtx<'_, '_>, &mut T, &Env) + 'static
) -> ControllerHost<Self, Click<T>>
[src]

Provide a closure to be called when this button is clicked.

Trait Implementations

impl<T: Data> Widget<T> for Button<T>[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for Button<T>[src]

impl<T> !Send for Button<T>[src]

impl<T> !Sync for Button<T>[src]

impl<T> Unpin for Button<T>[src]

impl<T> !UnwindSafe for Button<T>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> RoundFrom<T> for T

impl<T, U> RoundInto<U> for T where
    U: RoundFrom<T>, 

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.