Made tooltip overlay switch visibility only when changed.

Added Tooltip.SetVisibility.
Fixed bug where no events where triggered for change in visibility.
This commit is contained in:
Sander Schobers 2020-05-17 07:21:58 +02:00
parent 75fce53716
commit b9534ee255
3 changed files with 9 additions and 8 deletions

View File

@ -72,7 +72,6 @@ func (c *context) Overlays() *Overlays { return c.overlays }
func (c *context) Renderer() Renderer { return c.renderer } func (c *context) Renderer() Renderer { return c.renderer }
func (c *context) ShowTooltip(t string) { func (c *context) ShowTooltip(t string) {
c.overlays.Show(uiDefaultTooltipOverlay)
c.tooltip.Text = t c.tooltip.Text = t
} }

View File

@ -95,10 +95,8 @@ func (o *Overlays) Render(ctx Context) {
} }
} }
func (o *Overlays) Show(name string) { func (o *Overlays) SetVisibility(name string, visible bool) { o.setVisibility(name, visible) }
o.visible[name] = true
}
func (o *Overlays) Toggle(name string) { func (o *Overlays) Show(name string) { o.SetVisibility(name, true) }
o.visible[name] = !o.visible[name]
} func (o *Overlays) Toggle(name string) { o.SetVisibility(name, false) }

View File

@ -50,8 +50,12 @@ func RunWait(r Renderer, s *Style, view Control, wait bool) error {
return nil return nil
} }
ctx.overlays.Hide("ui-default-tooltip") tooltip := ctx.tooltip.Text
ctx.tooltip.Text = ""
r.PushEvents(ctx, wait) r.PushEvents(ctx, wait)
if ctx.tooltip.Text != tooltip {
ctx.overlays.SetVisibility(uiDefaultTooltipOverlay, ctx.tooltip.Text != "")
}
} }
return nil return nil
} }