-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathtoolbar.go
38 lines (34 loc) · 1.04 KB
/
toolbar.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
// Copyright (c) 2022, The Emergent Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package egui
import (
"cogentcore.org/core/core"
"cogentcore.org/core/events"
"cogentcore.org/core/icons"
"cogentcore.org/core/styles"
"cogentcore.org/core/tree"
)
// ToolbarItem holds the configuration values for a toolbar item
type ToolbarItem struct {
Label string
Icon icons.Icon
Tooltip string
Active ToolGhosting
Func func()
}
// AddToolbarItem adds a toolbar item but also checks when it be active in the UI
func (gui *GUI) AddToolbarItem(p *tree.Plan, item ToolbarItem) {
tree.AddAt(p, item.Label, func(w *core.Button) {
w.SetText(item.Label).SetIcon(item.Icon).
SetTooltip(item.Tooltip).OnClick(func(e events.Event) {
item.Func()
})
switch item.Active {
case ActiveStopped:
w.FirstStyler(func(s *styles.Style) { s.SetEnabled(!gui.IsRunning) })
case ActiveRunning:
w.FirstStyler(func(s *styles.Style) { s.SetEnabled(gui.IsRunning) })
}
})
}