-
Notifications
You must be signed in to change notification settings - Fork 0
/
styler.go
70 lines (59 loc) · 1.56 KB
/
styler.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
package box
import (
"image"
"image/color"
"github.com/codeation/lineation/palette"
"github.com/codeation/lineation/text"
)
type BoxTextOption struct {
text.TextStyler
b *Box
}
func newTextOption(b *Box) *BoxTextOption {
return &BoxTextOption{
TextStyler: text.NewSimpleTextOption(&text.TextOption{
Font: b.pal.DefaultFont(),
LineHeight: b.pal.DefaultFont().Height + b.pal.TextLineOffset(),
Margin: image.Pt(b.pal.HorizontalTextAlign(), b.pal.VerticalTextAlign()),
Foreground: b.pal.Color(palette.DefaultText),
}),
b: b,
}
}
func (o *BoxTextOption) Edge() int {
return o.b.pal.BoxWidth(o.b.level()) - o.b.pal.HorizontalTextAlign()*2
}
func (o *BoxTextOption) Size() image.Point {
if o.b.textBox != nil {
return image.Pt(o.b.width(), o.b.height())
}
return image.Pt(o.b.pal.BoxWidth(o.b.level()), o.b.pal.DefaultFont().Height)
}
func (o *BoxTextOption) Background() color.Color {
if o.b.emphasized || o.b.isActive {
return o.b.pal.Color(palette.ActiveBoxBackground)
}
return o.b.pal.Color(palette.DefaultBoxBackground)
}
func (o *BoxTextOption) Border() color.Color {
if o.b.isActive {
return o.b.pal.Color(palette.ActiveEdge)
}
return o.b.pal.Color(palette.DefaultEdge)
}
type BoxCursorOption struct {
text.CursorStyler
b *Box
}
func newCursorOption(b *Box) *BoxCursorOption {
return &BoxCursorOption{
CursorStyler: text.NewSimpleCursorOption(&text.CursorOption{
Foreground: b.pal.Color(palette.CursorBlock),
Size: b.pal.CursorSize(),
}),
b: b,
}
}
func (o *BoxCursorOption) Enable() bool {
return o.b.isActive
}