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.
A caption alone, or an icon alone, is centred, so a text-only button draws the same
coordinates whichever way its subtree reads. An icon beside a caption is
leading: it stands from the edge reading starts from by the inset a
text field's or a combo box's leading icon keeps, so icons line up down a form, and the caption
is centred in the rest of the button inside the button's own padding, which at the width the
button asks for puts it the icon gap away. Reading right to left the whole of that is mirrored.
Whether the glyph drawn inside the square turns around as well is the caller's to say —
see Icon.Mirroring.
An icon with no caption makes a square button: as wide as it is tall, which is the
control height of its ControlSize, 24, 28, 32, 40 or 50 points, the icon in the middle.
That is the width it asks for, and like any widget's it is the parent's to grant: a button that
should be wider or narrower says so with Widget.setMinWidth(float) or Widget.setMaxWidth(float), both
together for an exact width, and the icon stays in the middle of the box it is given. Those
bounds are the one way to say it, for this button as for any other widget; with none set, the
square is the default. At the smallest step the square is 24 points, the pointer target this
toolkit keeps every control at or above. A button with a caption, beside an icon or not, asks
for its caption's width and padding as before.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumHow much a button asks to be pressed, of the three looks a row of buttons is drawn in. -
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.protected voidhandleUserChange(Change.Aspect aspect) Runs this widget's application handler for a change it has just announced.booleanprotected voidWhat this button is to an assistive technology: oneAccessible.Role.BUTTONnamed by the caption it holds and offeringAccessible.Action.PRESS, and nothing else.protected booleanPerforms a press an assistive technology asked for, exactly as a click or a Space release does: the same private action slot, so the application is notified the same way.The application's response to the user pressing the button: a click, Space or Enter while focused, an assistive technology's press.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.setDestructive(boolean value) Marks the button as one that destroys something ("Delete order"), drawn in the palette's danger colour at whicheverButton.Styleit has: a primary one is filled in it, a secondary and a tertiary one write their caption in it.Sets a leading icon, drawn tinted to the label color.setIcon(@Nullable Icon newIcon, Icon.Mirroring mirroring) A leading icon that says whether its glyph turns around when the interface does.setStyle(Button.Style newStyle) Which of the three looks this button is drawn in;Button.Style.PRIMARYby default.Replaces the caption with a fixed string.setText(I18nString newText) Replaces the caption with a value that follows the UI language.style()text()The caption as it currently reads, an access letter's&mark taken out ("&Save" reads "Save"); seetextSource()for the value behind it.The localizable value this button holds, which a language change re-resolves.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
-
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
-
setStyle
Which of the three looks this button is drawn in;Button.Style.PRIMARYby default.- Parameters:
newStyle- the look; never null- Returns:
- this button
-
style
- Returns:
- the look this button is drawn in
-
setDestructive
Marks the button as one that destroys something ("Delete order"), drawn in the palette's danger colour at whicheverButton.Styleit has: a primary one is filled in it, a secondary and a tertiary one write their caption in it.Nothing is published for it: no platform carries the notion to a reader, and the caption is what says what the button does. A dialog's destructive button is never its default one; see
Dialog.addDestructiveButton(I18nString, String).- Parameters:
value- whether the button destroys something- Returns:
- this button
-
isDestructive
public boolean isDestructive()- Returns:
- whether the button is drawn as one that destroys something
-
onAction
The application's response to the user pressing the button: a click, Space or Enter while focused, an assistive technology's press. Not called while disabled. A press is announced to the watchers asINVOKEDfirst.- Parameters:
newAction- the handler, ornullto clear the slot- Returns:
- this button
- 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<Button>- Parameters:
aspect- what changed; the origin isUSERor this is not called
-
text
The caption as it currently reads, an access letter's&mark taken out ("&Save" reads "Save"); seetextSource()for the value 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<Button>
-
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<Button>
-
onPaint
Description copied from class:WidgetWidget's own background/content, in local coordinates. -
onAccessibility
What this button is to an assistive technology: oneAccessible.Role.BUTTONnamed by the caption it holds and offeringAccessible.Action.PRESS, 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 button 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, which is how an icon-only button is named by the tooltip it should have and a captioned one keeps the tooltip as its description. The role is unconditional so that a disabled button stays in the tree and is heard as disabled rather than vanishing.Declared here is all a reader is told. The focus and scroll-into-view verbs, the enabled, visible, showing, focusable and focused states and the box are the walk's; the pressed visual is not published, because no platform maps it and a press from an assistive technology never arms; whether this is a dialog's default button is the dialog's fact and not this widget's, which holds no such notion; and the icon is paint with no name and no operation, so it is not a node.
- Overrides:
onAccessibilityin classWidget<Button>- Parameters:
a- the node being described
-
onAccessibilityAction
Performs a press an assistive technology asked for, exactly as a click or a Space release does: the same private action slot, so the application is notified the same way. Any other verb is refused, and so is a press while this button is disabled, since the click and key paths rely on the scene never delivering to a disabled widget and this one keeps the guard itself.It does not arm, invalidate or request focus. A pointer click gets click-to-focus from the scene and not from this widget, a reader that wants focus has the focus verb, and a press that pulled focus out of a text field onto a tool-bar button would be worse than one that leaves it.
- Overrides:
onAccessibilityActionin classWidget<Button>- Parameters:
verb- what was askedarg- ignored; a press carries none- Returns:
- whether the action ran
-
onMouseEvent
Description copied from class:WidgetMouse events (bubbling); callevent.consume()when handled.- Overrides:
onMouseEventin classWidget<Button>
-
onKeyEvent
Description copied from class:WidgetKey events (focused widget first, then ancestors).- Overrides:
onKeyEventin classWidget<Button>
-
onFocusGained
protected void onFocusGained()Description copied from class:WidgetCalled when this widget takes keyboard focus. Default: nothing.- Overrides:
onFocusGainedin classWidget<Button>
-
onFocusLost
protected void onFocusLost()Description copied from class:WidgetCalled when this widget loses keyboard focus. Default: nothing.- Overrides:
onFocusLostin classWidget<Button>
-