fix tooltip

This commit is contained in:
Eduardo Bart 2011-11-14 12:30:35 -02:00
parent ff7f152522
commit 5784644701
2 changed files with 28 additions and 14 deletions

View File

@ -16,18 +16,10 @@ local function moveToolTip(tooltip)
tooltip:moveTo(pos) tooltip:moveTo(pos)
end end
local function onButtonHoverChange(button, hovered)
if hovered then
ToolTip.display(button:getStyle().tooltip)
else
ToolTip:hide()
end
end
-- public functions -- public functions
function ToolTip.display(text) function ToolTip.display(text)
ToolTip.hide()
if text then if text then
ToolTip.hide()
currentToolTip = UI.loadAndDisplay('/tooltip/tooltip.otui', UI.root) currentToolTip = UI.loadAndDisplay('/tooltip/tooltip.otui', UI.root)
currentToolTip.onMouseMove = moveToolTip currentToolTip.onMouseMove = moveToolTip
local label = currentToolTip:getChildById('toolTipText') local label = currentToolTip:getChildById('toolTipText')
@ -48,10 +40,31 @@ function ToolTip.hide()
end end
end end
function UIWidget:setTooltip(text) -- hooks
self:applyStyle({ tooltip = text }) local function onWidgetHoverChange(widget, hovered)
if hovered then
ToolTip.display(widget.tooltip)
else
ToolTip:hide()
end
end
local function onWidgetStyleApply(widget, style)
if not style or not style.tooltip then return end
print(style.tooltip)
widget.tooltip = style.tooltip
table.dump(style)
end
connect(UIWidget, { onStyleApply = onWidgetStyleApply,
onHoverChange = onWidgetHoverChange})
-- public extensions
function UIWidget:setTooltip(text)
self.tooltip = text
end
function UIWidget:getTooltip()
return self.tooltip
end end
-- hooks
connect(UIButton, { onHoverChange = onButtonHoverChange})
connect(UIProgressBar, { onHoverChange = onButtonHoverChange})

View File

@ -741,6 +741,7 @@ void UIWidget::applyStyle(const OTMLNodePtr& styleNode)
{ {
try { try {
onStyleApply(styleNode); onStyleApply(styleNode);
callLuaField("onStyleApply", styleNode);
} catch(std::exception& e) { } catch(std::exception& e) {
logError("failed to apply widget '", m_id, "' style: ", e.what()); logError("failed to apply widget '", m_id, "' style: ", e.what());
} }