From 32c53eb9478bfaad85ec08fc4e3309d7e4b0a585 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Sun, 17 May 2020 21:02:07 +0200 Subject: [PATCH] Fixed tooltip flickering when not blocking on events. --- allg5ui/renderer.go | 5 +++-- sdlui/renderer.go | 5 ++++- ui/renderer.go | 2 +- ui/ui.go | 9 ++++++--- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/allg5ui/renderer.go b/allg5ui/renderer.go index 0c2e71f..311048b 100644 --- a/allg5ui/renderer.go +++ b/allg5ui/renderer.go @@ -66,12 +66,12 @@ type Renderer struct { // Renderer implementation (events) -func (r *Renderer) PushEvents(t ui.EventTarget, wait bool) { +func (r *Renderer) PushEvents(t ui.EventTarget, wait bool) bool { r.disp.Flip() var ev = eventWait(r.eq, wait) if ev == nil { - return + return false } cursor := r.cursor @@ -141,6 +141,7 @@ func (r *Renderer) PushEvents(t ui.EventTarget, wait bool) { r.disp.SetMouseCursor(allg5.MouseCursorEdit) } } + return true } func (r *Renderer) RegisterRecorder(rec *allg5.Recorder) { diff --git a/sdlui/renderer.go b/sdlui/renderer.go index 45c385f..9242502 100644 --- a/sdlui/renderer.go +++ b/sdlui/renderer.go @@ -100,7 +100,7 @@ func (r *Renderer) WindowBounds() geom.RectangleF32 { return geom.RectF32(float32(x), float32(y), float32(x+w), float32(y+h)) } -func (r *Renderer) PushEvents(t ui.EventTarget, wait bool) { +func (r *Renderer) PushEvents(t ui.EventTarget, wait bool) bool { r.renderer.Present() waitOrPoll := func() sdl.Event { @@ -111,7 +111,9 @@ func (r *Renderer) PushEvents(t ui.EventTarget, wait bool) { } cursor := r.cursor + var pushed bool for event := waitOrPoll(); event != nil; event = sdl.PollEvent() { + pushed = true r.cursor = ui.MouseCursorDefault var unhandled bool @@ -191,6 +193,7 @@ func (r *Renderer) PushEvents(t ui.EventTarget, wait bool) { sdl.SetCursor(r.SystemCursor(sdl.SYSTEM_CURSOR_IBEAM)) } } + return pushed } func (r *Renderer) Refresh() { diff --git a/ui/renderer.go b/ui/renderer.go index 31c4547..85a2488 100644 --- a/ui/renderer.go +++ b/ui/renderer.go @@ -9,7 +9,7 @@ import ( type Renderer interface { // Events - PushEvents(t EventTarget, wait bool) + PushEvents(t EventTarget, wait bool) bool Refresh() // Lifetime diff --git a/ui/ui.go b/ui/ui.go index 134c0ec..737fcfd 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -55,9 +55,12 @@ func RunWait(r Renderer, s *Style, view Control, wait bool) error { tooltip := ctx.tooltip.Text ctx.tooltip.Text = "" - r.PushEvents(ctx, wait) - if ctx.tooltip.Text != tooltip { - ctx.overlays.SetVisibility(uiDefaultTooltipOverlay, ctx.tooltip.Text != "") + if r.PushEvents(ctx, wait) { + if ctx.tooltip.Text != tooltip { + ctx.overlays.SetVisibility(uiDefaultTooltipOverlay, ctx.tooltip.Text != "") + } + } else { + ctx.tooltip.Text = tooltip } } return nil