Fix the flashing tooltip issue
This commit is contained in:
parent
2353076b37
commit
fc46946ea1
|
@ -18,6 +18,8 @@ function StatusView:new()
|
||||||
StatusView.super.new(self)
|
StatusView.super.new(self)
|
||||||
self.message_timeout = 0
|
self.message_timeout = 0
|
||||||
self.message = {}
|
self.message = {}
|
||||||
|
self.tooltip_mode = false
|
||||||
|
self.tooltip = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,13 +42,13 @@ end
|
||||||
|
|
||||||
|
|
||||||
function StatusView:show_tooltip(text)
|
function StatusView:show_tooltip(text)
|
||||||
self.message = { style.text, text }
|
self.tooltip = { text }
|
||||||
self.message_timeout = system.get_time() + 1000
|
self.tooltip_mode = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function StatusView:remove_tooltip()
|
function StatusView:remove_tooltip()
|
||||||
self.message_timeout = 0
|
self.tooltip_mode = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -148,9 +150,13 @@ function StatusView:draw()
|
||||||
self:draw_items(self.message, false, self.size.y)
|
self:draw_items(self.message, false, self.size.y)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self.tooltip_mode then
|
||||||
|
self:draw_items(self.tooltip)
|
||||||
|
else
|
||||||
local left, right = self:get_items()
|
local left, right = self:get_items()
|
||||||
self:draw_items(left)
|
self:draw_items(left)
|
||||||
self:draw_items(right, true)
|
self:draw_items(right, true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,10 @@ end
|
||||||
function ToolbarView:on_mouse_moved(px, py, ...)
|
function ToolbarView:on_mouse_moved(px, py, ...)
|
||||||
ToolbarView.super.on_mouse_moved(self, px, py, ...)
|
ToolbarView.super.on_mouse_moved(self, px, py, ...)
|
||||||
self.hovered_item = nil
|
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
|
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
|
if px > x and py > y and px <= x + w and py <= y + h then
|
||||||
self.hovered_item = item
|
self.hovered_item = item
|
||||||
core.status_view:show_tooltip(command.prettify_name(item.command))
|
core.status_view:show_tooltip(command.prettify_name(item.command))
|
||||||
|
@ -96,7 +99,9 @@ function ToolbarView:on_mouse_moved(px, py, ...)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
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()
|
core.status_view:remove_tooltip()
|
||||||
self.tooltip = false
|
self.tooltip = false
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue