2022-11-14 14:30:28 -06:00
|
|
|
package main
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
import (
|
|
|
|
"git.wit.org/wit/gui/toolkit"
|
|
|
|
"github.com/andlabs/ui"
|
|
|
|
_ "github.com/andlabs/ui/winmanifest"
|
|
|
|
)
|
2022-10-21 11:40:08 -05:00
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
func (t andlabsT) NewCheckbox(w *toolkit.Widget) *andlabsT {
|
|
|
|
log(debugToolkit, "NewCheckbox()", w.Name, w.Type)
|
2022-11-14 14:30:28 -06:00
|
|
|
var newt andlabsT
|
2023-03-01 11:35:36 -06:00
|
|
|
newt.tw = w
|
2022-10-21 11:40:08 -05:00
|
|
|
|
|
|
|
if t.broken() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
c := ui.NewCheckbox(w.Name)
|
2022-10-21 11:40:08 -05:00
|
|
|
newt.uiCheckbox = c
|
|
|
|
newt.uiBox = t.uiBox
|
|
|
|
t.uiBox.Append(c, stretchy)
|
|
|
|
|
|
|
|
c.OnToggled(func(spin *ui.Checkbox) {
|
2023-03-01 11:35:36 -06:00
|
|
|
newt.tw.B = newt.Checked()
|
|
|
|
log(debugChange, "val =", newt.tw.B)
|
|
|
|
newt.commonChange(newt.tw)
|
2022-10-21 11:40:08 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
return &newt
|
|
|
|
}
|
|
|
|
|
2022-11-14 14:30:28 -06:00
|
|
|
func (t andlabsT) Checked() bool {
|
2022-10-21 11:40:08 -05:00
|
|
|
if t.broken() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return t.uiCheckbox.Checked()
|
|
|
|
}
|
2023-02-25 14:05:25 -06:00
|
|
|
|
|
|
|
func NewCheckbox(parentW *toolkit.Widget, w *toolkit.Widget) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "NewCheckbox()", w.Name)
|
2023-02-25 14:05:25 -06:00
|
|
|
|
|
|
|
t := mapToolkits[parentW]
|
|
|
|
if (t == nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
listMap(debugError)
|
|
|
|
return
|
2023-02-25 14:05:25 -06:00
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
newt := t.NewCheckbox(w)
|
2023-02-25 14:05:25 -06:00
|
|
|
mapWidgetsToolkits(w, newt)
|
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
|
|
|
|
func doCheckbox(p *toolkit.Widget, c *toolkit.Widget) {
|
|
|
|
if broken(c) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (c.Action == "New") {
|
|
|
|
NewCheckbox(p, c)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ct := mapToolkits[c]
|
|
|
|
if (ct == nil) {
|
|
|
|
log(true, "Trying to do something on a widget that doesn't work or doesn't exist or something", c)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if ct.broken() {
|
|
|
|
log(true, "checkbox() ct.broken", ct)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (ct.uiCheckbox == nil) {
|
|
|
|
log(true, "checkbox() uiCheckbox == nil", ct)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log(true, "Going to attempt:", c.Action)
|
|
|
|
switch c.Action {
|
|
|
|
case "Enable":
|
|
|
|
ct.uiCheckbox.Enable()
|
|
|
|
case "Disable":
|
|
|
|
ct.uiCheckbox.Disable()
|
|
|
|
case "Show":
|
|
|
|
ct.uiCheckbox.Show()
|
|
|
|
case "Hide":
|
|
|
|
ct.uiCheckbox.Hide()
|
|
|
|
case "Set":
|
|
|
|
ct.uiCheckbox.SetText(c.S)
|
|
|
|
ct.uiCheckbox.SetChecked(c.B)
|
|
|
|
default:
|
|
|
|
log(true, "Can't do", c.Action, "to a checkbox")
|
|
|
|
}
|
|
|
|
}
|