Documentation ¶
Overview ¶
source codes of this package are copied from package gioui.org/widget and modified
Index ¶
- func Disabled(c color.NRGBA) (d color.NRGBA)
- func MulAlpha(c color.NRGBA, alpha uint8) color.NRGBA
- 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, font font.Font, size unit.Sp, ...) layout.Dimensions
- func (e *Editor) Len() int
- func (e *Editor) MoveCaret(startDelta, endDelta int)
- func (e *Editor) NextMatch(index int)
- func (e *Editor) Read(p []byte) (int, error)
- func (e *Editor) Regions(start, end int, regions []Region) []Region
- func (e *Editor) ReplaceAll(newStr string) int
- func (e *Editor) ScrollByRatio(gtx layout.Context, ratio float32)
- func (e *Editor) Seek(offset int64, whence int) (int64, error)
- 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) SetMatches(matches []MatchRange)
- func (e *Editor) SetText(s string, addHistory bool)
- 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)
- func (e *Editor) VisibleLines() ([]*LineInfo, error)
- func (e *Editor) WriteTo(w io.Writer) (int64, error)
- type EditorConf
- type EditorEvent
- type EditorStyle
- type LineInfo
- type MatchRange
- type Region
- type SelectEvent
- type SubmitEvent
- type TextStyle
- Bugs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ChangeEvent ¶
type ChangeEvent struct{}
A ChangeEvent is generated for every user change to the text.
type Editor ¶
type Editor struct { // 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 // SingleLine force the text to stay on a single line. // SingleLine also sets the scrolling direction to // horizontal. SingleLine bool // Submit enabled translation of carriage return keys to SubmitEvents. // If not enabled, carriage returns are inserted as newlines in the text. Submit 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 // MaxLen limits the editor content to a maximum length. Zero means no limit. MaxLen int // Filter is the list of characters allowed in the Editor. If Filter is empty, // all characters are allowed. Filter string // WrapPolicy configures how displayed text will be broken into lines. WrapPolicy text.WrapPolicy // Keep editor focused is set to true, the editor will keep the focus. // This is useful when the editor is used with a menu. so even when menu is focused, the editor will highlight the // selected text. KeepFocus bool // contains filtered or unexported fields }
Editor implements an editable and scrollable text area.
func (*Editor) CaretCoords ¶
CaretCoords returns the coordinates of the caret, relative to the editor itself.
func (*Editor) ClearSelection ¶
func (e *Editor) ClearSelection()
ClearSelection clears the selection, by setting the selection end equal to the selection start.
func (*Editor) Delete ¶
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) Layout ¶
func (e *Editor) Layout(gtx layout.Context, lt *text.Shaper, font font.Font, size unit.Sp, textMaterial, selectMaterial op.CallOp, lineMaterial op.CallOp, matchMaterial op.CallOp) layout.Dimensions
Layout lays out the editor using the provided textMaterial as the paint material for the text glyphs+caret and the selectMaterial as the paint material for the selection rectangle.
func (*Editor) 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 closely match what users perceive as "characters" even when the characters are multiple code points long.
func (*Editor) NextMatch ¶ added in v0.8.0
NextMatch is used to switch between the [MatchRange]s. This also selects the next match and causes the selection background drawn under the matched text.
func (*Editor) ReplaceAll ¶ added in v0.8.0
ReplaceAll assumes a context of "Find & Replace". newStr applies to a list of text MatchRange, and the matched text is replaced with newStr one by one. The number of replacement is saved to be used during undo/redo. It returns the number of occurrences replaced.
func (*Editor) SelectedText ¶
SelectedText returns the currently selected text (if any) from the editor.
func (*Editor) Selection ¶
Selection returns the start and end of the selection, as rune offsets. start can be > end.
func (*Editor) SelectionLen ¶
SelectionLen returns the length of the selection, in runes; it is equivalent to utf8.RuneCountInString(e.SelectedText()).
func (*Editor) SetCaret ¶
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) SetMatches ¶ added in v0.8.0
func (e *Editor) SetMatches(matches []MatchRange)
SetMatches sets the matched text ranges after a find operation.
func (*Editor) Update ¶
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 ¶
func (*Editor) ViewPortRatio ¶
returns start and end offset ratio of viewport
func (*Editor) VisibleLines ¶ added in v0.5.0
type EditorConf ¶ added in v0.0.2
type EditorConf struct { Shaper *text.Shaper TextColor color.NRGBA Bg color.NRGBA SelectionColor color.NRGBA LineHighlightColor color.NRGBA LineNumberColor color.NRGBA TextMatchColor color.NRGBA // typeface for editing TypeFace font.Typeface TextSize unit.Sp Weight font.Weight LineHeight unit.Sp LineHeightScale float32 //May be helpful for code syntax highlighting. ColorScheme string ShowLineNum bool // padding between line number and the editor content. LineNumPadding unit.Dp }
type EditorEvent ¶
type EditorEvent interface {
// contains filtered or unexported methods
}
type EditorStyle ¶
type EditorStyle struct { Font font.Font // LineHeight controls the distance between the baselines of lines of text. // If zero, a sensible default will be used. LineHeight unit.Sp // LineHeightScale applies a scaling factor to the LineHeight. If zero, a // sensible default will be used. LineHeightScale float32 TextSize unit.Sp // Color is the text color. Color color.NRGBA // Hint contains the text displayed when the editor is empty. Hint string // HintColor is the color of hint text. HintColor color.NRGBA // SelectionColor is the color of the background for selected text. SelectionColor color.NRGBA //LineHighlightColor is the color used to highlight the clicked logical line. // If not set, line will not be highlighted. LineHighlightColor color.NRGBA // TextMatchColor use the color used to highlight the matched substring. TextMatchColor color.NRGBA Editor *Editor ShowLineNum bool // contains filtered or unexported fields }
func NewEditor ¶
func NewEditor(editor *Editor, conf *EditorConf, hint string) EditorStyle
func (EditorStyle) Layout ¶
func (e EditorStyle) Layout(gtx layout.Context) layout.Dimensions
type MatchRange ¶ added in v0.8.0
type MatchRange struct { // offset of the start rune the match. Start int // offset of the end rune the match. End int }
Matched substring range.
type Region ¶
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 ¶
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).
type SubmitEvent ¶ added in v0.5.0
type SubmitEvent struct {
Text string
}
A SubmitEvent is generated when Submit is set and a carriage return key is pressed.
Notes ¶
Bugs ¶
this method's definition of a "word" is currently whitespace-delimited. Languages that do not use whitespace to delimit words will experience counter-intuitive behavior when navigating by word.