more moving of all variables into a common structure

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-22 19:11:43 -07:00
parent 9189fcde04
commit 7ea694b086
3 changed files with 53 additions and 60 deletions

32
area.go
View File

@ -7,10 +7,6 @@ import _ "github.com/andlabs/ui/winmanifest"
import "github.com/davecgh/go-spew/spew" import "github.com/davecgh/go-spew/spew"
var fontButton *ui.FontButton
var attrstr *ui.AttributedString
var splashArea *ui.Area
func areaClick(a int, b string) { func areaClick(a int, b string) {
log.Println("GOT areaClick(a,b) =", a, b) log.Println("GOT areaClick(a,b) =", a, b)
} }
@ -18,26 +14,26 @@ func areaClick(a int, b string) {
func makeSplashArea(custom func(int, string)) *ui.Area { func makeSplashArea(custom func(int, string)) *ui.Area {
// make this button just to get the default font (but don't display the button) // make this button just to get the default font (but don't display the button)
// There should be another way to do this (?) // There should be another way to do this (?)
fontButton = CreateFontButton("SplashFont", "CLOSE", custom) Data.fontButton = CreateFontButton("SplashFont", "CLOSE", custom)
makeAttributedString() makeAttributedString()
splashArea = ui.NewArea(myAH) Data.splashArea = ui.NewArea(myAH)
spew.Dump(splashArea) spew.Dump(Data.splashArea)
return splashArea return Data.splashArea
} }
func appendWithAttributes(what string, attrs ...ui.Attribute) { func appendWithAttributes(what string, attrs ...ui.Attribute) {
start := len(attrstr.String()) start := len(Data.attrstr.String())
end := start + len(what) end := start + len(what)
attrstr.AppendUnattributed(what) Data.attrstr.AppendUnattributed(what)
for _, a := range attrs { for _, a := range attrs {
attrstr.SetAttribute(a, start, end) Data.attrstr.SetAttribute(a, start, end)
} }
} }
func makeAttributedString() { func makeAttributedString() {
attrstr = ui.NewAttributedString("") Data.attrstr = ui.NewAttributedString("")
appendWithAttributes("Welcome to the Cloud Control Panel\n", ui.TextSize(16), ui.TextColor{0.0, 0.0, 0.8, .8}) // "RGBT" appendWithAttributes("Welcome to the Cloud Control Panel\n", ui.TextSize(16), ui.TextColor{0.0, 0.0, 0.8, .8}) // "RGBT"
@ -46,13 +42,13 @@ func makeAttributedString() {
appendWithAttributes("This control panel was designed to be an interface to your 'private' cloud. ", ui.TextWeightBold) appendWithAttributes("This control panel was designed to be an interface to your 'private' cloud. ", ui.TextWeightBold)
appendWithAttributes("The concept of a private cloud means that you can use a providers system, or, seemlessly, use your own hardware in your own datacenter. ", ui.TextWeightBold) appendWithAttributes("The concept of a private cloud means that you can use a providers system, or, seemlessly, use your own hardware in your own datacenter. ", ui.TextWeightBold)
attrstr.AppendUnattributed("\n") Data.attrstr.AppendUnattributed("\n")
attrstr.AppendUnattributed("\n") Data.attrstr.AppendUnattributed("\n")
appendWithAttributes("This control panel requires:\n") appendWithAttributes("This control panel requires:\n")
attrstr.AppendUnattributed("\n") Data.attrstr.AppendUnattributed("\n")
appendWithAttributes("IPv6\n") appendWithAttributes("IPv6\n")
appendWithAttributes("Your hostname in DNS\n") appendWithAttributes("Your hostname in DNS\n")
attrstr.AppendUnattributed("\n\n\n\n\n") Data.attrstr.AppendUnattributed("\n\n\n\n\n")
appendWithAttributes("<click or press any key>\n", ui.TextSize(10)) appendWithAttributes("<click or press any key>\n", ui.TextSize(10))
} }
@ -66,8 +62,8 @@ var myAH areaHandler
func (ah areaHandler) Draw(a *ui.Area, p *ui.AreaDrawParams) { func (ah areaHandler) Draw(a *ui.Area, p *ui.AreaDrawParams) {
tl := ui.DrawNewTextLayout(&ui.DrawTextLayoutParams{ tl := ui.DrawNewTextLayout(&ui.DrawTextLayoutParams{
String: attrstr, String: Data.attrstr,
DefaultFont: fontButton.Font(), DefaultFont: Data.fontButton.Font(),
Width: p.AreaWidth, Width: p.AreaWidth,
Align: ui.DrawTextAlign(1), Align: ui.DrawTextAlign(1),
}) })

View File

@ -8,9 +8,6 @@ import _ "github.com/andlabs/ui/winmanifest"
// import "github.com/davecgh/go-spew/spew" // import "github.com/davecgh/go-spew/spew"
var jcarrButton *ui.Button
var jcarrEntry *ui.MultilineEntry
func hostnameButton(hostname string) ui.Control { func hostnameButton(hostname string) ui.Control {
tmpbox := ui.NewHorizontalBox() tmpbox := ui.NewHorizontalBox()
tmpbox.SetPadded(true) tmpbox.SetPadded(true)
@ -19,8 +16,6 @@ func hostnameButton(hostname string) ui.Control {
tmpbox.Append(tmpButton, false) tmpbox.Append(tmpButton, false)
tmpButton.OnClicked(defaultButtonClick) tmpButton.OnClicked(defaultButtonClick)
jcarrButton = tmpButton
return tmpbox return tmpbox
} }
@ -34,7 +29,7 @@ func makeGroupEntries() ui.Control {
entryForm.SetPadded(true) entryForm.SetPadded(true)
group.SetChild(entryForm) group.SetChild(entryForm)
jcarrEntry = ui.NewMultilineEntry() jcarrEntry := ui.NewMultilineEntry()
entryForm.Append("Entry", ui.NewEntry(), false) entryForm.Append("Entry", ui.NewEntry(), false)
entryForm.Append("Password Entry", ui.NewPasswordEntry(), false) entryForm.Append("Password Entry", ui.NewPasswordEntry(), false)
entryForm.Append("Search Entry", ui.NewSearchEntry(), false) entryForm.Append("Search Entry", ui.NewSearchEntry(), false)
@ -134,7 +129,7 @@ func makeDataChoosersPage() ui.Control {
entry := ui.NewEntry() entry := ui.NewEntry()
entry.SetReadOnly(true) entry.SetReadOnly(true)
button.OnClicked(func(*ui.Button) { button.OnClicked(func(*ui.Button) {
filename := ui.OpenFile(mainwin) filename := ui.OpenFile(Data.mainwin)
if filename == "" { if filename == "" {
filename = "(cancelled)" filename = "(cancelled)"
} }
@ -151,7 +146,7 @@ func makeDataChoosersPage() ui.Control {
entry2 := ui.NewEntry() entry2 := ui.NewEntry()
entry2.SetReadOnly(true) entry2.SetReadOnly(true)
button.OnClicked(func(*ui.Button) { button.OnClicked(func(*ui.Button) {
filename := ui.SaveFile(mainwin) filename := ui.SaveFile(Data.mainwin)
if filename == "" { if filename == "" {
filename = "(cancelled)" filename = "(cancelled)"
} }
@ -172,7 +167,7 @@ func makeDataChoosersPage() ui.Control {
button = ui.NewButton("Message Box") button = ui.NewButton("Message Box")
button.OnClicked(func(*ui.Button) { button.OnClicked(func(*ui.Button) {
ui.MsgBox(mainwin, ui.MsgBox(Data.mainwin,
"This is a normal message box.", "This is a normal message box.",
"More detailed information can be shown here.") "More detailed information can be shown here.")
}) })
@ -181,7 +176,7 @@ func makeDataChoosersPage() ui.Control {
false, ui.AlignFill, false, ui.AlignFill) false, ui.AlignFill, false, ui.AlignFill)
button = ui.NewButton("Error Box") button = ui.NewButton("Error Box")
button.OnClicked(func(*ui.Button) { button.OnClicked(func(*ui.Button) {
ui.MsgBoxError(mainwin, ui.MsgBoxError(Data.mainwin,
"This message box describes an error.", "This message box describes an error.",
"More detailed information can be shown here.") "More detailed information can be shown here.")
}) })
@ -193,14 +188,14 @@ func makeDataChoosersPage() ui.Control {
} }
func AddChoosersDemo() { func AddChoosersDemo() {
maintab.Append("Choosers examples", makeDataChoosersPage()) Data.maintab.Append("Choosers examples", makeDataChoosersPage())
maintab.SetMargined(tabcount, true) Data.maintab.SetMargined(Data.tabcount, true)
tabcount += 1 Data.tabcount += 1
} }
// This hangs on GTK // This hangs on GTK
func AddEntriesDemo() { func AddEntriesDemo() {
maintab.Append("Group examples", makeGroupEntries()) Data.maintab.Append("Group examples", makeGroupEntries())
tabcount += 1 Data.tabcount += 1
maintab.SetMargined(tabcount, true) Data.maintab.SetMargined(Data.tabcount, true)
} }

54
gui.go
View File

@ -8,15 +8,6 @@ import _ "github.com/andlabs/ui/winmanifest"
import "github.com/gookit/config" import "github.com/gookit/config"
import "github.com/davecgh/go-spew/spew" import "github.com/davecgh/go-spew/spew"
var mainwin *ui.Window
var maintab *ui.Tab
var tabcount int
var Height int
var allButtons []ButtonMap
// //
// All GUI Data Structures and functions that are external // All GUI Data Structures and functions that are external
// If you need cross platform support, these might only // If you need cross platform support, these might only
@ -28,8 +19,19 @@ type GuiDataStructure struct {
State string State string
MainWindow *ui.Window MainWindow *ui.Window
Width int Width int
Height int
ButtonClick func(int, string) ButtonClick func(int, string)
cloudWindow *ui.Window cloudWindow *ui.Window
mainwin *ui.Window
maintab *ui.Tab
tabcount int
allButtons []ButtonMap
// stuff for the 'area'
fontButton *ui.FontButton
attrstr *ui.AttributedString
splashArea *ui.Area
} }
type TableColumnData struct { type TableColumnData struct {
@ -50,22 +52,22 @@ type ButtonMap struct {
} }
func setupUI() { func setupUI() {
mainwin = ui.NewWindow("Cloud Control Panel", Data.Width, Height, false) Data.mainwin = ui.NewWindow("Cloud Control Panel", Data.Width, Data.Height, false)
mainwin.OnClosing(func(*ui.Window) bool { Data.mainwin.OnClosing(func(*ui.Window) bool {
ui.Quit() ui.Quit()
return true return true
}) })
ui.OnShouldQuit(func() bool { ui.OnShouldQuit(func() bool {
mainwin.Destroy() Data.mainwin.Destroy()
return true return true
}) })
maintab = ui.NewTab() Data.maintab = ui.NewTab()
mainwin.SetChild(maintab) Data.mainwin.SetChild(Data.maintab)
mainwin.SetMargined(true) Data.mainwin.SetMargined(true)
tabcount = 0 Data.tabcount = 0
mainwin.Show() Data.mainwin.Show()
} }
func AddNewTab(mytab *ui.Tab, newbox ui.Control, tabOffset int) { func AddNewTab(mytab *ui.Tab, newbox ui.Control, tabOffset int) {
@ -176,12 +178,12 @@ func DoGUI() {
func defaultButtonClick(button *ui.Button) { func defaultButtonClick(button *ui.Button) {
log.Println("defaultButtonClick() button =", button) log.Println("defaultButtonClick() button =", button)
for key, foo := range allButtons { for key, foo := range Data.allButtons {
log.Println("allButtons =", key, foo) log.Println("Data.allButtons =", key, foo)
if allButtons[key].B == button { if Data.allButtons[key].B == button {
log.Println("\tBUTTON MATCHED") log.Println("\tBUTTON MATCHED")
if allButtons[key].custom != nil { if Data.allButtons[key].custom != nil {
allButtons[key].custom(42, "something foo") Data.allButtons[key].custom(42, "something foo")
} }
} }
} }
@ -189,8 +191,8 @@ func defaultButtonClick(button *ui.Button) {
func defaultFontButtonClick(button *ui.FontButton) { func defaultFontButtonClick(button *ui.FontButton) {
log.Println("defaultButtonClick() button =", button) log.Println("defaultButtonClick() button =", button)
for key, foo := range allButtons { for key, foo := range Data.allButtons {
log.Println("allButtons =", key, foo) log.Println("Data.allButtons =", key, foo)
} }
} }
@ -204,7 +206,7 @@ func CreateButton(name string, note string, custom func(int, string)) *ui.Button
newmap.note = note newmap.note = note
newmap.name = name newmap.name = name
newmap.custom = custom newmap.custom = custom
allButtons = append(allButtons, newmap) Data.allButtons = append(Data.allButtons, newmap)
return newB return newB
} }
@ -219,7 +221,7 @@ func CreateFontButton(name string, note string, custom func(int, string)) *ui.Fo
newmap.note = note newmap.note = note
newmap.name = name newmap.name = name
newmap.custom = custom newmap.custom = custom
allButtons = append(allButtons, newmap) Data.allButtons = append(Data.allButtons, newmap)
return newB return newB
} }