mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 19:44:54 +02:00
reorganize modules
This commit is contained in:
69
modules/core_widgets/tooltip/tooltip.lua
Normal file
69
modules/core_widgets/tooltip/tooltip.lua
Normal file
@@ -0,0 +1,69 @@
|
||||
ToolTip = {}
|
||||
|
||||
-- private variables
|
||||
local currentToolTip
|
||||
|
||||
-- private functions
|
||||
local function moveToolTip(tooltip)
|
||||
local pos = g_window.getMousePos()
|
||||
pos.y = pos.y + 1
|
||||
local xdif = g_window.getSize().width - (pos.x + tooltip:getWidth())
|
||||
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
|
||||
ToolTip.hide()
|
||||
currentToolTip = UI.display('tooltip.otui')
|
||||
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
|
||||
currentToolTip:setSize(size)
|
||||
moveToolTip(currentToolTip)
|
||||
end
|
||||
end
|
||||
|
||||
function ToolTip.hide()
|
||||
if currentToolTip then
|
||||
currentToolTip:destroy()
|
||||
currentToolTip = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- UIWidget hooks
|
||||
local function onWidgetHoverChange(widget, hovered)
|
||||
if hovered then
|
||||
ToolTip.display(widget.tooltip)
|
||||
else
|
||||
ToolTip:hide()
|
||||
end
|
||||
end
|
||||
|
||||
local function onWidgetStyleApply(widget, style)
|
||||
if style and style.tooltip then
|
||||
widget.tooltip = style.tooltip
|
||||
end
|
||||
end
|
||||
|
||||
connect(UIWidget, { onStyleApply = onWidgetStyleApply,
|
||||
onHoverChange = onWidgetHoverChange})
|
||||
|
||||
-- UIWidget extensions
|
||||
function UIWidget:setTooltip(text)
|
||||
self.tooltip = text
|
||||
end
|
||||
|
||||
function UIWidget:getTooltip()
|
||||
return self.tooltip
|
||||
end
|
||||
|
9
modules/core_widgets/tooltip/tooltip.otui
Normal file
9
modules/core_widgets/tooltip/tooltip.otui
Normal file
@@ -0,0 +1,9 @@
|
||||
RectPanel
|
||||
background-color: #111111bb
|
||||
size: 200 200
|
||||
id: toolTip
|
||||
focusable: false
|
||||
|
||||
Label
|
||||
id: toolTipText
|
||||
anchors.centerIn: parent
|
Reference in New Issue
Block a user