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 Classes -
Constructor Summary
ConstructorsConstructorDescriptionCheckbox(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. -
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.booleanThe current state.Called with the new state on user toggles only, not onsetChecked(boolean).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: centredStrokes.FOCUS_GAP_INDICATORout with aStrokes.FOCUS_RING_THINpen, its outer ink reaches 2.25pt past the indicator.setChecked(boolean newChecked) Sets the state, animating the visual transition.voidtoggle()Flips the state and firesonChange, as a click does.Methods inherited from class limn.scene.Widget
acceptsTextInput, add, baselineOffsetOf, caretRect, children, clipboard, clipsChildren, controlSize, cursor, declaredControlSize, declaredLayoutDirection, declaredLocale, focusArrivedByTraversal, height, hitTest, imageCursor, invalidate, invalidate, isEnabled, isFocusable, isFocused, isShowing, isVisible, layoutBox, layoutDirection, locale, localToSceneX, localToSceneY, markNeedsContainedLayout, markNeedsLayout, measure, moveChild, neutralBase, onAttached, onCharTyped, onDetached, onFileDrop, onLayout, onPaintOverlay, onPreedit, overlayPassesPointer, paintChildren, paintWidget, parent, remove, requestFocus, revealInView, scene, sceneToLocalX, sceneToLocalY, setControlSize, setCursor, setEnabled, setFocusable, setImageCursor, setInheritanceHost, setLayoutDirection, setLocale, setTooltip, setTooltip, setVisible, shapeText, textRuler, tooltip, width, x, y
-
Constructor Details
-
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
Called with the new state on user toggles only, not onsetChecked(boolean). -
isChecked
public boolean isChecked()The current state. -
setChecked
Sets the state, animating the visual transition. -
toggle
public void toggle()Flips the state and firesonChange, as a click does. 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: centredStrokes.FOCUS_GAP_INDICATORout with aStrokes.FOCUS_RING_THINpen, its outer ink reaches 2.25pt 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
-
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,(height() - metrics.height()) / 2 + metrics.ascent().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, float, float), which moves without re-running layout.- Overrides:
baselineOffsetin classWidget
-
onMouseEvent
Description copied from class:WidgetMouse events (bubbling); callevent.consume()when handled.- Overrides:
onMouseEventin classWidget
-
onKeyEvent
Description copied from class:WidgetKey events (focused widget first, then ancestors).- Overrides:
onKeyEventin classWidget
-
onFocusGained
protected void onFocusGained()Description copied from class:WidgetCalled when this widget takes keyboard focus. Default: nothing.- Overrides:
onFocusGainedin classWidget
-
onFocusLost
protected void onFocusLost()Description copied from class:WidgetCalled when this widget loses keyboard focus. Default: nothing.- Overrides:
onFocusLostin classWidget
-