-
Notifications
You must be signed in to change notification settings - Fork 58
Description
I wanted to change the default yellow tooltip without copying\editing any of the core files. So I looked into SetTooltipPanel. https://wiki.garrysmod.com/page/Panel/SetTooltipPanel
The description on the wiki says -
Sets the panel object to be displayed as a tooltip when a player hovers over the panel object with their cursor.
After trying to set a custom panel to be displayed, I noticed the paint hook was not being called. So I did a bit of digging and noticed that in
"garrysmod/garrysmod/lua/vgui/dtooltip.lua"
The panel that you set with the function is actually set to PANEL.Contents and soon after is set to not visible.
function PANEL:SetContents( panel, bDelete )
panel:SetParent( self )
self.Contents = panel
self.DeleteContentsOnClose = bDelete or false
self.Contents:SizeToContents()
self:InvalidateLayout( true )
self.Contents:SetVisible( false )
endOkay so if I set it to visible then Paint works but the panel is set within the yellow box since of course it's the parent and the parent is still drawing the yellow box.
function PANEL:PerformLayout()
if ( self.Contents ) then
self:SetWide( self.Contents:GetWide() + 8 )
self:SetTall( self.Contents:GetTall() + 8 )
self.Contents:SetPos( 4, 4 )
else
local w, h = self:GetContentSize()
self:SetSize( w + 8, h + 6 )
self:SetContentAlignment( 5 )
end
endSo the sizing makes sense now. So lets move on to the paint.
function PANEL:Paint( w, h )
self:PositionTooltip()
derma.SkinHook( "Paint", "Tooltip", self, w, h )
endThe tooltip was never going to stop displaying it self if a custom panel was provided.
A quick fix for this..
function PANEL:Paint( w, h )
self:PositionTooltip()
if self.Contents && self.Contents.Paint then
self.Contents.Paint(self,w,h)
else
derma.SkinHook( "Paint", "Tooltip", self, w, h )
end
endOf course the size will actually be increased by 8 both ways due to what happens in PANEL:PerformLayout().
So okay.. What if I wanted a way to push the settooltip text to the new panel? It's not possible because if you set the tooltip text then it will not push the new panel to the dtooltip.
"garrysmod/garrysmod/lua/includes/util/tooltips.lua"
function ChangeTooltip( panel )
RemoveTooltip()
local Text, Panel, PositionPanel = FindTooltip( panel )
if ( !Text && !Panel ) then return end
Tooltip = vgui.Create( "DTooltip" )
if ( Text ) then
Tooltip:SetText( Text )
else
Tooltip:SetContents( Panel, false )
end
Tooltip:OpenForPanel( PositionPanel )
TooltippedPanel = panel
endFindTooltip just pulls the text & panel that you have set with the panel functions. And as you can see, text is prioritized over the custom panel. I feel like these should cooperate together instead of against each other.
Now assuming that the description provided on the wiki is exactly what it's supposed to do then the system is bugged. And if it's not then please explain to me what it's actually used for so if I decide to replace them then I won't break anything that strictly relies on it.