So I need to make buttons highlight when they're hovered on, but no errors pop up and it doesn't work. This is a portion of my code.
cl_init.lua
[CODE] for k, v in pairs (buttons) do
v["buttonvar"] = vgui.Create("DButton", ButtonsLay)
v["buttonvar"]:SetFont("MelonButton")
v["buttonvar"]:SetText(tostring(v["text"]))
v["buttonvar"]:Dock(TOP)
v["buttonvar"]:DockMargin( ScrH() / 70, ScrH() / 30, ScrH() / 70, ScrH() / 30 )
v["buttonvar"]:InvalidateParent( true )
v["buttonvar"]:SetSize(v["buttonvar"]:GetWide(), ScrH() / 30)
v["buttonvar"]:InvalidateParent( true )
v["buttonvar"]:SetTextColor( Color( 213, 213, 216, 255 ) )
v["buttonvar"]:SetContentAlignment( 4 )
v["buttonvar"].Paint = function(btn, w, h)
draw.RoundedBox( 2, 0, 0, w, h, Color( 213, 0, 0, 0 ) )
end
v["buttonvar"].DoClick = function ()
if IsValid(MFM_FirstPanel) then
MFM_FirstPanel:Close()
end
if IsValid(self.ActivePanel) then
self.ActivePanel:Close()
end
v["panelvar"] = vgui.Create(v["panel"], self)
self.ActivePanel = v["panelvar"]
end
local highlight = vgui.Create("DPanel", v["buttonvar"])
highlight:SetSize( 0, v["buttonvar"]:GetTall() )
highlight:Dock( LEFT )
highlight.Paint = function(btn, w, h)
if v["buttonvar"]:IsHovered() then
highlight:SizeTo( v["buttonvar"], h, 1, 0, function ()
end)
end
draw.RoundedBoxEx( 0, 0, 0, w, h, Color( 255, 0, 0, 100 ) )
end
end[/CODE]
IsHovered() is not a function. You have to use the Hovered variable that's part of the DButton.
[editline]9th July 2016[/editline]
[CODE]
somebutton.Hovered -- true or false
[/CODE]
[url]https://wiki.garrysmod.com/page/Panel/IsHovered[/url]
But it says right here that it is, but I'll try your way. Thanks MPan. :)
Oh, I didn't notice that. Maybe it doesn't work for DButtons for some reason, but I know self.Hovered does
Ok Thank you MPan :)
EDIT: I might just being stupid or something, but the same thing is still happening. Here's my new portion of code.
[CODE]
for k, v in pairs (buttons) do
v["buttonvar"] = vgui.Create("DButton", ButtonsLay)
v["buttonvar"]:SetFont("MelonButton")
v["buttonvar"]:SetText(tostring(v["text"]))
v["buttonvar"]:Dock(TOP)
v["buttonvar"]:DockMargin( ScrH() / 70, ScrH() / 30, ScrH() / 70, ScrH() / 30 )
v["buttonvar"]:InvalidateParent( true )
v["buttonvar"]:SetSize(v["buttonvar"]:GetWide(), ScrH() / 30)
v["buttonvar"]:InvalidateParent( true )
v["buttonvar"]:SetTextColor( Color( 213, 213, 216, 255 ) )
v["buttonvar"]:SetContentAlignment( 4 )
v["buttonvar"].Paint = function(btn, w, h)
draw.RoundedBox( 2, 0, 0, w, h, Color( 213, 0, 0, 0 ) )
end
v["buttonvar"].DoClick = function ()
if IsValid(MFM_FirstPanel) then
MFM_FirstPanel:Close()
end
if IsValid(self.ActivePanel) then
self.ActivePanel:Close()
end
v["panelvar"] = vgui.Create(v["panel"], self)
self.ActivePanel = v["panelvar"]
end
local highlight = vgui.Create("DPanel", v["buttonvar"])
highlight:SetSize( 0, v["buttonvar"]:GetTall() )
highlight:Dock( LEFT )
highlight.Paint = function(btn, w, h)
if v["buttonvar"].Hovered then
highlight:SizeTo( v["buttonvar"]:GetWide(), h, 1, 0, function ()
end)
end
draw.RoundedBoxEx( 0, 0, 0, w, h, Color( 255, 0, 0, 100 ) )
end
end
end
vgui.Register("MFM_Cover", PANEL, "DFrame")[/CODE]
Bump?
use IsHovered. Add prints after the IsHovered check to see if it is actually called.
Sorry, you need to Log In to post a reply to this thread.