From 17ec92568d4563b2c837505fb78aa5c1686e50a4 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 17 May 2019 14:25:40 -0700 Subject: [PATCH] close on mouse click and keypress events Signed-off-by: Jeff Carr --- example-splash/addAccount.go | 55 ++++++++++++++++++++++++++++++++++++ example-splash/area.go | 24 ++++++++++++++++ example-splash/crash1 | 35 ----------------------- example-splash/main.go | 5 ++-- example-splash/splash.go | 10 ++++--- 5 files changed, 88 insertions(+), 41 deletions(-) create mode 100644 example-splash/addAccount.go delete mode 100644 example-splash/crash1 diff --git a/example-splash/addAccount.go b/example-splash/addAccount.go new file mode 100644 index 0000000..77b012b --- /dev/null +++ b/example-splash/addAccount.go @@ -0,0 +1,55 @@ +package main + +import "log" +import "runtime" + +import "github.com/andlabs/ui" +import _ "github.com/andlabs/ui/winmanifest" + +// import "github.com/davecgh/go-spew/spew" + +func addAccountWindow() { + accounthWin := ui.NewWindow("Create New 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() + + 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("Add Account") + okButton.OnClicked(func(*ui.Button) { + log.Println("OK. Closing window.") + accounthWin.Destroy() + 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) +} diff --git a/example-splash/area.go b/example-splash/area.go index 5255d3b..efda60e 100644 --- a/example-splash/area.go +++ b/example-splash/area.go @@ -73,6 +73,18 @@ func (areaHandler) Draw(a *ui.Area, p *ui.AreaDrawParams) { 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) { @@ -85,6 +97,18 @@ func (areaHandler) DragBroken(a *ui.Area) { 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 } diff --git a/example-splash/crash1 b/example-splash/crash1 deleted file mode 100644 index 17c4245..0000000 --- a/example-splash/crash1 +++ /dev/null @@ -1,35 +0,0 @@ -2019/05/17 10:59:15 name= Test 128 -2019/05/17 10:59:15 sleep -2019/05/17 10:59:15 sleep -2019/05/17 10:59:15 name= Test 129 -2019/05/17 10:59:16 sleep -fatal error: unexpected signal during runtime execution -[signal SIGSEGV: segmentation violation code=0x1 addr=0x7f8c000000b8 pc=0x7f8cbfb2f8e5] - -runtime stack: -runtime.throw(0x50c4b8, 0x2a) - /usr/lib/go-1.11/src/runtime/panic.go:608 +0x72 -runtime.sigpanic() - /usr/lib/go-1.11/src/runtime/signal_unix.go:374 +0x2f2 - -goroutine 19 [syscall]: -runtime.cgocall(0x4b5490, 0xc00004df78, 0xc0000ac048) - /usr/lib/go-1.11/src/runtime/cgocall.go:128 +0x5e fp=0xc00004df48 sp=0xc00004df10 pc=0x41688e -github.com/andlabs/ui._Cfunc_uiMain() - _cgo_gotypes.go:2518 +0x41 fp=0xc00004df78 sp=0xc00004df48 pc=0x4a9711 -github.com/andlabs/ui.Main(0x50d890, 0xc00003a701, 0xc0000842c0) - /home/jcarr/go/src/github.com/andlabs/ui/main.go:41 +0xfd fp=0xc00004dfc8 sp=0xc00004df78 pc=0x4ad6cd -runtime.goexit() - /usr/lib/go-1.11/src/runtime/asm_amd64.s:1333 +0x1 fp=0xc00004dfd0 sp=0xc00004dfc8 pc=0x466461 -created by main.main - /home/jcarr/go/src/git.wit.com/wit/cloud-control-panel/example-splash/main.go:68 +0x53 - -goroutine 1 [sleep, locked to thread]: -time.Sleep(0x11e1a300) - /usr/lib/go-1.11/src/runtime/time.go:105 +0x14f -main.main() - /home/jcarr/go/src/git.wit.com/wit/cloud-control-panel/example-splash/main.go:74 +0x74 -exit status 2 -make: *** [Makefile:2: run] Error 1 -jcarr@librem15:~/go/src/git.wit.com/wit/cloud-control-panel/example-splash$ git diff - diff --git a/example-splash/main.go b/example-splash/main.go index 1724e33..d715e7e 100644 --- a/example-splash/main.go +++ b/example-splash/main.go @@ -10,7 +10,6 @@ import _ "github.com/andlabs/ui/winmanifest" var mainwin *ui.Window var hbox *ui.Box -var vbox *ui.Box func makeSplashPage() ui.Control { hbox = ui.NewHorizontalBox() @@ -20,7 +19,7 @@ func makeSplashPage() ui.Control { group.SetMargined(true) hbox.Append(group, true) - vbox = ui.NewVerticalBox() + vbox := ui.NewVerticalBox() vbox.SetPadded(true) group.SetChild(vbox) @@ -68,6 +67,8 @@ func setupUI() { func main() { ui.Main(showSplash) + ui.Main(addAccountWindow) + go ui.Main(setupUI) // locks up GTK after a while (50 times) diff --git a/example-splash/splash.go b/example-splash/splash.go index a7ccf61..e29c972 100644 --- a/example-splash/splash.go +++ b/example-splash/splash.go @@ -1,17 +1,19 @@ package main +// import "github.com/davecgh/go-spew/spew" // import "time" -import "log" // import "fmt" + +import "log" import "runtime" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" -// import "github.com/davecgh/go-spew/spew" +var splashWin *ui.Window func showSplash() { - splashWin := ui.NewWindow("", 640, 480, false) + splashWin = ui.NewWindow("", 640, 480, false) splashWin.OnClosing(func(*ui.Window) bool { ui.Quit() return true @@ -21,7 +23,7 @@ func showSplash() { return true }) - vbox = ui.NewVerticalBox() + vbox := ui.NewVerticalBox() vbox.SetPadded(true) splashWin.SetChild(vbox) splashWin.SetMargined(true)