summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--area.go10
-rw-r--r--box.go8
-rw-r--r--cmds/gui-demo/demo-window.go73
-rw-r--r--entry.go14
-rw-r--r--new-structs.go24
-rw-r--r--structs.go10
-rw-r--r--table.go9
7 files changed, 120 insertions, 28 deletions
diff --git a/area.go b/area.go
index 0cc7531..7c42c6c 100644
--- a/area.go
+++ b/area.go
@@ -107,10 +107,10 @@ func (ah GuiArea) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) {
return false
}
-func ShowTextBox(box *GuiBox, newText *ui.AttributedString, custom func(*GuiButton), name string) {
+func (b *GuiBox) ShowTextBox(newText *ui.AttributedString, custom func(*GuiButton), name string) {
log.Println("ShowTextBox() START")
- gw := box.Window
+ gw := b.Window
if (gw == nil) {
log.Println("ShowTextBox() ERROR gw = nil")
return
@@ -127,10 +127,10 @@ func ShowTextBox(box *GuiBox, newText *ui.AttributedString, custom func(*GuiButt
*/
// TODO: allow padded & axis here
- box.UiBox.SetPadded(true)
+ b.UiBox.SetPadded(true)
// add(gw.BoxMap["MAINBOX"], newbox)
- makeGenericArea(box, newText, custom)
- box.UiBox.Append(box.Window.Area.UiArea, true)
+ makeGenericArea(b, newText, custom)
+ b.UiBox.Append(b.Window.Area.UiArea, true)
}
diff --git a/box.go b/box.go
index 9d9833d..61ee2e7 100644
--- a/box.go
+++ b/box.go
@@ -102,9 +102,9 @@ func (n *Node) AddBox(axis int, name string) *Node {
return newNode
}
-func NewBox(box *GuiBox, axis int, name string) *GuiBox {
+func (b *GuiBox) NewBox(axis int, name string) *GuiBox {
log.Println("gui.NewBox() START")
- n := box.FindNode()
+ n := b.FindNode()
if (n == nil) {
log.Println("gui.NewBox() SERIOUS ERROR. CAN NOT FIND NODE")
os.Exit(0)
@@ -113,7 +113,7 @@ func NewBox(box *GuiBox, axis int, name string) *GuiBox {
}
var newbox *GuiBox
newbox = new(GuiBox)
- newbox.Window = box.Window
+ newbox.Window = b.Window
newbox.Name = name
var uiBox *ui.Box
@@ -124,7 +124,7 @@ func NewBox(box *GuiBox, axis int, name string) *GuiBox {
}
uiBox.SetPadded(true)
newbox.UiBox = uiBox
- add(box, newbox)
+ add(b, newbox)
// panic("gui.NewBox")
return newbox
}
diff --git a/cmds/gui-demo/demo-window.go b/cmds/gui-demo/demo-window.go
index f0cfcce..c0e426d 100644
--- a/cmds/gui-demo/demo-window.go
+++ b/cmds/gui-demo/demo-window.go
@@ -1,7 +1,14 @@
package main
+import "log"
+
import "git.wit.org/wit/gui"
+/*
+import "github.com/andlabs/ui"
+import _ "github.com/andlabs/ui/winmanifest"
+*/
+
func addDemoTab(n *gui.Node, title string) {
newNode := n.AddTab(title, nil)
if (gui.Config.Debug) {
@@ -11,7 +18,73 @@ func addDemoTab(n *gui.Node, title string) {
groupNode1 := newNode.AddGroup("group 1")
groupNode1.AddComboBox("demoCombo1", "foo", "bar", "stuff")
+ groupNode1.AddComboBox("demoCombo3", "foo 3", "bar", "stuff")
+
+ groupNode1.Dump()
+ /*
+ b := groupNode1.FindBox()
+ b.Dump()
+ */
+ // n1, b1 := addButton(groupNode1, "Data.ListChildren(false)")
+/*
+ b1.OnClicked(func(*ui.Button) {
+ gui.Data.ListChildren(false)
+ })
+*/
+
+ //n2, b2 := addButton(groupNode1, "dumpBox(window)")
+ newNode2 := groupNode1.AppendButton("foo 3 " + "AppendButton()", func(groupNode1 *gui.Node) {
+ log.Println("Dumping groupNode1")
+ groupNode1.Dump()
+ })
+ newNode2.Dump()
+/*
+ b2.OnClicked(func(*ui.Button) {
+ x := cbox.Selected()
+ log.Println("x =", x)
+ log.Println("names[x] =", names[x])
+ x.Dump(names[x])
+ })
+ n2.Dump()
+*/
groupNode2 := newNode.AddGroup("group 2")
groupNode2.AddComboBox("demoCombo2", "more 1", "more 2", "more 3")
}
+
+/*
+func addButton(n *gui.Node, name string) (*gui.Node, *ui.Button) {
+ // val := &myButtonInfo{}
+ button := ui.NewButton(name)
+ // val.uiC = button
+
+ button.OnClicked(func(*ui.Button) {
+ log.Println("Should do something here")
+ })
+
+ // n.Append(button, false)
+ newNode := n.AppendButton(name + "AppendButton", func() {
+ log.Println("Should do something here also")
+ })
+ return newNode, button
+}
+*/
+
+/*
+type myButtonInfo struct {
+ Custom func (*gui.GuiButton)
+ ADD func (*gui.GuiButton)
+ Name string
+ Action string
+ Node *gui.Node
+}
+
+func newMakeButton(n *gui.Node, name string, action string, custom func(*gui.GuiButton)) *gui.Node {
+ val := &myButtonInfo{}
+ val.Custom = custom
+ val.Name = name
+ val.Node = n
+ // val.Action = action
+ return n.CreateButton(custom, name, val)
+}
+*/
diff --git a/entry.go b/entry.go
index 12fc835..b2ef8f4 100644
--- a/entry.go
+++ b/entry.go
@@ -24,21 +24,17 @@ func (n *Node) NewLabel(text string) *Node {
return newNode
}
-func GetText(box *GuiBox, name string) string {
- if (box == nil) {
- log.Println("gui.GetText() ERROR box == nil")
- return ""
- }
- if (box.Window.EntryMap == nil) {
+func (b *GuiBox) GetText(name string) string {
+ if (b.Window.EntryMap == nil) {
log.Println("gui.GetText() ERROR b.Box.Window.EntryMap == nil")
return ""
}
- spew.Dump(box.Window.EntryMap)
- if (box.Window.EntryMap[name] == nil) {
+ spew.Dump(b.Window.EntryMap)
+ if (b.Window.EntryMap[name] == nil) {
log.Println("gui.GetText() ERROR box.Window.EntryMap[", name, "] == nil ")
return ""
}
- e := box.Window.EntryMap[name]
+ e := b.Window.EntryMap[name]
log.Println("gui.GetText() box.Window.EntryMap[", name, "] = ", e.UiEntry.Text())
log.Println("gui.GetText() END")
return e.UiEntry.Text()
diff --git a/new-structs.go b/new-structs.go
index 5ef3309..915f881 100644
--- a/new-structs.go
+++ b/new-structs.go
@@ -3,6 +3,7 @@ package gui
import (
"log"
"fmt"
+ "reflect"
// "github.com/davecgh/go-spew/spew"
@@ -50,7 +51,8 @@ type Node struct {
window *GuiWindow
box *GuiBox
- uiControl *ui.Control
+ uiControl *ui.Control
+ uiButton *ui.Button
uiWindow *ui.Window
uiTab *ui.Tab
uiBox *ui.Box
@@ -85,6 +87,7 @@ func (n *Node) Dump() {
log.Println("gui.Node.Dump() uiTab = ", n.uiTab)
log.Println("gui.Node.Dump() uiBox = ", n.uiBox)
log.Println("gui.Node.Dump() uiControl = ", n.uiControl)
+ log.Println("gui.Node.Dump() uiButton = ", n.uiButton)
if (n.id == "") {
panic("gui.Node.Dump() id == nil")
}
@@ -120,6 +123,25 @@ func (n *Node) Append(child *Node) {
// time.Sleep(3 * time.Second)
}
+func (n *Node) AppendButton(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)
+ log.Println("reflect.TypeOF(uiBox) =", reflect.TypeOf(n.uiBox))
+ log.Println("reflect.TypeOF(uiButton) =", reflect.TypeOf(button))
+ n.uiBox.Append(button, false)
+ n.uiButton = button
+ button.OnClicked(func(*ui.Button) {
+ log.Println("gui.AppendButton() Button Clicked. Running custom()")
+ custom(n)
+ })
+ // panic("AppendButton")
+ // time.Sleep(3 * time.Second)
+ return n
+}
+
func (n *Node) List() {
findByIdDFS(n, "test")
}
diff --git a/structs.go b/structs.go
index 13dc2ea..c15f4b7 100644
--- a/structs.go
+++ b/structs.go
@@ -105,11 +105,11 @@ type GuiWindow struct {
UiTab *ui.Tab // if this != nil, the window is 'tabbed'
}
-func (gw *GuiWindow) Dump() {
- log.Println("gui.GuiWindow.Dump() Name = ", gw.Name)
- log.Println("gui.GuiWindow.Dump() node = ", gw.node)
- log.Println("gui.GuiWindow.Dump() Width = ", gw.Width)
- log.Println("gui.GuiWindow.Dump() Height = ", gw.Height)
+func (w *GuiWindow) Dump() {
+ log.Println("gui.GuiWindow.Dump() Name = ", w.Name)
+ log.Println("gui.GuiWindow.Dump() node = ", w.node)
+ log.Println("gui.GuiWindow.Dump() Width = ", w.Width)
+ log.Println("gui.GuiWindow.Dump() Height = ", w.Height)
}
// GuiBox is any type of ui.Hbox or ui.Vbox
diff --git a/table.go b/table.go
index 3ed8c6a..92ae871 100644
--- a/table.go
+++ b/table.go
@@ -99,10 +99,11 @@ func InitColumns(mh *TableData, parts []TableColumnData) {
func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnData) *TableData {
node := NewWindow()
- return AddTableBox(node.box, name, rowcount, parts)
+ b := node.box
+ return b.AddTableBox(name, rowcount, parts)
}
-func AddTableBox(box *GuiBox, name string, rowcount int, parts []TableColumnData) *TableData {
+func (b *GuiBox) AddTableBox(name string, rowcount int, parts []TableColumnData) *TableData {
mh := new(TableData)
mh.RowCount = rowcount
@@ -141,9 +142,9 @@ func AddTableBox(box *GuiBox, name string, rowcount int, parts []TableColumnData
// is this needed?
// gw.BoxMap[name] = box
- mh.Box = box
+ mh.Box = b
- box.UiBox.Append(table, true)
+ b.UiBox.Append(table, true)
return mh
}