Class TextField
- Direct Known Subclasses:
PasswordField,SearchField
Theme, metrics from the
SizeTokens row of the step resolved on this widget, and every stroke from
Strokes, which is why a focus ring is the same weight at XSMALL and XLARGE.
The reference implementation for the text cluster: PasswordField and
SearchField inherit all of this geometry and declare none of their own.
Every horizontal coordinate here comes from one shaped line, held in a field and
re-shaped only when its inputs change. Caret x is ShapedText.caretX(limn.graphics.ShapedText.Position), a click is
ShapedText.hitTest(float), the selection band is the N boxes
selection returns, and the arrow keys step
through ShapedText.caretLeft(limn.graphics.ShapedText.Position)/ShapedText.caretRight(limn.graphics.ShapedText.Position). None of it is the width of a
prefix of the string, because with a shaper in the pipeline that width is not a thing that
exists: inside their line characters join, ligate, kern and reorder differently than
they do alone, so a prefix measurement is not a slower way to place a caret but a wrong one.
shapeDisplay(java.lang.String, limn.graphics.Font) is where a subclass substitutes a display form, and its index space is the
model's, which is what lets the substitution happen without any index arithmetic at all.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumValidation state; colors the border (and a caller-supplied message). -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanWhether this widget edits text and should drive the platform input method (IME): the scene enables the IME while such a widget holds focus and disables it otherwise, so composition never intercepts keys meant for non-text UI.protected booleanWhether copy/cut may export the content (password fields say no).protected booleanWhether modifier+arrow/delete may move word-wise (seePasswordField).protected floatDistance from this widget's top edge to its first text baseline, in logical points: the alignment reference forFlex.CrossAlignment.BASELINE.protected RectThe caret rectangle in scene coordinates (logical points) used to place the IME candidate window;nullwhen there is no caret to anchor (or the widget is not laid out yet).protected voidNotifies the change listener with the current text; for subclasses that edit the model directly.insertText(String text) Insertstextat the cursor (replacing any selection), as if typed.protected final voidDrops the held display line, so the next paint rebuilds it throughshapeDisplay(java.lang.String, limn.graphics.Font).model()Called with the full text after every edit, typed or programmatic.protected voidonCharTyped(CharEvent event) Committed text input (focused widget first, then ancestors).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 voidonPreedit(PreeditEvent event) In-progress IME composition ("preedit") for this widget while it is focused: the still-composing text, shown inline but not yet committed (the commit later arrives asWidget.onCharTyped(limn.scene.event.CharEvent)).protected voidpaintDisplayText(Canvas canvas, ShapedText display, float x, float baseline, TextMetrics metrics, SizeTokens t, Color ink) Draws a display line with its left edge atx: the paint-side twin ofshapeDisplay(java.lang.String, limn.graphics.Font).The placeholder as it currently reads.setError(boolean error) Convenience:ERRORwhen true,NONEwhen false.setLeadingIcon(Icon icon) A leading icon inside the field, tinted to the muted text color (nullclears).setLeadingIcon(Icon icon, Icon.Mirroring mirroring) A leading icon that says whether it turns around when the interface does.setPlaceholder(String newPlaceholder) Sets a fixed placeholder, shown only while the field is empty.setPlaceholder(I18nString newPlaceholder) Sets a placeholder that follows the UI language.setPreferredWidth(float width) Overrides the step'sfieldWidth; a negative value restores it.Replaces the contents, clearing the selection and undo history.setTrailingButton(Icon icon, Runnable action) A trailing coupled button (icon + action) inside the field, the caret/arrow region idiom ofComboBox.setTrailingButton(Icon icon, Runnable action, Icon.Mirroring mirroring) A trailing coupled button whose icon says whether it turns around when the interface does; seesetLeadingIcon(Icon, Icon.Mirroring)for why the toolkit does not decide that.Sets the validation state; colors the border danger/warning/success.protected ShapedTextshapeDisplay(String text, Font font) The display form of this field's content as a shaped line: the one place a subclass changes what is drawn and how wide it is.protected voidshowContextMenu(float localX, float localY) Raises the Cut/Copy/Paste/Select All menu at a point in this widget's own coordinates.protected voidRaises the same menu for a request that carries no point: the Menu key or Shift+F10, where the caret is the only place the user can have meant.text()The current contents.The current validation state, which drives the border and helper colours.Methods inherited from class limn.scene.Widget
add, baselineOffsetOf, 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, onDetached, onFileDrop, onLayout, onPaintOverlay, overlayPassesPointer, paintChildren, paintOutset, 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
-
Field Details
-
model
-
-
Constructor Details
-
TextField
public TextField()An empty single-line field.
-
-
Method Details
-
text
The current contents. -
setText
Replaces the contents, clearing the selection and undo history. UI thread only. -
setPlaceholder
Sets a fixed placeholder, shown only while the field is empty. -
setPlaceholder
Sets a placeholder that follows the UI language. A subclass shipping a default one (seeSearchField) simply calls this in its constructor: an application's ownsetPlaceholderreplaces the value, so there is no "did the app override it" state to track. -
placeholder
The placeholder as it currently reads. -
onChange
Called with the full text after every edit, typed or programmatic. -
insertText
Insertstextat the cursor (replacing any selection), as if typed. UI thread. -
setPreferredWidth
Overrides the step'sfieldWidth; a negative value restores it. -
setLeadingIcon
A leading icon inside the field, tinted to the muted text color (nullclears). Drawn as authored whichever way the field reads; usesetLeadingIcon(Icon, Icon.Mirroring)for an icon that means a direction. -
setLeadingIcon
A leading icon that says whether it 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. -
setTrailingButton
A trailing coupled button (icon + action) inside the field, the caret/arrow region idiom ofComboBox.icon == nullremoves it. -
setTrailingButton
A trailing coupled button whose icon says whether it turns around when the interface does; seesetLeadingIcon(Icon, Icon.Mirroring)for why the toolkit does not decide that. -
setValidation
Sets the validation state; colors the border danger/warning/success. -
setError
Convenience:ERRORwhen true,NONEwhen false. -
validation
The current validation state, which drives the border and helper colours. -
model
- Returns:
- the editing model (cursor/selection state), for tests and subclasses
-
allowClipboardCopy
protected boolean allowClipboardCopy()Whether copy/cut may export the content (password fields say no). -
shapeDisplay
The display form of this field's content as a shaped line: the one place a subclass changes what is drawn and how wide it is.Its index space is the model's.
ShapedText.caretX(limn.graphics.ShapedText.Position),ShapedText.hitTest(float)andselectionon the returned value take and return offsets intotext, with no translation anywhere in this component. That is what deletes the prefix arithmetic the caret used to rest on rather than moving it one layer down, and it is the whole contract: an override that returns a line shaped from some other string, with its own boundaries, puts the caret on a neighbour of the character it edits and a click one mark away from the pointer. An override that substitutes marks keepstextas the returned value'sShapedText.text()and changes only the geometry —ShapedText.uniform(java.lang.String, limn.graphics.Font, float, limn.graphics.TextMetrics, long)builds exactly that, from one multiplication, with no glyphs and without the content reaching a shaper at all.fontis the font this line must be shaped for, and it is half the key the held value is refreshed against, so an override that shapes in some other font makes that value lie about when it is stale. There is deliberately noSizeTokensparameter: the font is the only thing in that row a display line can legitimately depend on, and two ways to reach it is one too many.An override whose display form depends on its own state — a reveal toggle — must call
invalidateDisplayLine()when that state changes: the key is text, font and ruler epoch, and it cannot see a field it does not know about.- Parameters:
text- the model's text, which is the index space of the resultfont- the font the line is drawn in- Returns:
- the shaped display line; never null
-
paintDisplayText
protected void paintDisplayText(Canvas canvas, ShapedText display, float x, float baseline, TextMetrics metrics, SizeTokens t, Color ink) Draws a display line with its left edge atx: the paint-side twin ofshapeDisplay(java.lang.String, limn.graphics.Font).metricsis passed rather than only the baseline so an override can place ink against the same band the caret and the selection fill use: the ink box starts atbaseline - metrics.ascent()and ismetrics.height()tall.- Parameters:
canvas- where to drawdisplay- the shaped display line, asshapeDisplay(java.lang.String, limn.graphics.Font)produced itx- left edge of the line, in this widget's coordinatesbaseline- the text baseline, in this widget's coordinatesmetrics- the line's vertical bandt- the size row resolved for this passink- the colour to draw in
-
invalidateDisplayLine
protected final void invalidateDisplayLine()Drops the held display line, so the next paint rebuilds it throughshapeDisplay(java.lang.String, limn.graphics.Font).For a subclass whose display form depends on state of its own: the held value is refreshed against the text, the font and the ruler's epoch, and none of those changes when a reveal toggle does.
-
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()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
-
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
-
onCharTyped
Description copied from class:WidgetCommitted text input (focused widget first, then ancestors).- Overrides:
onCharTypedin classWidget
-
acceptsTextInput
protected boolean acceptsTextInput()Description copied from class:WidgetWhether this widget edits text and should drive the platform input method (IME): the scene enables the IME while such a widget holds focus and disables it otherwise, so composition never intercepts keys meant for non-text UI. Text widgets override this totrue. Default:false.- Overrides:
acceptsTextInputin classWidget
-
allowsWordJumps
protected boolean allowsWordJumps()Whether modifier+arrow/delete may move word-wise (seePasswordField). -
composingText
- Returns:
- the text currently being composed by the IME (empty when not composing)
-
onPreedit
Description copied from class:WidgetIn-progress IME composition ("preedit") for this widget while it is focused: the still-composing text, shown inline but not yet committed (the commit later arrives asWidget.onCharTyped(limn.scene.event.CharEvent)). Only widgets that accept text input receive it. Default: ignored. -
caretRect
Description copied from class:WidgetThe caret rectangle in scene coordinates (logical points) used to place the IME candidate window;nullwhen there is no caret to anchor (or the widget is not laid out yet). Consulted by the scene only while this widget is focused andWidget.acceptsTextInput()is true. -
showContextMenu
protected void showContextMenu(float localX, float localY) Raises the Cut/Copy/Paste/Select All menu at a point in this widget's own coordinates.Protected so a subclass with different clipboard rules can suppress or replace it;
PasswordFielddoes not need to, becauseallowClipboardCopy()already greys the two rows that would let a secret out. -
showContextMenuForFocus
protected void showContextMenuForFocus()Raises the same menu for a request that carries no point: the Menu key or Shift+F10, where the caret is the only place the user can have meant. Protected for the same reason as its pointer twin, and a subclass suppressing one has to suppress both. -
fireChange
protected void fireChange()Notifies the change listener with the current text; for subclasses that edit the model directly. -
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
-