REFACTOR: remove GuiWindow & GuiBox

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2021-10-31 21:46:30 -05:00
parent d6980daa81
commit db6c60decc
9 changed files with 45 additions and 211 deletions

14
area.go
View File

@ -12,22 +12,24 @@ func makeGenericArea(n *Node, newText *ui.AttributedString, custom func(*GuiButt
// There should be another way to do this (?)
var newB *GuiButton
newB = CreateFontButton(n, "AREA")
// newB.Box = gb
newB.Custom = custom
/*
gw := n.window
// initialize the GuiArea{}
gw.Area = new(GuiArea)
gw.Area.Button = newB
*/
area := new(GuiArea)
// gw.Area.Box = gb
gw.Area.UiAttrstr = newText
gw.Area.UiArea = ui.NewArea(gw.Area)
n.uiAttrstr = newText
n.uiArea = ui.NewArea(area)
if (Config.Debug) {
spew.Dump(gw.Area.UiArea)
spew.Dump(n.uiArea)
log.Println("DEBUGGING", Config.Debug)
} else {
log.Println("NOT DEBUGGING AREA mhAH.Button =", gw.Area.Button)
log.Println("NOT DEBUGGING AREA mhAH.Button =", n.uiButton)
}
}

View File

@ -7,7 +7,7 @@ import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"github.com/davecgh/go-spew/spew"
// "github.com/davecgh/go-spew/spew"
)
var names = make([]string, 100)
@ -33,6 +33,7 @@ func makeWindowDebug() *ui.Box {
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
/*
/////////////////////////////////////////////////////
vbox := addGroup(hbox, "range Data.WindowMap")
cbox := ui.NewCombobox()
@ -44,7 +45,6 @@ func makeWindowDebug() *ui.Box {
addName(cbox, name)
}
cbox.SetSelected(0)
vbox.Append(cbox, false)
cbox.OnSelected(func(*ui.Combobox) {
@ -65,76 +65,6 @@ func makeWindowDebug() *ui.Box {
dumpBox(names[x])
})
b2 := addButton(vbox, "SetMargined(tab)")
b2.OnClicked(func(*ui.Button) {
x := cbox.Selected()
log.Println("x =", x)
log.Println("FindWindow; names[x] =", names[x])
gw := FindWindow(names[x])
if gw == nil {
return
}
if gw.UiTab == nil {
return
}
if gw.TabNumber == nil {
return
}
scs := spew.ConfigState{MaxDepth: 1}
scs.Dump(gw)
log.Println("gui.DumpBoxes()\tWindow.UiTab =", gw.UiTab)
log.Println("gui.DumpBoxes()\tWindow.TabNumber =", *gw.TabNumber)
gw.UiTab.SetMargined(*gw.TabNumber, true)
})
b3 := addButton(vbox, "Hide(tab)")
b3.OnClicked(func(*ui.Button) {
x := cbox.Selected()
log.Println("x =", x)
log.Println("FindWindow; names[x] =", names[x])
gw := FindWindow(names[x])
if gw == nil {
return
}
if gw.UiTab == nil {
return
}
gw.UiTab.Hide()
})
b4 := addButton(vbox, "Show(tab)")
b4.OnClicked(func(*ui.Button) {
x := cbox.Selected()
log.Println("x =", x)
log.Println("FindWindow; names[x] =", names[x])
gw := FindWindow(names[x])
if gw == nil {
return
}
if gw.UiTab == nil {
return
}
gw.UiTab.Show()
})
b5 := addButton(vbox, "Delete(tab)")
b5.OnClicked(func(*ui.Button) {
x := cbox.Selected()
log.Println("x =", x)
log.Println("FindWindow; names[x] =", names[x])
gw := FindWindow(names[x])
if gw == nil {
return
}
if gw.UiTab == nil {
return
}
if gw.TabNumber == nil {
return
}
gw.UiTab.Delete(*gw.TabNumber)
})
/////////////////////////////////////////////////////
vbox = addGroup(hbox, "Global Debug")
@ -152,6 +82,7 @@ func makeWindowDebug() *ui.Box {
dump1.OnClicked(func(*ui.Button) {
DumpMap()
})
*/
/////////////////////////////////////////////////////
nodeBox := addGroup(hbox, "Windows:")
@ -179,7 +110,7 @@ func makeWindowDebug() *ui.Box {
})
/////////////////////////////////////////////////////
vbox = addGroup(hbox, "Node Debug")
vbox := addGroup(hbox, "Node Debug")
n1 := addButton(vbox, "Data.DumpNodeMap()")
n1.OnClicked(func(*ui.Button) {
@ -277,6 +208,7 @@ func addGroup(b *ui.Box, name string) *ui.Box {
return vbox
}
/*
func dumpBox(s string) {
var name string
var window *GuiWindow
@ -295,20 +227,6 @@ func dumpBox(s string) {
// log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow))
log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow)
log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab)
/*
log.Println("gui.dumpBox() BoxMap START")
for name, abox := range window.BoxMap {
log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name)
abox.Dump()
if name == "MAINBOX" {
if Config.Debug {
scs := spew.ConfigState{MaxDepth: 1}
scs.Dump(abox.UiBox)
}
}
}
log.Println("gui.dumpBox() BoxMap END")
*/
if window.UiTab != nil {
pages := window.UiTab.NumPages()
log.Println("gui.DumpBoxes()\tWindow.UiTab.NumPages() =", pages)
@ -320,6 +238,7 @@ func dumpBox(s string) {
}
}
}
*/
func addButton(box *ui.Box, name string) *ui.Button {
button := ui.NewButton(name)

View File

@ -5,7 +5,7 @@ import (
"log"
"time"
"github.com/davecgh/go-spew/spew"
// "github.com/davecgh/go-spew/spew"
)
// WatchGUI() opens a goroutine
@ -22,7 +22,7 @@ func WatchGUI() {
if count > 20 {
log.Println("Sleep() in watchGUI()")
if Config.Debug {
DumpBoxes()
// DumpBoxes()
}
count = 0
}
@ -31,6 +31,7 @@ func WatchGUI() {
}
}
/*
func DumpWindows() {
for name, _ := range Data.WindowMap {
log.Println("gui.DumpWindows() window =", name)
@ -41,11 +42,9 @@ func DumpMap() {
for name, window := range Data.WindowMap {
log.Println("gui.DumpBoxes() MAP: ", name)
log.Println("gui.DumpBoxes() window:", window)
/*
for name, abox := range window.BoxMap {
log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name)
}
*/
}
}
@ -61,7 +60,6 @@ func DumpBoxes() {
// log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow))
log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow)
log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab)
/*
for name, abox := range window.BoxMap {
log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name)
if name == "MAINBOX" {
@ -71,7 +69,6 @@ func DumpBoxes() {
}
}
}
*/
if window.UiTab != nil {
// log.Println("gui.DumpBoxes()\tWindow.UiTab type =", reflect.TypeOf(window.UiTab))
// log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab)
@ -89,7 +86,6 @@ func DumpBoxes() {
}
}
}
/*
for i, window := range Data.Windows {
if (window.TabNumber == nil) {
log.Println("gui.DumpBoxes() Data.Windows", i, "Name =", window.Name, "TabNumber = nil")
@ -97,8 +93,8 @@ func DumpBoxes() {
log.Println("gui.DumpBoxes() Data.Windows", i, "Name =", window.Name, "TabNumber =", *window.TabNumber)
}
}
*/
}
*/
func addTableTab() {
var parts []TableColumnData

12
find.go
View File

@ -17,19 +17,11 @@ func (n *Node) FindControl() *ui.Control {
return n.uiControl
}
/*
func (w *GuiWindow) FindNode() *Node {
return w.node
}
func FindWindow(s string) *GuiWindow {
for name, window := range Data.WindowMap {
if name == s {
return window
}
}
log.Printf("COULD NOT FIND WINDOW " + s)
return nil
}
*/
func FindNode(name string) *Node {
if Data.NodeMap == nil {

2
gui.go
View File

@ -17,7 +17,7 @@ func init() {
log.Println("gui.init() has been run")
Data.buttonMap = make(map[*ui.Button]*GuiButton)
Data.WindowMap = make(map[string]*GuiWindow)
// Data.WindowMap = make(map[string]*GuiWindow)
Data.NodeMap = make(map[string]*Node)
Data.NodeSlice = make([]*Node, 0)

View File

@ -49,16 +49,18 @@ type Node struct {
parent *Node
children []*Node
window *GuiWindow
// window *GuiWindow
area *GuiArea
custom func(*Node)
uiControl *ui.Control
uiButton *ui.Button
uiWindow *ui.Window
uiTab *ui.Tab
uiBox *ui.Box
uiText *ui.EditableCombobox
uiAttrstr *ui.AttributedString
uiTab *ui.Tab
uiBox *ui.Box
uiArea *ui.Area
uiText *ui.EditableCombobox
}
func (n *Node) Parent() *Node {
@ -83,7 +85,7 @@ func (n *Node) Dump() {
}
log.Println("gui.Node.Dump() children = ", n.children)
log.Println("gui.Node.Dump() window = ", n.window)
// log.Println("gui.Node.Dump() window = ", n.window)
// log.Println("gui.Node.Dump() box = ", n.box)
log.Println("gui.Node.Dump() uiWindow = ", n.uiWindow)

View File

@ -2,7 +2,7 @@ package gui
import (
"image/color"
"log"
// "log"
"github.com/andlabs/ui"
"golang.org/x/image/font"
@ -42,7 +42,7 @@ type GuiData struct {
// A map of all the entry boxes
AllEntries []*GuiEntry
WindowMap map[string]*GuiWindow
// WindowMap map[string]*GuiWindow
// Store access to everything via binary tree's
NodeMap map[string]*Node
@ -62,7 +62,7 @@ type GuiData struct {
type GuiTab struct {
Name string // field for human readable name
Number int // the andlabs/ui tab index
Window *GuiWindow // the parent Window
// Window *GuiWindow // the parent Window
}
//
@ -83,6 +83,7 @@ type GuiTab struct {
// This struct keeps track of what is in the window so you
// can destroy and replace it with something else
//
/*
type GuiWindow struct {
Name string // field for human readable name
Width int
@ -90,11 +91,7 @@ type GuiWindow struct {
Axis int // does it add items to the X or Y axis
TabNumber *int // the andlabs/ui tab index
// the callback function to make the window contents
// MakeWindow func(*GuiBox) *GuiBox
// the components of the window
// BoxMap map[string]*GuiBox
EntryMap map[string]*GuiEntry
Area *GuiArea
@ -104,7 +101,9 @@ type GuiWindow struct {
UiWindow *ui.Window
UiTab *ui.Tab // if this != nil, the window is 'tabbed'
}
*/
/*
func (w *GuiWindow) Dump() {
log.Println("gui.GuiWindow.Dump() Name = ", w.Name)
log.Println("gui.GuiWindow.Dump() node = ", w.node)
@ -112,43 +111,6 @@ func (w *GuiWindow) Dump() {
log.Println("gui.GuiWindow.Dump() Height = ", w.Height)
}
/*
// GuiBox is any type of ui.Hbox or ui.Vbox
// There can be lots of these for each GuiWindow
type GuiBox struct {
Name string // field for human readable name
Axis int // does it add items to the X or Y axis
Window *GuiWindow // the parent Window
node *Node
// andlabs/ui abstraction mapping
UiBox *ui.Box
}
*/
/*
func (b *GuiBox) Dump() {
log.Println("gui.GuiBox.Dump() Name = ", b.Name)
log.Println("gui.GuiBox.Dump() Axis = ", b.Axis)
log.Println("gui.GuiBox.Dump() GuiWindow = ", b.Window)
log.Println("gui.GuiBox.Dump() node = ", b.node)
log.Println("gui.GuiBox.Dump() UiBox = ", b.UiBox)
}
func (b *GuiBox) SetTitle(title string) {
log.Println("DID IT!", title)
if b.Window == nil {
return
}
if b.Window.UiWindow == nil {
return
}
b.Window.UiWindow.SetTitle(title)
return
}
*/
func (w *GuiWindow) SetNode(n *Node) {
if (w.node != nil) {
w.Dump()
@ -160,27 +122,6 @@ func (w *GuiWindow) SetNode(n *Node) {
panic("gui.SetNode() node == nil")
}
}
/*
func (b *GuiBox) SetNode(n *Node) {
if (b.node != nil) {
b.Dump()
panic("gui.SetNode() Error not nil")
}
b.node = n
if (b.node == nil) {
b.Dump()
panic("gui.SetNode() node == nil")
}
}
func (b *GuiBox) Append(child ui.Control, x bool) {
if b.UiBox == nil {
panic("GuiBox.Append() can't work. UiBox == nil")
return
}
b.UiBox.Append(child, x)
}
*/
// Note: every mouse click is handled
@ -189,7 +130,6 @@ func (b *GuiBox) Append(child ui.Control, x bool) {
// call this 'GuiMouseClick'
type GuiButton struct {
Name string // field for human readable name
// box2 *GuiBox // what box the button click was in
// a callback function for the main application
Custom func(*GuiButton)
@ -210,7 +150,6 @@ type GuiEntry struct {
Normalize func(string) string // function to 'normalize' the data
B *GuiButton
// Box *GuiBox
// andlabs/ui abstraction mapping
UiEntry *ui.Entry
@ -223,7 +162,6 @@ type GuiEntry struct {
//
type GuiArea struct {
Button *GuiButton // what button handles mouse events
// Box *GuiBox
UiAttrstr *ui.AttributedString
UiArea *ui.Area
@ -261,7 +199,6 @@ type TableData struct {
Cells [20]CellData
Human [20]HumanMap
// Box *GuiBox
n *Node
lastRow int

View File

@ -97,7 +97,7 @@ func InitColumns(mh *TableData, parts []TableColumnData) {
}
}
func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnData) *TableData {
func AddTableTab(name string, rowcount int, parts []TableColumnData) *TableData {
n := NewWindow()
return n.AddTableBox(name, rowcount, parts)
}

View File

@ -9,14 +9,19 @@ import (
_ "github.com/andlabs/ui/winmanifest"
)
func MessageWindow(gw *GuiWindow, msg1 string, msg2 string) {
ui.MsgBox(gw.UiWindow, msg1, msg2)
func (n *Node) MessageWindow2(msg1 string, msg2 string) (*Node) {
ui.MsgBox(n.uiWindow, msg1, msg2)
// TODO: make new node
return n
}
func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) {
ui.MsgBoxError(gw.UiWindow, msg1, msg2)
func (n *Node) ErrorWindow2(msg1 string, msg2 string) (*Node) {
ui.MsgBoxError(n.uiWindow, msg1, msg2)
// TODO: make new node
return n
}
/*
func DeleteWindow(name string) {
log.Println("gui.DeleteWindow() START name =", name)
window := Data.WindowMap[name]
@ -51,6 +56,7 @@ func DeleteWindow(name string) {
}
}
}
*/
func makeNode(parent *Node, title string, x int, y int) *Node {
var node Node
@ -137,26 +143,6 @@ func (n *Node) uiNewWindow(title string, x int, y int) {
func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Node {
log.Println("gui.WindowMap START title =", title)
if Data.WindowMap[title] != nil {
log.Println("Data.WindowMap[title] already exists title =", title)
title = title + Config.prefix + strconv.Itoa(Config.counter)
Config.counter += 1
}
if Data.WindowMap[title] != nil {
log.Println("Data.WindowMap[title] already exists title =", title)
panic("Data.WindowMap[newGuiWindow.Name] already exists")
return nil
}
var newGuiWindow GuiWindow
newGuiWindow.Width = x
newGuiWindow.Height = y
newGuiWindow.Name = title
newGuiWindow.UiWindow = window
newGuiWindow.EntryMap = make(map[string]*GuiEntry)
Data.WindowMap[newGuiWindow.Name] = &newGuiWindow
node := makeNode(parent, title, x, y)
node.uiWindow = window