start using X & Y axis vars

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-06-03 00:20:28 -07:00
parent 584e3b60d4
commit b0d0c09c21
2 changed files with 68 additions and 26 deletions

90
box.go
View File

@ -1,10 +1,13 @@
package gui package gui
import "log" import "log"
// import "reflect"
import "github.com/andlabs/ui" import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest" import _ "github.com/andlabs/ui/winmanifest"
// import "github.com/davecgh/go-spew/spew"
// add(nil, newbox, "") // use this when the Window is created. Always called 'MAINBOX' // add(nil, newbox, "") // use this when the Window is created. Always called 'MAINBOX'
// add(gw.BoxMap["MAINBOX"], newbox, name) // use this to add a box off the main box // add(gw.BoxMap["MAINBOX"], newbox, name) // use this to add a box off the main box
// add(gw.BoxMap["BUTTONBOX"], newbox, name) // use this to add something to the box called 'BUTTONBOX' // add(gw.BoxMap["BUTTONBOX"], newbox, name) // use this to add something to the box called 'BUTTONBOX'
@ -43,6 +46,16 @@ func add(box *GuiBox, newbox *GuiBox) {
log.Println("\tgui.add() adding", newbox.Name, "to", box.Name) log.Println("\tgui.add() adding", newbox.Name, "to", box.Name)
// copy the box settings over // copy the box settings over
newbox.Window = box.Window newbox.Window = box.Window
if (box.UiBox == nil) {
log.Println("\tgui.add() ERROR box.UiBox == nil")
panic("crap")
}
if (newbox.UiBox == nil) {
log.Println("\tgui.add() ERROR newbox.UiBox == nil")
panic("crap")
}
// log.Println("\tgui.add() newbox.UiBox == ", newbox.UiBox.GetParent())
// spew.Dump(newbox.UiBox)
box.UiBox.Append(newbox.UiBox, false) box.UiBox.Append(newbox.UiBox, false)
// add the newbox to the Window.BoxMap[] // add the newbox to the Window.BoxMap[]
@ -50,54 +63,83 @@ func add(box *GuiBox, newbox *GuiBox) {
log.Println("gui.add() END") log.Println("gui.add() END")
} }
/*
func HardHorizontalBox(gw *GuiWindow) *GuiBox { func HardHorizontalBox(gw *GuiWindow) *GuiBox {
log.Println("HardHorizontalBreak START") log.Println("HardHorizontalBreak START")
box := gw.BoxMap["MAINBOX"]
if (box != nil) { HorizontalBreak(box) }
var newbox *GuiBox var newbox *GuiBox
newbox = new(GuiBox) newbox = new(GuiBox)
newbox.Window = gw newbox.Window = gw
box := gw.BoxMap["MAINBOX"]
if (box != nil) {
// There is already a box. Add a Seperator
tmp := ui.NewHorizontalSeparator()
box.UiBox.Append(tmp, true)
add(gw.BoxMap["MAINBOX"], newbox)
}
hbox := ui.NewVerticalBox() hbox := ui.NewVerticalBox()
hbox.SetPadded(true) hbox.SetPadded(true)
newbox.UiBox = hbox newbox.UiBox = hbox
newbox.Name = "Hbox1" newbox.Name = "Hbox1 HARD"
add(gw.BoxMap["MAINBOX"], newbox) add(gw.BoxMap["MAINBOX"], newbox)
log.Println("HardHorizontalBreak END") log.Println("HardHorizontalBreak END")
return newbox return newbox
} }
*/
func HardVerticalBreak(box *GuiBox) { func VerticalBox(box *GuiBox, name string) *GuiBox {
log.Println("HardVerticalBreak START") log.Println("VerticalBox START")
gw := box.Window var newbox *GuiBox
mainbox := gw.BoxMap["MAIN"] newbox = new(GuiBox)
if (mainbox == nil) { newbox.Window = box.Window
log.Println("HardHorizontalBreak ERROR MAIN box == nil") newbox.Name = name
return
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
newbox.UiBox = vbox
add(box, newbox)
return newbox
}
func HardBox(gw *GuiWindow, axis int) *GuiBox {
log.Println("HardBox() START axis =", axis)
// add a Vertical Seperator if there is already a box
// Is this right?
box := gw.BoxMap["MAINBOX"]
if (box != nil) {
if (axis == Xaxis) {
VerticalBreak(box)
} else {
HorizontalBreak(box)
}
} }
tmp := ui.NewVerticalSeparator() // make the new vbox
mainbox.UiBox.Append(tmp, false) var uiBox *ui.Box
if (axis == Xaxis) {
uiBox = ui.NewHorizontalBox()
} else {
uiBox = ui.NewVerticalBox()
}
uiBox.SetPadded(true)
hbox := ui.NewVerticalBox() // Init a new GuiBox
hbox.SetPadded(true) newbox := new(GuiBox)
box.UiBox = hbox newbox.Window = gw
mainbox.UiBox.Append(hbox, false) newbox.UiBox = uiBox
log.Println("HardVerticalBreak END") newbox.Name = "Vbox1 HARD"
add(gw.BoxMap["MAINBOX"], newbox)
log.Println("HardBoxk END")
return newbox
} }
func HorizontalBreak(box *GuiBox) { func HorizontalBreak(box *GuiBox) {
log.Println("VerticalSeparator added to box =", box.Name)
tmp := ui.NewHorizontalSeparator() tmp := ui.NewHorizontalSeparator()
box.UiBox.Append(tmp, false) box.UiBox.Append(tmp, false)
} }
func VerticalBreak(box *GuiBox) { func VerticalBreak(box *GuiBox) {
log.Println("VerticalSeparator added to box =", box.Name)
tmp := ui.NewVerticalSeparator() tmp := ui.NewVerticalSeparator()
box.UiBox.Append(tmp, false) box.UiBox.Append(tmp, false)
} }

4
gui.go
View File

@ -7,8 +7,8 @@ import "regexp"
import "github.com/andlabs/ui" import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest" import _ "github.com/andlabs/ui/winmanifest"
const Xaxis = 0 const Xaxis = 0 // box that is horizontal
const Yaxis = 1 const Yaxis = 1 // box that is vertical
func GuiInit() { func GuiInit() {
Data.buttonMap = make(map[*ui.Button]*GuiButton) Data.buttonMap = make(map[*ui.Button]*GuiButton)