Radio

Radio create a group of radio items and return its selected value.

API

func Radio(c *tgframe.Container, label string, items []string, conf ...*RadioConf) *int
  • c is Parent container.
  • label is the label for options group.
  • items is the list of options.
  • conf is an optional configuration, at most one.
  • Return the index of the selected item, 0-indexed. nil if no item is selected.
// RadioConf is the configuration for the Radio component.
type RadioConf struct {
	tgframe.Base // ID

	// Default is the item the group starts on, as an index into items,
	// 0-based like the return. It is only read until the app user first
	// touches the component, and one that points outside items is ignored.
	Default *int

	// Disabled is true if the radio group is disabled.
	Disabled bool
}

func (c *RadioConf) SetDefault(v int) *RadioConf

Example

	selIdx := tgcomp.Radio(p.Main,
		"Radio", []string{"Value3", "Value4"})

	selItem := ""
	if selIdx != nil {
		selItem = fmt.Sprintf("Value%d", (*selIdx)+3)
	}

	tgcomp.Text(p.Main, "Value: "+selItem,
		&tgcomp.TextConf{ID: "radio_result"})

Starting on the second item, until the app user picks another:

tgcomp.Radio(p.Main, "Radio", []string{"Value3", "Value4"},
	(&tgcomp.RadioConf{}).SetDefault(1))

radio component