• Derma Panel Scrollbar
    8 replies, posted
While I was playing around with derma to learn how things work I wanted to make a scrollbar but everything I tried didn't work. So how exactly do I make a scrollbar? The wiki didn't really help me. [IMG]http://i.imgur.com/5r2ZXZu.png[/IMG]
Use [url]http://wiki.garrysmod.com/page/Category:DScrollPanel[/url]
[QUOTE=mjctechguy;50005492]Use [url]http://wiki.garrysmod.com/page/Category:DScrollPanel[/url][/QUOTE] I tried a DScrollPanel but it didn't work. Did I do something wrong? [CODE]local panel1 = vgui.Create( "DScrollPanel", sheet ) panel1:SetWide(600) panel1:SetTall(465) --panel1:SetParent( Panel ) panel1:Dock(RIGHT) panel1:DockMargin(-15,-28,-174,0) panel1.Paint = function( self, w, h ) draw.RoundedBox( 4, 0, 0, 600, h, Color( 190, 190, 190, 255 ) ) for k,v in pairs(player.GetAll()) do surface.SetTextPos( 15, -35+k*50 ) surface.SetFont("MyFont1") surface.SetTextColor(255,255,255,255) surface.DrawText("Name:"..v:Nick()) surface.SetDrawColor(255,255,255) surface.DrawOutlinedRect(0,-50+k*50,350,50) surface.SetTextPos(170, -35+k*50 ) surface.DrawText(v:getDarkRPVar( "money")) end[/CODE]
you have to make a dpanel for each of the players
[QUOTE=mjctechguy;50005591]you have to make a dpanel for each of the players[/QUOTE] Now the first name etc. gets spammed at one panel. How can I make a panel for each name etc.? There is also no visible scrollbar but I can scroll with the mousewheel. [IMG]http://i.imgur.com/6YpsB9k.png[/IMG] [CODE]local panel1 = vgui.Create( "DScrollPanel", sheet ) panel1:SetWide(600) panel1:SetTall(465) --panel1:SetParent( Panel ) panel1:Dock(RIGHT) panel1:DockMargin(-15,-28,-174,0) panel1.Paint = function( self, w, h ) draw.RoundedBox( 4, 0, 0, 600, h, Color( 190, 190, 190, 255 ) ) for k,v in pairs(player.GetAll()) do panelP = vgui.Create( "DPanel") panelP:SetWide(350) panelP:SetTall(50) panelP:SetPos(0,-50+k*50) panelP:SetParent(panel1) function panelP:Paint() surface.SetTextPos( 15, -35+k*50 ) surface.SetFont("MyFont1") surface.SetTextColor(255,255,255,255) surface.DrawText("Name:"..v:Nick()) surface.SetDrawColor(255,255,255) surface.DrawOutlinedRect(0,-50+k*50,350,50) surface.SetTextPos(170, -35+k*50 ) surface.DrawText(v:getDarkRPVar( "money")) end end[/CODE]
Try removing the panelP:SetPos bit (I think the scrollpanel automatically sets the position) [editline]26th March 2016[/editline] Also, in your paint function I don't think you need to be setting the text's height by multiplying it by k since it's local to the panel
[QUOTE=MPan1;50006840]Try removing the panelP:SetPos bit (I think the scrollpanel automatically sets the position) [editline]26th March 2016[/editline] Also, in your paint function I don't think you need to be setting the text's height by multiplying it by k since it's local to the panel[/QUOTE] Thanks, that helped a lot. But still every panel in the scrollpanel gets spammed and there is also no scrollbar but I can scroll with the mousewheel. [IMG]http://i.imgur.com/phdkmVL.png[/IMG] Edit: And if I remove panelP:SetPos it looks like that: [IMG]http://i.imgur.com/4CMHZtt.png[/IMG]
local panel1 = vgui.Create( "DScrollPanel", sheet ) needs to be local panel1 = vgui.Create( "DPanelList", sheet ) with EnableScrollBar() or instead of that, you could just make panelP = vgui.Create( "DPanel") into a [URL]http://wiki.garrysmod.com/page/Category:DLabel[/URL] also whenever ive used dscrollpanel the scrollbar never visibly showed up for me, just try scrolling (just to make sure)
I took the code for the panels out of the scrollpanels paint function and it works now. [QUOTE=Soren;50008869] also whenever ive used dscrollpanel the scrollbar never visibly showed up for me, just try scrolling (just to make sure)[/QUOTE] It works like you said. Is there a way to make the scrollbar visible? Edit: [QUOTE=Soren;50008869] local panel1 = vgui.Create( "DScrollPanel", sheet ) needs to be local panel1 = vgui.Create( "DPanelList", sheet ) with EnableScrollBar() [/QUOTE] That doesn't work. [CODE] [ERROR] addons/mytestaddon/lua/autorun/cl_init.lua:198: attempt to call method 'EnableScrollBar' (a nil value) 1. fn - addons/mytestaddon/lua/autorun/cl_init.lua:198 2. unknown - addons/ulib/lua/ulib/shared/hook.lua:179 [/CODE] [CODE] local panel1 = vgui.Create( "DScrollPanel", sheet ) panel1:SetWide(600) panel1:SetTall(465) panel1:EnableScrollBar() -- Line 198 panel1:Dock(RIGHT) panel1:DockMargin(-15,-28,-174,0) panel1.Paint = function( self, w, h ) draw.RoundedBox( 4, 0, 0, 600, h, Color( 190, 190, 190, 255 ) ) [/CODE]
Sorry, you need to Log In to post a reply to this thread.