pub struct Button {
pub text: Option<String>,
/* private fields */
}
Expand description
A basic button widget with an optional label.
A Widget that can be pressed and released and may emit an event on_press and on_release. The button can also be triggered with a keyboard key (default space bar).
§Example
Create a button which closes the window when pressed:
Button::new()
.on_press(|_, state, button| {
button.emit(state, WindowEvent::CloseWindow);
})
.build(state, parent, |builder| builder);
Fields§
§text: Option<String>
Implementations§
Source§impl Button
impl Button
Sourcepub fn new() -> Button
pub fn new() -> Button
Create a new button widget with no callbacks.
§Example
Button::new().build(state, parent, |builder| builder);
Sourcepub fn with_label(text: &str) -> Button
pub fn with_label(text: &str) -> Button
Create a new button widget with a specified text label.
§Example
Button::with_label("A Button").build(state, parent, |builder| builder);
Sourcepub fn on_press<F>(self, callback: F) -> Button
pub fn on_press<F>(self, callback: F) -> Button
Set the callback triggered when the button is pressed.
§Example
Creates a button which closes the window when pressed:
Button::new()
.on_press(|_, state, button| {
button.emit(state, WindowEvent::CloseWindow);
})
.build(state, parent, |builder| builder);
Sourcepub fn on_release<F>(self, callback: F) -> Button
pub fn on_release<F>(self, callback: F) -> Button
Set the callback triggered when the button is released.
§Example
Create a button which closes the window when released:
Button::new()
.on_release(|_, state, button| {
button.emit(state, WindowEvent::CloseWindow);
})
.build(state, parent, |builder| builder);
Trait Implementations§
Source§impl Widget for Button
impl Widget for Button
type Ret = Entity
type Data = ()
fn widget_name(&self) -> String
fn on_build( &mut self, state: &mut State, entity: Entity, ) -> <Button as Widget>::Ret
fn on_event(&mut self, state: &mut State, entity: Entity, event: &mut Event)
Source§fn build<F>(
self,
state: &mut State,
parent: impl AsEntity,
builder: F,
) -> Self::Ret
fn build<F>( self, state: &mut State, parent: impl AsEntity, builder: F, ) -> Self::Ret
Adds the widget into state and returns the associated type Ret - an entity id or a tuple of entity ids
fn bind<L, F>(self, lens: L, converter: F) -> Wrapper<L, Self>
fn bind2<L>(self, lens: L) -> LensWrap<L, Self>where
L: Lens,
fn on_update(&mut self, state: &mut State, entity: Entity, data: &Self::Data)
fn on_style( &mut self, state: &mut State, entity: Entity, property: (String, PropType), )
fn on_draw( &mut self, state: &mut State, entity: Entity, canvas: &mut Canvas<OpenGl>, )
Auto Trait Implementations§
impl Freeze for Button
impl !RefUnwindSafe for Button
impl !Send for Button
impl !Sync for Button
impl Unpin 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