Fixed tooltip flickering when not blocking on events.

This commit is contained in:
Sander Schobers 2020-05-17 21:02:07 +02:00
parent 0f54224cc7
commit 32c53eb947
4 changed files with 14 additions and 7 deletions

View File

@ -66,12 +66,12 @@ type Renderer struct {
// Renderer implementation (events) // 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() r.disp.Flip()
var ev = eventWait(r.eq, wait) var ev = eventWait(r.eq, wait)
if ev == nil { if ev == nil {
return return false
} }
cursor := r.cursor cursor := r.cursor
@ -141,6 +141,7 @@ func (r *Renderer) PushEvents(t ui.EventTarget, wait bool) {
r.disp.SetMouseCursor(allg5.MouseCursorEdit) r.disp.SetMouseCursor(allg5.MouseCursorEdit)
} }
} }
return true
} }
func (r *Renderer) RegisterRecorder(rec *allg5.Recorder) { func (r *Renderer) RegisterRecorder(rec *allg5.Recorder) {

View File

@ -100,7 +100,7 @@ func (r *Renderer) WindowBounds() geom.RectangleF32 {
return geom.RectF32(float32(x), float32(y), float32(x+w), float32(y+h)) 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() r.renderer.Present()
waitOrPoll := func() sdl.Event { waitOrPoll := func() sdl.Event {
@ -111,7 +111,9 @@ func (r *Renderer) PushEvents(t ui.EventTarget, wait bool) {
} }
cursor := r.cursor cursor := r.cursor
var pushed bool
for event := waitOrPoll(); event != nil; event = sdl.PollEvent() { for event := waitOrPoll(); event != nil; event = sdl.PollEvent() {
pushed = true
r.cursor = ui.MouseCursorDefault r.cursor = ui.MouseCursorDefault
var unhandled bool var unhandled bool
@ -191,6 +193,7 @@ func (r *Renderer) PushEvents(t ui.EventTarget, wait bool) {
sdl.SetCursor(r.SystemCursor(sdl.SYSTEM_CURSOR_IBEAM)) sdl.SetCursor(r.SystemCursor(sdl.SYSTEM_CURSOR_IBEAM))
} }
} }
return pushed
} }
func (r *Renderer) Refresh() { func (r *Renderer) Refresh() {

View File

@ -9,7 +9,7 @@ import (
type Renderer interface { type Renderer interface {
// Events // Events
PushEvents(t EventTarget, wait bool) PushEvents(t EventTarget, wait bool) bool
Refresh() Refresh()
// Lifetime // Lifetime

View File

@ -55,10 +55,13 @@ func RunWait(r Renderer, s *Style, view Control, wait bool) error {
tooltip := ctx.tooltip.Text tooltip := ctx.tooltip.Text
ctx.tooltip.Text = "" ctx.tooltip.Text = ""
r.PushEvents(ctx, wait) if r.PushEvents(ctx, wait) {
if ctx.tooltip.Text != tooltip { if ctx.tooltip.Text != tooltip {
ctx.overlays.SetVisibility(uiDefaultTooltipOverlay, ctx.tooltip.Text != "") ctx.overlays.SetVisibility(uiDefaultTooltipOverlay, ctx.tooltip.Text != "")
} }
} else {
ctx.tooltip.Text = tooltip
}
} }
return nil return nil
} }