Skip to content

Component ToggleButton

MeowLynxSea edited this page Jun 13, 2026 · 5 revisions

ToggleButton

A button with a "selected" state. Like Button plus a selected(bool) and on_toggle(bool, …) instead of on_click.

Import

use yororen_ui::headless::toggle_button::toggle_button;

Minimal example

use yororen_ui::headless::toggle_button::toggle_button;

toggle_button("bold", cx)
    .caption("B")
    .selected(self.bold)
    .on_toggle({
        let entity = cx.entity();
        move |new: bool, _window, cx| {
            entity.update(cx, |s, _cx| s.bold = new);
        }
    })
    .render(cx)

Props

Method Purpose
caption(text) Button label.
icon(source) Optional leading IconSource.
icon_size(px) Size of the leading icon.
caption_icon(text, source) Convenience: set both caption and icon in one call.
variant(v) One of the ActionVariantKind values.
selected(v) Current toggled state.
disabled(v) Disable the toggle.
on_toggle(closure) Fn(bool, &mut Window, &mut App) + 'static + Send + Sync. Fired with the new state.

Notes

  • Factory takes (id, cx). The cx is needed for the focus handle.
  • No state entity. Capture self with cx.entity().clone().
  • .render(cx) returns Stateful<Div>.

See also

Button, IconButton, Switch, Checkbox

Clone this wiki locally