Fix the flashing tooltip issue

This commit is contained in:
Francesco Abbate 2021-02-21 11:09:51 +01:00
parent 2353076b37
commit fc46946ea1
2 changed files with 18 additions and 7 deletions

View File

@ -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

View File

@ -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