[−][src]Struct druid::widget::Button
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]
self,
f: impl Fn(&mut EventCtx<'_, '_>, &mut T, &Env) + 'static
) -> ControllerHost<Self, Click<T>>
Provide a closure to be called when this button is clicked.
Trait Implementations
impl<T: Data> Widget<T> for Button<T>
[src]
pub fn event(
&mut self,
ctx: &mut EventCtx<'_, '_>,
event: &Event,
_data: &mut T,
_env: &Env
)
[src]
&mut self,
ctx: &mut EventCtx<'_, '_>,
event: &Event,
_data: &mut T,
_env: &Env
)
pub fn lifecycle(
&mut self,
ctx: &mut LifeCycleCtx<'_, '_>,
event: &LifeCycle,
data: &T,
env: &Env
)
[src]
&mut self,
ctx: &mut LifeCycleCtx<'_, '_>,
event: &LifeCycle,
data: &T,
env: &Env
)
pub fn update(
&mut self,
ctx: &mut UpdateCtx<'_, '_>,
old_data: &T,
data: &T,
env: &Env
)
[src]
&mut self,
ctx: &mut UpdateCtx<'_, '_>,
old_data: &T,
data: &T,
env: &Env
)
pub fn layout(
&mut self,
ctx: &mut LayoutCtx<'_, '_>,
bc: &BoxConstraints,
data: &T,
env: &Env
) -> Size
[src]
&mut self,
ctx: &mut LayoutCtx<'_, '_>,
bc: &BoxConstraints,
data: &T,
env: &Env
) -> Size
pub fn paint(&mut self, ctx: &mut PaintCtx<'_, '_, '_>, data: &T, env: &Env)
[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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> RoundFrom<T> for T
pub fn round_from(x: T) -> T
impl<T, U> RoundInto<U> for T where
U: RoundFrom<T>,
U: RoundFrom<T>,
pub fn round_into(self) -> U
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]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,