Class Button
onAction(Runnable) fired by click or by
Enter/Space while focused. All visuals come from the Theme. Keep
actions short (the slow-handler instrumentation will flag violations);
heavy work goes through Ui.async.
Sizes follow the ControlSize resolved on this widget: every metric comes from
the SizeTokens row, every weight from Strokes. Tokens are resolved once per
pass into a local and threaded down; resolving twice inside one pass is how measure and
paint end up disagreeing about where the label sits.
The icon-and-caption block is centred, so a text-only button draws the same coordinates
whichever way its subtree reads. What the direction decides is the order of the two
things inside that block: the icon is leading, which is the block's
left end reading left to right and its right end reading right to left. Whether the glyph
drawn inside that square turns around as well is the caller's to say — see
Icon.Mirroring.
-
Constructor Summary
ConstructorsConstructorDescriptionA button with a fixed caption; see theI18nStringconstructor for localized text.Button(I18nString text) A button whose caption follows the UI language; seeI18nString. -
Method Summary
Modifier and TypeMethodDescriptionprotected floatThe baseline BASELINE rows align on, the very expressiononPaint(limn.graphics.Canvas)draws with.Called on click, or on Space/Enter while focused.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 drawn OUTSIDE the box: centredStrokes.FOCUS_GAP_BUTTONout with aStrokes.FOCUS_RINGpen, so its outer ink reachesStrokes.FOCUS_RING_OUTSET, and damage has to know that.Sets a leading icon, drawn tinted to the label color.setIcon(Icon newIcon, Icon.Mirroring mirroring) A leading icon that says whether its glyph turns around when the interface does.setSecondary(boolean value) Secondary style: a surface-filled, outlined button instead of the filled primary.Replaces the caption with a fixed string.setText(I18nString newText) Replaces the caption with a value that follows the UI language.text()The caption as it currently reads; seetextSource()for the key behind it.The localizable value this button holds, which a language change re-resolves.withControlSize(ControlSize size) 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
-
Button
A button with a fixed caption; see theI18nStringconstructor for localized text. -
Button
A button whose caption follows the UI language; seeI18nString.
-
-
Method Details
-
setIcon
Sets a leading icon, drawn tinted to the label color.nullclears it. Leading is the end of the caption block reading starts from, so the square trades ends with the caption when the button reads right to left; the glyph inside it is drawn as authored. UsesetIcon(Icon, Icon.Mirroring)for an icon that means a direction. -
setIcon
A leading icon that says whether its glyph turns around when the interface does. Only the code that placed an icon knows whether its arrow means "back" or "download", which is why this is a flag here and never a classification inside the toolkit.- Parameters:
mirroring-Icon.Mirroring.NEVERunless this glyph is directional; the square's own end of the block moves either way
-
setSecondary
Secondary style: a surface-filled, outlined button instead of the filled primary. -
withControlSize
-
onAction
Called on click, or on Space/Enter while focused. Not called while disabled. -
text
The caption as it currently reads; seetextSource()for the key behind it. -
textSource
The localizable value this button holds, which a language change re-resolves. -
setText
Replaces the caption with a fixed string. UI thread only. -
setText
Replaces the caption with a value that follows the UI language. 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. -
baselineOffset
protected float baselineOffset()The baseline BASELINE rows align on, the very expressiononPaint(limn.graphics.Canvas)draws with.- Overrides:
baselineOffsetin classWidget
-
paintOutset
protected float paintOutset()The focus ring is drawn OUTSIDE the box: centredStrokes.FOCUS_GAP_BUTTONout with aStrokes.FOCUS_RINGpen, so its outer ink reachesStrokes.FOCUS_RING_OUTSET, and damage has to know that.Sceneinflates a widget's damage rect by1 + paintOutset(), so without this override the fade-out of a ring on the toolkit's most-used widget sheds stale pixels under partial rendering.Declares reach only; it moves no ink. Checkbox, RadioButton and Label carry the same kind of override for the same reason.
- Overrides:
paintOutsetin classWidget
-
onPaint
Description copied from class:WidgetWidget's own background/content, in local coordinates. -
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
-