Skip to main content

button

Function button 

Source
pub fn button(label_text: impl Into<Value<String>>) -> Element<Panel>
Expand description

Creates a push button that shows label_text.

The button is focusable and can be pressed with on_press, which is chained on the element it returns. While it holds the keyboard focus, a press of Enter or Space fires the same handler; the activation is what activate_on_keys provides, and a key repeat fires nothing. The focus ring draws only while the focus last moved by keyboard navigation, so a press on the button draws none.

The colors come from the theme: ColorToken::SURFACE at rest, ColorToken::SURFACE_HOVER under the pointer, ColorToken::SURFACE_PRESSED while a press is held, and a ColorToken::FOCUS_RING border of two logical pixels while the focus came from the keyboard. The border’s space is reserved in every state, so the ring appears without a layout change.

use smudge_core::reactive::{prelude::*, signal_local};
use smudge_widgets::button;

let (clicks, set_clicks) = signal_local(0u32);
let ok = button("OK").on_press(move || {
    set_clicks.set(clicks.get() + 1);
});