newCheckRadio creates and returns a pointer to a new CheckRadio widget with the specified type and text
(check bool, text string)
| 59 | // newCheckRadio creates and returns a pointer to a new CheckRadio widget |
| 60 | // with the specified type and text |
| 61 | func newCheckRadio(check bool, text string) *CheckRadio { |
| 62 | |
| 63 | cb := new(CheckRadio) |
| 64 | cb.styles = &StyleDefault().CheckRadio |
| 65 | |
| 66 | // Adapts to specified type: CheckBox or RadioButton |
| 67 | cb.check = check |
| 68 | cb.state = false |
| 69 | if cb.check { |
| 70 | cb.codeON = checkON |
| 71 | cb.codeOFF = checkOFF |
| 72 | } else { |
| 73 | cb.codeON = radioON |
| 74 | cb.codeOFF = radioOFF |
| 75 | } |
| 76 | |
| 77 | // Initialize panel |
| 78 | cb.Panel.Initialize(cb, 0, 0) |
| 79 | |
| 80 | // Subscribe to events |
| 81 | cb.Panel.Subscribe(OnKeyDown, cb.onKey) |
| 82 | cb.Panel.Subscribe(OnCursorEnter, cb.onCursor) |
| 83 | cb.Panel.Subscribe(OnCursorLeave, cb.onCursor) |
| 84 | cb.Panel.Subscribe(OnMouseDown, cb.onMouse) |
| 85 | cb.Panel.Subscribe(OnEnable, func(evname string, ev interface{}) { cb.update() }) |
| 86 | |
| 87 | // Creates label |
| 88 | cb.Label = NewLabel(text) |
| 89 | cb.Label.Subscribe(OnResize, func(evname string, ev interface{}) { cb.recalc() }) |
| 90 | cb.Panel.Add(cb.Label) |
| 91 | |
| 92 | // Creates icon label |
| 93 | cb.icon = NewIcon(" ") |
| 94 | cb.Panel.Add(cb.icon) |
| 95 | |
| 96 | cb.recalc() |
| 97 | cb.update() |
| 98 | return cb |
| 99 | } |
| 100 | |
| 101 | // Value returns the current state of the checkbox |
| 102 | func (cb *CheckRadio) Value() bool { |
no test coverage detected