A vertical scroller in VGUI.

NEVERMIND, this has been solved!

Well, I’m not too good at VGUI so I decided to make some things as a test. I’m having a problem making a vertical scroll bar though. I based it on the Derma horizontal scroller, it aligns all the items in it right, but it doesn’t actually scroll.

Here is my little test script, the scroller code starts at line 54:
[lua]/================
Main Panel
================
/
local PANEL = {}

function PANEL:Init()

self:SetSize(600,ScrH()-8)
self:Center()

end

function PANEL:Paint()

draw.RoundedBox(16,0,0,self:GetWide(),self:GetTall(),Color(255,255,255))

end

function PANEL:OnMousePressed()

self:Remove()

end

vgui.Register(“CBFrame”, PANEL)

/=================
Item Button
=================
/
local PANEL = {}

AccessorFunc(PANEL, “isClicked”, “Clicked”, FORCE_BOOL)

function PANEL:Init()

self:SetSize(100,50)
self.SetClicked = false

end

function PANEL:Paint()

local col = Color(100,100,100)
if self.isClicked then col = Color(0,255,0) end

draw.RoundedBox(4,0,0,self:GetWide(),self:GetTall(),col)
draw.RoundedBox(4,4,4,self:GetWide()-8,self:GetTall()-8,Color(255,255,255))

end

vgui.Register(“CBButton”, PANEL, “Button”)

/=======================
Vertical Scroller
=======================
/
local PANEL = {}

AccessorFunc(PANEL, “m_iOverlap”, “Overlap”)

function PANEL:Init()

self.Panels = {}
self.OffsetY = 0

self.pnlCanvas 	= vgui.Create( "Panel", self )

self:SetOverlap( 0 )

end

function PANEL:AddPanel( pnl )

table.insert( self.Panels, pnl )

pnl:SetParent( self )

end

function PANEL:OnMouseWheeled( dlta )

self.OffsetY = self.OffsetY + dlta * -30
self:InvalidateLayout( true )

return true

end

function PANEL:PerformLayout()

local w, h = self:GetSize()

self.pnlCanvas:SetWide( w )

local y = 0

for k, v in pairs( self.Panels ) do

	v:SetPos( 0, y )
	v:SetWide( w )
	v:ApplySchemeSettings()
	
	y = y + v:GetTall() - self.m_iOverlap

end

self.pnlCanvas:SetTall( y + self.m_iOverlap )

self.OffsetY = math.Clamp( self.OffsetY, 0, self.pnlCanvas:GetTall() - self:GetTall() )

end

vgui.Register(“CBVScroller”, PANEL)

/=====================
Test ConCommand
=====================
/
concommand.Add(“GuiTest”,function(ply,cmd,args)

local main = vgui.Create("CBFrame")
main:MakePopup()

local scroll = vgui.Create("CBVScroller", main)
scroll:SetSize(100,400)
scroll:Center()
scroll:SetOverlap(-10)

for i=1,10 do
	
	local Butt = vgui.Create("DButton")
	Butt:SetSize(100,100)
	Butt:SetText("BUTTON "..i)
	scroll:AddPanel(Butt)
	
end

end)

RunConsoleCommand(“GuiTest”)[/lua]