Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GuiState instead of manual calculation for tooltips #884

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 deletions plugin/src/App/Components/Tooltip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ local Trigger = Roact.Component:extend("TooltipTrigger")
function Trigger:init()
self.id = HttpService:GenerateGUID(false)
self.ref = Roact.createRef()
self.mousePos = Vector2.zero
self.showingPopup = false

self.destroy = function()
Expand Down Expand Up @@ -195,18 +194,22 @@ end
function Trigger:isHovering()
local rbx = self.ref.current
if rbx then
local pos = rbx.AbsolutePosition
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
return rbx.GuiState == Enum.GuiState.Hover
end
return false
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()
if self:isHovering() then
if self.showingPopup or self.showDelayThread then
Expand All @@ -217,7 +220,7 @@ function Trigger:managePopup()
self.showDelayThread = task.delay(DELAY, function()
self.props.context.addTip(self.id, {
Text = self.props.text,
Position = self.mousePos,
Position = self:getMousePos(),
Trigger = self.ref,
})
self.showDelayThread = nil
Expand All @@ -234,13 +237,7 @@ function Trigger:managePopup()
end

function Trigger:render()
local function recalculate(rbx)
local widget = rbx:FindFirstAncestorOfClass("DockWidgetPluginGui")
if not widget then
return
end
self.mousePos = widget:GetRelativeMousePosition()

local function recalculate()
self:managePopup()
end

Expand All @@ -250,11 +247,9 @@ function Trigger:render()
ZIndex = self.props.zIndex or 100,
[Roact.Ref] = self.ref,

[Roact.Change.GuiState] = recalculate,
[Roact.Change.AbsolutePosition] = recalculate,
[Roact.Change.AbsoluteSize] = recalculate,
[Roact.Event.MouseMoved] = recalculate,
[Roact.Event.MouseLeave] = recalculate,
[Roact.Event.MouseEnter] = recalculate,
})
end

Expand Down
Loading