Documentation
¶
Index ¶
- type Region
- type SelectionAction
- type TextView
- func (e *TextView) AddDecorations(styles ...decoration.Decoration) error
- func (e *TextView) ByteOffset(runeOffset int) int64
- func (e *TextView) CaretCoords() f32.Point
- func (e *TextView) CaretInfo() (pos image.Point, ascent, descent int)
- func (e *TextView) CaretPos() (line, col int)
- func (e *TextView) Changed() bool
- func (e *TextView) ClearDecorations(source string) error
- func (e *TextView) ClearSelection()
- func (e *TextView) ConvertPos(line, col int) int
- func (e *TextView) Dimensions() layout.Dimensions
- func (e *TextView) FindParagraph(runeIdx int) (int, lt.Paragraph)
- func (e *TextView) FullDimensions() layout.Dimensions
- func (e *TextView) HighlightMatchingBrackets(gtx layout.Context, material op.CallOp)
- func (e *TextView) IndentLines(dedent bool) int
- func (e *TextView) IndentOnBreak(s string) int
- func (e *TextView) Indentation() string
- func (e *TextView) IsWordSeperator(r rune) bool
- func (e *TextView) Layout(gtx layout.Context, lt *text.Shaper)
- func (e *TextView) Len() int
- func (e *TextView) MoveCaret(startDelta, endDelta int)
- func (e *TextView) MoveCoord(pos image.Point)
- func (e *TextView) MoveLineEnd(selAct SelectionAction)
- func (e *TextView) MoveLineStart(selAct SelectionAction)
- func (e *TextView) MoveLines(distance int, selAct SelectionAction)
- func (e *TextView) MovePages(pages int, selAct SelectionAction)
- func (e *TextView) MoveTextEnd(selAct SelectionAction)
- func (e *TextView) MoveTextStart(selAct SelectionAction)
- func (e *TextView) MoveWords(distance int, selAct SelectionAction)
- func (e *TextView) NearestMatchingBrackets() (left int, right int)
- func (e *TextView) PaintCaret(gtx layout.Context, material op.CallOp)
- func (e *TextView) PaintLineHighlight(gtx layout.Context, material op.CallOp)
- func (e *TextView) PaintLineNumber(gtx layout.Context, lt *text.Shaper, material op.CallOp) layout.Dimensions
- func (e *TextView) PaintOverlay(gtx layout.Context, offset image.Point, overlay layout.Widget)
- func (e *TextView) PaintSelection(gtx layout.Context, material op.CallOp)
- func (e *TextView) PaintText(gtx layout.Context, material op.CallOp)
- func (e *TextView) Paragraphs() int
- func (e *TextView) PartialLineSelected() bool
- func (e *TextView) QueryPos(pos image.Point) (line, col int, runeOff int)
- func (e *TextView) ReadRuneAt(runeOff int) (rune, error)
- func (e *TextView) ReadUntil(direction int, seperator func(r rune) bool) string
- func (e *TextView) ReadWord(bySpace bool) (string, int)
- func (e *TextView) Redo() ([]buffer.CursorPos, bool)
- func (e *TextView) Regions(start, end int, regions []Region) []Region
- func (e *TextView) Replace(start, end int, s string) int
- func (e *TextView) RuneCoords(runeIdx int) f32.Point
- func (e *TextView) ScrollBounds() image.Rectangle
- func (e *TextView) ScrollOff() image.Point
- func (e *TextView) ScrollRel(dx, dy int)
- func (e *TextView) ScrollToCaret()
- func (e *TextView) SelectedLineRange() (start, end int)
- func (e *TextView) SelectedLineText(buf []byte) ([]byte, int, int)
- func (e *TextView) SelectedText(buf []byte) []byte
- func (e *TextView) Selection() (start, end int)
- func (e *TextView) SelectionLen() int
- func (e *TextView) SetCaret(start, end int)
- func (e *TextView) SetColorScheme(scheme *syntax.ColorScheme)
- func (e *TextView) SetSyntaxTokens(tokens ...syntax.Token)
- func (e *TextView) SetText(s string) int
- func (e *TextView) SetWrapLine(enabled bool)
- func (e *TextView) Source() buffer.TextSource
- func (e *TextView) Undo() ([]buffer.CursorPos, bool)
- type TextViewSplitter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SelectionAction ¶
type SelectionAction int
const ( SelectionExtend SelectionAction = iota SelectionClear )
type TextView ¶
type TextView 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 controls the distance between the baselines of lines of text.
// If zero, the font size will be used.
LineHeight unit.Sp
// LineHeightScale applies a scaling factor to the LineHeight. If zero, a default
// value 1.2 will be used.
LineHeightScale float32
// CaretWidth set the visual width of a caret.
CaretWidth unit.Dp
// 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
// WrapLine configures whether the displayed text will be broken into lines or not.
WrapLine bool
// 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
// Brackets and quote pairs that can be auto-completed when the left half is entered.
BracketsQuotes *bracketsQuotes
// contains filtered or unexported fields
}
TextView provides efficient shaping and indexing of interactive text. When provided with a TextSource, TextView will shape and cache the runes within that source. It provides methods for configuring a viewport onto the shaped text which can be scrolled, and for configuring and drawing text selection boxes.
func NewTextView ¶
func NewTextView() *TextView
func (*TextView) AddDecorations ¶
func (e *TextView) AddDecorations(styles ...decoration.Decoration) error
func (*TextView) ByteOffset ¶
ByteOffset returns the start byte of the rune at the given rune offset.
func (*TextView) CaretCoords ¶
CaretCoords returns the coordinates of the caret, relative to the editor itself.
func (*TextView) ClearDecorations ¶
func (*TextView) ClearSelection ¶
func (e *TextView) ClearSelection()
ClearSelection clears the selection, by setting the selection end equal to the selection start.
func (*TextView) ConvertPos ¶
ConvertPos convert a line/col position to rune offset. line is counted by paragrah, and col is counted by rune.
func (*TextView) Dimensions ¶
func (e *TextView) Dimensions() layout.Dimensions
Dimensions returns the dimensions of the visible text.
func (*TextView) FindParagraph ¶
find a paragraph by rune index, returning the line number(starting from zero) and the paragraph itself.
func (*TextView) FullDimensions ¶
func (e *TextView) FullDimensions() layout.Dimensions
FullDimensions returns the dimensions of all shaped text, including text that isn't visible within the current viewport.
func (*TextView) HighlightMatchingBrackets ¶
func (*TextView) IndentLines ¶
IndentLines indent or dedent each of the selected non-empty lines with one tab(soft tab or hard tab). If there is no selection, the current line is indented or dedented.
func (*TextView) IndentOnBreak ¶
IndentOnBreak insert a line break at the the current caret position, and if there is any indentation of the previous line, it indent the new inserted line with the same size. Furthermore, if the newline if between a pair of brackets, it also insert indented lines between them.
This is mainly used as the line break handler when Enter or Return is pressed.
func (*TextView) Indentation ¶
Indentation returns the text sequence used to indent the lines(paragraphs).
func (*TextView) IsWordSeperator ¶
IsWordSeperator check r to see if it is a word seperator. A word seperator set the boundary when navigating by words, or deleting by words. TODO: does it make sence to use unicode space definition here?
func (*TextView) MoveCaret ¶
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 better match the expectations of users than runes.
func (*TextView) MoveCoord ¶
MoveCoord moves the caret to the position closest to the provided point that is aligned to a grapheme cluster boundary.
func (*TextView) MoveLineEnd ¶
func (e *TextView) MoveLineEnd(selAct SelectionAction)
MoveLineEnd moves the caret to the end of the current line, ensuring that the resulting cursor position is on a grapheme cluster boundary.
func (*TextView) MoveLineStart ¶
func (e *TextView) MoveLineStart(selAct SelectionAction)
MoveLineStart moves the caret to the start of the current line, ensuring that the resulting cursor position is on a grapheme cluster boundary.
func (*TextView) MoveLines ¶
func (e *TextView) MoveLines(distance int, selAct SelectionAction)
MaxLines moves the cursor the specified number of lines vertically, ensuring that the resulting position is aligned to a grapheme cluster.
func (*TextView) MovePages ¶
func (e *TextView) MovePages(pages int, selAct SelectionAction)
MovePages moves the caret position by vertical pages of text, ensuring that the final position is aligned to a grapheme cluster boundary.
func (*TextView) MoveTextEnd ¶
func (e *TextView) MoveTextEnd(selAct SelectionAction)
MoveTextEnd moves the caret to the end of the text.
func (*TextView) MoveTextStart ¶
func (e *TextView) MoveTextStart(selAct SelectionAction)
MoveTextStart moves the caret to the start of the text.
func (*TextView) MoveWords ¶
func (e *TextView) MoveWords(distance int, selAct SelectionAction)
MoveWord moves the caret to the next few words in the specified direction. Positive is forward, negative is backward. The final caret position will be aligned to a grapheme cluster boundary.
func (*TextView) NearestMatchingBrackets ¶
NearestMatchingBrackets finds the nearest matching brackets of the caret.
func (*TextView) PaintCaret ¶
PaintCaret clips and paints the caret rectangle, adding material immediately before painting to set the appropriate paint material.
func (*TextView) PaintLineHighlight ¶
paintLineHighlight clips and paints the visible line that the caret is in when there is no text selected.
func (*TextView) PaintLineNumber ¶
func (*TextView) PaintOverlay ¶
func (*TextView) PaintSelection ¶
PaintSelection clips and paints the visible text selection rectangles using the provided material to fill the rectangles.
func (*TextView) PaintText ¶
PaintText clips and paints the visible text glyph outlines using the provided material to fill the glyphs.
func (*TextView) Paragraphs ¶ added in v0.4.1
Paragraphs returns the total number of rendered paragraphs(or logical lines).
func (*TextView) PartialLineSelected ¶
partialLineSelected checks if the current selection is a partial single line.
func (*TextView) QueryPos ¶
QueryPos querys the line/column and rune offset of the passed position. If pos is outside of the line boundary, it returns zero line and col, and a negative runeOff.
func (*TextView) ReadRuneAt ¶
ReadRuneAt reads a rune at the rune offset runeOff. It returns an error while reading from the underlying buffer.
func (*TextView) ReadUntil ¶
ReadUntil reads in the specified direction from the current caret position until the seperator returns false. It returns the read text.
func (*TextView) ReadWord ¶
ReadWord tries to read one word nearby the caret, returning the word if there's one, and the offset of the caret in the word.
The word boundary is checked using the word boundary characters or just spaces.
func (*TextView) Replace ¶
Replace the text between start and end with s. Indices are in runes. It returns the number of runes inserted.
func (*TextView) RuneCoords ¶ added in v0.4.3
RuneCoords returns the coordinates of the rune at runeIdx, relative to the editor itself.
func (*TextView) ScrollBounds ¶
func (*TextView) ScrollToCaret ¶
func (e *TextView) ScrollToCaret()
func (*TextView) SelectedLineRange ¶
SelectedLineRange returns the start and end rune index of the paragraphs selected by the caret. If there is no selection, the range of current paragraph the caret is in is returned.
func (*TextView) SelectedLineText ¶
SelectedLine returns the text of the selected lines and the rune range. An empty selection is treated as a single line selection.
func (*TextView) SelectedText ¶
SelectedText returns the currently selected text (if any) from the editor, filling the provided byte slice if it is large enough or allocating and returning a new byte slice if the provided one is insufficient. Callers can guarantee that the buf is large enough by providing a buffer with capacity e.SelectionLen()*utf8.UTFMax.
func (*TextView) Selection ¶
Selection returns the start and end of the selection, as rune offsets. start can be > end.
func (*TextView) SelectionLen ¶
SelectionLen returns the length of the selection, in runes; it is equivalent to utf8.RuneCountInString(e.SelectedText()).
func (*TextView) SetCaret ¶
SetCaret moves the caret to start, and sets the selection end to end. Then the two ends are clamped to the nearest grapheme cluster boundary. start and end are in runes, and represent offsets into the editor text.
func (*TextView) SetColorScheme ¶
func (e *TextView) SetColorScheme(scheme *syntax.ColorScheme)
func (*TextView) SetSyntaxTokens ¶
func (*TextView) SetWrapLine ¶
func (*TextView) Source ¶
func (e *TextView) Source() buffer.TextSource
type TextViewSplitter ¶
type TextViewSplitter struct {
}