Skip to content

Commit

Permalink
Add the ability to override Tooltip's delay per panel (#1875)
Browse files Browse the repository at this point in the history
Adds the following methods to Panel:
```lua
Panel:SetTooltipDelay( delay )
Panel:GetTooltipDelay()
```
Internally this sets the `numTooltipDelay` value on the affected panel.  
DToolTip's will also have the `OpenDelay` value, which is determined by the above functions, and defaults to the existing convar value.
  • Loading branch information
djsime1 authored Apr 17, 2023
1 parent bb6b79f commit c3724a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 14 additions & 0 deletions garrysmod/lua/includes/extensions/client/panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,13 @@ function meta:GetTooltipPanel()
return self.pnlTooltipPanel
end

--[[---------------------------------------------------------
Name: GetTooltipDelay
-----------------------------------------------------------]]
function meta:GetTooltipDelay()
return self.numTooltipDelay
end

--[[---------------------------------------------------------
Name: SetTooltip
-----------------------------------------------------------]]
Expand All @@ -310,6 +317,13 @@ function meta:SetTooltipPanelOverride( panel )
self.pnlTooltipPanelOverride = panel
end

--[[---------------------------------------------------------
Name: SetTooltipDelay
-----------------------------------------------------------]]
function meta:SetTooltipDelay( delay )
self.numTooltipDelay = delay
end

--[[---------------------------------------------------------
Name: SizeToContentsY (Only works on Labels)
-----------------------------------------------------------]]
Expand Down
6 changes: 4 additions & 2 deletions garrysmod/lua/vgui/dtooltip.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

--
-- The delay before a tooltip appears
-- Can be overridden with PANEL:SetTooltipDelay
--
local tooltip_delay = CreateClientConVar( "tooltip_delay", "0.5", true, false )

Expand Down Expand Up @@ -98,15 +99,16 @@ end
function PANEL:OpenForPanel( panel )

self.TargetPanel = panel
self.OpenDelay = isnumber( panel.numTooltipDelay ) and panel.numTooltipDelay or tooltip_delay:GetFloat()
self:PositionTooltip()

-- Use the parent panel's skin
self:SetSkin( panel:GetSkin().Name )

if ( tooltip_delay:GetFloat() > 0 ) then
if ( self.OpenDelay > 0 ) then

self:SetVisible( false )
timer.Simple( tooltip_delay:GetFloat(), function()
timer.Simple( self.OpenDelay, function()

if ( !IsValid( self ) ) then return end
if ( !IsValid( panel ) ) then return end
Expand Down

0 comments on commit c3724a4

Please sign in to comment.