-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathradiobutton.go
54 lines (46 loc) · 1.27 KB
/
radiobutton.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
// SPDX-License-Identifier: Unlicense OR MIT
package gel
import (
"golang.org/x/exp/shiny/materialdesign/icons"
l "github.com/p9c/gio/layout"
)
type RadioButton struct {
*Checkable
*Window
key string
group *Enum
}
// RadioButton returns a RadioButton with a label. The key specifies the value for the Enum.
func (w *Window) RadioButton(checkable *Checkable, group *Enum, key,
label string) *RadioButton {
// if checkable == nil {
// debug.PrintStack()
// os.Exit(0)
// }
return &RadioButton{
group: group,
Window: w,
Checkable: checkable.
CheckedStateIcon(&icons.ToggleRadioButtonChecked). // Color("Primary").
UncheckedStateIcon(&icons.ToggleRadioButtonUnchecked). // Color("PanelBg").
Label(label), // .Color("DocText").IconColor("PanelBg"),
key: key,
}
}
// Key sets the key initially active on the radiobutton
func (r *RadioButton) Key(key string) *RadioButton {
r.key = key
return r
}
// Group sets the enum group of the radio button
func (r *RadioButton) Group(group *Enum) *RadioButton {
r.group = group
return r
}
// Fn updates enum and displays the radio button.
func (r RadioButton) Fn(gtx l.Context) l.Dimensions {
dims := r.Checkable.Fn(gtx, r.group.Value() == r.key)
gtx.Constraints.Min = dims.Size
r.group.Fn(gtx, r.key)
return dims
}