BOX: start node.button() funcs in the rabbit hole

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2021-10-28 19:47:49 -05:00
parent 8a87d0cb59
commit 15f9f92c62
3 changed files with 39 additions and 6 deletions

12
box.go
View File

@ -73,18 +73,18 @@ func add(box *GuiBox, newbox *GuiBox) {
log.Println("gui.add() END") log.Println("gui.add() END")
} }
func (n *Node) NewBox(axis int, name string) *Node { func (n *Node) AddBox(axis int, name string) *Node {
if (n.box == nil) {
log.Println("box == nil. I can't add a box!")
panic("gui.Node.NewBox() node.box == nil")
}
newBox := new(GuiBox) newBox := new(GuiBox)
newBox.Window = n.window newBox.Window = n.window
newBox.Name = name newBox.Name = name
if (n.box == nil) {
n.box = newBox
}
// make a new box & a new node // make a new box & a new node
newNode := n.makeNode(name, 111, 100 + Config.counter) newNode := n.makeNode(name, 111, 100 + Config.counter)
newNode.box = newBox
Config.counter += 1 Config.counter += 1
var uiBox *ui.Box var uiBox *ui.Box

View File

@ -50,6 +50,32 @@ func guiButtonClick(button *GuiButton) {
} }
} }
func (n *Node) CreateButton(custom func(*GuiButton), name string, values interface {}) *Node {
newNode := n.AddBox(Xaxis, "test")
box := newNode.FindBox()
if (box == nil) {
panic("node.CreateButton().FindBox() == nil")
}
newUiB := ui.NewButton(name)
newUiB.OnClicked(defaultButtonClick)
var newB *GuiButton
newB = new(GuiButton)
newB.B = newUiB
if (box.UiBox == 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
Data.AllButtons = append(Data.AllButtons, newB)
box.Append(newB.B, false)
return newNode
}
func CreateButton(box *GuiBox, custom func(*GuiButton), name string, values interface {}) *GuiButton { func CreateButton(box *GuiBox, custom func(*GuiButton), name string, values interface {}) *GuiButton {
newUiB := ui.NewButton(name) newUiB := ui.NewButton(name)
newUiB.OnClicked(defaultButtonClick) newUiB.OnClicked(defaultButtonClick)

View File

@ -18,6 +18,13 @@ func (n *Node) FindControl() *ui.Control {
} }
func (n *Node) FindBox() *GuiBox { func (n *Node) FindBox() *GuiBox {
if (n.box != nil) {
return n.box
}
if (n.parent != nil) {
p := n.parent
return p.box
}
return n.box return n.box
} }