UXSegment
UXSegment is one segment of a
UXSegmentedControl.
#use <UXKit> // or #import "UXSegmentedControl.xc"Overview
Section titled “Overview”class UXSegment : Object { u8* label; i32 tag; // your identity for it bool selected; i16 x; i16 w; // computed layout, within the control}The five fields split in two. label, tag and selected are model, which
you set. x and w are layout, which the control computes.
Model and layout in one object
Section titled “Model and layout in one object”x and w are filled in when the control lays itself out, and overwritten the
next time it does. Values written to them by hand do not last.
They are public because hit-testing needs them. Finding the segment a click
landed on is a walk over the segments comparing against x and x + w. Keeping
the geometry beside the item makes that a loop rather than a recalculation.
Read them; do not set them.
The tag is your identity
Section titled “The tag is your identity”i32 tagAn integer the toolkit never interprets. An action handler uses it to know which segment was chosen without depending on the index. Indices shift when segments are inserted or removed; tags do not.
Use an enum value, a mode constant, or a row id. The label is for the user; the tag is for your code.
selected is a field, not a command
Section titled “selected is a field, not a command”bool selectedSetting it marks the segment. It does not enforce the control’s selection
mode. Making two segments selected in a single-selection control leaves both
marked, because the field is state rather than a request.
Go through the control’s selection methods and the mode is applied for you. Reading the field directly is fine and tells you which segments are on.
For a multiple-selection control, several being true is the normal case, and reading the segments collects the set.
Fields
Section titled “Fields”u8* labelThe text. Kept, not copied: pass a literal, or a
UXStr.dup of anything built at run time.
i32 tagselected
Section titled “selected”bool selectedi16 x; i16 wPosition and width within the control, in its coordinates. Recomputed on layout.
Conforms to
Section titled “Conforms to”- Inherits
Object
See also
Section titled “See also”UXSegmentedControl: the controlUXRadioGroup: the same one-of-several idea as separate controlsUXPopUpItem: one-of-many when there is no room for a row