gogui: checkboxes
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
70253c31f2
commit
90e45a4a3e
|
@ -0,0 +1,26 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
// "github.com/awesome-gocui/gocui"
|
||||||
|
"git.wit.org/wit/gui/toolkit"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (w *cuiWidget) setCheckbox(b bool) {
|
||||||
|
if (w.widgetType != toolkit.Checkbox) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (b) {
|
||||||
|
w.b = b
|
||||||
|
w.text = "X " + w.name
|
||||||
|
} else {
|
||||||
|
w.b = b
|
||||||
|
w.text = " " + w.name
|
||||||
|
}
|
||||||
|
t := len(w.text) + 1
|
||||||
|
w.realWidth = t
|
||||||
|
w.gocuiSize.width = t
|
||||||
|
|
||||||
|
w.setWH()
|
||||||
|
w.deleteView()
|
||||||
|
w.drawView()
|
||||||
|
}
|
|
@ -28,6 +28,12 @@ func (w *cuiWidget) doWidgetClick() {
|
||||||
case toolkit.Group:
|
case toolkit.Group:
|
||||||
w.placeWidgets()
|
w.placeWidgets()
|
||||||
w.toggleTree()
|
w.toggleTree()
|
||||||
|
case toolkit.Checkbox:
|
||||||
|
if (w.b) {
|
||||||
|
w.setCheckbox(false)
|
||||||
|
} else {
|
||||||
|
w.setCheckbox(true)
|
||||||
|
}
|
||||||
case toolkit.Grid:
|
case toolkit.Grid:
|
||||||
me.rootNode.hideWidgets()
|
me.rootNode.hideWidgets()
|
||||||
w.placeGrid()
|
w.placeGrid()
|
||||||
|
|
|
@ -69,6 +69,7 @@ func (w *cuiWidget) Set(val any) {
|
||||||
switch v := val.(type) {
|
switch v := val.(type) {
|
||||||
case bool:
|
case bool:
|
||||||
w.b = val.(bool)
|
w.b = val.(bool)
|
||||||
|
w.setCheckbox(val.(bool))
|
||||||
case string:
|
case string:
|
||||||
w.SetText(val.(string))
|
w.SetText(val.(string))
|
||||||
case int:
|
case int:
|
||||||
|
|
|
@ -81,7 +81,7 @@ func (w *cuiWidget) drawView() {
|
||||||
me.baseGui.SetKeybinding(w.v.Name(), gocui.MouseLeft, gocui.ModNone, click)
|
me.baseGui.SetKeybinding(w.v.Name(), gocui.MouseLeft, gocui.ModNone, click)
|
||||||
|
|
||||||
w.v.Wrap = true
|
w.v.Wrap = true
|
||||||
fmt.Fprintln(w.v, " " + w.text)
|
fmt.Fprintln(w.v, w.text)
|
||||||
|
|
||||||
w.setDefaultWidgetColor()
|
w.setDefaultWidgetColor()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue