Documentation
¶
Overview ¶
Package modifiers provides text modifier implementations for foundation text components.
This package contains the selection controller and related types for handling text selection in compose text components.
Index ¶
- type LayoutCoordinates
- type MouseSelectionObserver
- type MultiWidgetSelectionDelegate
- func (d *MultiWidgetSelectionDelegate) AppendSelectableInfoToBuilder(builder selection.SelectionLayoutBuilder)
- func (d *MultiWidgetSelectionDelegate) GetBoundingBox(offset int) geometry.Rect
- func (d *MultiWidgetSelectionDelegate) GetCenterYForOffset(offset int) float32
- func (d *MultiWidgetSelectionDelegate) GetHandlePosition(sel selection.Selection, isStartHandle bool) geometry.Offset
- func (d *MultiWidgetSelectionDelegate) GetLastVisibleOffset() int
- func (d *MultiWidgetSelectionDelegate) GetLayoutCoordinates() layout.LayoutCoordinates
- func (d *MultiWidgetSelectionDelegate) GetLineHeight(offset int) float32
- func (d *MultiWidgetSelectionDelegate) GetLineLeft(offset int) float32
- func (d *MultiWidgetSelectionDelegate) GetLineRight(offset int) float32
- func (d *MultiWidgetSelectionDelegate) GetRangeOfLineContaining(offset int) text.TextRange
- func (d *MultiWidgetSelectionDelegate) GetSelectAllSelection() *selection.Selection
- func (d *MultiWidgetSelectionDelegate) GetText() text.AnnotatedString
- func (d *MultiWidgetSelectionDelegate) SelectableId() int64
- func (d *MultiWidgetSelectionDelegate) TextLayoutResult() *text.TextLayoutResult
- type RememberObserver
- type Selectable
- type Selection
- type SelectionAdjustment
- type SelectionController
- func (sc *SelectionController) BackgroundSelectionColor() graphics.Color
- func (sc *SelectionController) Draw(drawPath func(path graphics.Path, color graphics.Color, shouldClip bool))
- func (sc *SelectionController) Modifier() ui.Modifier
- func (sc *SelectionController) OnAbandoned()
- func (sc *SelectionController) OnForgotten()
- func (sc *SelectionController) OnRemembered()
- func (sc *SelectionController) SelectableId() int64
- func (sc *SelectionController) UpdateGlobalPosition(coordinates LayoutCoordinates)
- func (sc *SelectionController) UpdateTextLayout(textLayoutResult *text.TextLayoutResult)
- type SelectionRegistrar
- type SelectionRegistrarExtended
- type StaticTextSelectionParams
- func (p StaticTextSelectionParams) Copy(layoutCoordinates LayoutCoordinates, textLayoutResult *text.TextLayoutResult) StaticTextSelectionParams
- func (p StaticTextSelectionParams) CopyWithLayoutCoordinates(layoutCoordinates LayoutCoordinates) StaticTextSelectionParams
- func (p StaticTextSelectionParams) CopyWithTextLayoutResult(textLayoutResult *text.TextLayoutResult) StaticTextSelectionParams
- func (p StaticTextSelectionParams) GetPathForRange(start, end int) graphics.Path
- func (p StaticTextSelectionParams) LayoutCoordinatesValue() LayoutCoordinates
- func (p StaticTextSelectionParams) ShouldClip() bool
- func (p StaticTextSelectionParams) TextLayoutResultValue() *text.TextLayoutResult
- type TextDragObserver
- type TextSubstitutionValue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LayoutCoordinates ¶
type LayoutCoordinates = layout.LayoutCoordinates
LayoutCoordinates provides access to layout coordinates for a composable. Use layout.LayoutCoordinates for new code.
type MouseSelectionObserver ¶
type MouseSelectionObserver interface {
// OnExtend is called when the selection should be extended to the given position.
// Returns true if the extension was successful.
OnExtend(downPosition geometry.Offset) bool
// OnExtendDrag is called during a drag to extend the selection.
// Returns true if the drag should continue.
OnExtendDrag(dragPosition geometry.Offset) bool
// OnStart is called when a mouse selection gesture starts.
// The adjustment determines how the selection should be adjusted (e.g., word on double-click).
// The clickCount indicates single, double, or triple click.
// Returns true if the selection was started successfully.
OnStart(downPosition geometry.Offset, adjustment SelectionAdjustment, clickCount int) bool
// OnDrag is called during a mouse drag gesture.
// The adjustment determines how the selection should be adjusted.
// Returns true if the drag should continue.
OnDrag(dragPosition geometry.Offset, adjustment SelectionAdjustment) bool
// OnDragDone is called when the mouse drag gesture ends.
OnDragDone()
}
MouseSelectionObserver observes mouse selection gestures. This is used for click-and-drag selection with a mouse.
type MultiWidgetSelectionDelegate ¶
type MultiWidgetSelectionDelegate struct {
// CoordinatesCallback returns the current layout coordinates.
CoordinatesCallback func() layout.LayoutCoordinates
// LayoutResultCallback returns the current text layout result.
LayoutResultCallback func() *text.TextLayoutResult
// contains filtered or unexported fields
}
MultiWidgetSelectionDelegate is a selection delegate that coordinates selection across multiple text widgets. It implements the Selectable interface.
func NewMultiWidgetSelectionDelegate ¶
func NewMultiWidgetSelectionDelegate( selectableId int64, coordinatesCallback func() layout.LayoutCoordinates, layoutResultCallback func() *text.TextLayoutResult, ) *MultiWidgetSelectionDelegate
NewMultiWidgetSelectionDelegate creates a new MultiWidgetSelectionDelegate.
func (*MultiWidgetSelectionDelegate) AppendSelectableInfoToBuilder ¶
func (d *MultiWidgetSelectionDelegate) AppendSelectableInfoToBuilder(builder selection.SelectionLayoutBuilder)
AppendSelectableInfoToBuilder implements Selectable.AppendSelectableInfoToBuilder.
func (*MultiWidgetSelectionDelegate) GetBoundingBox ¶
func (d *MultiWidgetSelectionDelegate) GetBoundingBox(offset int) geometry.Rect
GetBoundingBox implements Selectable.GetBoundingBox.
func (*MultiWidgetSelectionDelegate) GetCenterYForOffset ¶
func (d *MultiWidgetSelectionDelegate) GetCenterYForOffset(offset int) float32
GetCenterYForOffset implements Selectable.GetCenterYForOffset.
func (*MultiWidgetSelectionDelegate) GetHandlePosition ¶
func (d *MultiWidgetSelectionDelegate) GetHandlePosition(sel selection.Selection, isStartHandle bool) geometry.Offset
GetHandlePosition implements Selectable.GetHandlePosition.
func (*MultiWidgetSelectionDelegate) GetLastVisibleOffset ¶
func (d *MultiWidgetSelectionDelegate) GetLastVisibleOffset() int
GetLastVisibleOffset implements Selectable.GetLastVisibleOffset.
func (*MultiWidgetSelectionDelegate) GetLayoutCoordinates ¶
func (d *MultiWidgetSelectionDelegate) GetLayoutCoordinates() layout.LayoutCoordinates
GetLayoutCoordinates implements Selectable.GetLayoutCoordinates.
func (*MultiWidgetSelectionDelegate) GetLineHeight ¶
func (d *MultiWidgetSelectionDelegate) GetLineHeight(offset int) float32
GetLineHeight implements Selectable.GetLineHeight.
func (*MultiWidgetSelectionDelegate) GetLineLeft ¶
func (d *MultiWidgetSelectionDelegate) GetLineLeft(offset int) float32
GetLineLeft implements Selectable.GetLineLeft.
func (*MultiWidgetSelectionDelegate) GetLineRight ¶
func (d *MultiWidgetSelectionDelegate) GetLineRight(offset int) float32
GetLineRight implements Selectable.GetLineRight.
func (*MultiWidgetSelectionDelegate) GetRangeOfLineContaining ¶
func (d *MultiWidgetSelectionDelegate) GetRangeOfLineContaining(offset int) text.TextRange
GetRangeOfLineContaining implements Selectable.GetRangeOfLineContaining.
func (*MultiWidgetSelectionDelegate) GetSelectAllSelection ¶
func (d *MultiWidgetSelectionDelegate) GetSelectAllSelection() *selection.Selection
GetSelectAllSelection implements Selectable.GetSelectAllSelection.
func (*MultiWidgetSelectionDelegate) GetText ¶
func (d *MultiWidgetSelectionDelegate) GetText() text.AnnotatedString
GetText implements Selectable.GetText.
func (*MultiWidgetSelectionDelegate) SelectableId ¶
func (d *MultiWidgetSelectionDelegate) SelectableId() int64
SelectableId implements Selectable.SelectableId.
func (*MultiWidgetSelectionDelegate) TextLayoutResult ¶
func (d *MultiWidgetSelectionDelegate) TextLayoutResult() *text.TextLayoutResult
TextLayoutResult implements Selectable.TextLayoutResult.
type RememberObserver ¶
type RememberObserver interface {
// OnRemembered is called when the object is successfully stored by remember.
OnRemembered()
// OnForgotten is called when the object is no longer being remembered.
OnForgotten()
// OnAbandoned is called when the remember call was not committed to the composition.
OnAbandoned()
}
RememberObserver is an interface for objects that need lifecycle callbacks when remembered in composition.
type Selectable ¶
type Selectable = selection.Selectable
Selectable is an alias to the selection package's Selectable. Use selection.Selectable for new code.
type Selection ¶
Selection is an alias to the selection package's Selection. Use selection.Selection for new code.
type SelectionAdjustment ¶
type SelectionAdjustment int
SelectionAdjustment determines how selection should be adjusted during gestures.
const ( // SelectionAdjustmentNone means no adjustment to selection. SelectionAdjustmentNone SelectionAdjustment = iota // SelectionAdjustmentCharacter adjusts selection to character boundaries. SelectionAdjustmentCharacter // SelectionAdjustmentWord adjusts selection to word boundaries. SelectionAdjustmentWord // SelectionAdjustmentParagraph adjusts selection to paragraph boundaries. SelectionAdjustmentParagraph )
func (SelectionAdjustment) String ¶
func (s SelectionAdjustment) String() string
String returns the string representation of SelectionAdjustment.
type SelectionController ¶
type SelectionController struct {
// contains filtered or unexported fields
}
SelectionController manages text selection for a text composable. It handles registration with the selection system, updates on text/position changes, and drawing of selection highlights.
This is essentially a Modifier.Node moved into remember because we need pointerInput.
func NewSelectionController ¶
func NewSelectionController( selectableId int64, selectionRegistrar SelectionRegistrar, backgroundSelectionColor graphics.Color, ) *SelectionController
NewSelectionController creates a new SelectionController.
func (*SelectionController) BackgroundSelectionColor ¶
func (sc *SelectionController) BackgroundSelectionColor() graphics.Color
BackgroundSelectionColor returns the background color used for selection highlights.
func (*SelectionController) Draw ¶
func (sc *SelectionController) Draw(drawPath func(path graphics.Path, color graphics.Color, shouldClip bool))
Draw draws the selection highlight using the provided draw function. The drawPath function is called with the selection path and background color.
This is a simplified version that takes a draw function instead of DrawScope, as DrawScope depends on platform-specific graphics systems.
func (*SelectionController) Modifier ¶
func (sc *SelectionController) Modifier() ui.Modifier
Modifier returns the modifier for this selection controller. This modifier should be applied to the text composable to enable selection.
func (*SelectionController) OnAbandoned ¶
func (sc *SelectionController) OnAbandoned()
OnAbandoned is called when the remember was abandoned before being committed. It unsubscribes from the selection registrar.
func (*SelectionController) OnForgotten ¶
func (sc *SelectionController) OnForgotten()
OnForgotten is called when the controller is no longer remembered. It unsubscribes from the selection registrar.
func (*SelectionController) OnRemembered ¶
func (sc *SelectionController) OnRemembered()
OnRemembered is called when the controller is remembered in composition. It subscribes to the selection registrar.
func (*SelectionController) SelectableId ¶
func (sc *SelectionController) SelectableId() int64
SelectableId returns the unique identifier for this selectable.
func (*SelectionController) UpdateGlobalPosition ¶
func (sc *SelectionController) UpdateGlobalPosition(coordinates LayoutCoordinates)
UpdateGlobalPosition updates the layout coordinates and notifies the selection registrar.
func (*SelectionController) UpdateTextLayout ¶
func (sc *SelectionController) UpdateTextLayout(textLayoutResult *text.TextLayoutResult)
UpdateTextLayout updates the text layout result. If the text content has changed, it notifies the selection registrar.
type SelectionRegistrar ¶
type SelectionRegistrar = selection.SelectionRegistrar
SelectionRegistrar is an alias to the selection package's SelectionRegistrar. Use selection.SelectionRegistrar for new code.
type SelectionRegistrarExtended ¶
type SelectionRegistrarExtended interface {
SelectionRegistrar
// HasSelection returns true if there is an active selection for the given selectableId.
HasSelection(selectableId int64) bool
// MakeSelectionModifier creates a modifier for handling selection gestures.
// This is platform-specific and may return different implementations on different platforms.
MakeSelectionModifier(
selectableId int64,
layoutCoordinates func() LayoutCoordinates,
) interface{} // Returns Modifier, but typed as interface{} to avoid circular dependencies
}
SelectionRegistrarExtended extends SelectionRegistrar with methods needed for the default selection modifier implementation.
Note: NotifySelectionUpdateStart, NotifySelectionUpdate, and NotifySelectionUpdateEnd are inherited from the embedded SelectionRegistrar interface.
type StaticTextSelectionParams ¶
type StaticTextSelectionParams struct {
// contains filtered or unexported fields
}
StaticTextSelectionParams holds the parameters needed for static text selection. This is used to track layout coordinates and text layout results for selection handling.
func EmptyStaticTextSelectionParams ¶
func EmptyStaticTextSelectionParams() StaticTextSelectionParams
EmptyStaticTextSelectionParams returns an empty StaticTextSelectionParams instance.
func NewStaticTextSelectionParams ¶
func NewStaticTextSelectionParams( layoutCoordinates LayoutCoordinates, textLayoutResult *text.TextLayoutResult, ) StaticTextSelectionParams
NewStaticTextSelectionParams creates a new StaticTextSelectionParams.
func (StaticTextSelectionParams) Copy ¶
func (p StaticTextSelectionParams) Copy( layoutCoordinates LayoutCoordinates, textLayoutResult *text.TextLayoutResult, ) StaticTextSelectionParams
Copy creates a copy of StaticTextSelectionParams with optional overrides.
func (StaticTextSelectionParams) CopyWithLayoutCoordinates ¶
func (p StaticTextSelectionParams) CopyWithLayoutCoordinates(layoutCoordinates LayoutCoordinates) StaticTextSelectionParams
CopyWithLayoutCoordinates creates a copy with updated layout coordinates.
func (StaticTextSelectionParams) CopyWithTextLayoutResult ¶
func (p StaticTextSelectionParams) CopyWithTextLayoutResult(textLayoutResult *text.TextLayoutResult) StaticTextSelectionParams
CopyWithTextLayoutResult creates a copy with updated text layout result.
func (StaticTextSelectionParams) GetPathForRange ¶
func (p StaticTextSelectionParams) GetPathForRange(start, end int) graphics.Path
GetPathForRange returns the path for the given text range, or nil if not available.
func (StaticTextSelectionParams) LayoutCoordinatesValue ¶
func (p StaticTextSelectionParams) LayoutCoordinatesValue() LayoutCoordinates
LayoutCoordinatesValue returns the layout coordinates.
func (StaticTextSelectionParams) ShouldClip ¶
func (p StaticTextSelectionParams) ShouldClip() bool
ShouldClip returns true if the selection should be clipped to the layout bounds. This is true when the text has visual overflow and the overflow mode is not Visible.
func (StaticTextSelectionParams) TextLayoutResultValue ¶
func (p StaticTextSelectionParams) TextLayoutResultValue() *text.TextLayoutResult
TextLayoutResultValue returns the text layout result.
type TextDragObserver ¶
type TextDragObserver interface {
// OnDown is called when the pointer first touches down.
// Not supported for long-press-drag selection.
OnDown(point geometry.Offset)
// OnUp is called when the pointer is released.
OnUp()
// OnStart is called when a drag gesture starts (after long-press is detected).
// The selectionAdjustment determines how the selection should be adjusted.
OnStart(startPoint geometry.Offset, selectionAdjustment SelectionAdjustment)
// OnDrag is called during a drag gesture with the delta from the previous position.
OnDrag(delta geometry.Offset)
// OnStop is called when the drag gesture ends normally.
OnStop()
// OnCancel is called when the drag gesture is cancelled.
OnCancel()
}
TextDragObserver observes text drag gestures for selection. This is used for long-press-drag selection on touch devices.
type TextSubstitutionValue ¶
type TextSubstitutionValue struct {
Original text.AnnotatedString
Substitution text.AnnotatedString
IsShowingSubstitution bool
}