Struct Button

Source
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

Source

pub fn new() -> Button

Create a new button widget with no callbacks.

§Example
Button::new().build(state, parent, |builder| builder);
Source

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);
Source

pub fn on_press<F>(self, callback: F) -> Button
where F: 'static + Fn(&mut Button, &mut State, Entity),

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);
Source

pub fn on_release<F>(self, callback: F) -> Button
where F: 'static + Fn(&mut Button, &mut State, Entity),

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);
Source

pub fn with_key(self, key: Code) -> Button

Set the keyboard key which triggers the button.

§Example

Triggers the button’s on_press callback when the Enter key is pressed and the button has focus.

Button::new()
    .with_key(Code::Enter)
   .build(state, parent, |builder| builder);

Trait Implementations§

Source§

impl Default for Button

Source§

fn default() -> Button

Returns the “default value” for a type. Read more
Source§

impl Widget for Button

Source§

type Ret = Entity

Source§

type Data = ()

Source§

fn widget_name(&self) -> String

Source§

fn on_build( &mut self, state: &mut State, entity: Entity, ) -> <Button as Widget>::Ret

Source§

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
where F: FnMut(Builder<'_, Self>) -> Builder<'_, Self>, Self: Sized + 'static,

Adds the widget into state and returns the associated type Ret - an entity id or a tuple of entity ids
Source§

fn bind<L, F>(self, lens: L, converter: F) -> Wrapper<L, Self>
where L: Lens, F: 'static + Fn(&<L as Lens>::Target) -> Self::Data,

Source§

fn bind2<L>(self, lens: L) -> LensWrap<L, Self>
where L: Lens,

Source§

fn on_update(&mut self, state: &mut State, entity: Entity, data: &Self::Data)

Source§

fn on_style( &mut self, state: &mut State, entity: Entity, property: (String, PropType), )

Source§

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> 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> EventHandler for T
where T: Widget + 'static,

Source§

fn widget_name(&self) -> String

Source§

fn on_update( &mut self, state: &mut State, entity: Entity, node: &(dyn Node + 'static), )

Source§

fn on_event_(&mut self, state: &mut State, entity: Entity, event: &mut Event)

Source§

fn on_style( &mut self, state: &mut State, entity: Entity, property: (String, PropType), )

Source§

fn on_draw_( &mut self, state: &mut State, entity: Entity, canvas: &mut Canvas<OpenGl>, )

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
Source§

impl<T> Node for T
where T: 'static,