summaryrefslogtreecommitdiff
path: root/button.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2022-10-08 23:22:47 -0500
committerJeff Carr <[email protected]>2022-10-08 23:22:47 -0500
commit086986b6b8f55d15d18595bcbf3f76c023365b61 (patch)
tree9f1dc4da5b2d125f7a017418d4d9912e16b71039 /button.go
parentf92a50e2e665a18e2201f1d6714025dcc39301cc (diff)
parent45644ef9bc333f5def62d1c7f474dc96274e63fa (diff)
Merge branch 'master' into jcarr
Diffstat (limited to 'button.go')
-rw-r--r--button.go108
1 files changed, 50 insertions, 58 deletions
diff --git a/button.go b/button.go
index bf36f23..755d9ab 100644
--- a/button.go
+++ b/button.go
@@ -1,10 +1,15 @@
package gui
import "log"
+import "reflect"
+// import "image/color"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
// import "github.com/davecgh/go-spew/spew"
+
+// TODO: bring this generic mouse click function back
+//
// This is the default mouse click handler
// Every mouse click that hasn't been assigned to
// something specific will fall into this routine
@@ -14,77 +19,64 @@ import _ "github.com/andlabs/ui/winmanifest"
// 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
//
-// There is a []GuiButton which has all the buttons. We search
-// for the button and then call the function below
//
-func defaultButtonClick(button *ui.Button) {
- log.Println("gui.defaultButtonClick() LOOK FOR BUTTON button =", button)
- for key, foo := range Data.AllButtons {
- if (Config.Debug) {
- log.Println("gui.defaultButtonClick() Data.AllButtons =", key, foo)
- // spew.Dump(foo)
- }
- if Data.AllButtons[key].B == button {
- log.Println("\tgui.defaultButtonClick() BUTTON MATCHED")
- guiButtonClick(Data.AllButtons[key])
- return
- }
+
+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
}
- log.Println("\tgui.defaultButtonClick() ERROR: BUTTON NOT FOUND")
+ button := ui.NewButton(name)
if (Config.Debug) {
- panic("gui.defaultButtonClick() ERROR: UNMAPPED ui.Button")
+ log.Println("reflect.TypeOF(uiBox) =", reflect.TypeOf(n.uiBox))
+ log.Println("reflect.TypeOF(uiButton) =", reflect.TypeOf(button))
}
-}
+ // true == expand, false == make normal size button
+ n.uiBox.Append(button, Config.Stretchy)
+ n.uiButton = button
-func guiButtonClick(button *GuiButton) {
- log.Println("\tgui.guiButtonClick() button.Name =", button.Name)
- if button.Custom != nil {
- log.Println("\tgui.guiButtonClick() DOING CUSTOM FUNCTION")
- button.Custom(button)
- return
- }
- if (Data.MouseClick != nil) {
- Data.MouseClick(button)
- } else {
- log.Println("\tgui.guiButtonClick() IGNORING BUTTON. MouseClick() is nil")
- }
-}
+ newNode := n.makeNode(name, 888, 888 + Config.counter)
+ newNode.uiButton = button
+ newNode.custom = custom
-func CreateButton(box *GuiBox, custom func(*GuiButton), name string, values interface {}) *GuiButton {
- newUiB := ui.NewButton(name)
- newUiB.OnClicked(defaultButtonClick)
+ button.OnClicked(func(*ui.Button) {
+ log.Println("gui.AppendButton() Button Clicked. Running custom()")
+ custom(newNode)
+ })
+ return newNode
+}
- var newB *GuiButton
- newB = new(GuiButton)
- newB.B = newUiB
- if (box.Window == nil) {
- log.Println("CreateButton() box.Window == nil")
- // ErrorWindow(box.Window, "Login Failed", msg) // can't even do this
- panic("maybe print an error and return nil? or make a fake button?")
- }
- newB.Box = box
- newB.Custom = custom
- newB.Values = values
+func (n *Node) CreateFontButton(action string) *Node {
+ n.uiFontButton = ui.NewFontButton()
- Data.AllButtons = append(Data.AllButtons, newB)
+ n.uiFontButton.OnChanged(func (*ui.FontButton) {
+ log.Println("FontButton.OnChanged() START")
+ n.Dump()
+ })
+ n.uiBox.Append(n.uiFontButton, Config.Stretchy)
- box.UiBox.Append(newB.B, false)
- return newB
+ // TODO: implement Grid
+ n.uiGrid = ui.NewGrid()
+ return n
}
-func CreateFontButton(box *GuiBox, action string) *GuiButton {
+func (n *Node) CreateColorButton(custom func(*Node), name string, values interface {}) *Node {
// create a 'fake' button entry for the mouse clicks
- var newGB GuiButton
- newGB.Name = "FONT"
- newGB.FB = ui.NewFontButton()
- newGB.Box = box
- Data.AllButtons = append(Data.AllButtons, &newGB)
+ n.uiColorButton = ui.NewColorButton()
+ n.custom = custom
+ n.values = values
- newGB.FB.OnChanged(func (*ui.FontButton) {
- log.Println("FontButton.OnChanged() START mouseClick(&newBM)", newGB)
- if (Data.MouseClick != nil) {
- Data.MouseClick(&newGB)
+ n.uiColorButton.OnChanged(func (*ui.ColorButton) {
+ log.Println("ColorButton.OnChanged() START Color Button Click")
+ rgba := n.Color
+ r, g, b, a := rgba.R, rgba.G, rgba.B, rgba.A
+ log.Println("ColorButton.OnChanged() Color() =", r, g, b, a)
+ if (n.custom != nil) {
+ n.custom(n)
+ } else if (Data.MouseClick != nil) {
+ Data.MouseClick(n)
}
})
- return &newGB
+ n.uiBox.Append(n.uiColorButton, Config.Stretchy)
+ return n
}