I guess all GUI stuff must go in here. No other goroutine can ever
interact with the GUI or Windows cross platform support breaks. Lame Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
5c07e5f605
commit
522581dbaf
|
@ -0,0 +1,65 @@
|
|||
package gui
|
||||
|
||||
import "log"
|
||||
|
||||
import "github.com/andlabs/ui"
|
||||
import _ "github.com/andlabs/ui/winmanifest"
|
||||
|
||||
// import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
func AddAccountWindow() {
|
||||
accounthWin := ui.NewWindow("Add Account", 400, 300, false)
|
||||
accounthWin.OnClosing(func(*ui.Window) bool {
|
||||
ui.Quit()
|
||||
return true
|
||||
})
|
||||
ui.OnShouldQuit(func() bool {
|
||||
accounthWin.Destroy()
|
||||
return true
|
||||
})
|
||||
|
||||
vbox := ui.NewVerticalBox()
|
||||
vbox.SetPadded(true)
|
||||
accounthWin.SetChild(vbox)
|
||||
accounthWin.SetMargined(true)
|
||||
|
||||
// This displays the window
|
||||
accounthWin.Show()
|
||||
|
||||
// START create new account button
|
||||
newAccountButton := ui.NewButton("Create New Account")
|
||||
newAccountButton.OnClicked(func(*ui.Button) {
|
||||
log.Println("OK. Closing window.")
|
||||
accounthWin.Destroy()
|
||||
ui.Quit()
|
||||
})
|
||||
vbox.Append(newAccountButton, false)
|
||||
// END create new account button
|
||||
|
||||
vbox.Append(ui.NewHorizontalSeparator(), false)
|
||||
|
||||
okButton := ui.NewButton("I Have an Account")
|
||||
okButton.OnClicked(func(*ui.Button) {
|
||||
log.Println("OK. Closing window.")
|
||||
accounthWin.Destroy()
|
||||
ui.Quit()
|
||||
})
|
||||
vbox.Append(okButton, false)
|
||||
// END add account hbox
|
||||
}
|
||||
|
||||
func AddAccountBox(junk *ui.Box, custom func(int, string)) *ui.Box {
|
||||
newbox := ui.NewVerticalBox()
|
||||
newbox.SetPadded(true)
|
||||
|
||||
// create new account button
|
||||
newButton := CreateButton("Create New Account", "CLOSE", custom)
|
||||
newbox.Append(newButton, false)
|
||||
|
||||
newbox.Append(ui.NewHorizontalSeparator(), false)
|
||||
|
||||
okButton := CreateButton("I Have an Account", "CLOSE", custom)
|
||||
newbox.Append(okButton, false)
|
||||
|
||||
return newbox
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
package gui
|
||||
|
||||
import "log"
|
||||
|
||||
import "github.com/andlabs/ui"
|
||||
import _ "github.com/andlabs/ui/winmanifest"
|
||||
|
||||
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) {
|
||||
log.Println("GOT areaClick(a,b) =", a, b)
|
||||
}
|
||||
|
||||
func makeSplashArea(custom func(int, string)) *ui.Area {
|
||||
// make this button just to get the default font (but don't display the button)
|
||||
// There should be another way to do this (?)
|
||||
fontButton = CreateFontButton("SplashFont", "CLOSE", custom)
|
||||
|
||||
makeAttributedString()
|
||||
splashArea = ui.NewArea(myAH)
|
||||
|
||||
spew.Dump(splashArea)
|
||||
return splashArea
|
||||
}
|
||||
|
||||
func appendWithAttributes(what string, attrs ...ui.Attribute) {
|
||||
start := len(attrstr.String())
|
||||
end := start + len(what)
|
||||
attrstr.AppendUnattributed(what)
|
||||
for _, a := range attrs {
|
||||
attrstr.SetAttribute(a, start, end)
|
||||
}
|
||||
}
|
||||
|
||||
func makeAttributedString() {
|
||||
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("(alpha)\n\n", ui.TextSize(10))
|
||||
|
||||
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)
|
||||
|
||||
attrstr.AppendUnattributed("\n")
|
||||
attrstr.AppendUnattributed("\n")
|
||||
appendWithAttributes("This control panel requires:\n")
|
||||
attrstr.AppendUnattributed("\n")
|
||||
appendWithAttributes("IPv6\n")
|
||||
appendWithAttributes("Your hostname in DNS\n")
|
||||
attrstr.AppendUnattributed("\n\n\n\n\n")
|
||||
|
||||
appendWithAttributes("<click or press any key>\n", ui.TextSize(10))
|
||||
}
|
||||
|
||||
type areaHandler struct{
|
||||
buttonFunc func(int, int)
|
||||
closeFunc func(int)
|
||||
}
|
||||
|
||||
var myAH areaHandler
|
||||
|
||||
func (ah areaHandler) Draw(a *ui.Area, p *ui.AreaDrawParams) {
|
||||
tl := ui.DrawNewTextLayout(&ui.DrawTextLayoutParams{
|
||||
String: attrstr,
|
||||
DefaultFont: fontButton.Font(),
|
||||
Width: p.AreaWidth,
|
||||
Align: ui.DrawTextAlign(1),
|
||||
})
|
||||
p.Context.Text(tl, 0, 0)
|
||||
defer tl.Free()
|
||||
}
|
||||
|
||||
func (ah areaHandler) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {
|
||||
log.Println("GOT MouseEvent()")
|
||||
spew.Dump(me)
|
||||
if (me.Down == 1) {
|
||||
log.Println("GOT MOUSE DOWN")
|
||||
log.Println("GOT MOUSE DOWN")
|
||||
log.Println("GOT MOUSE DOWN")
|
||||
}
|
||||
if (me.Up == 1) {
|
||||
log.Println("GOT MOUSE UP")
|
||||
log.Println("GOT MOUSE UP")
|
||||
log.Println("GOT MOUSE UP")
|
||||
// splashWin.Destroy()
|
||||
// ui.Quit()
|
||||
}
|
||||
areaClick(1, "done")
|
||||
}
|
||||
|
||||
func (ah areaHandler) MouseCrossed(a *ui.Area, left bool) {
|
||||
log.Println("GOT MouseCrossed()")
|
||||
}
|
||||
|
||||
func (ah areaHandler) DragBroken(a *ui.Area) {
|
||||
log.Println("GOT DragBroken()")
|
||||
}
|
||||
|
||||
func (ah areaHandler) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) {
|
||||
log.Println("GOT KeyEvent()")
|
||||
if (ke.Key == 10) {
|
||||
log.Println("GOT ENTER")
|
||||
log.Println("GOT ENTER")
|
||||
log.Println("GOT ENTER")
|
||||
}
|
||||
if (ke.Key == 32) {
|
||||
log.Println("GOT ENTER")
|
||||
log.Println("GOT ENTER")
|
||||
log.Println("GOT ENTER")
|
||||
}
|
||||
spew.Dump(ke)
|
||||
// splashWin.Destroy()
|
||||
// ui.Quit()
|
||||
return false
|
||||
}
|
20
examples.go
20
examples.go
|
@ -1,35 +1,23 @@
|
|||
package gui
|
||||
|
||||
import "log"
|
||||
// import "log"
|
||||
|
||||
import "github.com/gookit/config"
|
||||
// import "github.com/gookit/config"
|
||||
import "github.com/andlabs/ui"
|
||||
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 buttonClick(button *ui.Button) {
|
||||
log.Println("hostname =", config.String("hostname"), button)
|
||||
spew.Dump(button)
|
||||
if (jcarrButton == button) {
|
||||
log.Println("This is the jcarrButton")
|
||||
cur := jcarrEntry.Text()
|
||||
jcarrEntry.SetText(cur + "THIS IS A GREAT IDEA\n")
|
||||
} else {
|
||||
log.Println("This is NOT the jcarrButton")
|
||||
}
|
||||
}
|
||||
|
||||
func hostnameButton(hostname string) ui.Control {
|
||||
tmpbox := ui.NewHorizontalBox()
|
||||
tmpbox.SetPadded(true)
|
||||
|
||||
tmpButton := ui.NewButton(hostname)
|
||||
tmpbox.Append(tmpButton, false)
|
||||
tmpButton.OnClicked(buttonClick)
|
||||
tmpButton.OnClicked(defaultButtonClick)
|
||||
|
||||
jcarrButton = tmpButton
|
||||
|
||||
|
|
15
gui.go
15
gui.go
|
@ -17,6 +17,19 @@ var Height int
|
|||
|
||||
var allButtons []ButtonMap
|
||||
|
||||
var internalDS GuiDS
|
||||
|
||||
func GetDataStructures() *GuiDS {
|
||||
return &internalDS
|
||||
}
|
||||
|
||||
// All GUI Data Structures that are external
|
||||
type GuiDS struct {
|
||||
State string
|
||||
MainWindow *ui.Window
|
||||
ButtonClick func(int, string)
|
||||
}
|
||||
|
||||
type TableColumnData struct {
|
||||
Index int
|
||||
CellType string
|
||||
|
@ -219,7 +232,7 @@ func closeButtonClick(button *ui.Button) {
|
|||
|
||||
func closeButton(name string, mytab *ui.Tab) ui.Control {
|
||||
tmpButton := ui.NewButton(name)
|
||||
tmpButton.OnClicked(buttonClick)
|
||||
tmpButton.OnClicked(defaultButtonClick)
|
||||
|
||||
return tmpButton
|
||||
}
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
package gui
|
||||
|
||||
// import "github.com/davecgh/go-spew/spew"
|
||||
// import "time"
|
||||
// import "fmt"
|
||||
|
||||
// import "log"
|
||||
import "runtime"
|
||||
|
||||
import "github.com/andlabs/ui"
|
||||
import _ "github.com/andlabs/ui/winmanifest"
|
||||
|
||||
// var splashWin *ui.Window
|
||||
var MyArea *ui.Area
|
||||
|
||||
func ShowSplash() *ui.Window {
|
||||
splashWin := ui.NewWindow("", 640, 480, true)
|
||||
splashWin.SetBorderless(true)
|
||||
splashWin.OnClosing(func(*ui.Window) bool {
|
||||
ui.Quit()
|
||||
return true
|
||||
})
|
||||
ui.OnShouldQuit(func() bool {
|
||||
splashWin.Destroy()
|
||||
return true
|
||||
})
|
||||
|
||||
vbox := ui.NewVerticalBox()
|
||||
vbox.SetPadded(true)
|
||||
splashWin.SetChild(vbox)
|
||||
splashWin.SetMargined(true)
|
||||
|
||||
// This displays the window
|
||||
// splashWin.Show()
|
||||
|
||||
ShowSplashBox(vbox, nil, nil)
|
||||
|
||||
return splashWin
|
||||
}
|
||||
|
||||
func ShowSplashBox(vbox *ui.Box, atest chan int, custom func(int, string)) *ui.Box {
|
||||
newbox := ui.NewVerticalBox()
|
||||
newbox.SetPadded(true)
|
||||
|
||||
makeAttributedString()
|
||||
MyArea = makeSplashArea(custom)
|
||||
|
||||
newbox.Append(MyArea, true)
|
||||
|
||||
if runtime.GOOS == "linux" {
|
||||
newbox.Append(ui.NewLabel("OS: Linux"), false)
|
||||
} else if runtime.GOOS == "windows" {
|
||||
newbox.Append(ui.NewLabel("OS: Windows"), false)
|
||||
} else {
|
||||
newbox.Append(ui.NewLabel("OS: " + runtime.GOOS), false)
|
||||
}
|
||||
|
||||
newbox.Append(ui.NewLabel("Version: v0.3"), false)
|
||||
okButton := CreateButton("OK", "CLOSE", custom)
|
||||
newbox.Append(okButton, false)
|
||||
|
||||
if (vbox != nil) {
|
||||
vbox.Append(newbox, true)
|
||||
}
|
||||
|
||||
return newbox
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package gui
|
||||
|
||||
import "log"
|
||||
import "time"
|
||||
|
||||
import "github.com/andlabs/ui"
|
||||
import _ "github.com/andlabs/ui/winmanifest"
|
||||
|
||||
// import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
var cloudWindow *ui.Window
|
||||
var cloudTab *ui.Tab
|
||||
var cloudBox *ui.Box
|
||||
var smallBox *ui.Box
|
||||
var state string
|
||||
|
||||
func splashClose(a int, b string) {
|
||||
log.Println("GOT splashClose(a,b) =", a, b)
|
||||
|
||||
log.Println("cloudBox Delete(0) START")
|
||||
cloudBox.Delete(0)
|
||||
log.Println("smallBox.Hide() START")
|
||||
smallBox.Hide()
|
||||
|
||||
state = "kill"
|
||||
}
|
||||
|
||||
func buttonClick(i int, s string) {
|
||||
log.Println("test2 buttonClick() i, s =", i, s)
|
||||
cloudTab.Delete(0)
|
||||
|
||||
log.Println("Sleep(2000)")
|
||||
time.Sleep(2000 * time.Millisecond)
|
||||
|
||||
smallBox = AddAccountBox(nil, splashClose)
|
||||
cloudTab.InsertAt("Intro", 0, smallBox)
|
||||
cloudTab.SetMargined(0, true)
|
||||
}
|
||||
|
||||
func ShowAccountTab() {
|
||||
cloudTab.Delete(0)
|
||||
|
||||
log.Println("Sleep(1000)")
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
|
||||
smallBox = AddAccountBox(nil, splashClose)
|
||||
cloudTab.InsertAt("Intro", 0, smallBox)
|
||||
cloudTab.SetMargined(0, true)
|
||||
}
|
||||
|
||||
func GoMainWindow() {
|
||||
ui.Main(makeCloudWindow)
|
||||
}
|
||||
|
||||
func makeCloudWindow() {
|
||||
cloudWindow := ui.NewWindow("", 640, 480, true)
|
||||
// cloudWindow.SetBorderless(true)
|
||||
cloudWindow.OnClosing(func(*ui.Window) bool {
|
||||
ui.Quit()
|
||||
return true
|
||||
})
|
||||
ui.OnShouldQuit(func() bool {
|
||||
cloudWindow.Destroy()
|
||||
return true
|
||||
})
|
||||
|
||||
// cloudBox = ui.NewVerticalBox()
|
||||
// cloudBox.SetPadded(true)
|
||||
// cloudWindow.SetChild(cloudBox)
|
||||
// cloudWindow.SetMargined(true)
|
||||
|
||||
cloudTab = ui.NewTab()
|
||||
cloudWindow.SetChild(cloudTab)
|
||||
cloudWindow.SetMargined(true)
|
||||
|
||||
cloudBox = ShowSplashBox(nil, nil, buttonClick)
|
||||
|
||||
cloudTab.Append("WIT Splash", cloudBox)
|
||||
cloudTab.SetMargined(0, true)
|
||||
|
||||
cloudWindow.Show()
|
||||
// state = "done"
|
||||
}
|
Loading…
Reference in New Issue