• Add padding to the most left and most right panel of DHorizontalScroller
    7 replies, posted
Is there a way to add padding to the most left and most right panel of DHorizontalScroller? By this I mean that by going as left as you can go there's a space between the edge of the panel and the edge of the DHorizontalScroller frame and the same for going as right as you can.
Yes serveral ways. Give us your code so we can see which is the best option to advise
Well there's not really a ton of code to show yet. I basically just need to give it padding when it's scrolled 100% to left and 100% to right(0 and max). I need W to be the full width cause i want the panels to normally stretch all the way out to the edges if I'm not on the first or last panel.
You haven't tried anything yet? If you want to learn how to code, you'll have to at least try stuff, before asking questions. Search the wiki for help next time: Garry's Mod Wiki Dock the DHorizontalScroller in it's parent, so it will assume it's width (or set the width to scroll:GetParent():GetWide()). For the padding, check if setting Panel/DockMargin or Panel/DockPadding has any effect on the items you want to have padding. If it doesn't work the way you want to, consider not adding the children directly to the DHorizontalScroller, but putting a parent in between that will force space, e.g: local paddingHorizon = 8 local childSize = 64 local parent = vgui.Create("Panel") local child = -- This is the thing you were originally adding to the DHorizontalScroller. local scroller = -- This is your DHorizontalScroller parent:SetSize(childSize + paddingHorizon, childSize) -- The parent is almost exactly the size of the child, except with single padding child:SetParent(parent) child:SetSize(childSize, childSize) child:SetPos(paddingHorizon, 0) -- Position it off the left of the parent by the padding amount -- Now add the parent to the DHorizontalScroller, instead of the child directly. scroller:AddPanel(parent)
Oh don't get me wrong I tried all of the things you suggested. I searched the wiki trying to find a solution and spent a good amount of time trying to figure it out. I just couldn't find a solution. I was thinking of changing the size and pos of the parent but there's no "GetScroll" to see current scroll.
Ah okay sorry in that case, made a bad assumption. Looking at the source code of DHorizontalScroller I can find that OffsetX is what should work for you.
If you want to add padding, you should use panel:GetCanvas():DockPadding(left, top, right, bottom), since you're adding elements inside the scroll panel canvas, not sure why calling it inside it parent doesn't set it padding for the canvas itself
Problem with it is if you use that method when you then scroll it doesn't go to the edges, instead it stops a bit inside the frame. I solved if however, after alot of hours of tinkering and some math. I'll post my code here for anyone with a similar problem. I solved it by adding an external "Scroll" number which firstly and lastly moves the frame and only in between changes the actual DHorizontalScroller scroller-number. Code: local _ = 0 mainmenucharacterselectionframe = vgui.Create("DHorizontalScroller",mainmenubackgroundframe) mainmenucharacterselectionframe:SetSize(ScrW(),ScrH()-(ScrH() / 8 * 3)) mainmenucharacterselectionframe:SetPos(0,ScrH()/8) mainmenucharacterselectionframe:SetOverlap( -DM.FW:getWSize(mainmenucharacterselectionframe) / 100 ) mainmenucharacterselectionframe:SetVisible(true) mainmenucharacterselectionframe:MoveToFront() mainmenucharacterselectionframe:SetDrawOnTop(true) mainmenucharacterselectionframe:SetMouseInputEnabled(true) mainmenucharacterselectionframe.PanelCount = 9 mainmenucharacterselectionframe.MaxScroll = ((DM.FW:getWSize(mainmenucharacterselectionframe) / 4 - DM.FW:getWSize(mainmenucharacterselectionframe)/100 * 1.25) * (mainmenucharacterselectionframe.PanelCount - 4) ) + ((DM.FW:getWSize(mainmenucharacterselectionframe)/100) * (mainmenucharacterselectionframe.PanelCount - 6) ) mainmenucharacterselectionframe.FullScroll = 0 mainmenucharacterselectionframe.SetFullScroll = function(scrollamount) mainmenucharacterselectionframe.FullScroll = math.Clamp(scrollamount,0,mainmenucharacterselectionframe.MaxScroll + DM.FW:getWSize(mainmenucharacterselectionframe) / 100 * 2) end mainmenucharacterselectionframe.Think = function() if mainmenucharacterselectionframe.FullScroll <= DM.FW:getWSize(mainmenucharacterselectionframe)/100 then mainmenucharacterselectionframe:SetPos(DM.FW:getWSize(mainmenucharacterselectionframe)/100 - mainmenucharacterselectionframe.FullScroll ,ScrH()/8) elseif mainmenucharacterselectionframe.MaxScroll - mainmenucharacterselectionframe.FullScroll <= DM.FW:getWSize(mainmenucharacterselectionframe)/100 then mainmenucharacterselectionframe:SetPos( -(DM.FW:getWSize(mainmenucharacterselectionframe)/100 - math.Clamp(mainmenucharacterselectionframe.MaxScroll - mainmenucharacterselectionframe.FullScroll, 0 , 999999999)) ,ScrH()/8) else mainmenucharacterselectionframe:SetPos(0,ScrH()/8) end mainmenucharacterselectionframe:SetScroll(math.Clamp(mainmenucharacterselectionframe.FullScroll - DM.FW:getWSize(mainmenucharacterselectionframe)/100,0,999999999)) _ = _ + 2 mainmenucharacterselectionframe.SetFullScroll(_) end mainmenucharacterselectionframe.Paint = function() end mainmenucharacterselectionframe.OnClose = function() mainmenucharacterselectionframe:Remove() end for i = 1, mainmenucharacterselectionframe.PanelCount do local selectionimage = vgui.Create( "DImage", mainmenucharacterselectionframe ) selectionimage:SetSize(DM.FW:getWSize(mainmenucharacterselectionframe)/4 - (DM.FW:getWSize(mainmenucharacterselectionframe)/100 * 1.25) ,DM.FW:getHSize(mainmenucharacterselectionframe)) selectionimage:SetPos(DM.FW:getWSize(mainmenucharacterselectionframe)/100,0) selectionimage:SetImage( "scripted/breen_fakemonitor_1" ) mainmenucharacterselectionframe:AddPanel( selectionimage ) end
Sorry, you need to Log In to post a reply to this thread.