maybe each stage needs to be it's own package for now until

there is better abstraction of the GUI

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-19 20:18:42 -07:00
parent 36d67d0d2e
commit 50d084fc39
7 changed files with 485 additions and 8 deletions

140
account1/addAccount.go Normal file
View File

@ -0,0 +1,140 @@
package account1
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)
vbox.Append(ui.NewLabel("or"), false)
vbox.Append(ui.NewHorizontalSeparator(), false)
// START add account hbox
hboxAccount := ui.NewHorizontalBox()
hboxAccount.SetPadded(true)
vbox.Append(hboxAccount, false)
// Start 'Provider' vertical box
vboxC := ui.NewVerticalBox()
vboxC.SetPadded(true)
vboxC.Append(ui.NewLabel("Cloud Provider:"), false)
cbox := ui.NewCombobox()
cbox.Append("WIT")
cbox.Append("Evocative")
vboxC.Append(cbox, false)
cbox.SetSelected(0)
cbox.OnSelected(func(*ui.Combobox) {
log.Println("OK. Selected Cloud Provider =", cbox.Selected())
})
hboxAccount.Append(vboxC, false)
// End 'Cloud Provider' vertical box
// Start 'Region' vertical box
vboxR := ui.NewVerticalBox()
vboxR.SetPadded(true)
vboxR.Append(ui.NewLabel("Region:"), false)
regbox := ui.NewCombobox()
regbox.Append("Any")
regbox.Append("SF")
vboxR.Append(regbox, false)
regbox.SetSelected(0)
regbox.OnSelected(func(*ui.Combobox) {
log.Println("OK. Selected something =", regbox.Selected())
})
hboxAccount.Append(vboxR, false)
// End 'Region' vertical box
// Start 'Nickname' vertical box
vboxN := ui.NewVerticalBox()
vboxN.SetPadded(true)
vboxN.Append(ui.NewLabel("Account Nickname:"), false)
entryNick := ui.NewEntry()
entryNick.SetReadOnly(false)
vboxN.Append(entryNick, false)
entryNick.OnChanged(func(*ui.Entry) {
log.Println("OK. nickname =", entryNick.Text())
})
hboxAccount.Append(vboxN, false)
// End 'Nickname' vertical box
// Start 'Username' vertical box
vboxU := ui.NewVerticalBox()
vboxU.SetPadded(true)
vboxU.Append(ui.NewLabel("Account Username:"), false)
entryUser := ui.NewEntry()
entryUser.SetReadOnly(false)
vboxU.Append(entryUser, false)
entryUser.OnChanged(func(*ui.Entry) {
log.Println("OK. username =", entryUser.Text())
})
hboxAccount.Append(vboxU, false)
// End 'Username' vertical box
// Start 'Password' vertical box
vboxP := ui.NewVerticalBox()
vboxP.SetPadded(true)
vboxP.Append(ui.NewLabel("Account Password:"), false)
entryPass := ui.NewEntry()
entryPass.SetReadOnly(false)
vboxP.Append(entryPass, false)
entryPass.OnChanged(func(*ui.Entry) {
log.Println("OK. password =", entryPass.Text())
})
hboxAccount.Append(vboxP, false)
// End 'Password' vertical box
vbox.Append(ui.NewHorizontalSeparator(), false)
okButton := ui.NewButton("Add Account")
okButton.OnClicked(func(*ui.Button) {
log.Println("OK. Closing window.")
accounthWin.Destroy()
ui.Quit()
})
vbox.Append(okButton, false)
// END add account hbox
}

140
account2/addAccount.go Normal file
View File

@ -0,0 +1,140 @@
package account2
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)
vbox.Append(ui.NewLabel("or"), false)
vbox.Append(ui.NewHorizontalSeparator(), false)
// START add account hbox
hboxAccount := ui.NewHorizontalBox()
hboxAccount.SetPadded(true)
vbox.Append(hboxAccount, false)
// Start 'Provider' vertical box
vboxC := ui.NewVerticalBox()
vboxC.SetPadded(true)
vboxC.Append(ui.NewLabel("Cloud Provider:"), false)
cbox := ui.NewCombobox()
cbox.Append("WIT")
cbox.Append("Evocative")
vboxC.Append(cbox, false)
cbox.SetSelected(0)
cbox.OnSelected(func(*ui.Combobox) {
log.Println("OK. Selected Cloud Provider =", cbox.Selected())
})
hboxAccount.Append(vboxC, false)
// End 'Cloud Provider' vertical box
// Start 'Region' vertical box
vboxR := ui.NewVerticalBox()
vboxR.SetPadded(true)
vboxR.Append(ui.NewLabel("Region:"), false)
regbox := ui.NewCombobox()
regbox.Append("Any")
regbox.Append("SF")
vboxR.Append(regbox, false)
regbox.SetSelected(0)
regbox.OnSelected(func(*ui.Combobox) {
log.Println("OK. Selected something =", regbox.Selected())
})
hboxAccount.Append(vboxR, false)
// End 'Region' vertical box
// Start 'Nickname' vertical box
vboxN := ui.NewVerticalBox()
vboxN.SetPadded(true)
vboxN.Append(ui.NewLabel("Account Nickname:"), false)
entryNick := ui.NewEntry()
entryNick.SetReadOnly(false)
vboxN.Append(entryNick, false)
entryNick.OnChanged(func(*ui.Entry) {
log.Println("OK. nickname =", entryNick.Text())
})
hboxAccount.Append(vboxN, false)
// End 'Nickname' vertical box
// Start 'Username' vertical box
vboxU := ui.NewVerticalBox()
vboxU.SetPadded(true)
vboxU.Append(ui.NewLabel("Account Username:"), false)
entryUser := ui.NewEntry()
entryUser.SetReadOnly(false)
vboxU.Append(entryUser, false)
entryUser.OnChanged(func(*ui.Entry) {
log.Println("OK. username =", entryUser.Text())
})
hboxAccount.Append(vboxU, false)
// End 'Username' vertical box
// Start 'Password' vertical box
vboxP := ui.NewVerticalBox()
vboxP.SetPadded(true)
vboxP.Append(ui.NewLabel("Account Password:"), false)
entryPass := ui.NewEntry()
entryPass.SetReadOnly(false)
vboxP.Append(entryPass, false)
entryPass.OnChanged(func(*ui.Entry) {
log.Println("OK. password =", entryPass.Text())
})
hboxAccount.Append(vboxP, false)
// End 'Password' vertical box
vbox.Append(ui.NewHorizontalSeparator(), false)
okButton := ui.NewButton("Add Account")
okButton.OnClicked(func(*ui.Button) {
log.Println("OK. Closing window.")
accounthWin.Destroy()
ui.Quit()
})
vbox.Append(okButton, false)
// END add account hbox
}

View File

@ -26,6 +26,21 @@ func addAccountWindow() {
// 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)
vbox.Append(ui.NewLabel("or"), false)
vbox.Append(ui.NewHorizontalSeparator(), false)
// START add account hbox
hboxAccount := ui.NewHorizontalBox()
hboxAccount.SetPadded(true)
vbox.Append(hboxAccount, false)
@ -121,12 +136,5 @@ func addAccountWindow() {
ui.Quit()
})
vbox.Append(okButton, false)
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 add account hbox
}

114
splash/area.go Normal file
View File

@ -0,0 +1,114 @@
package splash
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 makeSplashArea() *ui.Area {
fontButton = ui.NewFontButton()
fontButton.OnChanged(func(*ui.FontButton) {
spew.Dump(fontButton.Font())
// SplashArea.QueueRedrawAll()
})
spew.Dump(fontButton.Font())
makeAttributedString()
splashArea = ui.NewArea(areaHandler{})
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{}
func (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),
})
defer tl.Free()
p.Context.Text(tl, 0, 0)
}
func (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()
}
}
func (areaHandler) MouseCrossed(a *ui.Area, left bool) {
log.Println("GOT MouseCrossed()")
}
func (areaHandler) DragBroken(a *ui.Area) {
log.Println("GOT DragBroken()")
}
func (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
}

57
splash/splash.go Normal file
View File

@ -0,0 +1,57 @@
package splash
// 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
func ShowSplash() {
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()
makeAttributedString()
myArea := makeSplashArea()
vbox.Append(myArea, true)
if runtime.GOOS == "linux" {
vbox.Append(ui.NewLabel("OS: Linux"), false)
} else if runtime.GOOS == "windows" {
vbox.Append(ui.NewLabel("OS: Windows"), false)
} else {
vbox.Append(ui.NewLabel("OS: " + runtime.GOOS), false)
}
vbox.Append(ui.NewLabel("Version: v0.3"), false)
okButton := ui.NewButton("OK")
okButton.OnClicked(func(*ui.Button) {
log.Println("OK. Closing window.")
splashWin.Destroy()
ui.Quit()
})
vbox.Append(okButton, false)
}

2
test2/Makefile Normal file
View File

@ -0,0 +1,2 @@
run:
go run *.go

16
test2/main.go Normal file
View File

@ -0,0 +1,16 @@
package main
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
import "git.wit.com/wit/cloud-control-panel/splash"
import "git.wit.com/wit/cloud-control-panel/account1"
import "git.wit.com/wit/cloud-control-panel/account2"
func main() {
ui.Main(splash.ShowSplash)
ui.Main(account1.AddAccountWindow)
ui.Main(account2.AddAccountWindow)
}