Class Checkbox
BOX with a check
mark, and the mobile-style SWITCH whose thumb slides. The check/slide
is driven by a shared Transition (the toolkit's reusable animator),
so it only renders while moving. Toggled by click, or Space/Enter when
focused. Colours come from the Theme, extents from the
SizeTokens row resolved on this widget, and every pen from
Strokes.
This row is under the 24 pt pointer target
The row measuresmax(indicator, lineHeight) and the indicator wins that max at
every step (18 pt at MEDIUM for BOX, 22 for SWITCH), which is below the
24 pt target of WCAG 2.2 SC 2.5.8 (AA) on the axis that decides it: a label widens a
target, it never heightens it. A toggle's pointer target is exactly the box it paints;
there is no hit outset.
The standard's own Spacing exception is what an application relies on: an
undersized target conforms while a 24 pt circle centred on it clears every neighbour. A
lone toggle already satisfies that; a column of them does not until the pitch reaches 24,
which is what Tokens.toggleColumnGap(limn.scene.Widget) gives. Stack toggles on
that gap, not a tighter one.
Which way the row reads
The indicator sits on the leading edge and the label follows it, so the whole row moves to the other side when the resolved direction is right to left. That move is a translation of the indicator and nothing else: the check mark is a tick, and no platform mirrors a tick. The thumb of aSWITCH is the one
thing inside the indicator that does know a direction, because its two ends are a value axis:
OFF is the leading end and ON the trailing one.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumHow the flag is drawn and published: a box that takes a check mark, or a switch whose knob slides. -
Constructor Summary
ConstructorsConstructorDescriptionA check box (Checkbox.Variant.BOX) with a fixed label.Checkbox(Checkbox.Variant variant, String text) A toggle with a fixed label; see theI18nStringconstructor for localized text.Checkbox(Checkbox.Variant variant, I18nString text) A checkbox whose label follows the UI language; seeI18nString.Checkbox(I18nString text) A check box (Checkbox.Variant.BOX) whose label follows the UI language. -
Method Summary
Modifier and TypeMethodDescriptionprotected floatDistance from this widget's top edge to its first text baseline, in logical points: the alignment reference forFlex.CrossAlignment.BASELINE.protected voidhandleUserChange(Change.Aspect aspect) Runs this widget's application handler for a change it has just announced.booleanThe current state.protected voidWhat this toggle is to an assistive technology: oneAccessible.Role.CHECK_BOXorAccessible.Role.SWITCH, by variant, named by the caption it holds, carrying a two-state toggle facet and offeringAccessible.Action.TOGGLE, and nothing else.protected booleanonAccessibilityAction(Accessible.Action action, Accessible.Argument arg) Performs a toggle an assistive technology asked for, exactly as a click or a Space press does: through the from-the-user seam, so the application'sonChangehandler is notified the same way, and never throughsetChecked(boolean)ortoggle(), which are a caller's writes.The application's response to the user toggling the box: a click, Space, Enter or an assistive technology's toggle.protected voidCalled when this widget takes keyboard focus.protected voidCalled when this widget loses keyboard focus.protected voidonKeyEvent(KeyEvent event) Key events (focused widget first, then ancestors).protected SizeonMeasure(Constraints constraints) Reports the size this widget wants withinconstraints.protected voidonMouseEvent(MouseEvent event) Mouse events (bubbling); callevent.consume()when handled.protected voidWidget's own background/content, in local coordinates.protected floatThe focus ring is the only thing that paints outside the box, and it paints well outside: aStrokes.FOCUS_RING_THINpen beyond a clear gap ofStrokes.FOCUS_GAP_INDICATOR, its outer ink 3pt past the indicator.setChecked(boolean newChecked) Sets the state, animating the visual transition.text()voidtoggle()Flips the state: aCODEwrite spelled as a verb, exactly likesetChecked(boolean), so it announcesVALUE/CODEand reaches no handler.variant()Methods inherited from class limn.scene.Widget
acceptsTextInput, accessibleLabelAccessKey, accessibleLabelTarget, accessibleLabelText, add, add, announceChange, backdropReach, baselineOffsetOf, caretRect, children, clipboard, clipHeight, clipsChildren, clipWidth, clipX, clipY, controlSize, cursor, declaredControlSize, declaredLayoutDirection, declaredLocale, focusArrivedBackward, focusArrivedByTraversal, height, hitTest, hitTestChild, id, imageCursor, inheritanceHost, invalidate, invalidate, invalidateAccessible, isEnabled, isFocusable, isFocused, isRightToLeft, isSelfEnabled, isShowing, isVisible, isVisibleByItsOwnFlag, layoutBox, layoutDirection, locale, localToScene, localToSceneBounds, markNeedsContainedLayout, markNeedsLayout, markNeedsLayoutInPlace, maxHeight, maxWidth, measure, minHeight, minWidth, moveChild, moveChild, moveChild, neutralBase, notifyChange, notifyTextEdit, observeChanges, onAccessibilityChild, onAccessibilityChildAction, onAccessibilityChildIdentity, onAttached, onCanEdit, onCharTyped, onDetached, onDragExit, onDragOver, onDragStart, onDrop, onEdit, onHitTest, onLayout, onPaintOverlay, onPreedit, onSyntheticAction, overlayPassesPointer, paintChildren, paintsDecoration, paintsFromBackdrop, paintWidget, parent, remove, remove, requestFocus, requestFocus, revealInView, revealInView, runHandler, scene, sceneNanos, sceneToLocal, self, setAccessibleDescribedBy, setAccessibleDescription, setAccessibleDescription, setAccessibleIgnored, setAccessibleLabelledBy, setAccessibleName, setAccessibleName, setAccessibleRole, setControlSize, setCursor, setEnabled, setFocusable, setId, setImageCursor, setInheritanceHost, setLayoutDirection, setLocale, setMaxHeight, setMaxWidth, setMinHeight, setMinWidth, setPresentedElsewhere, setTooltip, setTooltip, setVisible, shapeText, textRuler, tooltip, tooltipSource, width, x, y
-
Constructor Details
-
Checkbox
A check box (Checkbox.Variant.BOX) with a fixed label. -
Checkbox
A check box (Checkbox.Variant.BOX) whose label follows the UI language. -
Checkbox
A toggle with a fixed label; see theI18nStringconstructor for localized text. -
Checkbox
A checkbox whose label follows the UI language; seeI18nString.
-
-
Method Details
-
onChange
The application's response to the user toggling the box: a click, Space, Enter or an assistive technology's toggle. Never forsetChecked(boolean)ortoggle(), which are a caller's writes; to hear every flip whatever caused it, watch the checkbox instead.- Parameters:
listener- the handler, ornullto clear the slot- Returns:
- this checkbox
- Throws:
IllegalStateException- if a handler is already registered
-
handleUserChange
Description copied from class:WidgetRuns this widget's application handler for a change it has just announced. Called byWidget.runHandler(limn.scene.Change), and so byWidget.notifyChange(limn.scene.Change), only for aUSERorigin and after every watcher has run.A component overrides it once and switches on the aspect, reading its own accessors for the payload: a slider passes
value(), a combo boxselectedIndex(), a text fieldtext(). A component with no handler does not override it.An override that does not recognise the aspect must call
super, because a subclass of a component that has a handler inherits that component's dispatch through this method: aSearchFieldthat overrode this for its own aspect and did not chain would silently deleteTextField's. The ordering lives in the base class, this is the one link in it a subclass can break, and the contract test drives every subclass through its parent's gestures to catch one that does.- Overrides:
handleUserChangein classWidget<Checkbox>- Parameters:
aspect- what changed; the origin isUSERor this is not called
-
text
- Returns:
- the caption beside the indicator, resolved in this widget's own language. The accessible tree takes this as the control's name, so a caption that is not reachable is a control a screen reader cannot announce.
-
textSource
-
variant
- Returns:
- how the toggle is drawn: a box with a check mark or a switch
-
isChecked
public boolean isChecked()The current state. -
setChecked
Sets the state, animating the visual transition. AnnouncesVALUE/CODEwhen it moved, and reaches no handler. -
toggle
public void toggle()Flips the state: aCODEwrite spelled as a verb, exactly likesetChecked(boolean), so it announcesVALUE/CODEand reaches no handler. It carries no enabled guard for the same reasonsetCheckedcarries none: a write may move a disabled widget's state and always could, and the entry point a gesture or an assistive technology reaches is guarded already. UI thread only. -
onMeasure
Description copied from class:WidgetReports the size this widget wants withinconstraints. Called once per layout pass, and the result is cached against the constraints and the resolved axes (size step, layout direction, locale), so it must be a pure function of them and of this widget's own state.Resolve the
ControlSizeand theLayoutDirectiononce each here and thread them down; never read either in a constructor. The locale needs no threading: it is in scope, andI18n.locale()answers it wherever text is resolved. -
onPaint
Description copied from class:WidgetWidget's own background/content, in local coordinates. -
paintOutset
protected float paintOutset()The focus ring is the only thing that paints outside the box, and it paints well outside: aStrokes.FOCUS_RING_THINpen beyond a clear gap ofStrokes.FOCUS_GAP_INDICATOR, its outer ink 3pt past the indicator. The indicator is flush with the widget's leading edge, with its top and bottom at every step (the row is the indicator), and with the trailing edge when there is no label, so that reach is outsideboundson all four sides whichever way the row reads.Sceneassumes only 1pt of AA feather, so the fading ring left stale pixels under partial rendering even at a 1pt gap (reach 1.75); the 1.5pt gap widens the gap to 1.5 and the reach with it. Locked, like both quantities it is composed of.- Overrides:
paintOutsetin classWidget<Checkbox>
-
baselineOffset
protected float baselineOffset()Description copied from class:WidgetDistance from this widget's top edge to its first text baseline, in logical points: the alignment reference forFlex.CrossAlignment.BASELINE. Defaultheight(): align on the bottom edge, the correct fallback for a widget with no text. Text-bearing components override with the expression they already paint with; a single-line control's istextRuler().centredBaseline(font, height()), which stands the line's capitals in the middle of the box.Valid only once this widget has been given a box.
Flexguarantees that: it lays every child of a BASELINE line out at cross position 0 first, reads the baselines, then repositions withWidget.moveChild(limn.scene.Widget<?>, int), which moves without re-running layout.- Overrides:
baselineOffsetin classWidget<Checkbox>
-
onAccessibility
What this toggle is to an assistive technology: oneAccessible.Role.CHECK_BOXorAccessible.Role.SWITCH, by variant, named by the caption it holds, carrying a two-state toggle facet and offeringAccessible.Action.TOGGLE, and nothing else.The name is the held
I18nStringhanded over by reference, nevertext(): the walk compares the reference, the locale and the translation epoch, so a hover or focus fade that damages this row on every frame concludes that nothing moved without allocating. It is handed over even when the caption is empty, because the walk names a nameless node from its tooltip and describes a named one with it; a caption-less toggle with no tooltip publishes an empty name, which is the application's to fix and not this widget's to invent.The toggle facet reads the
checkedfield and never the eased visual: the model flips and the handler fires before the animation starts, so a reader asking mid-slide is told what the application already knows. There is no third state, so the facet is on or off and the checked bit follows it. The caption is not a child node: the indicator and its label are one control, and a label node beside it would be announced twice. The box, the focus and scroll-into-view verbs and the enabled, visible, showing, focusable and focused states are the walk's; Space and Enter are the platform's own convention for a toggle, not an accelerator, so no key binding is declared.- Overrides:
onAccessibilityin classWidget<Checkbox>- Parameters:
a- the node being described
-
onAccessibilityAction
Performs a toggle an assistive technology asked for, exactly as a click or a Space press does: through the from-the-user seam, so the application'sonChangehandler is notified the same way, and never throughsetChecked(boolean)ortoggle(), which are a caller's writes. Any other verb is refused, and so is a toggle while this widget is disabled, because the answer here has to be truthful.The state change that results is what a reader hears: the flip invalidates, the next frame republishes, and the difference raises the checked-state event on this node. No invocation event is raised for a toggle, on any platform.
- Overrides:
onAccessibilityActionin classWidget<Checkbox>- Parameters:
action- what was askedarg- ignored; a toggle carries none- Returns:
- whether the toggle ran
-
onMouseEvent
Description copied from class:WidgetMouse events (bubbling); callevent.consume()when handled.- Overrides:
onMouseEventin classWidget<Checkbox>
-
onKeyEvent
Description copied from class:WidgetKey events (focused widget first, then ancestors).- Overrides:
onKeyEventin classWidget<Checkbox>
-
onFocusGained
protected void onFocusGained()Description copied from class:WidgetCalled when this widget takes keyboard focus. Default: nothing.- Overrides:
onFocusGainedin classWidget<Checkbox>
-
onFocusLost
protected void onFocusLost()Description copied from class:WidgetCalled when this widget loses keyboard focus. Default: nothing.- Overrides:
onFocusLostin classWidget<Checkbox>
-