Toggle
The pressed-state button, and groups with single or multiple selection.
Toggle stays filled while On; clicking flips it.
ToggleGroup coordinates a row — radio semantics by default
(Sel), independent bools with Multiple.
Installation
Use the module import (the default), or own the source: lotusui add
vendors the component into your app and lotusui update keeps the copy mergeable —
see Registry.
go get github.com/ikaito-com/lotusui
# or vendor the source into your app:
go run github.com/ikaito-com/lotusui/cmd/lotusui add toggle
Usage
var bold lotusui.Toggle
bold.Layout(th, gtx, lotusui.ToggleOpts{Icon: lotusui.IconTextBold})
if bold.On { /* … */ }
ToggleGroup — single
var format = lotusui.ToggleGroup{Sel: 0}
format.Layout(th, gtx, lotusui.SizeMD,
lotusui.ToggleGroupItem{Icon: lotusui.IconTextBold},
lotusui.ToggleGroupItem{Icon: lotusui.IconTextItalic},
lotusui.ToggleGroupItem{Icon: lotusui.IconTextUnderline},
)
ToggleGroup — multiple
var marks = lotusui.ToggleGroup{Multiple: true}
Sizes
small.Layout(th, gtx, lotusui.ToggleOpts{Label: "Small", Outline: true, Size: lotusui.SizeSM})
Disabled
t.Layout(th, gtx, lotusui.ToggleOpts{Label: "Disabled", Disabled: true})
Group outline
var g = lotusui.ToggleGroup{Sel: 0, Outline: true}
Group sizes
The size is the Layout parameter — the whole group moves together.
g.Layout(th, gtx, lotusui.SizeSM, items...)
Group disabled
var g = lotusui.ToggleGroup{Multiple: true, Disabled: true}
Group vertical
var g = lotusui.ToggleGroup{Multiple: true, Vertical: true, Spacing: 1}
Group spacing
Spacing overrides the 2dp gap between items.
var g = lotusui.ToggleGroup{Sel: 0, Outline: true, Spacing: 8}
Font weight selector
Content replaces Icon/Label with arbitrary content inside the item's chrome — composed here with a Field.
lotusui.ToggleGroupItem{Content: weightCell("Aa", "Bold", font.Bold)}
API
| Option | Type | Description |
|---|---|---|
On | bool | The pressed state — yours; clicking flips it. |
Icon / Label | string | One or both. |
Content | layout.Widget | Replaces Icon/Label with arbitrary content in the chrome. |
Size | Size | The shared size presets. |
Outline | bool | Bordered while off. |
Disabled | bool | Dimmed, unclickable. |
ToggleGroup.Sel / Multiple / On | int / bool / []bool | Single-select index, or independent bools. |
ToggleGroup.Outline / Disabled | bool | Group-wide chrome and state. |
ToggleGroup.Vertical / Spacing | bool / unit.Dp | Stacked axis; gap override (default 2dp). |