ui/app: introduce DestroyEvent for ending the event loop

Replace the StageDead stage with DestroyEvent dedicated to ending
the event loop and, for premature window closes, the error.

Drop the error return from NewWindow; any errors in window creation
will appear as an immediate DestroyEvent with its Err field set.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-07-13 11:41:12 +02:00
parent 8e307b40a6
commit 59e92e8233
6 changed files with 51 additions and 30 deletions
+4 -2
View File
@@ -61,6 +61,7 @@ type window struct {
width int
height int
stage Stage
dead bool
mu sync.Mutex
animating bool
@@ -319,7 +320,8 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
w.scrollEvent(wParam, lParam)
case _WM_DESTROY:
delete(winMap, hwnd)
w.setStage(StageDead)
w.dead = true
w.w.event(DestroyEvent{})
case _WM_REDRAW:
w.mu.Lock()
anim := w.animating
@@ -368,7 +370,7 @@ func (w *window) scrollEvent(wParam, lParam uintptr) {
// Adapted from https://blogs.msdn.microsoft.com/oldnewthing/20060126-00/?p=32513/
func (w *window) loop() error {
loop:
for w.stage > StageDead {
for !w.dead {
var msg msg
// Since posted messages are always returned before system messages,
// but we want our WM_REDRAW to always come last, just like WM_PAINT.