Skip to content

Component ToggleButton

MeowLynxSea edited this page Jun 18, 2026 · 5 revisions

ToggleButton

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

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, _, cx| entity.update(cx, |s, _| 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) Set both caption and icon in one call.
variant(v) ActionVariantKind.
selected(v) Current toggled state.
disabled(v) Disable the toggle.
on_toggle(closure) Fn(bool, &mut Window, &mut App) + 'static + Send + Sync.

.render(cx) returns Stateful<Div>. No state entity.

See also: Button, Switch, Checkbox.

Clone this wiki locally