From 9a49f56147cd79c116243fb2e0f9830437abff02 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 17 May 2019 13:07:45 -0700 Subject: [PATCH] seperate the area code into it's own file Signed-off-by: Jeff Carr --- .gitignore | 2 + example-splash/area.go | 88 +++++++++++++++++++++++++++++++++++++ example-splash/splash.go | 95 +++------------------------------------- 3 files changed, 97 insertions(+), 88 deletions(-) create mode 100644 example-splash/area.go diff --git a/.gitignore b/.gitignore index ed435ff..06986a8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +*.swp + cloud-control-panel example-gui/example-gui example-systray/example-systray diff --git a/example-splash/area.go b/example-splash/area.go new file mode 100644 index 0000000..724688d --- /dev/null +++ b/example-splash/area.go @@ -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 +} diff --git a/example-splash/splash.go b/example-splash/splash.go index 8b4992d..a7ccf61 100644 --- a/example-splash/splash.go +++ b/example-splash/splash.go @@ -8,14 +8,10 @@ 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 +// import "github.com/davecgh/go-spew/spew" func showSplash() { - splashWin := ui.NewWindow("Splash Screen", 640, 480, false) + splashWin := ui.NewWindow("", 640, 480, false) splashWin.OnClosing(func(*ui.Window) bool { ui.Quit() return true @@ -25,38 +21,18 @@ func showSplash() { return true }) - hbox := ui.NewHorizontalBox() - hbox.SetPadded(true) - splashWin.SetChild(hbox) + vbox = ui.NewVerticalBox() + vbox.SetPadded(true) + splashWin.SetChild(vbox) splashWin.SetMargined(true) // This displays the window 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() - SplashArea = ui.NewArea(areaHandler{}) + myArea := makeSplashArea() - spew.Dump(attrstr) - spew.Dump(SplashArea) - ahbox.Append(SplashArea, true) + vbox.Append(myArea, true) if runtime.GOOS == "linux" { vbox.Append(ui.NewLabel("OS: Linux"), false) @@ -76,60 +52,3 @@ func showSplash() { }) 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 -}