forked from oligo/gvcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption.go
80 lines (71 loc) · 2.33 KB
/
option.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package gvcode
import (
"gioui.org/font"
"gioui.org/text"
"gioui.org/unit"
)
// EditorOption defines a function to configure the editor.
type EditorOption func(*Editor)
// WithOptions applies various options to configure the editor.
func (e *Editor) WithOptions(opts ...EditorOption) {
for _, opt := range opts {
opt(e)
}
}
// WithShaperParams set the basic shaping params for the editor.
func WithShaperParams(font font.Font, textSize unit.Sp, alignment text.Alignment, lineHeight unit.Sp, lineHeightScale float32) EditorOption {
return func(e *Editor) {
e.initBuffer()
e.text.Font = font
e.text.TextSize = textSize
e.text.Alignment = alignment
e.text.LineHeight = lineHeight
e.text.LineHeightScale = lineHeightScale
}
}
// WithTabWidth 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.
func WithTabWidth(tabWidth int) EditorOption {
return func(e *Editor) {
e.initBuffer()
e.text.TabWidth = tabWidth
}
}
// WithSoftTab 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.
func WithSoftTab(enabled bool) EditorOption {
return func(e *Editor) {
e.initBuffer()
e.text.SoftTab = enabled
}
}
// WithWordSeperators configures a set of characters that will be used as word separators
// when doing word related operations, like navigating or deleting by word.
func WithWordSeperators(seperators string) EditorOption {
return func(e *Editor) {
e.initBuffer()
e.text.WordSeperators = seperators
}
}
// ReadOnlyMode 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.
func ReadOnlyMode(enabled bool) EditorOption {
return func(e *Editor) {
e.initBuffer()
e.readOnly = enabled
}
}
// WrapLine configures whether the displayed text will be broken into lines or not.
func WrapLine(enabled bool) EditorOption {
return func(e *Editor) {
e.initBuffer()
changed := e.text.WrapLine == enabled
e.text.WrapLine = enabled
if changed {
e.text.invalidate()
}
}
}