forked from rojo-rbx/rojo
Use GuiState instead of manual calculation for tooltips (#884)
This commit is contained in:
@@ -163,7 +163,6 @@ local Trigger = Roact.Component:extend("TooltipTrigger")
|
|||||||
function Trigger:init()
|
function Trigger:init()
|
||||||
self.id = HttpService:GenerateGUID(false)
|
self.id = HttpService:GenerateGUID(false)
|
||||||
self.ref = Roact.createRef()
|
self.ref = Roact.createRef()
|
||||||
self.mousePos = Vector2.zero
|
|
||||||
self.showingPopup = false
|
self.showingPopup = false
|
||||||
|
|
||||||
self.destroy = function()
|
self.destroy = function()
|
||||||
@@ -195,18 +194,22 @@ end
|
|||||||
function Trigger:isHovering()
|
function Trigger:isHovering()
|
||||||
local rbx = self.ref.current
|
local rbx = self.ref.current
|
||||||
if rbx then
|
if rbx then
|
||||||
local pos = rbx.AbsolutePosition
|
return rbx.GuiState == Enum.GuiState.Hover
|
||||||
local size = rbx.AbsoluteSize
|
|
||||||
local mousePos = self.mousePos
|
|
||||||
|
|
||||||
return mousePos.X >= pos.X
|
|
||||||
and mousePos.X <= pos.X + size.X
|
|
||||||
and mousePos.Y >= pos.Y
|
|
||||||
and mousePos.Y <= pos.Y + size.Y
|
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Trigger:getMousePos()
|
||||||
|
local rbx = self.ref.current
|
||||||
|
if rbx then
|
||||||
|
local widget = rbx:FindFirstAncestorOfClass("DockWidgetPluginGui")
|
||||||
|
if widget then
|
||||||
|
return widget:GetRelativeMousePosition()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return Vector2.zero
|
||||||
|
end
|
||||||
|
|
||||||
function Trigger:managePopup()
|
function Trigger:managePopup()
|
||||||
if self:isHovering() then
|
if self:isHovering() then
|
||||||
if self.showingPopup or self.showDelayThread then
|
if self.showingPopup or self.showDelayThread then
|
||||||
@@ -217,7 +220,7 @@ function Trigger:managePopup()
|
|||||||
self.showDelayThread = task.delay(DELAY, function()
|
self.showDelayThread = task.delay(DELAY, function()
|
||||||
self.props.context.addTip(self.id, {
|
self.props.context.addTip(self.id, {
|
||||||
Text = self.props.text,
|
Text = self.props.text,
|
||||||
Position = self.mousePos,
|
Position = self:getMousePos(),
|
||||||
Trigger = self.ref,
|
Trigger = self.ref,
|
||||||
})
|
})
|
||||||
self.showDelayThread = nil
|
self.showDelayThread = nil
|
||||||
@@ -234,13 +237,7 @@ function Trigger:managePopup()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Trigger:render()
|
function Trigger:render()
|
||||||
local function recalculate(rbx)
|
local function recalculate()
|
||||||
local widget = rbx:FindFirstAncestorOfClass("DockWidgetPluginGui")
|
|
||||||
if not widget then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
self.mousePos = widget:GetRelativeMousePosition()
|
|
||||||
|
|
||||||
self:managePopup()
|
self:managePopup()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -250,11 +247,9 @@ function Trigger:render()
|
|||||||
ZIndex = self.props.zIndex or 100,
|
ZIndex = self.props.zIndex or 100,
|
||||||
[Roact.Ref] = self.ref,
|
[Roact.Ref] = self.ref,
|
||||||
|
|
||||||
|
[Roact.Change.GuiState] = recalculate,
|
||||||
[Roact.Change.AbsolutePosition] = recalculate,
|
[Roact.Change.AbsolutePosition] = recalculate,
|
||||||
[Roact.Change.AbsoluteSize] = recalculate,
|
[Roact.Change.AbsoluteSize] = recalculate,
|
||||||
[Roact.Event.MouseMoved] = recalculate,
|
|
||||||
[Roact.Event.MouseLeave] = recalculate,
|
|
||||||
[Roact.Event.MouseEnter] = recalculate,
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user