2022-11-14 14:30:28 -06:00
|
|
|
package main
|
2022-10-16 08:07:13 -05:00
|
|
|
|
2022-11-14 14:30:28 -06:00
|
|
|
import (
|
|
|
|
"git.wit.org/wit/gui/toolkit"
|
2022-10-16 08:07:13 -05:00
|
|
|
|
2022-11-14 14:30:28 -06:00
|
|
|
"github.com/andlabs/ui"
|
|
|
|
_ "github.com/andlabs/ui/winmanifest"
|
|
|
|
)
|
|
|
|
|
2023-03-03 14:41:38 -06:00
|
|
|
func (t *andlabsT) newSlider(w *toolkit.Widget) *andlabsT {
|
2022-10-16 08:07:13 -05:00
|
|
|
// make new node here
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, w.Name, w.Type, w.X, w.Y)
|
2022-11-14 14:30:28 -06:00
|
|
|
var newt andlabsT
|
2022-10-16 08:07:13 -05:00
|
|
|
|
2022-10-19 13:23:22 -05:00
|
|
|
if (t.uiBox == nil) {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "node.UiBox == nil. I can't add a range UI element without a place to put it")
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "probably could just make a box here?")
|
|
|
|
exit("internal golang wit/gui/toolkit error")
|
2022-10-19 13:23:22 -05:00
|
|
|
return nil
|
2022-10-16 08:07:13 -05:00
|
|
|
}
|
2022-10-19 13:23:22 -05:00
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
s := ui.NewSlider(w.X, w.Y)
|
2022-10-19 13:23:22 -05:00
|
|
|
newt.uiSlider = s
|
|
|
|
newt.uiBox = t.uiBox
|
2023-03-01 11:35:36 -06:00
|
|
|
newt.tw = w
|
2022-10-21 11:40:08 -05:00
|
|
|
t.uiBox.Append(s, stretchy)
|
2022-10-16 08:07:13 -05:00
|
|
|
|
|
|
|
s.OnChanged(func(spin *ui.Slider) {
|
2023-03-03 14:41:38 -06:00
|
|
|
newt.tw.I = newt.uiSlider.Value()
|
2023-03-01 11:35:36 -06:00
|
|
|
newt.commonChange(newt.tw)
|
2022-10-16 08:07:13 -05:00
|
|
|
})
|
|
|
|
|
2022-10-19 13:23:22 -05:00
|
|
|
return &newt
|
2022-10-16 08:07:13 -05:00
|
|
|
}
|
2022-11-14 14:30:28 -06:00
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
func newSlider(parentW *toolkit.Widget, w *toolkit.Widget) {
|
2022-11-14 14:30:28 -06:00
|
|
|
var newt *andlabsT
|
2023-03-12 08:47:16 -05:00
|
|
|
log(debugToolkit, "newSlider()", w.Name)
|
2022-11-14 14:30:28 -06:00
|
|
|
|
|
|
|
t := mapToolkits[parentW]
|
|
|
|
if (t == nil) {
|
2023-03-12 08:47:16 -05:00
|
|
|
log(debugError, "newSlider() ERROR toolkit struct == nil. name=", parentW.Name, w.Name)
|
2022-11-14 14:30:28 -06:00
|
|
|
return
|
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
newt = t.newSlider(w)
|
2022-11-14 14:30:28 -06:00
|
|
|
mapWidgetsToolkits(w, newt)
|
|
|
|
}
|
2023-03-12 08:47:16 -05:00
|
|
|
|
|
|
|
// This routine is very specific to this toolkit
|
|
|
|
// It's annoying and has to be copied to each widget when there are changes
|
|
|
|
// it could be 'simplfied' maybe or made to be more generic, but this is as far as I've gotten
|
|
|
|
// it's probably not worth working much more on this toolkit, the andlabs/ui has been great and got me here!
|
|
|
|
// but it's time to write direct GTK, QT, macos and windows toolkit plugins
|
|
|
|
// -- jcarr 2023/03/09
|
|
|
|
|
|
|
|
func doSlider(p *toolkit.Widget, c *toolkit.Widget) {
|
|
|
|
if broken(c) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log(debugChange, "Going to attempt:", c.Action)
|
|
|
|
if (c.Action == "New") {
|
|
|
|
newSlider(p, c)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ct := mapToolkits[c]
|
|
|
|
if (ct == nil) {
|
|
|
|
log(debugError, "Trying to do something on a widget that doesn't work or doesn't exist or something", c)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if ct.broken() {
|
|
|
|
log(debugError, "Slider() ct.broken", ct)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (ct.uiSlider == nil) {
|
|
|
|
log(debugError, "Label() uiSlider == nil", ct)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
switch c.Action {
|
|
|
|
case "Enable":
|
|
|
|
ct.uiSlider.Enable()
|
|
|
|
case "Disable":
|
|
|
|
ct.uiSlider.Disable()
|
|
|
|
case "Show":
|
|
|
|
ct.uiSlider.Show()
|
|
|
|
case "Hide":
|
|
|
|
ct.uiSlider.Hide()
|
|
|
|
case "Set":
|
|
|
|
ct.uiSlider.SetValue(c.I)
|
|
|
|
case "Get":
|
|
|
|
c.I = ct.uiSlider.Value()
|
|
|
|
default:
|
|
|
|
log(debugError, "Can't do", c.Action, "to a Slider")
|
|
|
|
}
|
|
|
|
}
|