diff --git a/area.go b/area.go index 7c42c6c..d25bd74 100644 --- a/area.go +++ b/area.go @@ -7,19 +7,19 @@ import _ "github.com/andlabs/ui/winmanifest" import "github.com/davecgh/go-spew/spew" -func makeGenericArea(gb *GuiBox, newText *ui.AttributedString, custom func(*GuiButton)) { +func makeGenericArea(n *Node, newText *ui.AttributedString, custom func(*GuiButton)) { // make this button just to get the default font (but don't display the button) // There should be another way to do this (?) var newB *GuiButton - newB = CreateFontButton(gb, "AREA") - newB.Box = gb + newB = CreateFontButton(n, "AREA") + // newB.Box = gb newB.Custom = custom - gw := gb.Window + gw := n.window // initialize the GuiArea{} gw.Area = new(GuiArea) gw.Area.Button = newB - gw.Area.Box = gb + // gw.Area.Box = gb gw.Area.UiAttrstr = newText gw.Area.UiArea = ui.NewArea(gw.Area) @@ -107,10 +107,10 @@ func (ah GuiArea) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) { return false } -func (b *GuiBox) ShowTextBox(newText *ui.AttributedString, custom func(*GuiButton), name string) { +func (n *Node) ShowTextBox(newText *ui.AttributedString, custom func(*GuiButton), name string) { log.Println("ShowTextBox() START") - gw := b.Window + gw := n.Window if (gw == nil) { log.Println("ShowTextBox() ERROR gw = nil") return @@ -127,10 +127,10 @@ func (b *GuiBox) ShowTextBox(newText *ui.AttributedString, custom func(*GuiButto */ // TODO: allow padded & axis here - b.UiBox.SetPadded(true) + n.uiBox.SetPadded(true) // add(gw.BoxMap["MAINBOX"], newbox) - makeGenericArea(b, newText, custom) - b.UiBox.Append(b.Window.Area.UiArea, true) + makeGenericArea(n, newText, custom) + n.uiBox.Append(n.area.UiArea, true) } diff --git a/button.go b/button.go index 4d4e1d0..8135962 100644 --- a/button.go +++ b/button.go @@ -19,40 +19,6 @@ import _ "github.com/andlabs/ui/winmanifest" // 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 - } - } - log.Println("\tgui.defaultButtonClick() ERROR: BUTTON NOT FOUND") - if (Config.Debug) { - panic("gui.defaultButtonClick() ERROR: UNMAPPED ui.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") - } -} -*/ func (n *Node) AddButton(name string, custom func(*Node)) *Node { if (n.uiBox == nil) { @@ -79,66 +45,12 @@ func (n *Node) AddButton(name string, custom func(*Node)) *Node { return newNode } -/* -func (n *Node) CreateButton(custom func(*GuiButton), name string, values interface {}) *Node { - newNode := n.AddBox(Xaxis, "test CreateButton") - 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?") - } else { - // uibox := box.UiBox - // uibox.Append(newUiB, true) - } - 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) - - 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 - - Data.AllButtons = append(Data.AllButtons, newB) - - box.Append(newB.B, false) - return newB -} -*/ - -func CreateFontButton(box *GuiBox, action string) *GuiButton { +func CreateFontButton(n *Node, action string) *GuiButton { // create a 'fake' button entry for the mouse clicks var newGB GuiButton newGB.Name = "FONT" newGB.FB = ui.NewFontButton() - newGB.Box = box + newGB.Box = n.box Data.AllButtons = append(Data.AllButtons, &newGB) newGB.FB.OnChanged(func (*ui.FontButton) { @@ -150,12 +62,12 @@ func CreateFontButton(box *GuiBox, action string) *GuiButton { return &newGB } -func CreateColorButton(box *GuiBox, custom func(*GuiButton), name string, values interface {}) *GuiButton { +func CreateColorButton(n *Node, custom func(*GuiButton), name string, values interface {}) *GuiButton { // create a 'fake' button entry for the mouse clicks var newCB GuiButton newCB.Name = name newCB.CB = ui.NewColorButton() - newCB.Box = box + newCB.Box = n.box newCB.Custom = custom newCB.Values = values @@ -171,6 +83,6 @@ func CreateColorButton(box *GuiBox, custom func(*GuiButton), name string, values Data.MouseClick(&newCB) } }) - box.Append(newCB.CB, false) + n.box.Append(newCB.CB, false) return &newCB } diff --git a/find.go b/find.go index 7323596..619ba36 100644 --- a/find.go +++ b/find.go @@ -17,44 +17,10 @@ func (n *Node) FindControl() *ui.Control { return n.uiControl } -/* -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 -} - -func (n *Node) FindWindowBox() *GuiBox { - if (n.box == nil) { - panic("SERIOUS ERROR n.box == nil in FindWindowBox()") - } - return n.box -} -*/ - func (w *GuiWindow) FindNode() *Node { return w.node } -/* -func (b *GuiBox) FindNode() *Node { - log.Println("gui.FindNode() on GuiBox") - if b.node != nil { - return b.node - } - Data.ListChildren(true) - b.Dump() - log.Println("gui.FindNode() on GuiBox is nil") - os.Exit(-1) - return nil -} -*/ - func FindWindow(s string) *GuiWindow { for name, window := range Data.WindowMap { if name == s { @@ -65,21 +31,6 @@ func FindWindow(s string) *GuiWindow { return nil } -func FindBox(s string) *GuiBox { - for name, window := range Data.WindowMap { - if name != s { - continue - } - for name, abox := range window.BoxMap { - log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) - return abox - } - log.Println("gui.FindBox() NEED TO INIT WINDOW name =", name) - } - log.Println("gui.FindBox() COULD NOT FIND BOX", s) - return nil -} - func FindNode(name string) *Node { if Data.NodeMap == nil { log.Println("gui.FindNode() gui.Data.NodeMap == nil") diff --git a/new-structs.go b/new-structs.go index 109b4af..8097fbc 100644 --- a/new-structs.go +++ b/new-structs.go @@ -51,6 +51,7 @@ type Node struct { window *GuiWindow box *GuiBox + area *GuiArea custom func(*Node) uiControl *ui.Control