Skip to main content

button

Function button 

Source
pub fn button(
    state: Arc<Mutex<StatefulInner<ButtonState>>>,
    label: impl Into<String>,
) -> Button
Expand description

Create a button with a text label and context-managed state

The state handle should be created via ctx.use_state_for() for persistence across rebuilds. This is the most common button constructor. For buttons with custom content (icons, multiple elements, etc.), use button_with().

§Example

let btn_state = ctx.use_state_for("save_btn", ButtonState::Idle);
button(btn_state, "Save")
    .on_click(|_| save_data())
    .bg_color(Color::GREEN)