What to try
Switch grouped buttons and observe the active option.
Usage notes
Choose action, single-select or multi-select mode. Use stable item keys so changing labels does not change business identity.
Create through Screen
The Screen constructor returns a node ID. Pass that ID to Screen layout, state and event APIs. It is separate from the standalone control object documented below.
Native Xu setup fragment: call configure during initialization of an existing Screen. See the complete example for window creation, event dispatch and cleanup.
#ui/widgets
fn configure(screen $&widgets.Screen) int {
items := [widgets.button_group_item(1,"Save"),widgets.button_group_item(2,"Export")]
id := screen.button_group(&items,widgets.BUTTON_GROUP_SINGLE) or >>
screen.place(id,24.0,24.0,320.0,80.0) or >>
<< id
}
($&Screen) button_group
pub fn (s $&Screen) button_group(items &[]ButtonGroupItem,mode int) int
Purpose
Create ButtonGroup in Screen and return the component node ID; throw on creation failure.
Parameters
s $&Screen- The
Screen instance used by this call (exclusive borrow).
items &[]ButtonGroupItem- items (read-only borrow; caller keeps the original; type &[]ButtonGroupItem)
mode int- mode (int)
Returns
int — component node ID for place and other Screen methods.
Placement, state and events
The application owns the component. Screen.place positions nodes; Screen.set_enabled and Screen.set_visible control availability and visibility. Present again after state changes, handle or errors, and keep topology changes outside paint callbacks. ToastHost uses its own queue API.
Action · Styles · UI lifecycle and styling guide
Screen.place · Screen.set_enabled · Screen.set_visible
Standalone control object API
These types and methods support applications that manage control objects, input and painting directly. Their receiver is a control object, not a Screen node ID. For Screen usage, use the constructor above and the Screen methods in the Widgets module.
struct ButtonGroup
pub struct ButtonGroup {
}
Purpose
ButtonGroup context or state structure.
Public fields
This type has no public fields.
(&ButtonGroup) id
pub fn (g &ButtonGroup) id() int
Purpose
Return the unique integer ID of the element or control.
Parameters
g &ButtonGroup- The
ButtonGroup instance used by this call (borrow).
Returns
int — a value of this type
(&ButtonGroup) bounds
pub fn (g &ButtonGroup) bounds() layout.Rect
Purpose
Return the bounding Rectangle of the control or geometry.
Parameters
g &ButtonGroup- The
ButtonGroup instance used by this call (borrow).
Returns
layout.Rect — a value of this type
(&ButtonGroup) needs_paint
pub fn (g &ButtonGroup) needs_paint() bool
Purpose
Return whether the control needs repainting; call painted after painting to clear the flag.
Parameters
g &ButtonGroup- The
ButtonGroup instance used by this call (borrow).
Returns
bool — true or false
($&ButtonGroup) painted
pub fn (g $&ButtonGroup) painted()
Purpose
Acknowledge the painted frame and clear the dirty flag; this is not a query.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
Returns
This call does not return a value.
(&ButtonGroup) is_enabled
pub fn (g &ButtonGroup) is_enabled() bool
Purpose
Return whether the control is currently enabled.
Parameters
g &ButtonGroup- The
ButtonGroup instance used by this call (borrow).
Returns
bool — true or false
(&ButtonGroup) is_selectable
pub fn (g &ButtonGroup) is_selectable() bool
Purpose
Operation on &ButtonGroup: whether it is selectable.
Parameters
g &ButtonGroup- The
ButtonGroup instance used by this call (borrow).
Returns
bool — true or false
($&ButtonGroup) set_selectable
pub fn (g $&ButtonGroup) set_selectable(selectable bool)
Purpose
Operation on $&ButtonGroup: set selectable.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
selectable bool- selectable (bool)
Returns
This call does not return a value.
(&ButtonGroup) is_focused
pub fn (g &ButtonGroup) is_focused() bool
Purpose
Return whether the control currently has input focus.
Parameters
g &ButtonGroup- The
ButtonGroup instance used by this call (borrow).
Returns
bool — true or false
(&ButtonGroup) active_key
pub fn (g &ButtonGroup) active_key() int
Purpose
Operation on &ButtonGroup: active key.
Parameters
g &ButtonGroup- The
ButtonGroup instance used by this call (borrow).
Returns
int — a value of this type
(&ButtonGroup) values
pub fn (g &ButtonGroup) values() []int
Purpose
Return a slice containing all values in the collection.
Parameters
g &ButtonGroup- The
ButtonGroup instance used by this call (borrow).
Returns
[]int — slice result
($&ButtonGroup) set_items
pub fn (g $&ButtonGroup) set_items(items &[]ButtonGroupItem) int
Purpose
Operation on $&ButtonGroup: set items. Throws on failure; handle the error or propagate it to the caller.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
items &[]ButtonGroupItem- items (read-only borrow; caller keeps the original; type &[]ButtonGroupItem)
Returns
int — a value of this type
($&ButtonGroup) set_appearance
pub fn (g $&ButtonGroup) set_appearance(a &ButtonGroupAppearance) int
Purpose
Operation on $&ButtonGroup: set appearance. Throws on failure; handle the error or propagate it to the caller.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
a &ButtonGroupAppearance- value (read-only borrow; caller keeps the original; type &ButtonGroupAppearance)
Returns
int — a value of this type
($&ButtonGroup) set_item_enabled
pub fn (g $&ButtonGroup) set_item_enabled(key int,enabled bool) int
Purpose
Operation on $&ButtonGroup: set item enabled. Throws on failure; handle the error or propagate it to the caller.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
key int- key (int)
enabled bool- enabled (bool)
Returns
int — a value of this type
($&ButtonGroup) set_item_label
pub fn (g $&ButtonGroup) set_item_label(key int,label string) int
Purpose
Operation on $&ButtonGroup: set item label. Throws on failure; handle the error or propagate it to the caller.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
key int- key (int)
label string- label (string)
Returns
int — a value of this type
($&ButtonGroup) set_checked
pub fn (g $&ButtonGroup) set_checked(key int,selected bool) int
Purpose
Operation on $&ButtonGroup: set checked. Throws on failure; handle the error or propagate it to the caller.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
key int- key (int)
selected bool- selected (bool)
Returns
int — a value of this type
($&ButtonGroup) set_focus
pub fn (g $&ButtonGroup) set_focus(value bool)
Purpose
Operation on $&ButtonGroup: set focus.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
value bool- value (bool)
Returns
This call does not return a value.
($&ButtonGroup) cancel
pub fn (g $&ButtonGroup) cancel()
Purpose
Execute cancel on $&ButtonGroup.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
Returns
This call does not return a value.
($&ButtonGroup) set_enabled
pub fn (g $&ButtonGroup) set_enabled(value bool)
Purpose
Operation on $&ButtonGroup: set enabled.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
value bool- value (bool)
Returns
This call does not return a value.
($&ButtonGroup) set_read_only
pub fn (g $&ButtonGroup) set_read_only(value bool)
Purpose
Operation on $&ButtonGroup: set read only.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
value bool- value (bool)
Returns
This call does not return a value.
($&ButtonGroup) set_bounds
pub fn (g $&ButtonGroup) set_bounds(bounds &layout.Rect) int
Purpose
Operation on $&ButtonGroup: set bounds. Throws on failure; handle the error or propagate it to the caller.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
bounds &layout.Rect- bounds (read-only borrow; caller keeps the original; type &layout.Rect)
Returns
int — a value of this type
($&ButtonGroup) set_style
pub fn (g $&ButtonGroup) set_style(style &ControlStyle) int
Purpose
Operation on $&ButtonGroup: set style. Throws on failure; handle the error or propagate it to the caller.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
style &ControlStyle- style (read-only borrow; caller keeps the original; type &ControlStyle)
Returns
int — a value of this type
($&ButtonGroup) clear_style
pub fn (g $&ButtonGroup) clear_style()
Purpose
Operation on $&ButtonGroup: clear style.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
Returns
This call does not return a value.
($&ButtonGroup) set_motion
pub fn (g $&ButtonGroup) set_motion(spec &MotionSpec) int
Purpose
Operation on $&ButtonGroup: set motion. Throws on failure; handle the error or propagate it to the caller.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
spec &MotionSpec- spec (read-only borrow; caller keeps the original; type &MotionSpec)
Returns
int — a value of this type
($&ButtonGroup) apply_styles
pub fn (g $&ButtonGroup) apply_styles(styles &Styles) int
Purpose
Resolve and apply theme metrics to the control. Throws on failure; handle the error or propagate it to the caller.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
styles &Styles- styles (read-only borrow; caller keeps the original; type &Styles)
Returns
int — a value of this type
(&ButtonGroup) item_bounds
pub fn (g &ButtonGroup) item_bounds(key int) layout.Rect
Purpose
Operation on &ButtonGroup: item bounds. Throws on failure; handle the error or propagate it to the caller.
Parameters
g &ButtonGroup- The
ButtonGroup instance used by this call (borrow).
key int- key (int)
Returns
layout.Rect — a value of this type
($&ButtonGroup) input
pub fn (g $&ButtonGroup) input(event &ui.InputEvent) Action
Purpose
Process routed mouse, keyboard, or touch input events. Throws on failure; handle the error or propagate it to the caller.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
event &ui.InputEvent- event (read-only borrow; caller keeps the original; type &ui.InputEvent)
Returns
Action — input result with kind, id, repaint and focus requests.
($&ButtonGroup) route
pub fn (g $&ButtonGroup) route(kind int,event &ui.InputEvent) Action
Purpose
Route and dispatch the input event to matching targets. Throws on failure; handle the error or propagate it to the caller.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
kind int- kind tag (int)
event &ui.InputEvent- event (read-only borrow; caller keeps the original; type &ui.InputEvent)
Returns
Action — input result with kind, id, repaint and focus requests.
($&ButtonGroup) tick
pub fn (g $&ButtonGroup) tick(styles &Styles,now time.Instant,reduced bool) bool
Purpose
Advance animation clock and state transition step. Throws on failure; handle the error or propagate it to the caller.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
styles &Styles- styles (read-only borrow; caller keeps the original; type &Styles)
now time.Instant- now (time.Instant)
reduced bool- reduced (bool)
Returns
bool — true or false
(&ButtonGroup) next_tick
pub fn (g &ButtonGroup) next_tick(now time.Instant) time.Instant
Purpose
Operation on &ButtonGroup: next tick. Throws on failure; handle the error or propagate it to the caller.
Parameters
g &ButtonGroup- The
ButtonGroup instance used by this call (borrow).
now time.Instant- now (time.Instant)
Returns
time.Instant — a value of this type
($&ButtonGroup) paint_styled
pub fn (g $&ButtonGroup) paint_styled(frame $&draw.Frame,styles &Styles) int
Purpose
Operation on $&ButtonGroup: paint styled. Throws on failure; handle the error or propagate it to the caller.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
frame $&draw.Frame- frame (exclusive borrow; may modify the original; type $&draw.Frame)
styles &Styles- styles (read-only borrow; caller keeps the original; type &Styles)
Returns
int — a value of this type
($&ButtonGroup) dispose
pub fn (g $&ButtonGroup) dispose()
Purpose
Release and dispose native resources and underlying handles.
Parameters
g $&ButtonGroup- The
ButtonGroup instance used by this call (exclusive borrow).
Returns
This call does not return a value.
Complete native example
Component Workshop · Back to Widgets