From b9534ee255ecc037bae6c1460473784eeb736399 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Sun, 17 May 2020 07:21:58 +0200 Subject: [PATCH] Made tooltip overlay switch visibility only when changed. Added Tooltip.SetVisibility. Fixed bug where no events where triggered for change in visibility. --- ui/context.go | 1 - ui/overlays.go | 10 ++++------ ui/ui.go | 6 +++++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ui/context.go b/ui/context.go index 9e50161..d37bd5c 100644 --- a/ui/context.go +++ b/ui/context.go @@ -72,7 +72,6 @@ func (c *context) Overlays() *Overlays { return c.overlays } func (c *context) Renderer() Renderer { return c.renderer } func (c *context) ShowTooltip(t string) { - c.overlays.Show(uiDefaultTooltipOverlay) c.tooltip.Text = t } diff --git a/ui/overlays.go b/ui/overlays.go index fffa909..e8edaaf 100644 --- a/ui/overlays.go +++ b/ui/overlays.go @@ -95,10 +95,8 @@ func (o *Overlays) Render(ctx Context) { } } -func (o *Overlays) Show(name string) { - o.visible[name] = true -} +func (o *Overlays) SetVisibility(name string, visible bool) { o.setVisibility(name, visible) } -func (o *Overlays) Toggle(name string) { - o.visible[name] = !o.visible[name] -} +func (o *Overlays) Show(name string) { o.SetVisibility(name, true) } + +func (o *Overlays) Toggle(name string) { o.SetVisibility(name, false) } diff --git a/ui/ui.go b/ui/ui.go index ac710f4..040050d 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -50,8 +50,12 @@ func RunWait(r Renderer, s *Style, view Control, wait bool) error { return nil } - ctx.overlays.Hide("ui-default-tooltip") + tooltip := ctx.tooltip.Text + ctx.tooltip.Text = "" r.PushEvents(ctx, wait) + if ctx.tooltip.Text != tooltip { + ctx.overlays.SetVisibility(uiDefaultTooltipOverlay, ctx.tooltip.Text != "") + } } return nil }