toggle

package
v1.0.31-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package toggle provides an on/off switch with an animated knob, the standard settings control on iOS and Android.

Index

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

func New(label string, st ...styles.Styles) *Switch

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

func (s *Switch) CacheSafe() bool

CacheSafe reports true: what it draws comes from its own fields, which the cache watches.

func (*Switch) Checked

func (s *Switch) Checked() bool

Checked reports whether the switch is on.

func (*Switch) Disabled

func (s *Switch) Disabled(v bool) *Switch

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) Layout

func (s *Switch) Layout(gtx layout.Context) layout.Dimensions

func (*Switch) OnChange

func (s *Switch) OnChange(fn func(on bool)) *Switch

OnChange sets the handler called when the user flips the switch. It returns s for chaining.

func (*Switch) SetChecked

func (s *Switch) SetChecked(v bool)

SetChecked sets the state without invoking OnChange.

func (*Switch) Toggle

func (s *Switch) Toggle()

Toggle flips the switch and invokes OnChange, as a tap would.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL