Documentation
¶
Overview ¶
Package toggle provides an on/off switch with an animated knob, the standard settings control on iOS and Android.
Index ¶
- type Switch
- func (s *Switch) CacheSafe() bool
- func (s *Switch) Checked() bool
- func (s *Switch) Disabled(v bool) *Switch
- func (s *Switch) KnobColor(off, on properties.Color) *Switch
- func (s *Switch) Layout(gtx layout.Context) layout.Dimensions
- func (s *Switch) OnChange(fn func(on bool)) *Switch
- func (s *Switch) SetChecked(v bool)
- func (s *Switch) Toggle()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Switch ¶
type Switch struct {
// Contextual gives it a context menu (Context).
elements.Contextual
// contains filtered or unexported fields
}
Switch is a stateful on/off switch with an optional label. Create it once with New and lay it out every frame.
func New ¶
New returns a switch. label is optional; it shows left of the track and fills the row, as in a settings list. The styles argument is optional: Background is the track when on (default theme.primary), BorderColor the track when off (default theme.border), Color the label (default theme.text), FontSize the label size.
func (*Switch) CacheSafe ¶
CacheSafe reports true: what it draws comes from its own fields, which the cache watches.
func (*Switch) Disabled ¶
Disabled greys the switch out and ignores input. It returns s for chaining.
func (*Switch) KnobColor ¶
func (s *Switch) KnobColor(off, on properties.Color) *Switch
KnobColor sets the knob's color when off and when on (white by default), so it stays visible on a light track: a white "on" track in a monochrome theme hides a white knob. It returns s for chaining.
func (*Switch) OnChange ¶
OnChange sets the handler called when the user flips the switch. It returns s for chaining.
func (*Switch) SetChecked ¶
SetChecked sets the state without invoking OnChange.