• DLabel help
    2 replies, posted
[lua] function ShowURPInfo(name, text) local DermaPanel = vgui.Create( "DFrame" ) -- Creates the frame itself DermaPanel:SetPos( (ScrW() / 2) - 125, (ScrH() / 2) - 300) -- Position on the players screen DermaPanel:SetSize( 250, 150 ) -- Size of the frame DermaPanel:SetTitle( "UltimateRP - " .. (name or "Information")) -- Title of the frame DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( false ) -- Draggable by mouse? DermaPanel:ShowCloseButton( true ) -- Show the close button? DermaPanel:MakePopup() -- Show the frame DermaPanel:SetMouseInputEnabled(true) DermaPanel:SetSkin("DarkRP") surface.SetFont("default") local w, h = surface.GetTextSize(text) local UText = vgui.Create("DLabel", DermaPanel) UText:SetPos(5,23) UText:SetSize(240, h + 23) UText:SetWrap(true) UText:SetText(text) if h > 127 then //We need a scrollbar local scrollBar = vgui.Create( "DVScrollBar", DermaPanel ) scrollBar:SetSize( 16, 134) scrollBar:SetPos(DermaPanel:GetWide() - 16,23) scrollBar:SetUp(1,h) scrollBar:SetEnabled(true) end end [/lua] I'm trying to make a scrollable DFrame with multiline text, it does alright with a bit of text. But after a while, my code doesn't create a scrollbar when it should and shifts the position of DLabel down for some reason. I'm trying not to use a DTextBox, will I have to?
First, you could try to use SizeToContents() on the label.
That messes up the size limit, I don't want it to overlap the DFrame. [lua] local DermaPanel = vgui.Create( "DFrame" ) -- Creates the frame itself DermaPanel:SetPos( (ScrW() / 2) - 125, (ScrH() / 2) - 300) -- Position on the players screen DermaPanel:SetSize( 250, 150 ) -- Size of the frame DermaPanel:SetTitle( "UltimateRP - " .. (name or "Information")) -- Title of the frame DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( false ) -- Draggable by mouse? DermaPanel:ShowCloseButton( true ) -- Show the close button? DermaPanel:MakePopup() -- Show the frame DermaPanel:SetMouseInputEnabled(true) DermaPanel:SetSkin("DarkRP") local UText = vgui.Create("DTextEntry", DermaPanel) UText:SetPos(5,28) UText:SetSize(240, 117) UText:SetMultiline(true) UText:SetWrap(true) UText:SetText(text) UText:SetDrawBackground(false) UText:SetDrawBorder(false) UText:SetEditable(false) [/lua] Works well, but I don't know how to add a scroll bar.
Sorry, you need to Log In to post a reply to this thread.