...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package views
16
17 import (
18 "sync"
19
20 "github.com/gdamore/tcell/v2"
21 )
22
23
24
25
26
27
28 type SimpleStyledTextBar struct {
29 left *SimpleStyledText
30 right *SimpleStyledText
31 center *SimpleStyledText
32 once sync.Once
33
34 BoxLayout
35 }
36
37
38
39 func (s *SimpleStyledTextBar) SetRight(m string) {
40 s.initialize()
41 s.right.SetMarkup(m)
42 }
43
44
45
46 func (s *SimpleStyledTextBar) SetLeft(m string) {
47 s.initialize()
48 s.left.SetMarkup(m)
49 }
50
51
52
53 func (s *SimpleStyledTextBar) SetCenter(m string) {
54 s.initialize()
55 s.center.SetMarkup(m)
56 }
57
58 func (s *SimpleStyledTextBar) RegisterRightStyle(r rune, style tcell.Style) {
59 s.initialize()
60 s.right.RegisterStyle(r, style)
61 }
62
63 func (s *SimpleStyledTextBar) RegisterLeftStyle(r rune, style tcell.Style) {
64 s.initialize()
65 s.left.RegisterStyle(r, style)
66 }
67
68 func (s *SimpleStyledTextBar) RegisterCenterStyle(r rune, style tcell.Style) {
69 s.initialize()
70 s.center.RegisterStyle(r, style)
71 }
72
73 func (s *SimpleStyledTextBar) Size() (int, int) {
74 s.initialize()
75 w, h := s.BoxLayout.Size()
76 if h < 1 {
77 h = 1
78 }
79 if w < 1 {
80 w = 1
81 }
82 return w, h
83 }
84
85 func (s *SimpleStyledTextBar) initialize() {
86 s.once.Do(func() {
87 s.center = NewSimpleStyledText()
88 s.left = NewSimpleStyledText()
89 s.right = NewSimpleStyledText()
90 s.center.SetAlignment(VAlignTop | HAlignCenter)
91 s.left.SetAlignment(VAlignTop | HAlignLeft)
92 s.right.SetAlignment(VAlignTop | HAlignRight)
93 s.BoxLayout.SetOrientation(Horizontal)
94 s.BoxLayout.AddWidget(s.left, 0.0)
95 s.BoxLayout.AddWidget(NewSpacer(), 1.0)
96 s.BoxLayout.AddWidget(s.center, 0.0)
97 s.BoxLayout.AddWidget(NewSpacer(), 1.0)
98 s.BoxLayout.AddWidget(s.right, 0.0)
99 })
100 }
101
102
103
104 func (s *SimpleStyledTextBar) Init() {
105 s.initialize()
106 }
107
108
109 func NewSimpleStyledTextBar() *SimpleStyledTextBar {
110 s := &SimpleStyledTextBar{}
111 s.initialize()
112 return s
113 }
114
View as plain text