Switches
Switches allow users to select one or more options out of a list of items represented with switch widgets (core.Switches).
Properties
You can make switches from a list of strings:
core.NewSwitches(b).SetStrings("Go", "Python", "C++")If you need to customize the items more, you can use a list of core.SwitchItem objects:
core.NewSwitches(b).SetItems(
core.SwitchItem{Value: "Go", Tooltip: "Elegant, fast, and easy-to-use"},
core.SwitchItem{Value: "Python", Tooltip: "Slow and duck-typed"},
core.SwitchItem{Value: "C++", Tooltip: "Hard to use and slow to compile"},
)You can make switches mutually exclusive so that only one can be selected at a time:
core.NewSwitches(b).SetMutex(true).SetStrings("Go", "Python", "C++")Types
You can make switches render as chips:
core.NewSwitches(b).SetType(core.SwitchChip).SetStrings("Go", "Python", "C++")You can make switches render as checkboxes:
core.NewSwitches(b).SetType(core.SwitchCheckbox).SetStrings("Go", "Python", "C++")You can make switches render as radio buttons:
core.NewSwitches(b).SetType(core.SwitchRadioButton).SetStrings("Go", "Python", "C++")You can make switches render as segmented buttons:
core.NewSwitches(b).SetType(core.SwitchSegmentedButton).SetStrings("Go", "Python", "C++")Events
You can detect when the user changes which switches are selected:
sw := core.NewSwitches(b).SetStrings("Go", "Python", "C++")
sw.OnChange(func(e events.Event) {
core.MessageSnackbar(sw, fmt.Sprintf("Currently selected: %v", sw.SelectedItems()))
})Styles
You can make switches render vertically:
core.NewSwitches(b).SetStrings("Go", "Python", "C++").Styler(func(s *styles.Style) {
s.Direction = styles.Column
})You can change the font size of switches:
sw := core.NewSwitches(b).SetStrings("Go", "Python", "C++")
sw.Styler(func(s *styles.Style) {
s.Font.Size.Dp(25)
})You can change the icon size of switches:
sw := core.NewSwitches(b).SetType(core.SwitchCheckbox).SetStrings("Go", "Python", "C++")
sw.Styler(func(s *styles.Style) {
s.IconSize.Set(units.Dp(40))
})