Documentation
¶
Index ¶
- type ChangeEvent
- type Editor
- func (e *Editor) CaretCoords() f32.Point
- func (e *Editor) CaretPos() (line, col int)
- func (e *Editor) ClearSelection()
- func (e *Editor) Delete(graphemeClusters int) (deletedRunes int)
- func (e *Editor) Insert(s string) (insertedRunes int)
- func (e *Editor) Layout(gtx layout.Context, lt *text.Shaper) layout.Dimensions
- func (e *Editor) Len() int
- func (e *Editor) MoveCaret(startDelta, endDelta int)
- func (e *Editor) ReplaceAll(texts []TextRange, newStr string) int
- func (e *Editor) ScrollByRatio(gtx layout.Context, ratio float32)
- func (e *Editor) SelectedText() string
- func (e *Editor) Selection() (start, end int)
- func (e *Editor) SelectionLen() int
- func (e *Editor) SetCaret(start, end int)
- func (e *Editor) SetHighlights(highlights []TextRange)
- func (e *Editor) SetText(s string)
- func (e *Editor) Text() string
- func (e *Editor) Update(gtx layout.Context) (EditorEvent, bool)
- func (e *Editor) UpdateTextStyles(styles []*TextStyle)
- func (e *Editor) ViewPortRatio() (float32, float32)
- type EditorEvent
- type Region
- type SelectEvent
- type TextRange
- type TextStyle
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChangeEvent ¶ added in v0.0.2
type ChangeEvent struct{}
A ChangeEvent is generated for every user change to the text.
type Editor ¶ added in v0.0.2
type Editor struct {
// Font set the font used to draw the text.
Font font.Font
// TextSize set the size of both the main text and line number.
TextSize unit.Sp
// Alignment controls the alignment of text within the editor.
Alignment text.Alignment
// LineHeight determines the gap between baselines of text. If zero, a sensible
// default will be used.
LineHeight unit.Sp
// LineHeightScale is multiplied by LineHeight to determine the final gap
// between baselines. If zero, a sensible default will be used.
LineHeightScale float32
// WrapLine configures whether the displayed text will be broken into lines or not.
WrapLine bool
// ReadOnly controls whether the contents of the editor can be altered by
// user interaction. If set to true, the editor will allow selecting text
// and copying it interactively, but not modifying it.
ReadOnly bool
// InputHint specifies the type of on-screen keyboard to be displayed.
InputHint key.InputHint
// SoftTab controls the behaviour when user try to insert a Tab character.
// If set to true, the editor will insert the amount of space characters specified by
// TabWidth, else the editor insert a \t character.
SoftTab bool
// TabWidth set how many spaces to represent a tab character. In the case of
// soft tab, this determines the number of space characters to insert into the editor.
// While for hard tab, this controls the maximum width of the 'tab' glyph to expand to.
TabWidth int
// LineNumberGutter specifies the gap between the line number and the main text.
LineNumberGutter unit.Dp
// Color used to paint text
TextMaterial op.CallOp
// Color used to highlight the selections.
SelectMaterial op.CallOp
// Color used to highlight the current paragraph.
LineMaterial op.CallOp
// Color used to paint the line number
LineNumberMaterial op.CallOp
// Color used to highlight the text snippets, such as search matches.
TextHighlightMaterial op.CallOp
// WordSeperators configures a set of characters that will be used as word separators
// when doing word related operations, like navigating or deleting by word.
WordSeperators string
// contains filtered or unexported fields
}
Editor implements an editable and scrollable text area.
func (*Editor) CaretCoords ¶ added in v0.0.2
CaretCoords returns the coordinates of the caret, relative to the editor itself.
func (*Editor) ClearSelection ¶ added in v0.0.2
func (e *Editor) ClearSelection()
ClearSelection clears the selection, by setting the selection end equal to the selection start.
func (*Editor) Delete ¶ added in v0.0.2
Delete runes from the caret position. The sign of the argument specifies the direction to delete: positive is forward, negative is backward.
If there is a selection, it is deleted and counts as a single grapheme cluster.
func (*Editor) MoveCaret ¶ added in v0.0.2
MoveCaret moves the caret (aka selection start) and the selection end relative to their current positions. Positive distances moves forward, negative distances moves backward. Distances are in grapheme clusters, which closely match what users perceive as "characters" even when the characters are multiple code points long.
func (*Editor) ReplaceAll ¶ added in v0.0.2
ReplaceAll replaces all texts specifed in TextRange with newStr. It returns the number of occurrences replaced.
func (*Editor) ScrollByRatio ¶ added in v0.0.2
func (*Editor) SelectedText ¶ added in v0.0.2
SelectedText returns the currently selected text (if any) from the editor.
func (*Editor) Selection ¶ added in v0.0.2
Selection returns the start and end of the selection, as rune offsets. start can be > end.
func (*Editor) SelectionLen ¶ added in v0.0.2
SelectionLen returns the length of the selection, in runes; it is equivalent to utf8.RuneCountInString(e.SelectedText()).
func (*Editor) SetCaret ¶ added in v0.0.2
SetCaret moves the caret to start, and sets the selection end to end. start and end are in runes, and represent offsets into the editor text.
func (*Editor) SetHighlights ¶ added in v0.0.2
SetHighlights sets the texts to be highlighted.
func (*Editor) Update ¶ added in v0.0.2
func (e *Editor) Update(gtx layout.Context) (EditorEvent, bool)
Update the state of the editor in response to input events. Update consumes editor input events until there are no remaining events or an editor event is generated. To fully update the state of the editor, callers should call Update until it returns false.
func (*Editor) UpdateTextStyles ¶ added in v0.0.2
func (*Editor) ViewPortRatio ¶ added in v0.0.2
returns start and end offset ratio of viewport
type EditorEvent ¶ added in v0.0.2
type EditorEvent interface {
// contains filtered or unexported methods
}
type Region ¶ added in v0.0.2
type Region struct {
// Bounds is the coordinates of the bounding box relative to the containing
// widget.
Bounds image.Rectangle
// Baseline is the quantity of vertical pixels between the baseline and
// the bottom of bounds.
Baseline int
}
Region describes the position and baseline of an area of interest within shaped text.
type SelectEvent ¶ added in v0.0.2
type SelectEvent struct{}
A SelectEvent is generated when the user selects some text, or changes the selection (e.g. with a shift-click), including if they remove the selection. The selected text is not part of the event, on the theory that it could be a relatively expensive operation (for a large editor), most applications won't actually care about it, and those that do can call Editor.SelectedText() (which can be empty).