• Questions about Docking
    6 replies, posted
I am trying to create multiple DLabels that move on an auto increment down the list, but I am running into difficulties. I have tried docking with TOP using margins, and it doesn't come out right, and I have also tried using padding and it seems to have no affect. This is the code for the dock window I am using [CODE]local dockwindow = vgui.Create("DPanel", Window) dockwindow:SetPos(1, 25) dockwindow:SetSize(170, 380) dockwindow.Paint = function() draw.RoundedBoxEx( 8, 0, 0, dockwindow:GetWide(), dockwindow:GetTall(), Color(0,0,0,0), false, false, false, false) end[/CODE] and this is the code for setting the position: [CODE]function PANEL:SetTarget(target, pl, k, approve, deny) self.Target = target self.pl = pl if !self.pl then self.pl = self.Target end self:SetPos(1, (35 * (k - 1) ) ) end[/CODE] What I am trying to do is move it smoothly downward, but each time I attempt to do it (either with that SetPos or Docking) they become offset after the 2nd or 3rd dlabel created. I am not familiar with the Dock function so there may be something I am overlooking. The boxes being created need to have a gap between them in because they are separated by a DrawLine divider. I may be able to post screenshots of what exactly it looks like with Docking to further explain my issue. I tried DockMargin(0, 0, 0, 5) which did work but cut off the top of any boxes created below it, but when lowering it under 5 it had a major offset for some strange reason. I will post screenshots and additional information sometime tomorrow, heading to bed at the moment.
There's an example of docking DLabels in a list here. [url]http://wiki.garrysmod.com/page/Panel/Dock[/url] But yes, you should post pictures of what you're trying to achieve and what you currently have.
[IMG]http://i63.tinypic.com/2hdtso8.png[/IMG] [CODE]self:SetSize(0, 35) self:Dock(TOP) self:DockMargin(0, 0, 0, 5)[/CODE]
[QUOTE=KevinnTCG;50338197][IMG]http://i63.tinypic.com/2hdtso8.png[/IMG] [CODE]self:SetSize(0, 35) self:Dock(TOP) self:DockMargin(0, 0, 0, 5)[/CODE][/QUOTE] I am not sure what you are trying to do, but just give the parent spacing of 1 and fill in your panels?
Well I have it loop through each value and create the name and avatar, I used myself for all of the values to fill the menu. Even the names and avatars use this: [CODE]Avatar:SetPos(5, ( 40 * i ) - 15 ) name:SetPos( 40, 8 + ( 40 * ( k - 1 ) ) + ( 380 / 16 ) )[/CODE] The K is the loop value that I send to the function, 380 / 16 is something I did a long time ago I guess dividing the windows height by 16...still not quite sure why I did that but it seems to partially work (the names and avatar move very slightly downward as each one is created. I am mostly just looking for a way to (while looping i=1, 9) through the table values to add all of them with a steady increment. One problem I might have is creating an alternate DPanel (the one filled with red in the screenshot) drawn over the main DPanel that the text and avatar are written on. The name is just a label, the back is a button that is supposed to glow red when hovered over, but I toggled it on all of them to show the spacing. When going under any value under 5 on the Margin all of the spacing gets majorly messed up, I will keep messing with it of course but I was hoping there was something simple/obvious I was overlooking. EDIT: Maybe what I am confused on is how the DockMargin and DockPadding are different. Can't really find anything good online to explain their purposes.
DockPadding and DockMargin only work on Dock() ed elements, if you are positioning them yourself, they won't do jack shit. Get a Panel Dock(FILL) ed, Dock padding will be the "inner border spacing", then just do Dock( TOP ) on each of your child panels ( with parenting of course ), DockMargin will be the "outer border spacing of each of the player "lines".
Yeah I positioned the parent myself, but did not Dock(FILL) it. Other than that I was using DOCK( TOP ) with that dpanel parented. So the main issue was the lack of a Dock(FILL) on the parent?. Would just test it myself but I am currently in class.
Sorry, you need to Log In to post a reply to this thread.