-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrolclosewrapper.go
More file actions
77 lines (61 loc) · 1.69 KB
/
Copy pathcontrolclosewrapper.go
File metadata and controls
77 lines (61 loc) · 1.69 KB
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
package dynamic_gui_config
import (
"io"
"log"
"github.com/andlabs/ui"
)
// CloseFunc is a function type implementing the io.Closer interface
type CloseFunc func() error
// Close runs given the close function
func (c CloseFunc) Close() error {
return c()
}
// ControlCloseWrapper acts as a ui.Control and supports close functions.
// This can be used to wrap a control and run a close function when the control gets destroyed.
type ControlCloseWrapper struct {
Child ui.Control
CloseHandles []io.Closer
}
// NewControlCloseWrapper creates a ControlCloseWrapper with the given control type as child element
func NewControlCloseWrapper(child ui.Control) *ControlCloseWrapper {
return &ControlCloseWrapper{
Child: child,
CloseHandles: make([]io.Closer, 0),
}
}
// AddClosers adds the given io.Closer objects to the ControlCloseWrapper container
func (c *ControlCloseWrapper) AddClosers(closer ...io.Closer) {
c.CloseHandles = append(c.CloseHandles, closer...)
}
func (c ControlCloseWrapper) LibuiControl() uintptr {
return c.Child.LibuiControl()
}
func (c ControlCloseWrapper) Destroy() {
for _, closer := range c.CloseHandles {
if err := closer.Close(); err != nil {
log.Println("err closing: ", err)
}
}
c.Child.Destroy()
}
func (c ControlCloseWrapper) Handle() uintptr {
return c.Child.Handle()
}
func (c ControlCloseWrapper) Visible() bool {
return c.Child.Visible()
}
func (c ControlCloseWrapper) Show() {
c.Child.Show()
}
func (c ControlCloseWrapper) Hide() {
c.Child.Hide()
}
func (c ControlCloseWrapper) Enabled() bool {
return c.Child.Enabled()
}
func (c ControlCloseWrapper) Enable() {
c.Child.Enable()
}
func (c ControlCloseWrapper) Disable() {
c.Child.Disable()
}