2011-11-03 20:07:07 +01:00
|
|
|
ToolTip = {}
|
|
|
|
|
|
|
|
-- private variables
|
|
|
|
local currentToolTip
|
|
|
|
|
|
|
|
-- private functions
|
|
|
|
local function moveToolTip(tooltip)
|
2011-12-03 22:41:37 +01:00
|
|
|
local pos = g_window.getMousePos()
|
2011-11-03 20:07:07 +01:00
|
|
|
pos.y = pos.y + 1
|
2011-12-03 22:41:37 +01:00
|
|
|
local xdif = g_window.getSize().width - (pos.x + tooltip:getWidth())
|
2011-11-03 20:07:07 +01:00
|
|
|
if xdif < 2 then
|
|
|
|
pos.x = pos.x - tooltip:getWidth() - 3
|
|
|
|
else
|
|
|
|
pos.x = pos.x + 10
|
|
|
|
end
|
|
|
|
tooltip:moveTo(pos)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- public functions
|
|
|
|
function ToolTip.display(text)
|
|
|
|
if text then
|
2011-11-14 15:30:35 +01:00
|
|
|
ToolTip.hide()
|
2012-01-03 01:42:53 +01:00
|
|
|
currentToolTip = displayUI('tooltip.otui')
|
2011-11-03 20:07:07 +01:00
|
|
|
currentToolTip.onMouseMove = moveToolTip
|
|
|
|
local label = currentToolTip:getChildById('toolTipText')
|
|
|
|
label:setText(text)
|
|
|
|
label:resizeToText()
|
|
|
|
local size = label:getSize()
|
|
|
|
size.width = size.width + 4
|
|
|
|
size.height = size.height + 4
|
2011-12-07 01:31:55 +01:00
|
|
|
currentToolTip:resize(size)
|
2011-11-03 20:32:50 +01:00
|
|
|
moveToolTip(currentToolTip)
|
2011-11-03 20:07:07 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ToolTip.hide()
|
|
|
|
if currentToolTip then
|
|
|
|
currentToolTip:destroy()
|
|
|
|
currentToolTip = nil
|
|
|
|
end
|
|
|
|
end
|
2011-11-03 23:28:10 +01:00
|
|
|
|
2011-11-14 16:01:09 +01:00
|
|
|
-- UIWidget hooks
|
2011-11-14 15:30:35 +01:00
|
|
|
local function onWidgetHoverChange(widget, hovered)
|
|
|
|
if hovered then
|
|
|
|
ToolTip.display(widget.tooltip)
|
|
|
|
else
|
|
|
|
ToolTip:hide()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-04 11:26:58 +01:00
|
|
|
local function onWidgetStyleApply(widget, styleName, styleNode)
|
|
|
|
if styleNode.tooltip then
|
|
|
|
widget.tooltip = styleNode.tooltip
|
2011-11-14 16:01:09 +01:00
|
|
|
end
|
2011-11-14 15:30:35 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
connect(UIWidget, { onStyleApply = onWidgetStyleApply,
|
|
|
|
onHoverChange = onWidgetHoverChange})
|
|
|
|
|
2011-11-14 16:01:09 +01:00
|
|
|
-- UIWidget extensions
|
2011-11-14 03:40:18 +01:00
|
|
|
function UIWidget:setTooltip(text)
|
2011-11-14 15:30:35 +01:00
|
|
|
self.tooltip = text
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIWidget:getTooltip()
|
|
|
|
return self.tooltip
|
2011-11-14 03:40:18 +01:00
|
|
|
end
|
|
|
|
|