Class Avatar
The size is the control height of the step (32 points at MEDIUM), so an avatar
sits in a row of controls at their height; give it a SizedBox for a
larger one, and the circle fills the smaller side of the box it is given. A box squeezed to a
point or so across draws the tinted circle without its letters, and one of no size draws nothing.
The colour is one of the chart palette's categorical colours
(ChartPalette.defaultFor(Theme)), chosen by the name's String.hashCode(), mixed, unless
setColorIndex(int) says which, so the same name has the same colour on every run and every
machine. Categorical, and never a state's tone: a person drawn in the danger colour reads as an
error. It is drawn as a tint, at 22 % (34 % in a dark palette), with the initials in the
palette's text colour, so their contrast is the palette's own text on its surface.
The initials, unless setInitials(java.lang.String) gives them, are the first grapheme of the
name's first word and of its last, upper-cased in the avatar's locale: "Ana Lima" is "AL", "Ana"
is "A", an accent or a joined emoji is kept whole, and a script without case stays as it is.
With neither initials nor a picture, a silhouette of a head and shoulders is drawn.
To a reader an avatar is an image named by the person, so one standing alone (a user
button's picture, a column of owners) is read. Beside the name it repeats, as in a contact's
row, take it out with setAccessibleIgnored(true). Inside an AvatarGroup it is
not published at all: the group is one node described by every name.
new Avatar("Ana Lima");
new Avatar("Rui Costa").setImage(photo);
-
Constructor Summary
ConstructorsConstructorDescriptionAn avatar for a person with a fixed name.Avatar(I18nString name) An avatar whose name follows the UI language, for a name that is a role ("Support"). -
Method Summary
Modifier and TypeMethodDescriptionintThe palette index the avatar is drawn in: the one given, or the name's hash modulo the palette's size.@Nullable Imageimage()name()protected voidOneAccessible.Role.IMAGEnamed by the person.protected SizeonMeasure(Constraints constraints) Reports the size this widget wants withinconstraints.protected voidWidget's own background/content, in local coordinates.protected floatHow far beyond this widget's bounds its painting may reach, in logical points: its own painting and any descendant no ancestor clips (a drop shadow, a glow, a child positioned outside the parent's box).setColorIndex(int index) Chooses the palette colour by its index instead of by the name, for two people whose names fall on the same colour side by side.Sets the person's picture, drawn covering the circle and clipped to it;nullbrings the initials back.setInitials(@Nullable String value) Gives the initials instead of deriving them from the name;nullderives them again.Replaces the name: the initials, the colour and what a reader hears follow it.setName(I18nString newName) Replaces the name with one that follows the UI language.Methods inherited from class limn.scene.Widget
acceptsTextInput, accessibleLabelAccessKey, accessibleLabelTarget, accessibleLabelText, add, add, announceChange, backdropReach, baselineOffset, 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, 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
-
Avatar
An avatar for a person with a fixed name.- Parameters:
name- the person's name; never null
-
Avatar
An avatar whose name follows the UI language, for a name that is a role ("Support").- Parameters:
name- the person's name; never null
-
-
Method Details
-
setName
Replaces the name: the initials, the colour and what a reader hears follow it.- Parameters:
newName- the name; never null- Returns:
- this avatar
-
setName
Replaces the name with one that follows the UI language.- Parameters:
newName- the name; never null- Returns:
- this avatar
-
name
- Returns:
- the person's name, in the language in effect
-
setInitials
Gives the initials instead of deriving them from the name;nullderives them again.- Parameters:
value- the initials, drawn as given; ornull- Returns:
- this avatar
-
setImage
Sets the person's picture, drawn covering the circle and clipped to it;nullbrings the initials back. An animated image is drawn at its first frame.- Parameters:
newImage- the picture, ornull- Returns:
- this avatar
-
image
- Returns:
- the picture, or
null
-
setColorIndex
Chooses the palette colour by its index instead of by the name, for two people whose names fall on the same colour side by side. Indexes past the palette's size repeat it.- Parameters:
index- the index, at least zero- Returns:
- this avatar
- Throws:
IllegalArgumentException- ifindexis negative
-
colorIndex
public int colorIndex()The palette index the avatar is drawn in: the one given, or the name's hash modulo the palette's size.- Returns:
- the index
-
paintOutset
protected float paintOutset()Description copied from class:WidgetHow far beyond this widget's bounds its painting may reach, in logical points: its own painting and any descendant no ancestor clips (a drop shadow, a glow, a child positioned outside the parent's box). Partial rendering uses it both ways:Widget.invalidate()damage grows by it, and a repaint pass skips this subtree only when bounds + outset miss the pass region; painting farther than declared leaves stale pixels.The work is divided by who knows the number. A widget declares what it paints itself outside its box:
Label's icon overhang, the focus ringButton,CheckboxandRadioButtondraw outside theirs. A widget that lays out children and does not clip them declares how far they may paint past it, because a ring on a child at its edge hangs past it too, and a pass landing only in that band would otherwise skip it and never reach the child. Every layout the toolkit ships does that by default with the reach the theme gives a focus ring, and takes another number through its publicpaintOverflow, which sets what this hook answers; a layout an application writes inherits both by extendinglimn.scene.layout.Container, and one that extends this class directly overrides this hook itself. A widget that clips its children declares only its own painting, since the clip bounds theirs.Asked of every widget a repaint pass considers, and on every
invalidate(), so an override answers in constant time without allocating: a number held or looked up, never a walk over the children. Default0: everything stays inside the bounds, which is true for most leaves.- Overrides:
paintOutsetin classWidget<Avatar>
-
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. -
onAccessibility
OneAccessible.Role.IMAGEnamed by the person. The name is the held string by reference, so a frame that repaints the avatar compares it without allocating.Its provenance is
Accessible.NameFrom.EXPLICIT, not content: the circle paints initials or a picture and never the name, so the name is text about the image, which macOS publishes asAXDescription, the attribute VoiceOver reads for a picture.- Overrides:
onAccessibilityin classWidget<Avatar>- Parameters:
a- the node being described
-