From fc46946ea1c1bf13cfd9b79af5a422c14a07dc7f Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sun, 21 Feb 2021 11:09:51 +0100 Subject: [PATCH] Fix the flashing tooltip issue --- data/core/statusview.lua | 18 ++++++++++++------ data/plugins/toolbarview.lua | 7 ++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/data/core/statusview.lua b/data/core/statusview.lua index 7b21d941..8d1a3653 100644 --- a/data/core/statusview.lua +++ b/data/core/statusview.lua @@ -18,6 +18,8 @@ function StatusView:new() StatusView.super.new(self) self.message_timeout = 0 self.message = {} + self.tooltip_mode = false + self.tooltip = {} end @@ -40,13 +42,13 @@ end function StatusView:show_tooltip(text) - self.message = { style.text, text } - self.message_timeout = system.get_time() + 1000 + self.tooltip = { text } + self.tooltip_mode = true end function StatusView:remove_tooltip() - self.message_timeout = 0 + self.tooltip_mode = false end @@ -148,9 +150,13 @@ function StatusView:draw() self:draw_items(self.message, false, self.size.y) end - local left, right = self:get_items() - self:draw_items(left) - self:draw_items(right, true) + if self.tooltip_mode then + self:draw_items(self.tooltip) + else + local left, right = self:get_items() + self:draw_items(left) + self:draw_items(right, true) + end end diff --git a/data/plugins/toolbarview.lua b/data/plugins/toolbarview.lua index 60d348d3..a12be317 100644 --- a/data/plugins/toolbarview.lua +++ b/data/plugins/toolbarview.lua @@ -88,7 +88,10 @@ end function ToolbarView:on_mouse_moved(px, py, ...) ToolbarView.super.on_mouse_moved(self, px, py, ...) self.hovered_item = nil + local x_min, x_max, y_min, y_max = self.size.x, 0, self.size.y, 0 for item, x, y, w, h in self:each_item() do + x_min, x_max = math.min(x, x_min), math.max(x + w, x_max) + y_min, y_max = y, y + h if px > x and py > y and px <= x + w and py <= y + h then self.hovered_item = item core.status_view:show_tooltip(command.prettify_name(item.command)) @@ -96,7 +99,9 @@ function ToolbarView:on_mouse_moved(px, py, ...) return end end - if self.tooltip then + if px > x_min and px <= x_max and py > y_min and py <= y_max then + self.tooltip = true + elseif self.tooltip then core.status_view:remove_tooltip() self.tooltip = false end