seperate the area code into it's own file

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-17 13:07:45 -07:00
parent 81dabbe53d
commit 9a49f56147
3 changed files with 97 additions and 88 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
*.swp
cloud-control-panel cloud-control-panel
example-gui/example-gui example-gui/example-gui
example-systray/example-systray example-systray/example-systray

88
example-splash/area.go Normal file
View File

@ -0,0 +1,88 @@
package main
// import "time"
// import "log"
// import "fmt"
// 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 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")
}
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
}

View File

@ -8,14 +8,10 @@ import "runtime"
import "github.com/andlabs/ui" import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest" 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 showSplash() { func showSplash() {
splashWin := ui.NewWindow("Splash Screen", 640, 480, false) splashWin := ui.NewWindow("", 640, 480, false)
splashWin.OnClosing(func(*ui.Window) bool { splashWin.OnClosing(func(*ui.Window) bool {
ui.Quit() ui.Quit()
return true return true
@ -25,38 +21,18 @@ func showSplash() {
return true return true
}) })
hbox := ui.NewHorizontalBox() vbox = ui.NewVerticalBox()
hbox.SetPadded(true) vbox.SetPadded(true)
splashWin.SetChild(hbox) splashWin.SetChild(vbox)
splashWin.SetMargined(true) splashWin.SetMargined(true)
// This displays the window // This displays the window
splashWin.Show() splashWin.Show()
vbox = ui.NewVerticalBox()
vbox.SetPadded(true)
hbox.Append(vbox, true)
fontButton = ui.NewFontButton()
fontButton.OnChanged(func(*ui.FontButton) {
spew.Dump(fontButton.Font())
// SplashArea.QueueRedrawAll()
})
// vbox.Append(fontButton, true)
spew.Dump(fontButton.Font())
ahbox := ui.NewHorizontalBox()
ahbox.SetPadded(true)
vbox.Append(ahbox, true)
makeAttributedString() makeAttributedString()
SplashArea = ui.NewArea(areaHandler{}) myArea := makeSplashArea()
spew.Dump(attrstr) vbox.Append(myArea, true)
spew.Dump(SplashArea)
ahbox.Append(SplashArea, true)
if runtime.GOOS == "linux" { if runtime.GOOS == "linux" {
vbox.Append(ui.NewLabel("OS: Linux"), false) vbox.Append(ui.NewLabel("OS: Linux"), false)
@ -76,60 +52,3 @@ func showSplash() {
}) })
vbox.Append(okButton, false) 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
}