Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-17 12:54:35 -07:00
parent 640c99c256
commit 81dabbe53d
1 changed files with 92 additions and 18 deletions

View File

@ -8,6 +8,12 @@ import "runtime"
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 showSplash() {
splashWin := ui.NewWindow("Splash Screen", 640, 480, false)
splashWin.OnClosing(func(*ui.Window) bool {
@ -19,9 +25,6 @@ func showSplash() {
return true
})
// Make this window a 'tabbed' window
// tab := ui.NewTab()
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
splashWin.SetChild(hbox)
@ -30,25 +33,30 @@ func showSplash() {
// This displays the window
splashWin.Show()
// tab is ready so now display it
// tab.Append("WIT Splash", hbox)
// tab.SetMargined(0, true)
group := ui.NewGroup("Numbers")
group.SetMargined(true)
hbox.Append(group, true)
vbox = ui.NewVerticalBox()
vbox.SetPadded(true)
group.SetChild(vbox)
okButton := ui.NewButton("OK")
okButton.OnClicked(func(*ui.Button) {
log.Println("OK. Closing window.")
splashWin.Destroy()
ui.Quit()
hbox.Append(vbox, true)
fontButton = ui.NewFontButton()
fontButton.OnChanged(func(*ui.FontButton) {
spew.Dump(fontButton.Font())
// SplashArea.QueueRedrawAll()
})
vbox.Append(okButton, false)
// vbox.Append(fontButton, true)
spew.Dump(fontButton.Font())
ahbox := ui.NewHorizontalBox()
ahbox.SetPadded(true)
vbox.Append(ahbox, true)
makeAttributedString()
SplashArea = ui.NewArea(areaHandler{})
spew.Dump(attrstr)
spew.Dump(SplashArea)
ahbox.Append(SplashArea, true)
if runtime.GOOS == "linux" {
vbox.Append(ui.NewLabel("OS: Linux"), false)
@ -58,4 +66,70 @@ func showSplash() {
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)
}
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")
}
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) {
// do nothing
}
func (areaHandler) MouseCrossed(a *ui.Area, left bool) {
// do nothing
}
func (areaHandler) DragBroken(a *ui.Area) {
// do nothing
}
func (areaHandler) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) {
// reject all keys
return false
}