input

package
v0.1.122 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSingleLine

func IsSingleLine(limits TextFieldLineLimits) bool

IsSingleLine returns true if the line limits enforce single-line behavior.

func ShouldWrap

func ShouldWrap(limits TextFieldLineLimits) bool

ShouldWrap returns whether the text field should wrap text.

Types

type AllCapsInputTransformation

type AllCapsInputTransformation struct {
	// Locale is currently unused but reserved for locale-aware case conversion.
	Locale string
}

AllCapsInputTransformation converts inserted text to uppercase.

func (*AllCapsInputTransformation) TransformInput

func (a *AllCapsInputTransformation) TransformInput(buffer *TextFieldBuffer)

TransformInput implements InputTransformation.

type ByValueInputTransformation

type ByValueInputTransformation struct {
	Transform func(current, proposed string) string
}

ByValueInputTransformation transforms based on comparing current and proposed values.

func (*ByValueInputTransformation) TransformInput

func (b *ByValueInputTransformation) TransformInput(buffer *TextFieldBuffer)

TransformInput implements InputTransformation.

type ChainedInputTransformation

type ChainedInputTransformation struct {
	First  InputTransformation
	Second InputTransformation
}

ChainedInputTransformation combines two transformations.

func (*ChainedInputTransformation) TransformInput

func (c *ChainedInputTransformation) TransformInput(buffer *TextFieldBuffer)

TransformInput implements InputTransformation by running first then second.

type ChainedOutputTransformation

type ChainedOutputTransformation struct {
	First  OutputTransformation
	Second OutputTransformation
}

ChainedOutputTransformation combines two output transformations.

func (*ChainedOutputTransformation) TransformOutput

func (c *ChainedOutputTransformation) TransformOutput(buffer *TextFieldBuffer)

TransformOutput implements OutputTransformation.

type Composable

type Composable = api.Composable

type EditableTextLayoutController

type EditableTextLayoutController struct {
	// contains filtered or unexported fields
}

EditableTextLayoutController manages editable text layout state and bridges between Compose input APIs and Gio widget.Editor rendering.

Unlike TextLayoutController which uses widget.TextView (read-only), this controller uses widget.Editor which provides full input handling including: - Keyboard input - Cursor positioning and blinking - Text selection - Undo/redo

func NewEditableTextLayoutController

func NewEditableTextLayoutController(state *TextFieldState) *EditableTextLayoutController

NewEditableTextLayoutController creates a new EditableTextLayoutController.

func (*EditableTextLayoutController) ClearSelection

func (c *EditableTextLayoutController) ClearSelection()

ClearSelection clears the selection.

func (*EditableTextLayoutController) ConfigureFromTextStyle

func (c *EditableTextLayoutController) ConfigureFromTextStyle(ts *text.TextStyle)

ConfigureFromTextStyle applies settings from a TextStyle.

func (*EditableTextLayoutController) Delete

func (c *EditableTextLayoutController) Delete(graphemeClusters int) int

Delete deletes runes from the caret position.

func (*EditableTextLayoutController) Editor

Editor returns the underlying widget.Editor for advanced use cases.

func (*EditableTextLayoutController) GetFont

func (c *EditableTextLayoutController) GetFont() font.Font

GetFont returns a Gio font from the current text style.

func (*EditableTextLayoutController) GetFontSize

func (c *EditableTextLayoutController) GetFontSize() unit.TextUnit

GetFontSize returns the font size in Sp.

func (*EditableTextLayoutController) Insert

Insert inserts text at the current caret position.

func (*EditableTextLayoutController) Layout

func (c *EditableTextLayoutController) Layout(gtx layout.Context, shaper *gioText.Shaper, textMaterial, selectMaterial gioOp.CallOp) layout.Dimensions

Layout performs text layout and returns dimensions.

func (*EditableTextLayoutController) LayoutAndPaint

func (c *EditableTextLayoutController) LayoutAndPaint(gtx layout.Context, shaper *gioText.Shaper, textMaterial gioOp.CallOp) layout.Dimensions

LayoutAndPaint performs update, layout and paints the text in one call. This is the main entry point for rendering editable text.

func (*EditableTextLayoutController) Len

Len returns the length of the text in runes.

func (*EditableTextLayoutController) SelectedText

func (c *EditableTextLayoutController) SelectedText() string

SelectedText returns the currently selected text.

func (*EditableTextLayoutController) Selection

func (c *EditableTextLayoutController) Selection() (start, end int)

Selection returns the current selection range in runes.

func (*EditableTextLayoutController) SetAlignment

func (c *EditableTextLayoutController) SetAlignment(alignment style.TextAlign)

SetAlignment sets text alignment.

func (*EditableTextLayoutController) SetCaret

func (c *EditableTextLayoutController) SetCaret(start, end int)

SetCaret sets the caret position and selection.

func (*EditableTextLayoutController) SetInputTransformation

func (c *EditableTextLayoutController) SetInputTransformation(t InputTransformation)

SetInputTransformation sets the input transformation.

func (*EditableTextLayoutController) SetLineHeight

func (c *EditableTextLayoutController) SetLineHeight(lineHeight gioUnit.Sp)

SetLineHeight sets the line height.

func (*EditableTextLayoutController) SetLineHeightScale

func (c *EditableTextLayoutController) SetLineHeightScale(scale float32)

SetLineHeightScale sets the line height scale.

func (*EditableTextLayoutController) SetMaxLines

func (c *EditableTextLayoutController) SetMaxLines(maxLines int)

SetMaxLines sets the maximum number of lines.

func (*EditableTextLayoutController) SetMinLines

func (c *EditableTextLayoutController) SetMinLines(minLines int)

SetMinLines sets the minimum number of lines.

func (*EditableTextLayoutController) SetOnValueChange

func (c *EditableTextLayoutController) SetOnValueChange(callback func(string))

SetOnValueChange sets the callback for text changes.

func (*EditableTextLayoutController) SetReadOnly

func (c *EditableTextLayoutController) SetReadOnly(readOnly bool)

SetReadOnly enables or disables read-only mode.

func (*EditableTextLayoutController) SetSelectionColor

func (c *EditableTextLayoutController) SetSelectionColor(color color.NRGBA)

SetSelectionColor sets the selection highlight color.

func (*EditableTextLayoutController) SetSingleLine

func (c *EditableTextLayoutController) SetSingleLine(singleLine bool)

SetSingleLine enables or disables single line mode.

func (*EditableTextLayoutController) SetSoftWrap

func (c *EditableTextLayoutController) SetSoftWrap(softWrap bool)

SetSoftWrap enables or disables soft wrapping.

func (*EditableTextLayoutController) SetText

func (c *EditableTextLayoutController) SetText(s string)

SetText sets the text content.

func (*EditableTextLayoutController) SetTextStyle

func (c *EditableTextLayoutController) SetTextStyle(textStyle *text.TextStyle)

SetTextStyle configures the text style.

func (*EditableTextLayoutController) SetWrapPolicy

func (c *EditableTextLayoutController) SetWrapPolicy(wrapPolicy gioText.WrapPolicy)

SetWrapPolicy sets the line wrap policy.

func (*EditableTextLayoutController) State

State returns the underlying TextFieldState.

func (*EditableTextLayoutController) Text

Text returns the current text content.

func (*EditableTextLayoutController) Update

Update processes input events and syncs state. Should be called before Layout.

This implements the controlled component pattern from Jetpack Compose: 1. Process editor events and call onValueChange with new text 2. Sync editor FROM state - if state wasn't updated by callback, editor reverts

type FilterInputTransformation

type FilterInputTransformation struct {
	Filter func(r rune) bool
}

FilterInputTransformation rejects characters that don't pass the filter.

func (*FilterInputTransformation) TransformInput

func (f *FilterInputTransformation) TransformInput(buffer *TextFieldBuffer)

TransformInput implements InputTransformation.

type InputTransformation

type InputTransformation interface {
	// TransformInput modifies the buffer to filter/transform input.
	// Call buffer.RevertAllChanges() to reject all changes.
	TransformInput(buffer *TextFieldBuffer)
}

InputTransformation filters/transforms user input after it's received.

Input transformations run AFTER user input is received but BEFORE it's committed to the TextFieldState. They can:

  • Reject changes (by calling buffer.RevertAllChanges())
  • Modify the input (e.g., convert to uppercase)
  • Adjust the selection

Transformations are called for all user-initiated input:

  • Keyboard input (hardware and software)
  • Paste operations
  • Drag and drop
  • Accessibility input
  • IME input

This is a port of androidx.compose.foundation.text.input.InputTransformation.

func AllCapsTransformation

func AllCapsTransformation() InputTransformation

AllCapsTransformation creates an InputTransformation that converts inserted text to uppercase.

func AllCapsTransformationWithLocale

func AllCapsTransformationWithLocale(locale string) InputTransformation

AllCapsTransformationWithLocale creates an InputTransformation that converts inserted text to uppercase using the specified locale.

func AlphanumericOnlyTransformation

func AlphanumericOnlyTransformation() InputTransformation

AlphanumericOnlyTransformation creates an InputTransformation that only allows letters and digits.

func ChainTransformations

func ChainTransformations(first, second InputTransformation) InputTransformation

ChainTransformations creates a transformation that runs first then second.

func DigitsOnlyTransformation

func DigitsOnlyTransformation() InputTransformation

DigitsOnlyTransformation creates an InputTransformation that only allows digits.

func InputTransformationByValue

func InputTransformationByValue(transform func(current, proposed string) string) InputTransformation

InputTransformationByValue creates a transformation from a comparison function. The function receives the current text and the proposed text (after user input), and returns the final text that should be used.

func MaxLengthTransformation

func MaxLengthTransformation(maxLength int) InputTransformation

MaxLengthTransformation creates an InputTransformation that rejects input exceeding the specified length.

type InputTransformationFunc

type InputTransformationFunc func(buffer *TextFieldBuffer)

InputTransformationFunc is a function type that implements InputTransformation.

func (InputTransformationFunc) Then

Then creates a chained transformation that runs this transformation first, then the other transformation.

func (InputTransformationFunc) TransformInput

func (f InputTransformationFunc) TransformInput(buffer *TextFieldBuffer)

TransformInput implements InputTransformation.

type MaxLengthInputTransformation

type MaxLengthInputTransformation struct {
	MaxLength int
}

MaxLengthInputTransformation truncates input that exceeds maxLength.

func (*MaxLengthInputTransformation) TransformInput

func (m *MaxLengthInputTransformation) TransformInput(buffer *TextFieldBuffer)

TransformInput implements InputTransformation.

type MultiLine

type MultiLine struct {
	// MinHeightInLines is the minimum height in lines. Default is 1.
	MinHeightInLines int

	// MaxHeightInLines is the maximum height in lines. Default is MaxInt.
	MaxHeightInLines int
}

MultiLine allows multiple lines with configurable height limits. The field grows from MinHeightInLines to MaxHeightInLines, then scrolls.

func NewMultiLine

func NewMultiLine() MultiLine

NewMultiLine creates a MultiLine with default values (1 to MaxInt lines).

func NewMultiLineWithLimits

func NewMultiLineWithLimits(minLines, maxLines int) MultiLine

NewMultiLineWithLimits creates a MultiLine with specified limits. Panics if minLines < 1 or maxLines < minLines.

type OutputTransformation

type OutputTransformation interface {
	// TransformOutput modifies the buffer for display purposes.
	// Changes do not affect the underlying TextFieldState.
	TransformOutput(buffer *TextFieldBuffer)
}

OutputTransformation transforms text for visual presentation only.

Output transformations modify how text is DISPLAYED without affecting the underlying TextFieldState. They are applied every frame and changes are discarded after rendering.

Common use cases:

  • Adding prefixes/suffixes (e.g., currency symbols)
  • Formatting (e.g., phone numbers with dashes)
  • Visual decorations

The selection and cursor positions are automatically mapped through the transformation, so users can still edit the underlying text normally.

This is a port of androidx.compose.foundation.text.input.OutputTransformation.

func ChainOutputTransformations

func ChainOutputTransformations(first, second OutputTransformation) OutputTransformation

ChainOutputTransformations creates an OutputTransformation that runs first then second.

func PhoneNumberTransformation

func PhoneNumberTransformation() OutputTransformation

PhoneNumberTransformation creates an OutputTransformation that formats text as a US phone number.

func PrefixTransformation

func PrefixTransformation(prefix string) OutputTransformation

PrefixTransformation creates an OutputTransformation that adds a prefix.

func SuffixTransformation

func SuffixTransformation(suffix string) OutputTransformation

SuffixTransformation creates an OutputTransformation that adds a suffix.

type OutputTransformationFunc

type OutputTransformationFunc func(buffer *TextFieldBuffer)

OutputTransformationFunc is a function type that implements OutputTransformation.

func (OutputTransformationFunc) TransformOutput

func (f OutputTransformationFunc) TransformOutput(buffer *TextFieldBuffer)

TransformOutput implements OutputTransformation.

type PhoneNumberOutputTransformation

type PhoneNumberOutputTransformation struct{}

PhoneNumberOutputTransformation formats text as a US phone number. This is an example transformation that formats "1234567890" as "(123) 456-7890".

func (*PhoneNumberOutputTransformation) TransformOutput

func (p *PhoneNumberOutputTransformation) TransformOutput(buffer *TextFieldBuffer)

TransformOutput implements OutputTransformation.

type PlacedAnnotation

type PlacedAnnotation = text.Range[text.Annotation]

PlacedAnnotation is an alias for text.Range[text.Annotation]. This represents an annotation with its position range in the text.

type PrefixOutputTransformation

type PrefixOutputTransformation struct {
	Prefix string
}

PrefixOutputTransformation adds a prefix to the displayed text.

func (*PrefixOutputTransformation) TransformOutput

func (p *PrefixOutputTransformation) TransformOutput(buffer *TextFieldBuffer)

TransformOutput implements OutputTransformation.

type SingleLine

type SingleLine struct{}

SingleLine makes the field always single-line, ignoring newlines. The field scrolls horizontally when text overflows.

type SuffixOutputTransformation

type SuffixOutputTransformation struct {
	Suffix string
}

SuffixOutputTransformation adds a suffix to the displayed text.

func (*SuffixOutputTransformation) TransformOutput

func (s *SuffixOutputTransformation) TransformOutput(buffer *TextFieldBuffer)

TransformOutput implements OutputTransformation.

type TextFieldBuffer

type TextFieldBuffer struct {
	// contains filtered or unexported fields
}

TextFieldBuffer is a mutable buffer for text field editing operations.

It provides methods for replacing, inserting, deleting, and appending text, as well as managing the selection/cursor state. All changes are tracked for undo/redo and input transformation purposes.

TextFieldBuffer is used within TextFieldState.Edit() blocks to perform atomic editing operations. It should not be retained across edit sessions.

This is a port of androidx.compose.foundation.text.input.TextFieldBuffer.

func NewTextFieldBuffer

func NewTextFieldBuffer(initialValue *TextFieldCharSequence) *TextFieldBuffer

NewTextFieldBuffer creates a new TextFieldBuffer initialized with the given value.

func NewTextFieldBufferWithTracker

func NewTextFieldBufferWithTracker(
	initialValue *TextFieldCharSequence,
	initialChanges *internal.ChangeTracker,
	offsetMappingCalculator *internal.OffsetMappingCalculator,
) *TextFieldBuffer

NewTextFieldBufferWithTracker creates a TextFieldBuffer with an optional change tracker and offset mapping calculator.

func (*TextFieldBuffer) AddStyle

func (b *TextFieldBuffer) AddStyle(style text.SpanStyle, start, end int)

AddStyle adds a SpanStyle annotation to the specified range. This allows styling a portion of the text buffer.

func (*TextFieldBuffer) Append

func (b *TextFieldBuffer) Append(text string) *TextFieldBuffer

Append adds text at the end of the buffer.

func (*TextFieldBuffer) AppendLine

func (b *TextFieldBuffer) AppendLine(text string) *TextFieldBuffer

AppendLine appends text followed by a newline.

func (*TextFieldBuffer) Changes

func (b *TextFieldBuffer) Changes() internal.ChangeList

Changes returns the list of changes made to this buffer.

func (*TextFieldBuffer) CharAt

func (b *TextFieldBuffer) CharAt(index int) rune

CharAt returns the rune at the given index.

func (*TextFieldBuffer) Clear

func (b *TextFieldBuffer) Clear()

Clear removes all text and resets selection to start.

func (*TextFieldBuffer) ComposingAnnotations

func (b *TextFieldBuffer) ComposingAnnotations() []PlacedAnnotation

ComposingAnnotations returns annotations attached to the composing region.

func (*TextFieldBuffer) Composition

func (b *TextFieldBuffer) Composition() *text.TextRange

Composition returns the current composition range (IME input in progress).

func (*TextFieldBuffer) ContentEquals

func (b *TextFieldBuffer) ContentEquals(other string) bool

ContentEquals returns true if the content equals the given string.

func (*TextFieldBuffer) Delete

func (b *TextFieldBuffer) Delete(start, end int)

Delete removes text from start to end.

func (*TextFieldBuffer) DeleteSelectedText

func (b *TextFieldBuffer) DeleteSelectedText() bool

DeleteSelectedText deletes the currently selected text. Returns true if text was deleted.

func (*TextFieldBuffer) GetSelectedText

func (b *TextFieldBuffer) GetSelectedText() string

GetSelectedText returns the currently selected text.

func (*TextFieldBuffer) GetTextAfterSelection

func (b *TextFieldBuffer) GetTextAfterSelection(maxChars int) string

GetTextAfterSelection returns the text after the selection.

func (*TextFieldBuffer) GetTextBeforeSelection

func (b *TextFieldBuffer) GetTextBeforeSelection(maxChars int) string

GetTextBeforeSelection returns the text before the selection.

func (*TextFieldBuffer) HasSelection

func (b *TextFieldBuffer) HasSelection() bool

HasSelection returns true if text is selected (selection is not collapsed).

func (*TextFieldBuffer) Highlight

func (b *TextFieldBuffer) Highlight() *TextHighlight

Highlight returns the current highlight for handwriting gesture previews.

func (*TextFieldBuffer) Insert

func (b *TextFieldBuffer) Insert(index int, text string)

Insert adds text at the given index.

func (*TextFieldBuffer) Length

func (b *TextFieldBuffer) Length() int

Length returns the number of characters (runes) in the buffer.

func (*TextFieldBuffer) OriginalSelection

func (b *TextFieldBuffer) OriginalSelection() text.TextRange

OriginalSelection returns the selection from the original value.

func (*TextFieldBuffer) OriginalValue

func (b *TextFieldBuffer) OriginalValue() *TextFieldCharSequence

OriginalValue returns the original value before any modifications.

func (*TextFieldBuffer) PlaceCursorAfterCharAt

func (b *TextFieldBuffer) PlaceCursorAfterCharAt(index int)

PlaceCursorAfterCharAt places the cursor after the character at the given index.

func (*TextFieldBuffer) PlaceCursorAtEnd

func (b *TextFieldBuffer) PlaceCursorAtEnd()

PlaceCursorAtEnd places the cursor at the end of the text.

func (*TextFieldBuffer) PlaceCursorBeforeCharAt

func (b *TextFieldBuffer) PlaceCursorBeforeCharAt(index int)

PlaceCursorBeforeCharAt places the cursor before the character at the given index.

func (*TextFieldBuffer) Replace

func (b *TextFieldBuffer) Replace(start, end int, replacement string)

Replace replaces text from start (inclusive) to end (exclusive) with the given text. Selection is adjusted to account for the text change.

func (*TextFieldBuffer) ReplaceAll

func (b *TextFieldBuffer) ReplaceAll(old, new string) int

ReplaceAll replaces all occurrences of old with new.

func (*TextFieldBuffer) RevertAllChanges

func (b *TextFieldBuffer) RevertAllChanges()

RevertAllChanges restores the buffer to its original state.

func (*TextFieldBuffer) SelectAll

func (b *TextFieldBuffer) SelectAll()

SelectAll selects all text in the buffer.

func (*TextFieldBuffer) SelectCharsIn

func (b *TextFieldBuffer) SelectCharsIn(rangeValue text.TextRange)

SelectCharsIn selects the characters in the given range.

func (*TextFieldBuffer) Selection

func (b *TextFieldBuffer) Selection() text.TextRange

Selection returns the current selection range.

func (*TextFieldBuffer) SetComposingAnnotations

func (b *TextFieldBuffer) SetComposingAnnotations(annotations []PlacedAnnotation)

SetComposingAnnotations sets the annotations for the composing region.

func (*TextFieldBuffer) SetComposition

func (b *TextFieldBuffer) SetComposition(composition *text.TextRange)

SetComposition sets or clears the composition range.

func (*TextFieldBuffer) SetHighlight

func (b *TextFieldBuffer) SetHighlight(highlight *TextHighlight)

SetHighlight sets or clears the highlight.

func (*TextFieldBuffer) SetSelection

func (b *TextFieldBuffer) SetSelection(start, end int)

SetSelection sets the selection range. Both start and end must be valid.

func (*TextFieldBuffer) String

func (b *TextFieldBuffer) String() string

String returns the current text content.

func (*TextFieldBuffer) SubSequence

func (b *TextFieldBuffer) SubSequence(start, end int) string

SubSequence returns a substring from start to end.

func (*TextFieldBuffer) ToTextFieldCharSequence

func (b *TextFieldBuffer) ToTextFieldCharSequence() *TextFieldCharSequence

ToTextFieldCharSequence creates an immutable snapshot of the current state.

func (*TextFieldBuffer) Write

func (b *TextFieldBuffer) Write(p []byte) (int, error)

Write implements io.Writer, appending bytes as UTF-8 string.

func (*TextFieldBuffer) WriteRune

func (b *TextFieldBuffer) WriteRune(r rune) (int, error)

WriteRune appends a single rune.

func (*TextFieldBuffer) WriteString

func (b *TextFieldBuffer) WriteString(s string) (int, error)

WriteString implements io.StringWriter, appending the string.

type TextFieldCharSequence

type TextFieldCharSequence struct {
	// contains filtered or unexported fields
}

TextFieldCharSequence is an immutable snapshot of the contents of a TextFieldState.

This type directly represents the text being edited along with:

  • selection: The current cursor position or selection range
  • composition: The range being composed by the IME (if any)
  • highlight: The highlighted range for handwriting gesture previews (if any)
  • composingAnnotations: Annotations attached to the composing region
  • outputAnnotations: Annotations from OutputTransformation

This is a port of androidx.compose.foundation.text.input.TextFieldCharSequence.

func NewTextFieldCharSequence

func NewTextFieldCharSequence(txt string, selection text.TextRange) *TextFieldCharSequence

NewTextFieldCharSequence creates a new TextFieldCharSequence with the given text and selection.

func NewTextFieldCharSequenceFull

func NewTextFieldCharSequenceFull(
	txt string,
	selection text.TextRange,
	composition *text.TextRange,
	highlight *TextHighlight,
	composingAnnotations []PlacedAnnotation,
	outputAnnotations []PlacedAnnotation,
) *TextFieldCharSequence

NewTextFieldCharSequenceFull creates a TextFieldCharSequence with all fields.

func NewTextFieldCharSequenceWithComposition

func NewTextFieldCharSequenceWithComposition(
	txt string,
	selection text.TextRange,
	composition *text.TextRange,
) *TextFieldCharSequence

NewTextFieldCharSequenceWithComposition creates a TextFieldCharSequence with composition range.

func (*TextFieldCharSequence) CharAt

func (t *TextFieldCharSequence) CharAt(index int) byte

CharAt returns the byte at the given index.

func (*TextFieldCharSequence) ComposingAnnotations

func (t *TextFieldCharSequence) ComposingAnnotations() []PlacedAnnotation

ComposingAnnotations returns annotations attached to the composing region. These are usually styling cues like underline or different background colors.

func (*TextFieldCharSequence) Composition

func (t *TextFieldCharSequence) Composition() *text.TextRange

Composition returns the current composing region dictated by the IME. Returns nil if there is no composing region.

func (*TextFieldCharSequence) ContentEquals

func (t *TextFieldCharSequence) ContentEquals(other string) bool

ContentEquals returns true if the text content equals the given string.

func (*TextFieldCharSequence) Equals

Equals returns true if other has the same contents, selection, composition, and highlight.

func (*TextFieldCharSequence) GetSelectedText

func (t *TextFieldCharSequence) GetSelectedText() string

GetSelectedText returns the currently selected text.

func (*TextFieldCharSequence) GetTextAfterSelection

func (t *TextFieldCharSequence) GetTextAfterSelection(maxChars int) string

GetTextAfterSelection returns the text after the selection. maxChars is the maximum number of characters (exclusive) after the selection maximum.

func (*TextFieldCharSequence) GetTextBeforeSelection

func (t *TextFieldCharSequence) GetTextBeforeSelection(maxChars int) string

GetTextBeforeSelection returns the text before the selection. maxChars is the maximum number of characters (inclusive) before the selection minimum.

func (*TextFieldCharSequence) Highlight

func (t *TextFieldCharSequence) Highlight() *TextHighlight

Highlight returns the current highlight for handwriting gesture previews. Returns nil if there is no highlight.

func (*TextFieldCharSequence) Len

func (t *TextFieldCharSequence) Len() int

Len returns the length of the text in bytes.

func (*TextFieldCharSequence) OutputAnnotations

func (t *TextFieldCharSequence) OutputAnnotations() []PlacedAnnotation

OutputAnnotations returns annotations added by OutputTransformation.

func (*TextFieldCharSequence) Selection

func (t *TextFieldCharSequence) Selection() text.TextRange

Selection returns the current selection range. If the selection is collapsed, it represents the cursor location.

func (*TextFieldCharSequence) ShouldShowSelection

func (t *TextFieldCharSequence) ShouldShowSelection() bool

ShouldShowSelection returns whether to show the cursor or selection and associated handles. When there is a handwriting gesture preview highlight, the cursor or selection should be hidden.

func (*TextFieldCharSequence) String

func (t *TextFieldCharSequence) String() string

String returns the plain text content (implements fmt.Stringer).

func (*TextFieldCharSequence) SubSequence

func (t *TextFieldCharSequence) SubSequence(startIndex, endIndex int) string

SubSequence returns a substring from startIndex (inclusive) to endIndex (exclusive).

func (*TextFieldCharSequence) Text

func (t *TextFieldCharSequence) Text() string

Text returns the plain text content.

func (*TextFieldCharSequence) ToCharArray

func (t *TextFieldCharSequence) ToCharArray(
	destination []byte,
	destinationOffset int,
	sourceStartIndex int,
	sourceEndIndex int,
)

ToCharArray copies the contents from [sourceStartIndex, sourceEndIndex) into destination starting at destinationOffset.

type TextFieldDecorator

type TextFieldDecorator interface {
	// Decoration renders decorations around the inner text field.
	//
	// Parameters:
	//   - innerTextField: A callback that renders the core text editing surface.
	//     This MUST be called exactly once.
	//
	// The decorator controls the layout of the inner text field relative to
	// any decorations (icons, labels, etc.).
	Decoration(innerTextField Composable) Composable
}

TextFieldDecorator adds decorations around the text field.

A decorator wraps the inner text field with custom UI elements like:

  • Leading/trailing icons
  • Labels and placeholder text
  • Helper/error messages
  • Borders and backgrounds

The decorator automatically expands the hit target area of the text field to include the decorated region.

This is a port of androidx.compose.foundation.text.input.TextFieldDecorator.

Operational Semantics:

  • The Decoration function receives an innerTextField callback that renders the actual text editing surface.
  • The innerTextField MUST be called exactly once within Decoration.
  • Calling innerTextField zero times or more than once is an error.
  • The decorator controls the layout and positioning of the inner text field relative to decorations.
  • Touch events on any part of the decorated area will focus the text field.

Example usage (pseudo-code):

decorator := func(innerTextField func()) {
    // Render leading icon
    renderIcon()
    // Render the actual text field
    innerTextField()
    // Render trailing icon
    renderClearButton()
}
var NoDecorationDecorator TextFieldDecorator = TextFieldDecoratorFunc(func(innerTextField Composable) Composable {
	return innerTextField
})

NoDecorationDecorator renders only the inner text field with no decorations.

type TextFieldDecoratorFunc

type TextFieldDecoratorFunc func(innerTextField Composable) Composable

TextFieldDecoratorFunc is a function type that implements TextFieldDecorator.

func (TextFieldDecoratorFunc) Decoration

func (f TextFieldDecoratorFunc) Decoration(innerTextField Composable) Composable

Decoration implements TextFieldDecorator.

type TextFieldLineLimits

type TextFieldLineLimits interface {
	// contains filtered or unexported methods
}

TextFieldLineLimits specifies text wrapping and height behavior.

This is a port of androidx.compose.foundation.text.input.TextFieldLineLimits.

var TextFieldLineLimitsDefault TextFieldLineLimits = NewMultiLine()

TextFieldLineLimitsDefault is the default line limits (multi-line with no restrictions).

var TextFieldLineLimitsSingleLine TextFieldLineLimits = SingleLine{}

TextFieldLineLimitsSingleLine is a convenience constant for single-line fields.

type TextFieldState

type TextFieldState struct {
	// contains filtered or unexported fields
}

TextFieldState is the editable text state for a text field.

This is the main state holder that manages:

  • Current text content
  • Cursor/selection position
  • Composition (IME input in progress)
  • Undo/redo history

Use Edit() to make atomic changes to the text. The edit block receives a TextFieldBuffer that can be modified. After the block returns, changes are committed and undo history is updated.

This is a port of androidx.compose.foundation.text.input.TextFieldState.

func NewTextFieldState

func NewTextFieldState(initialText string) *TextFieldState

NewTextFieldState creates a new TextFieldState with the given initial text. The cursor is placed at the end of the text.

func NewTextFieldStateWithSelection

func NewTextFieldStateWithSelection(initialText string, initialSelection text.TextRange) *TextFieldState

NewTextFieldStateWithSelection creates a TextFieldState with specified text and selection.

func (*TextFieldState) ClearText

func (s *TextFieldState) ClearText()

ClearText removes all text from the field.

func (*TextFieldState) Composition

func (s *TextFieldState) Composition() *text.TextRange

Composition returns the current IME composition range. Returns nil when there is no active composition.

func (*TextFieldState) Edit

func (s *TextFieldState) Edit(block func(*TextFieldBuffer))

Edit performs an atomic edit operation.

The provided block receives a TextFieldBuffer that reflects the current state. Any changes made to the buffer are committed when the block returns. Changes are recorded in the undo history.

Example:

state.Edit(func(buffer *TextFieldBuffer) {
    buffer.Append("Hello")
    buffer.PlaceCursorAtEnd()
})

func (*TextFieldState) IsEmpty

func (s *TextFieldState) IsEmpty() bool

IsEmpty returns true if the text field is empty.

func (*TextFieldState) Length

func (s *TextFieldState) Length() int

Length returns the length of the current text.

func (*TextFieldState) PlaceCursorAtEnd

func (s *TextFieldState) PlaceCursorAtEnd()

PlaceCursorAtEnd moves the cursor to the end of the text.

func (*TextFieldState) SelectAll

func (s *TextFieldState) SelectAll()

SelectAll selects all text in the field.

func (*TextFieldState) Selection

func (s *TextFieldState) Selection() text.TextRange

Selection returns the current selection range. If collapsed, this is the cursor position.

func (*TextFieldState) SetTextAndPlaceCursorAtEnd

func (s *TextFieldState) SetTextAndPlaceCursorAtEnd(newText string)

SetTextAndPlaceCursorAtEnd replaces all text and places the cursor at the end.

This is a convenience method equivalent to:

state.Edit(func(buffer *TextFieldBuffer) {
    buffer.Replace(0, buffer.Length(), newText)
    buffer.PlaceCursorAtEnd()
})

func (*TextFieldState) SetTextAndSelectAll

func (s *TextFieldState) SetTextAndSelectAll(newText string)

SetTextAndSelectAll replaces all text and selects it.

func (*TextFieldState) Text

func (s *TextFieldState) Text() string

Text returns the current text content.

func (*TextFieldState) Value

Value returns the current immutable snapshot of the text field contents.

type TextHighlight

type TextHighlight struct {
	Type  TextHighlightType
	Range text.TextRange
}

TextHighlight represents a highlighted range of text. This may be used to display handwriting gesture previews from the IME.

type TextHighlightType

type TextHighlightType int

TextHighlightType defines highlight styles for IME handwriting gestures. Used to visually preview gestures before they're committed.

This is a port of androidx.compose.foundation.text.input.TextHighlightType.

const (
	// TextHighlightTypeHandwritingSelectPreview previews text that would be selected
	// by an ongoing stylus handwriting select gesture.
	TextHighlightTypeHandwritingSelectPreview TextHighlightType = iota

	// TextHighlightTypeHandwritingDeletePreview previews text that would be deleted
	// by an ongoing stylus handwriting delete gesture.
	TextHighlightTypeHandwritingDeletePreview
)

func (TextHighlightType) String

func (t TextHighlightType) String() string

String returns a string representation of the TextHighlightType.

type TextLayoutController

type TextLayoutController struct {
	// contains filtered or unexported fields
}

TextLayoutController manages text layout state and bridges between Compose input APIs and Gio widget rendering.

It wraps a widget.TextView internally and provides a higher-level API for BasicText and BasicTextField composables.

func NewTextLayoutController

func NewTextLayoutController(source *TextSourceAdapter) *TextLayoutController

NewTextLayoutController creates a new TextLayoutController.

func (*TextLayoutController) ConfigureFromTextStyle

func (c *TextLayoutController) ConfigureFromTextStyle(ts *text.TextStyle)

ConfigureFromTextStyle applies settings from a TextStyle.

func (*TextLayoutController) GetFont

func (c *TextLayoutController) GetFont() font.Font

GetFont returns a Gio font from the current text style.

func (*TextLayoutController) GetFontSize

func (c *TextLayoutController) GetFontSize() unit.TextUnit

GetFontSize returns the font size in Sp.

func (*TextLayoutController) Layout

func (c *TextLayoutController) Layout(gtx layout.Context, shaper *gioText.Shaper, gioFont font.Font, size gioUnit.Sp) layout.Dimensions

Layout performs text layout and returns dimensions.

func (*TextLayoutController) LayoutAndPaint

func (c *TextLayoutController) LayoutAndPaint(gtx layout.Context, shaper *gioText.Shaper, textMaterial gioOp.CallOp) layout.Dimensions

LayoutAndPaint performs layout and paints the text in one call. This is the main entry point for rendering text.

func (*TextLayoutController) Len

func (c *TextLayoutController) Len() int

Len returns the length of the text in runes.

func (*TextLayoutController) PaintText

func (c *TextLayoutController) PaintText(gtx layout.Context, textMaterial gioOp.CallOp)

PaintText clips and paints the text glyphs using the provided material.

func (*TextLayoutController) Selection

func (c *TextLayoutController) Selection() (start, end int)

Selection returns the current selection range in runes.

func (*TextLayoutController) SetAlignment

func (c *TextLayoutController) SetAlignment(alignment style.TextAlign)

SetAlignment sets text alignment.

func (*TextLayoutController) SetCaret

func (c *TextLayoutController) SetCaret(start, end int)

SetCaret sets the caret position and selection.

func (*TextLayoutController) SetLineHeight

func (c *TextLayoutController) SetLineHeight(lineHeight gioUnit.Sp)

SetLineHeight sets the line height.

func (*TextLayoutController) SetLineHeightScale

func (c *TextLayoutController) SetLineHeightScale(scale float32)

SetLineHeightScale sets the line height scale.

func (*TextLayoutController) SetMaxLines

func (c *TextLayoutController) SetMaxLines(maxLines int)

SetMaxLines sets the maximum number of lines.

func (*TextLayoutController) SetMinLines

func (c *TextLayoutController) SetMinLines(minLines int)

SetMinLines sets the minimum number of lines.

func (*TextLayoutController) SetSingleLine

func (c *TextLayoutController) SetSingleLine(singleLine bool)

SetSingleLine enables or disables single line mode.

func (*TextLayoutController) SetSoftWrap

func (c *TextLayoutController) SetSoftWrap(softWrap bool)

SetSoftWrap enables or disables soft wrapping.

func (*TextLayoutController) SetTextStyle

func (c *TextLayoutController) SetTextStyle(textStyle *text.TextStyle)

SetTextStyle configures the text style.

func (*TextLayoutController) SetTruncator

func (c *TextLayoutController) SetTruncator(truncator string)

SetTruncator sets the truncation string.

func (*TextLayoutController) SetWrapPolicy

func (c *TextLayoutController) SetWrapPolicy(wrapPolicy gioText.WrapPolicy)

SetWrapPolicy sets the line wrap policy.

func (*TextLayoutController) Source

Source returns the text source adapter.

func (*TextLayoutController) TextView

func (c *TextLayoutController) TextView() *widget.TextView

TextView returns the underlying widget.TextView for advanced use cases.

func (*TextLayoutController) Truncated

func (c *TextLayoutController) Truncated() bool

Truncated returns whether the text is truncated.

type TextSourceAdapter

type TextSourceAdapter struct {
	// contains filtered or unexported fields
}

TextSourceAdapter adapts TextFieldCharSequence to implement the TextSource interface from the widget package for text rendering. This is the bridge between Compose-style text state management and Gio-based text rendering.

TextSourceAdapter can be used in two modes:

  • Read-only mode (from AnnotatedString): for BasicText
  • Editable mode (from TextFieldState): for BasicTextField

func NewTextSourceAdapterFromState

func NewTextSourceAdapterFromState(state *TextFieldState) *TextSourceAdapter

NewTextSourceAdapterFromState creates an editable TextSourceAdapter from a TextFieldState. This is suitable for use with BasicTextField.

func NewTextSourceAdapterFromString

func NewTextSourceAdapterFromString(text string) *TextSourceAdapter

NewTextSourceAdapterFromString creates a read-only TextSourceAdapter from a string. This is suitable for use with BasicText.

func (*TextSourceAdapter) Changed

func (a *TextSourceAdapter) Changed() bool

Changed returns whether the contents have changed since the last call to Changed.

func (*TextSourceAdapter) IsEditable

func (a *TextSourceAdapter) IsEditable() bool

IsEditable returns true if this adapter is backed by a TextFieldState.

func (*TextSourceAdapter) ReadAt

func (a *TextSourceAdapter) ReadAt(p []byte, off int64) (int, error)

ReadAt reads len(p) bytes into p starting at byte offset off. It implements io.ReaderAt.

func (*TextSourceAdapter) ReplaceRunes

func (a *TextSourceAdapter) ReplaceRunes(byteOffset int64, runeCount int64, replacement string)

ReplaceRunes replaces runeCount runes starting at byteOffset within the data with the provided string. For read-only adapters, this is a no-op. For editable adapters, this forwards to the TextFieldState.

func (*TextSourceAdapter) SetText

func (a *TextSourceAdapter) SetText(text string)

SetText updates the text content for read-only adapters. For editable adapters, use the TextFieldState directly.

func (*TextSourceAdapter) Size

func (a *TextSourceAdapter) Size() int64

Size returns the total length of the text data in bytes.

func (*TextSourceAdapter) State

func (a *TextSourceAdapter) State() *TextFieldState

State returns the underlying TextFieldState, or nil for read-only adapters.

func (*TextSourceAdapter) Text

func (a *TextSourceAdapter) Text() string

Text returns the current text content.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL