diff --git a/box.go b/box.go index ef7c265..9d9833d 100644 --- a/box.go +++ b/box.go @@ -73,18 +73,18 @@ func add(box *GuiBox, newbox *GuiBox) { log.Println("gui.add() END") } -func (n *Node) NewBox(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") - } - +func (n *Node) AddBox(axis int, name string) *Node { newBox := new(GuiBox) newBox.Window = n.window newBox.Name = name + if (n.box == nil) { + n.box = newBox + } + // make a new box & a new node newNode := n.makeNode(name, 111, 100 + Config.counter) + newNode.box = newBox Config.counter += 1 var uiBox *ui.Box diff --git a/button.go b/button.go index 825b79b..d616178 100644 --- a/button.go +++ b/button.go @@ -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 { newUiB := ui.NewButton(name) newUiB.OnClicked(defaultButtonClick) diff --git a/find.go b/find.go index 9f849e7..e046161 100644 --- a/find.go +++ b/find.go @@ -18,6 +18,13 @@ func (n *Node) FindControl() *ui.Control { } 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 }