Struct tuix::Button[]

pub struct Button {
    pub text: Option<String>,
    // some fields omitted
}
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

Create a new button widget with no callbacks.

Example

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

Create a new button widget with a specified text label.

Example

Button::with_label("A Button").build(state, parent, |builder| builder);

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

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

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

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

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.