2022-11-14 14:30:28 -06:00
|
|
|
package main
|
2022-10-19 13:23:22 -05:00
|
|
|
|
2023-02-25 14:05:25 -06:00
|
|
|
import (
|
|
|
|
"github.com/andlabs/ui"
|
|
|
|
_ "github.com/andlabs/ui/winmanifest"
|
2022-10-19 13:23:22 -05:00
|
|
|
|
2023-02-25 14:05:25 -06:00
|
|
|
"git.wit.org/wit/gui/toolkit"
|
|
|
|
)
|
2022-11-14 14:30:28 -06:00
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
func newButton(parentW *toolkit.Widget, w *toolkit.Widget) {
|
2022-11-14 14:30:28 -06:00
|
|
|
var t, newt *andlabsT
|
2022-10-19 13:23:22 -05:00
|
|
|
var b *ui.Button
|
2023-03-12 08:47:16 -05:00
|
|
|
log(debugToolkit, "newButton()", w.Name)
|
2022-10-19 13:23:22 -05:00
|
|
|
|
2022-11-14 14:30:28 -06:00
|
|
|
t = mapToolkits[parentW]
|
|
|
|
if (t == nil) {
|
2023-03-12 08:47:16 -05:00
|
|
|
log(debugToolkit, "newButton() toolkit struct == nil. name=", parentW.Name, w.Name)
|
2022-11-14 14:30:28 -06:00
|
|
|
return
|
2022-10-19 13:23:22 -05:00
|
|
|
}
|
|
|
|
|
2022-11-14 14:30:28 -06:00
|
|
|
if t.broken() {
|
|
|
|
return
|
2022-11-05 10:19:04 -05:00
|
|
|
}
|
2022-11-14 14:30:28 -06:00
|
|
|
newt = new(andlabsT)
|
|
|
|
|
|
|
|
b = ui.NewButton(w.Name)
|
2022-10-19 13:23:22 -05:00
|
|
|
newt.uiButton = b
|
2023-03-01 11:35:36 -06:00
|
|
|
newt.tw = w
|
|
|
|
newt.parent = t
|
2022-10-19 13:23:22 -05:00
|
|
|
|
|
|
|
b.OnClicked(func(*ui.Button) {
|
2023-03-01 11:35:36 -06:00
|
|
|
newt.commonChange(newt.tw)
|
2022-10-19 13:23:22 -05:00
|
|
|
})
|
|
|
|
|
2023-03-12 08:47:16 -05:00
|
|
|
log(debugToolkit, "newButton() about to append to Box parent t:", w.Name)
|
|
|
|
log(debugToolkit, "newButton() about to append to Box new t:", w.Name)
|
|
|
|
if (debugToolkit) {
|
|
|
|
ShowDebug ()
|
|
|
|
}
|
2023-02-25 14:05:25 -06:00
|
|
|
|
2022-11-06 12:59:24 -06:00
|
|
|
if (t.uiBox != nil) {
|
|
|
|
t.uiBox.Append(b, stretchy)
|
|
|
|
} else if (t.uiWindow != nil) {
|
|
|
|
t.uiWindow.SetChild(b)
|
|
|
|
} else {
|
2023-03-12 08:47:16 -05:00
|
|
|
log(debugError, "ERROR: wit/gui andlabs couldn't place this button in a box or a window")
|
|
|
|
log(debugError, "ERROR: wit/gui andlabs couldn't place this button in a box or a window")
|
2022-11-14 14:30:28 -06:00
|
|
|
return
|
2022-11-06 12:59:24 -06:00
|
|
|
}
|
2022-10-19 13:23:22 -05:00
|
|
|
|
2022-11-14 14:30:28 -06:00
|
|
|
mapWidgetsToolkits(w, newt)
|
2022-10-19 13:23:22 -05:00
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
|
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
|
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
func doButton(p *toolkit.Widget, c *toolkit.Widget) {
|
|
|
|
if broken(c) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (c.Action == "New") {
|
|
|
|
newButton(p, c)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ct := mapToolkits[c]
|
|
|
|
if (ct == nil) {
|
2023-03-12 08:47:16 -05:00
|
|
|
log(debugError, "Trying to do something on a widget that doesn't work or doesn't exist or something", c)
|
2023-03-01 11:35:36 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if ct.broken() {
|
2023-03-12 08:47:16 -05:00
|
|
|
log(debugError, "Button() ct.broken", ct)
|
2023-03-01 11:35:36 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if (ct.uiButton == nil) {
|
2023-03-12 08:47:16 -05:00
|
|
|
log(debugError, "Button() uiButton == nil", ct)
|
2023-03-01 11:35:36 -06:00
|
|
|
return
|
|
|
|
}
|
2023-03-12 08:47:16 -05:00
|
|
|
log(debugToolkit, "Going to attempt:", c.Action)
|
2023-03-01 11:35:36 -06:00
|
|
|
switch c.Action {
|
|
|
|
case "Enable":
|
|
|
|
ct.uiButton.Enable()
|
|
|
|
case "Disable":
|
|
|
|
ct.uiButton.Disable()
|
|
|
|
case "Show":
|
|
|
|
ct.uiButton.Show()
|
|
|
|
case "Hide":
|
|
|
|
ct.uiButton.Hide()
|
|
|
|
case "Set":
|
|
|
|
ct.uiButton.SetText(c.S)
|
|
|
|
default:
|
2023-03-12 08:47:16 -05:00
|
|
|
log(debugError, "Can't do", c.Action, "to a Button")
|
2023-03-01 11:35:36 -06:00
|
|
|
}
|
|
|
|
}
|