-
Notifications
You must be signed in to change notification settings - Fork 1
/
menu_bar.go
80 lines (69 loc) · 1.58 KB
/
menu_bar.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 ui
import (
"fmt"
"git.kirsle.net/go/render"
"git.kirsle.net/go/ui/theme"
)
// MenuFont is the default font settings for MenuBar buttons.
var MenuFont = render.Text{
Size: 12,
Color: render.Black,
PadX: 4,
PadY: 2,
}
// MenuBar is a frame that holds several MenuButtons, such as for the main
// menu at the top of a window.
type MenuBar struct {
Frame
name string
supervisor *Supervisor
buttons []*MenuButton
}
// NewMenuBar creates a new menu bar frame.
func NewMenuBar(name string) *MenuBar {
w := &MenuBar{
name: name,
buttons: []*MenuButton{},
}
w.SetBackground(theme.ButtonBackgroundColor)
w.Frame.Setup()
w.IDFunc(func() string {
return fmt.Sprintf("MenuBar<%s>", w.name)
})
return w
}
// Supervise the menu bar, making its child menu buttons work correctly.
func (w *MenuBar) Supervise(s *Supervisor) {
w.supervisor = s
// Supervise the existing buttons.
for _, btn := range w.buttons {
s.Add(btn)
btn.Supervise(s)
}
}
// AddMenu adds a new menu button to the bar. Returns the MenuButton
// object so that you can add items to it.
func (w *MenuBar) AddMenu(label string) *MenuButton {
btn := NewMenuButton(label, NewLabel(Label{
Text: label,
Font: MenuFont,
}))
w.buttons = append(w.buttons, btn)
// Pack and supervise it.
w.Pack(btn, Pack{
Side: W,
})
if w.supervisor != nil {
w.supervisor.Add(btn)
btn.Supervise(w.supervisor)
}
return btn
}
// PackTop returns the default Frame Pack settings to place the menu
// at the top of the parent widget.
func (w *MenuBar) PackTop() Pack {
return Pack{
Side: N,
FillX: true,
}
}