close on mouse click and keypress events
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
904cd2a221
commit
17ec92568d
|
@ -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)
|
||||||
|
}
|
|
@ -73,6 +73,18 @@ func (areaHandler) Draw(a *ui.Area, p *ui.AreaDrawParams) {
|
||||||
func (areaHandler) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {
|
func (areaHandler) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) {
|
||||||
log.Println("GOT MouseEvent()")
|
log.Println("GOT MouseEvent()")
|
||||||
spew.Dump(me)
|
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) {
|
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) {
|
func (areaHandler) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) {
|
||||||
log.Println("GOT KeyEvent()")
|
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)
|
spew.Dump(ke)
|
||||||
|
splashWin.Destroy()
|
||||||
|
ui.Quit()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ import _ "github.com/andlabs/ui/winmanifest"
|
||||||
|
|
||||||
var mainwin *ui.Window
|
var mainwin *ui.Window
|
||||||
var hbox *ui.Box
|
var hbox *ui.Box
|
||||||
var vbox *ui.Box
|
|
||||||
|
|
||||||
func makeSplashPage() ui.Control {
|
func makeSplashPage() ui.Control {
|
||||||
hbox = ui.NewHorizontalBox()
|
hbox = ui.NewHorizontalBox()
|
||||||
|
@ -20,7 +19,7 @@ func makeSplashPage() ui.Control {
|
||||||
group.SetMargined(true)
|
group.SetMargined(true)
|
||||||
hbox.Append(group, true)
|
hbox.Append(group, true)
|
||||||
|
|
||||||
vbox = ui.NewVerticalBox()
|
vbox := ui.NewVerticalBox()
|
||||||
vbox.SetPadded(true)
|
vbox.SetPadded(true)
|
||||||
group.SetChild(vbox)
|
group.SetChild(vbox)
|
||||||
|
|
||||||
|
@ -68,6 +67,8 @@ func setupUI() {
|
||||||
func main() {
|
func main() {
|
||||||
ui.Main(showSplash)
|
ui.Main(showSplash)
|
||||||
|
|
||||||
|
ui.Main(addAccountWindow)
|
||||||
|
|
||||||
go ui.Main(setupUI)
|
go ui.Main(setupUI)
|
||||||
|
|
||||||
// locks up GTK after a while (50 times)
|
// locks up GTK after a while (50 times)
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
// import "github.com/davecgh/go-spew/spew"
|
||||||
// import "time"
|
// import "time"
|
||||||
import "log"
|
|
||||||
// import "fmt"
|
// import "fmt"
|
||||||
|
|
||||||
|
import "log"
|
||||||
import "runtime"
|
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"
|
var splashWin *ui.Window
|
||||||
|
|
||||||
func showSplash() {
|
func showSplash() {
|
||||||
splashWin := ui.NewWindow("", 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
|
||||||
|
@ -21,7 +23,7 @@ func showSplash() {
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
vbox = ui.NewVerticalBox()
|
vbox := ui.NewVerticalBox()
|
||||||
vbox.SetPadded(true)
|
vbox.SetPadded(true)
|
||||||
splashWin.SetChild(vbox)
|
splashWin.SetChild(vbox)
|
||||||
splashWin.SetMargined(true)
|
splashWin.SetMargined(true)
|
||||||
|
|
Loading…
Reference in New Issue