Documentation
¶
Overview ¶
Package textwidget provides the theme-free core of the basicwidget text widgets: the editable Text widget and the input helpers it is built on.
Index ¶
- func IsKeyRepeating(key ebiten.Key) bool
- func IsMouseButtonRepeating(button ebiten.MouseButton) bool
- type CaretScrollTarget
- type SelectionSide
- type Text
- func (t *Text) AppendBoundsOfTextRange(dst []image.Rectangle, context *guigui.Context, bounds image.Rectangle, ...) []image.Rectangle
- func (t *Text) AppendHotspotRanges(dst []TextRange) []TextRange
- func (t *Text) Build(context *guigui.Context, adder *guigui.ChildAdder) error
- func (t *Text) CanCopy() bool
- func (t *Text) CanCut() bool
- func (t *Text) CanPaste() bool
- func (t *Text) CanRedo() bool
- func (t *Text) CanUndo() bool
- func (t *Text) CaretPositionAtTextIndexInBytes(context *guigui.Context, textIndexInBytes int) (top, bottom image.Point, ok bool)
- func (t *Text) CommitWithCurrentInputValue()
- func (t *Text) Copy() bool
- func (t *Text) CopyOverrideStyleRunsFrom(runs *textstyle.Runs, record bool)
- func (t *Text) CursorShape(context *guigui.Context, widgetBounds *guigui.WidgetBounds) (ebiten.CursorShapeType, bool)
- func (t *Text) Cut() bool
- func (t *Text) Draw(context *guigui.Context, widgetBounds *guigui.WidgetBounds, dst *ebiten.Image)
- func (t *Text) DrawPlainString(context *guigui.Context, widgetBounds *guigui.WidgetBounds, dst *ebiten.Image, ...)
- func (t *Text) EffectiveStyleAt(textIndexInBytes int) textstyle.Style
- func (t *Text) ForceSetValue(text string)
- func (t *Text) Generation() int64
- func (t *Text) HandleButtonInput(context *guigui.Context, widgetBounds *guigui.WidgetBounds) guigui.HandleInputResult
- func (t *Text) HandlePointingInput(context *guigui.Context, widgetBounds *guigui.WidgetBounds) guigui.HandleInputResult
- func (t *Text) HasValue() bool
- func (t *Text) HorizontalAlign() textutil.HorizontalAlign
- func (t *Text) IsEditable() bool
- func (t *Text) IsMultiline() bool
- func (t *Text) IsVisuallyEmpty() bool
- func (t *Text) Layout(context *guigui.Context, widgetBounds *guigui.WidgetBounds, ...)
- func (t *Text) LayoutWidth(bounds image.Rectangle) int
- func (t *Text) LineCount() int
- func (t *Text) LineHeight() float64
- func (t *Text) LineIndexFromTextIndexInBytes(textIndexInBytes int) int
- func (t *Text) LineStartInBytes(lineIndex int) int
- func (t *Text) LogicalLineHeight(context *guigui.Context, lineIndex, wrapWidth int) float64
- func (t *Text) MaxCaretXOfLogicalLine(context *guigui.Context, lineIndex, wrapWidth int) float64
- func (t *Text) Measure(context *guigui.Context, constraints guigui.Constraints) image.Point
- func (t *Text) MeasureBold(context *guigui.Context, constraints guigui.Constraints) image.Point
- func (t *Text) OnHandleButtonInput(...)
- func (t *Text) OnHotspotDown(f func(context *guigui.Context, textRange TextRange))
- func (t *Text) OnHotspotUp(f func(context *guigui.Context, textRange TextRange))
- func (t *Text) OnInsertionStyleReset(f func(context *guigui.Context))
- func (t *Text) OnScrollDelta(f func(context *guigui.Context, deltaX, deltaY float64))
- func (t *Text) OnScrollIntoView(f func(context *guigui.Context, start, end CaretScrollTarget))
- func (t *Text) OnValueChanged(f func(context *guigui.Context, text string, committed bool))
- func (t *Text) OnValueChangedWithoutText(f func(context *guigui.Context, committed bool))
- func (t *Text) Paste() bool
- func (t *Text) PasteWithoutStyles() bool
- func (t *Text) ReadBaseStyle(dst *textstyle.Style)
- func (t *Text) ReadEffectiveStyleRuns(dst *textstyle.Runs)
- func (t *Text) ReadEffectiveStyleRunsInRange(dst *textstyle.Runs, startInBytes, endInBytes int)
- func (t *Text) ReadOverrideStyleRuns(dst *textstyle.Runs)
- func (t *Text) ReadOverrideStyleRunsInRange(dst *textstyle.Runs, startInBytes, endInBytes int)
- func (t *Text) ReadValueFrom(r io.Reader) (int64, error)
- func (t *Text) Redo() bool
- func (t *Text) ReplaceOverrideStyleRunsInRange(runs *textstyle.Runs, startInBytes, endInBytes int, record bool)
- func (t *Text) ReplaceValueAtSelection(text string)
- func (t *Text) Scale() float64
- func (t *Text) SelectAll()
- func (t *Text) Selection() (start, end int)
- func (t *Text) SetBaseStyle(style textstyle.Style)
- func (t *Text) SetCaretBlinking(caretBlinking bool)
- func (t *Text) SetCaretColor(clr color.Color)
- func (t *Text) SetCompositionColors(inactive, active color.Color)
- func (t *Text) SetEditable(editable bool)
- func (t *Text) SetEllipsisString(str string)
- func (t *Text) SetFirstLogicalLineInViewport(idx int)
- func (t *Text) SetFontFamily(fontFamily *font.Family)
- func (t *Text) SetFontSize(size float64)
- func (t *Text) SetHorizontalAlign(align textutil.HorizontalAlign)
- func (t *Text) SetHotspotRanges(ranges []TextRange)
- func (t *Text) SetInsertionStyle(style textstyle.Style)
- func (t *Text) SetKeepTailingSpace(keep bool)
- func (t *Text) SetLang(lang language.Tag)
- func (t *Text) SetLineHeight(lineHeight float64)
- func (t *Text) SetLineHeightMode(lineHeightMode textutil.LineHeightMode)
- func (t *Text) SetMaskRune(maskRune rune)
- func (t *Text) SetMultiline(multiline bool)
- func (t *Text) SetPaddingForScrollOffset(padding guigui.Padding)
- func (t *Text) SetRichTextEditable(richTextEditable bool)
- func (t *Text) SetScale(scale float64)
- func (t *Text) SetSelectable(selectable bool)
- func (t *Text) SetSelection(start, end int)
- func (t *Text) SetSelectionColor(clr color.Color)
- func (t *Text) SetSelectionVisibleWhenUnfocused(visible bool)
- func (t *Text) SetSelectionWithSide(start, end int, shiftSide SelectionSide, adjustScroll bool)
- func (t *Text) SetTabWidth(tabWidth float64)
- func (t *Text) SetTextColor(clr color.Color)
- func (t *Text) SetValue(text string)
- func (t *Text) SetVerticalAlign(align textutil.VerticalAlign)
- func (t *Text) SetWrapMode(wrapMode textutil.WrapMode)
- func (t *Text) SetWrapWidth(width int)
- func (t *Text) ShiftSelectionSide() SelectionSide
- func (t *Text) Tick(context *guigui.Context, widgetBounds *guigui.WidgetBounds) error
- func (t *Text) Undo() bool
- func (t *Text) Value() string
- func (t *Text) VerticalAlign() textutil.VerticalAlign
- func (t *Text) VisualLineCountOfLogicalLine(context *guigui.Context, lineIndex, wrapWidth int) int
- func (t *Text) WrapMode() textutil.WrapMode
- func (t *Text) WriteStateKey(context *guigui.Context, w *guigui.StateKeyWriter)
- func (t *Text) WriteValueRangeTo(w io.Writer, startInBytes, endInBytes int) (int64, error)
- func (t *Text) WriteValueTo(w io.Writer) (int64, error)
- type TextRange
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsKeyRepeating ¶
IsKeyRepeating reports whether key is pressed and its press duration is at a key-repeat firing point.
func IsMouseButtonRepeating ¶
func IsMouseButtonRepeating(button ebiten.MouseButton) bool
IsMouseButtonRepeating reports whether button is pressed and its press duration is at a key-repeat firing point.
Types ¶
type CaretScrollTarget ¶
type CaretScrollTarget struct {
// LogicalLineIndex is the caret's committed-text logical-line index.
LogicalLineIndex int
// X is the caret's textBounds-relative X coordinate.
X float64
// Top is the caret's top Y, measured from the start of the logical line.
Top float64
// Bottom is the caret's bottom Y, measured from the start of the logical line.
Bottom float64
}
CaretScrollTarget describes one caret edge for scroll-into-view requests.
type SelectionSide ¶
type SelectionSide int
SelectionSide identifies one endpoint of a selection.
const ( SelectionSideNone SelectionSide = iota SelectionSideStart SelectionSideEnd )
type Text ¶
type Text struct {
guigui.DefaultWidget
// contains filtered or unexported fields
}
Text is a theme-free text widget: it owns the value, selection, caret, IME composition, input handling, layout, hit-testing, masking, and clipboard mechanism, and renders with concrete colors and face inputs set by a wrapping widget.
func (*Text) AppendBoundsOfTextRange ¶
func (t *Text) AppendBoundsOfTextRange(dst []image.Rectangle, context *guigui.Context, bounds image.Rectangle, startInBytes, endInBytes int) []image.Rectangle
AppendBoundsOfTextRange appends the bounding rectangles covering the text range [startInBytes, endInBytes) to dst and returns the extended slice, one rectangle per crossed visual line, in order. bounds is the widget's bounds; the rectangles are in the same coordinate space. A masked value appends nothing. Endpoints outside the text are clamped.
func (*Text) AppendHotspotRanges ¶
AppendHotspotRanges appends the current hotspot ranges to dst and returns the extended slice, reflecting the adjustments made for edits since Text.SetHotspotRanges.
func (*Text) CaretPositionAtTextIndexInBytes ¶
func (t *Text) CaretPositionAtTextIndexInBytes(context *guigui.Context, textIndexInBytes int) (top, bottom image.Point, ok bool)
CaretPositionAtTextIndexInBytes returns the on-screen top and bottom endpoints of a caret drawn at byte offset textIndexInBytes. ok is false when the offset is out of range or the caret's logical line is outside the viewport. Available after the layout phase.
func (*Text) CommitWithCurrentInputValue ¶
func (t *Text) CommitWithCurrentInputValue()
func (*Text) CopyOverrideStyleRunsFrom ¶
CopyOverrideStyleRunsFrom replaces the ranged style overrides with a copy of runs. record sets whether the replacement is recorded in the undo history; a recorded replacement leaving the overrides unchanged records nothing.
func (*Text) CursorShape ¶
func (t *Text) CursorShape(context *guigui.Context, widgetBounds *guigui.WidgetBounds) (ebiten.CursorShapeType, bool)
func (*Text) DrawPlainString ¶
func (t *Text) DrawPlainString(context *guigui.Context, widgetBounds *guigui.WidgetBounds, dst *ebiten.Image, str string, clr color.Color)
DrawPlainString draws str in clr with the widget's current text style, laid out as the value would be, without selection or composition decorations.
func (*Text) EffectiveStyleAt ¶
EffectiveStyleAt returns the effective style that text typed at textIndexInBytes adopts: the resolved base style with the overrides adopted from the neighboring byte merged on top.
func (*Text) ForceSetValue ¶
func (*Text) Generation ¶
Generation returns the store's content generation. The generation advances on every content mutation, so an unchanged generation means unchanged text.
func (*Text) HandleButtonInput ¶
func (t *Text) HandleButtonInput(context *guigui.Context, widgetBounds *guigui.WidgetBounds) guigui.HandleInputResult
func (*Text) HandlePointingInput ¶
func (t *Text) HandlePointingInput(context *guigui.Context, widgetBounds *guigui.WidgetBounds) guigui.HandleInputResult
func (*Text) HorizontalAlign ¶
func (t *Text) HorizontalAlign() textutil.HorizontalAlign
func (*Text) IsEditable ¶
func (*Text) IsMultiline ¶
IsMultiline reports whether the value may span multiple lines. It is always false while masking, which is single-line.
func (*Text) IsVisuallyEmpty ¶
IsVisuallyEmpty reports whether nothing of the value would be rendered: the committed text is empty and no IME composition is in progress.
func (*Text) Layout ¶
func (t *Text) Layout(context *guigui.Context, widgetBounds *guigui.WidgetBounds, layouter *guigui.ChildLayouter)
func (*Text) LayoutWidth ¶
LayoutWidth returns the width used to lay out the text within bounds: the wrap width when wrapping is bounded, else the bounds width.
func (*Text) LineCount ¶
LineCount returns the number of logical lines (spans between hard line breaks) in the value. The empty value has one logical line; a trailing line break creates an extra empty line at the end.
func (*Text) LineHeight ¶
LineHeight returns the line height in pixels, with the widget scale applied.
func (*Text) LineIndexFromTextIndexInBytes ¶
LineIndexFromTextIndexInBytes returns the index of the logical line containing textIndexInBytes, clamping out-of-range values to the first or last line.
func (*Text) LineStartInBytes ¶
LineStartInBytes returns the byte offset where the lineIndex-th logical line begins within the value. lineIndex must be in [0, Text.LineCount).
func (*Text) LogicalLineHeight ¶
LogicalLineHeight returns the rendered height of the lineIndex-th logical line when wrapped at wrapWidth. lineIndex must be in [0, Text.LineCount).
func (*Text) MaxCaretXOfLogicalLine ¶
MaxCaretXOfLogicalLine returns the maximum caret X coordinate over the visual lines of the lineIndex-th logical line when wrapped at wrapWidth. lineIndex must be in [0, Text.LineCount).
func (*Text) MeasureBold ¶
MeasureBold returns the size of the text under constraints as if it were rendered bold.
func (*Text) OnHandleButtonInput ¶
func (t *Text) OnHandleButtonInput(f func(context *guigui.Context, widgetBounds *guigui.WidgetBounds) guigui.HandleInputResult)
func (*Text) OnHotspotDown ¶
OnHotspotDown sets the event handler that is called when the left mouse button is pressed on a hotspot range. The handler is given the pressed range.
func (*Text) OnHotspotUp ¶
OnHotspotUp sets the event handler that is called when the left mouse button is released on the hotspot range it was pressed on. For selectable text, the click is canceled when the cursor moved or a selection was made between the press and the release: a drag selects, it does not click. The handler is given the released range.
func (*Text) OnInsertionStyleReset ¶
OnInsertionStyleReset sets an event handler invoked when the widget resets the insertion style: after applying it to inserted text, or when discarding it without applying, such as on a selection change. The handler is not invoked for Text.SetInsertionStyle.
func (*Text) OnScrollDelta ¶
OnScrollDelta registers a handler invoked when input handling needs the containing scrollable area to scroll by a delta in pixels.
func (*Text) OnScrollIntoView ¶
func (t *Text) OnScrollIntoView(f func(context *guigui.Context, start, end CaretScrollTarget))
OnScrollIntoView registers a handler invoked when the selection needs to be brought into view. start and end are the selection endpoints (start <= end as byte indices); both are equal when the selection has zero width.
func (*Text) OnValueChanged ¶
OnValueChanged sets the event handler that is called when the text value changes. The handler receives the current text and whether the change is committed. Dispatch and commit semantics are documented on the wrapping widget's OnValueChanged.
func (*Text) OnValueChangedWithoutText ¶
OnValueChangedWithoutText sets a handler that fires under the same conditions as Text.OnValueChanged but is not given the current text, so the value is not materialized into a string on every change.
func (*Text) PasteWithoutStyles ¶
PasteWithoutStyles pastes the clipboard text without the ranged styles copied along with it, even when the widget is rich text editable. The inserted text adopts the style of the surrounding text.
func (*Text) ReadBaseStyle ¶
ReadBaseStyle writes the base style's overridable properties to dst.
func (*Text) ReadEffectiveStyleRuns ¶
ReadEffectiveStyleRuns replaces dst's runs with the effective styles of the whole value: the resolved base style with the ranged overrides merged on top.
func (*Text) ReadEffectiveStyleRunsInRange ¶
ReadEffectiveStyleRunsInRange replaces dst's runs with the effective styles of [startInBytes, endInBytes): the resolved base style with the ranged overrides merged on top, rebased so that startInBytes maps to 0.
func (*Text) ReadOverrideStyleRuns ¶
ReadOverrideStyleRuns replaces dst's runs with a copy of the ranged style overrides, reflecting the adjustments made for edits since the overrides were set.
func (*Text) ReadOverrideStyleRunsInRange ¶
ReadOverrideStyleRunsInRange replaces dst's runs with a copy of the ranged style overrides in [startInBytes, endInBytes), rebased so that startInBytes maps to 0.
func (*Text) ReadValueFrom ¶
ReadValueFrom resets the value to the bytes read from r until EOF and returns the number of bytes read. The undo history is cleared and the selection is reset to (0, 0). On a non-EOF error, the value is reset to empty and the error is returned.
func (*Text) ReplaceOverrideStyleRunsInRange ¶
func (t *Text) ReplaceOverrideStyleRunsInRange(runs *textstyle.Runs, startInBytes, endInBytes int, record bool)
ReplaceOverrideStyleRunsInRange replaces the ranged style overrides in [startInBytes, endInBytes) with runs' overrides in [0, endInBytes-startInBytes), shifted so that 0 maps to startInBytes. record sets whether the replacement is recorded in the undo history; a recorded replacement leaving the overrides unchanged records nothing.
func (*Text) ReplaceValueAtSelection ¶
func (*Text) SetBaseStyle ¶
SetBaseStyle replaces the base style's overridable properties with style, except the font family, the text color and the language, which Text.SetFontFamily, Text.SetTextColor and Text.SetLang keep owning.
func (*Text) SetCaretBlinking ¶
SetCaretBlinking sets whether the caret blinks. The default value is true.
func (*Text) SetCaretColor ¶
SetCaretColor sets the concrete color of the caret.
func (*Text) SetCompositionColors ¶
SetCompositionColors sets the concrete colors of the underlines drawn below the inactive and active parts of an IME composition.
func (*Text) SetEditable ¶
func (*Text) SetEllipsisString ¶
func (*Text) SetFirstLogicalLineInViewport ¶
SetFirstLogicalLineInViewport sets the logical line that sits at widget-local Y=0. The default 0 means line 0 at the top; virtualizing parents set the topmost visible logical line so drawing, hit testing, and caret positioning need not walk the document prefix.
func (*Text) SetFontFamily ¶
SetFontFamily sets the resolved font family used to render the value. A nil family renders with the registered face source stack alone.
func (*Text) SetFontSize ¶
SetFontSize sets the font size at scale 1. The rendered size is the base size multiplied by the scale set via Text.SetScale.
func (*Text) SetHorizontalAlign ¶
func (t *Text) SetHorizontalAlign(align textutil.HorizontalAlign)
func (*Text) SetHotspotRanges ¶
SetHotspotRanges sets the hotspot ranges: over their rectangles the cursor turns into a pointer, and mouse presses and releases fire the hotspot down and up events. The ranges follow the text through edits like the ranged styles. While the value is editable, the hotspots are inert.
func (*Text) SetInsertionStyle ¶
SetInsertionStyle replaces the insertion style with style. Its set properties are applied as ranged style overrides over the next text inserted at the caret, on top of the adopted overrides, and the style is then reset. The widget also resets it without applying on other interactions, such as a selection change, a deletion, or an undo; neither setting nor resetting is recorded in the undo history.
func (*Text) SetKeepTailingSpace ¶
SetKeepTailingSpace sets whether spaces at the end of a visual line keep their advance instead of collapsing.
func (*Text) SetLang ¶
SetLang sets the language used to select the face and its features when shaping the value.
func (*Text) SetLineHeight ¶
SetLineHeight sets the line height at scale 1. The rendered line height is the base line height multiplied by the scale set via Text.SetScale.
func (*Text) SetLineHeightMode ¶
func (t *Text) SetLineHeightMode(lineHeightMode textutil.LineHeightMode)
SetLineHeightMode sets how a visual line's height responds to the font sizes on it.
func (*Text) SetMaskRune ¶
SetMaskRune sets the character drawn in place of each grapheme cluster of the value. A non-zero rune masks the text and forces it to a single line; the zero value renders it normally.
func (*Text) SetMultiline ¶
func (*Text) SetPaddingForScrollOffset ¶
SetPaddingForScrollOffset sets the padding kept between the caret and the viewport edges when scrolling the selection into view.
func (*Text) SetRichTextEditable ¶
SetRichTextEditable sets whether pasting applies the ranged styles copied along with the text. The default is false: pasting inserts plain text and the inserted text adopts the style of the surrounding text.
func (*Text) SetSelectable ¶
func (*Text) SetSelection ¶
SetSelection sets the selection to [start, end) in bytes. Offsets inside a UTF-8 sequence are snapped to rune boundaries: an empty selection moves to the start of the rune containing it, and a non-empty one expands to cover whole runes.
func (*Text) SetSelectionColor ¶
SetSelectionColor sets the concrete color of the selection highlight.
func (*Text) SetSelectionVisibleWhenUnfocused ¶
SetSelectionVisibleWhenUnfocused sets whether the selection range stays drawn while the widget is not focused. The default is false.
func (*Text) SetSelectionWithSide ¶
func (t *Text) SetSelectionWithSide(start, end int, shiftSide SelectionSide, adjustScroll bool)
SetSelectionWithSide sets the selection to the range spanned by start and end and records shiftSide as the endpoint moved by Shift and arrow keys.
func (*Text) SetTabWidth ¶
func (*Text) SetTextColor ¶
SetTextColor sets the concrete color the value is drawn in.
func (*Text) SetVerticalAlign ¶
func (t *Text) SetVerticalAlign(align textutil.VerticalAlign)
func (*Text) SetWrapMode ¶
SetWrapMode selects how visual lines wrap when text exceeds the available width. See textutil.WrapMode for the available modes.
func (*Text) SetWrapWidth ¶
SetWrapWidth sets the width text wraps at, keeping wrapping tied to a viewport even when the widget bounds are widened to cover horizontally overflowing content. A non-positive width wraps at the widget bounds.
func (*Text) ShiftSelectionSide ¶
func (t *Text) ShiftSelectionSide() SelectionSide
ShiftSelectionSide returns the selection endpoint moved by Shift and arrow keys.
func (*Text) VerticalAlign ¶
func (t *Text) VerticalAlign() textutil.VerticalAlign
func (*Text) VisualLineCountOfLogicalLine ¶
VisualLineCountOfLogicalLine returns the number of visual lines the lineIndex-th logical line occupies when wrapped at wrapWidth. lineIndex must be in [0, Text.LineCount).
func (*Text) WrapMode ¶
WrapMode reports how visual lines wrap when text exceeds the available width. The default is textutil.WrapModeNone.
func (*Text) WriteStateKey ¶
func (t *Text) WriteStateKey(context *guigui.Context, w *guigui.StateKeyWriter)
func (*Text) WriteValueRangeTo ¶
WriteValueRangeTo writes the bytes of the current value in [startInBytes, endInBytes), clamped to the value, to w.