-
Notifications
You must be signed in to change notification settings - Fork 1
/
button_linux.go
86 lines (70 loc) · 1.84 KB
/
button_linux.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
81
82
83
84
85
86
package goey
import (
"unsafe"
"bitbucket.org/rj/goey/base"
"github.com/gotk3/gotk3/gdk"
"github.com/gotk3/gotk3/gtk"
)
type buttonElement struct {
Control
onClick clickSlot
onFocus focusSlot
onBlur blurSlot
}
func (w *Button) mount(parent base.Control) (base.Element, error) {
// Create the control
control, err := gtk.ButtonNewWithLabel(w.Text)
if err != nil {
return nil, err
}
control.AddEvents(int(gdk.FOCUS_CHANGE_MASK))
parent.Handle.Add(control)
// Update properties on the control
control.SetSensitive(!w.Disabled)
control.SetCanDefault(w.Default)
control.Show()
// Create the element
retval := &buttonElement{
Control: Control{&control.Widget},
}
// Connect all callbacks for the events
control.Connect("destroy", buttonOnDestroy, retval)
retval.onClick.Set(&control.Widget, w.OnClick)
retval.onFocus.Set(&control.Widget, w.OnFocus)
retval.onBlur.Set(&control.Widget, w.OnBlur)
return retval, nil
}
func buttonOnDestroy(widget *gtk.Button, mounted *buttonElement) {
mounted.handle = nil
}
func (w *buttonElement) button() *gtk.Button {
return (*gtk.Button)(unsafe.Pointer(w.handle))
}
func (w *buttonElement) Click() {
w.button().Clicked()
}
func (w *buttonElement) Props() base.Widget {
button := w.button()
text, err := button.GetLabel()
if err != nil {
panic("Could not get label: " + err.Error())
}
return &Button{
Text: text,
Disabled: !button.GetSensitive(),
Default: button.GetCanDefault(),
OnClick: w.onClick.callback,
OnFocus: w.onFocus.callback,
OnBlur: w.onBlur.callback,
}
}
func (w *buttonElement) updateProps(data *Button) error {
button := w.button()
button.SetLabel(data.Text)
button.SetSensitive(!data.Disabled)
button.SetCanDefault(data.Default)
w.onClick.Set(w.handle, data.OnClick)
w.onFocus.Set(w.handle, data.OnFocus)
w.onBlur.Set(w.handle, data.OnBlur)
return nil
}