2019-06-02 15:40:44 -05:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import "log"
|
2021-10-31 14:21:36 -05:00
|
|
|
import "reflect"
|
2021-10-31 23:48:34 -05:00
|
|
|
// import "image/color"
|
2019-06-02 15:40:44 -05:00
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
// import "github.com/davecgh/go-spew/spew"
|
|
|
|
|
2021-10-31 14:21:36 -05:00
|
|
|
|
2021-11-01 00:24:56 -05:00
|
|
|
// TODO: bring this generic mouse click function back
|
|
|
|
//
|
2019-06-02 15:40:44 -05:00
|
|
|
// This is the default mouse click handler
|
|
|
|
// Every mouse click that hasn't been assigned to
|
|
|
|
// something specific will fall into this routine
|
|
|
|
// By default, all it runs is the call back to
|
|
|
|
// the main program that is using this library
|
|
|
|
//
|
|
|
|
// This routine MUST be here as this is how the andlabs/ui works
|
|
|
|
// This is the raw routine passed to every button in andlabs libui / ui
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
2021-10-31 14:21:36 -05:00
|
|
|
func (n *Node) AddButton(name string, custom func(*Node)) *Node {
|
|
|
|
if (n.uiBox == nil) {
|
|
|
|
log.Println("gui.Node.AppendButton() filed node.UiBox == nil")
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
button := ui.NewButton(name)
|
2021-11-03 01:44:32 -05:00
|
|
|
if (Config.Debug) {
|
|
|
|
log.Println("reflect.TypeOF(uiBox) =", reflect.TypeOf(n.uiBox))
|
|
|
|
log.Println("reflect.TypeOF(uiButton) =", reflect.TypeOf(button))
|
|
|
|
}
|
2021-10-31 19:39:57 -05:00
|
|
|
// true == expand, false == make normal size button
|
2021-11-04 02:23:41 -05:00
|
|
|
n.uiBox.Append(button, Config.Stretchy)
|
2021-10-31 14:21:36 -05:00
|
|
|
n.uiButton = button
|
|
|
|
|
|
|
|
newNode := n.makeNode(name, 888, 888 + Config.counter)
|
|
|
|
newNode.uiButton = button
|
|
|
|
newNode.custom = custom
|
|
|
|
|
|
|
|
button.OnClicked(func(*ui.Button) {
|
|
|
|
log.Println("gui.AppendButton() Button Clicked. Running custom()")
|
|
|
|
custom(newNode)
|
|
|
|
})
|
|
|
|
return newNode
|
|
|
|
}
|
|
|
|
|
2021-10-31 23:48:34 -05:00
|
|
|
func (n *Node) CreateFontButton(action string) *Node {
|
|
|
|
n.uiFontButton = ui.NewFontButton()
|
2019-06-02 15:40:44 -05:00
|
|
|
|
2021-10-31 23:48:34 -05:00
|
|
|
n.uiFontButton.OnChanged(func (*ui.FontButton) {
|
|
|
|
log.Println("FontButton.OnChanged() START")
|
|
|
|
n.Dump()
|
2019-06-02 15:40:44 -05:00
|
|
|
})
|
2021-11-04 03:25:42 -05:00
|
|
|
n.uiBox.Append(n.uiFontButton, Config.Stretchy)
|
2021-10-31 23:48:34 -05:00
|
|
|
return n
|
2019-06-02 15:40:44 -05:00
|
|
|
}
|
2019-06-05 12:01:36 -05:00
|
|
|
|
2021-10-31 23:48:34 -05:00
|
|
|
func (n *Node) CreateColorButton(custom func(*Node), name string, values interface {}) *Node {
|
2019-06-05 12:01:36 -05:00
|
|
|
// create a 'fake' button entry for the mouse clicks
|
2021-10-31 23:48:34 -05:00
|
|
|
n.uiColorButton = ui.NewColorButton()
|
|
|
|
n.custom = custom
|
|
|
|
n.values = values
|
2019-06-05 12:01:36 -05:00
|
|
|
|
2021-10-31 23:48:34 -05:00
|
|
|
n.uiColorButton.OnChanged(func (*ui.ColorButton) {
|
2019-06-05 12:01:36 -05:00
|
|
|
log.Println("ColorButton.OnChanged() START Color Button Click")
|
2021-10-31 23:48:34 -05:00
|
|
|
rgba := n.Color
|
|
|
|
r, g, b, a := rgba.R, rgba.G, rgba.B, rgba.A
|
2019-06-05 12:01:36 -05:00
|
|
|
log.Println("ColorButton.OnChanged() Color() =", r, g, b, a)
|
2021-10-31 23:48:34 -05:00
|
|
|
if (n.custom != nil) {
|
|
|
|
n.custom(n)
|
2019-06-05 12:01:36 -05:00
|
|
|
} else if (Data.MouseClick != nil) {
|
2021-10-31 23:48:34 -05:00
|
|
|
Data.MouseClick(n)
|
2019-06-05 12:01:36 -05:00
|
|
|
}
|
|
|
|
})
|
2021-11-04 02:23:41 -05:00
|
|
|
n.uiBox.Append(n.uiColorButton, Config.Stretchy)
|
2021-10-31 23:48:34 -05:00
|
|
|
return n
|
2019-06-05 12:01:36 -05:00
|
|
|
}
|