|
@@ -23,11 +23,12 @@ type CheckRadio struct {
|
|
|
icon *Label
|
|
icon *Label
|
|
|
styles *CheckRadioStyles
|
|
styles *CheckRadioStyles
|
|
|
check bool
|
|
check bool
|
|
|
- group string
|
|
|
|
|
|
|
+ group string // current group name
|
|
|
cursorOver bool
|
|
cursorOver bool
|
|
|
state bool
|
|
state bool
|
|
|
codeON string
|
|
codeON string
|
|
|
codeOFF string
|
|
codeOFF string
|
|
|
|
|
+ subroot bool // indicates root subcription
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type CheckRadioStyle struct {
|
|
type CheckRadioStyle struct {
|
|
@@ -101,19 +102,6 @@ func newCheckRadio(check bool, text string) *CheckRadio {
|
|
|
return cb
|
|
return cb
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// SetRoot overrides the IPanel.SetRoot method
|
|
|
|
|
-func (cb *CheckRadio) SetRoot(root *Root) {
|
|
|
|
|
-
|
|
|
|
|
- if cb.root == root || root == nil {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- cb.root = root
|
|
|
|
|
- // Subscribes once to this root panel OnRadioGroup events
|
|
|
|
|
- root.Subscribe(OnRadioGroup, func(name string, ev interface{}) {
|
|
|
|
|
- cb.onRadioGroup(ev.(*CheckRadio))
|
|
|
|
|
- })
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
// Value returns the current state of the checkbox
|
|
// Value returns the current state of the checkbox
|
|
|
func (cb *CheckRadio) Value() bool {
|
|
func (cb *CheckRadio) Value() bool {
|
|
|
|
|
|
|
@@ -154,6 +142,15 @@ func (cb *CheckRadio) SetStyles(bs *CheckRadioStyles) {
|
|
|
// toggleState toggles the current state of the checkbox/radiobutton
|
|
// toggleState toggles the current state of the checkbox/radiobutton
|
|
|
func (cb *CheckRadio) toggleState() {
|
|
func (cb *CheckRadio) toggleState() {
|
|
|
|
|
|
|
|
|
|
+ // Subscribes once to the root panel for OnRadioGroup events
|
|
|
|
|
+ // The root panel is used to dispatch events to all checkradios
|
|
|
|
|
+ if !cb.subroot {
|
|
|
|
|
+ cb.root.Subscribe(OnRadioGroup, func(name string, ev interface{}) {
|
|
|
|
|
+ cb.onRadioGroup(ev.(*CheckRadio))
|
|
|
|
|
+ })
|
|
|
|
|
+ cb.subroot = true
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if cb.check {
|
|
if cb.check {
|
|
|
cb.state = !cb.state
|
|
cb.state = !cb.state
|
|
|
} else {
|
|
} else {
|
|
@@ -215,7 +212,7 @@ func (cb *CheckRadio) onKey(evname string, ev interface{}) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// onRadioGroup receives subscriber OnRadioGroup events
|
|
|
|
|
|
|
+// onRadioGroup receives subscribed OnRadioGroup events
|
|
|
func (cb *CheckRadio) onRadioGroup(other *CheckRadio) {
|
|
func (cb *CheckRadio) onRadioGroup(other *CheckRadio) {
|
|
|
|
|
|
|
|
// If event is for this button, ignore
|
|
// If event is for this button, ignore
|