core/radio/item.go
Functions
func Children
func (it *Item) Children() []widget.Widget {
return nil
}
func Draw
Draw renders the radio item to the canvas.
func (it *Item) Draw(ctx widget.Context, canvas widget.Canvas) {
selected := it.group.isSelected(it.value)
it.painter.PaintRadio(canvas, PaintState{
Label: it.label,
Selected: selected,
Hovered: it.state == stateHover,
Pressed: it.state == statePressed,
Focused: it.IsFocused(),
Disabled: it.group.cfg.ResolvedDisabled(),
Bounds: it.Bounds(),
})
}
func Event
Event handles an input event and returns true if consumed.
func (it *Item) Event(ctx widget.Context, e event.Event) bool {
return handleItemEvent(it, ctx, e)
}
func IsFocusable
IsFocusable reports whether the item can currently receive focus.
An item is focusable when it is visible, enabled, and its group is not disabled.
func (it *Item) IsFocusable() bool {
return it.IsVisible() && it.IsEnabled() && !it.group.cfg.ResolvedDisabled()
}
func Label
Label returns the display label of this radio item.
func (it *Item) Label() string {
return it.label
}
func Layout
Layout calculates the item's preferred size within the given constraints.
func (it *Item) Layout(_ widget.Context, constraints geometry.Constraints) geometry.Size {
totalWidth := outerRadius*2 + itemPadding*2
totalHeight := outerRadius*2 + itemPadding*2
if it.label != "" {
textWidth := float32(len(it.label)) * defaultFontSize * charWidthRatio
totalWidth += labelGap + textWidth
}
if totalHeight < itemMinHeight {
totalHeight = itemMinHeight
}
preferred := geometry.Sz(totalWidth, totalHeight)
return constraints.Constrain(preferred)
}
func Value
Value returns the programmatic value of this radio item.
func (it *Item) Value() string {
return it.value
}
Structs
type Item struct
Item represents a single radio button within a [Group].
Items are created automatically by [NewGroup] from the [ItemDef] list
provided via the [Items] option. Each item holds a reference to its
parent group for mutual-exclusion selection.
type Item struct {
widget.WidgetBase
value string
label string
group *Group
state interactionState
painter Painter
}
Children returns nil because a radio item is a leaf widget.