Class Badge
One look, whatever the tone. A pill tinted in the Tone, and at its leading end
either the icon drawn in the tone or, with no icon, a dot of it; the word is
in the palette's text colour. The colour says the state at a glance and the word says it to
everyone, a person who does not tell red from green and a screen reader included, and the
word's contrast is the palette's own text on its surface, which every built-in palette is tested
for, at every tone.
Three kinds, by how the badge is made:
- a text badge,
Badge(I18nString), with a dot or an icon before the word; - a count,
ofCount(int): the number alone in the pill, in the digits the language is shown in, and "99+" past 99 so a badge does not grow with its count; - a dot,
dot(I18nString): the dot alone, twice as wide as a text badge's, and a name a reader hears in its place.
To an assistive technology a badge is a static text, a Accessible.Role.LABEL, named by
the word it shows, the number as shown, or a dot's name. It takes no focus and has no verb. An
application that wants a count read as "3 unread" names it with Widget.setAccessibleName(limn.i18n.I18nString); a
badge inside a table's row or an activatable Card is read through the row's or the card's
own name, as anything inside them is.
new Badge("Overdue").setTone(Tone.DANGER);
Badge.ofCount(unread).setTone(Tone.ACCENT).setAccessibleName(unread + " unread");
-
Constructor Summary
ConstructorsConstructorDescriptionA badge with a fixed word.Badge(Icon icon, I18nString text) A badge whose icon leads its word, drawn in the badge's tone in place of the dot.Badge(I18nString text) A badge whose word follows the UI language. -
Method Summary
Modifier and TypeMethodDescriptionprotected floatThe baseline a BASELINE row aligns on: the very expression the paint draws with.intcount()static Badgedot(I18nString name) A dot alone, for an "unread" or "changed" mark beside a row's name: twice as wide as a text badge's dot, with no pill and no word.@Nullable Iconicon()static BadgeofCount(int n) A badge that shows a number: in the digits the language is shown in, and "99+" past 99.protected voidA static text named by what it shows: the word, the number as drawn, or a dot's name.protected SizeonMeasure(Constraints constraints) Reports the size this widget wants withinconstraints.protected voidWidget's own background/content, in local coordinates.setCount(int n) Changes a count badge's number.Sets the icon drawn before the word in place of the dot, in the badge's tone;nullbrings the dot back.Replaces the word, or a dot's name, with a fixed string.setText(I18nString newText) Replaces the word, or a dot's name, with one that follows the UI language.Sets the tone the pill, the dot and the icon are drawn in;Tone.NEUTRALby default.text()tone()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, handleUserChange, 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, onAccessibilityAction, onAccessibilityChild, onAccessibilityChildAction, onAccessibilityChildIdentity, onAttached, onCanEdit, onCharTyped, onDetached, onDragExit, onDragOver, onDragStart, onDrop, onEdit, onFocusGained, onFocusLost, onHitTest, onKeyEvent, onLayout, onMouseEvent, onPaintOverlay, onPreedit, onSyntheticAction, overlayPassesPointer, paintChildren, paintOutset, 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
-
Badge
A badge with a fixed word.- Parameters:
text- the word; never null
-
Badge
A badge whose word follows the UI language.- Parameters:
text- the word; never null
-
Badge
A badge whose icon leads its word, drawn in the badge's tone in place of the dot.- Parameters:
icon- the icon; never nulltext- the word, which also names the badge; never null
-
-
Method Details
-
ofCount
A badge that shows a number: in the digits the language is shown in, and "99+" past 99.- Parameters:
n- the count; at least zero- Returns:
- the badge
- Throws:
IllegalArgumentException- ifnis negative
-
dot
A dot alone, for an "unread" or "changed" mark beside a row's name: twice as wide as a text badge's dot, with no pill and no word. The name is what a reader hears in its place.- Parameters:
name- what the dot means; never null- Returns:
- the badge
-
setText
Replaces the word, or a dot's name, with a fixed string.- Parameters:
newText- the word; never null- Returns:
- this badge
- Throws:
IllegalStateException- on a count badge, which shows itscount
-
setText
Replaces the word, or a dot's name, with one that follows the UI language. A layout runs only when the badge's width changes.- Parameters:
newText- the word; never null- Returns:
- this badge
- Throws:
IllegalStateException- on a count badge, which shows itscount
-
text
- Returns:
- the word, a dot's name, or for a count the number as shown
-
setIcon
Sets the icon drawn before the word in place of the dot, in the badge's tone;nullbrings the dot back. Not drawn by a count or a dot badge.- Parameters:
newIcon- the icon, ornull- Returns:
- this badge
-
icon
- Returns:
- the icon drawn before the word, or
nullfor the dot
-
setTone
Sets the tone the pill, the dot and the icon are drawn in;Tone.NEUTRALby default. Resolved against the palette on every paint, so a change of palette re-colours the badge.- Parameters:
newTone- the tone; never null- Returns:
- this badge
-
tone
- Returns:
- the tone the badge is drawn in
-
setCount
Changes a count badge's number. A layout runs only when the shown width changes, which is when the number of digits does.- Parameters:
n- the count; at least zero- Returns:
- this badge
- Throws:
IllegalArgumentException- ifnis negativeIllegalStateException- on a badge that is not acount
-
count
public int count()- Returns:
- a count badge's number, or zero for any other
-
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 a BASELINE row aligns on: the very expression the paint draws with.- Overrides:
baselineOffsetin classWidget<Badge>
-
onPaint
Description copied from class:WidgetWidget's own background/content, in local coordinates. -
onAccessibility
A static text named by what it shows: the word, the number as drawn, or a dot's name. The count's name is the held string with the counter that moves when it does, so a quiet frame compares a number and allocates nothing.- Overrides:
onAccessibilityin classWidget<Badge>- Parameters:
a- the node being described
-