Trying to resize a control panel's TextBox

Hi all,

I dislike the default height of a textbox in a control panel, and I would like to change it.

So I tried to replace this:

panel:AddControl( "TextBox",  { Label = "label", Command = "command" })

By this:

local left = vgui.Create( "DLabel", panel )
left:SetText( "label" )
left:SetDark( true )
local right = vgui.Create( "DTextEntry", panel )
right:SetConVar( "command" )
right:Dock( FILL )
panel:AddItem( left, right )

(This code is the original code of a textbox, I only added SetTall and SetHeight to it)

But this had no effect at all, the textbox is still created with the default size… How can I change it?

Why not use SetSize(w,h)

[editline]27th February 2014[/editline]

That’s not for labels, sorry.

SetSize is being ignored when you Dock it.
Use DockPadding or DockMargin instead.

I’d love to increase their height by default, but I never got it to work.

I solved it, by doing my own control…:

local control = vgui.Create( "DSizeToContents", panel )
control:Dock( TOP )
control:DockPadding( 10, 10, 10, 0 )

local label = vgui.Create( "DLabel", control )
label:SetText( "label" )
label:SetDark( true )
label:SetSize( 100, 20 )
label:Dock( LEFT )
local textbox = vgui.Create( "DTextEntry", control )
textbox:SetConVar( "command" )
textbox:SetToolTip( "description" )
textbox:SetTall( 25 )
textbox:SetPos( 110, 0 )
textbox:Dock( TOP )
table.insert( panel.Items, control )


Can someone explain to me what is InvalidateLayout and when it should be used? Should I use it in my above code?

I see it’s often used in the vgui files, but I have no idea what it is and I don’t see any visual difference with or without.

It is called when parent changes size ( and position? ) AFAIK.

Panels have a function called PerformLayout, in there, you should place all the layout related code, both of the panel itself, but also of any panels it might contain. Think the DFrame for example, it has to place the closebutton to the topright, if it changes size, it needs to reposition the closebutton. That is done in PerformLayout. Panel:SetSize and (perhaps?) Panel:SetPos calles Panel:InvalidateLayout() (which in turn calls PerformLayout). You can call InvalidateLayout yourself if you want to re-layout something, however, you -usually- don’t need to call this yourself.

Here’s how to change a DTextEntry height size:

[lua] local textbox = vgui.Create( “DTextEntry”, parent );
textbox:SetMultiline( true ); – Enable multiline to resize height
textbox:SetWide( ( parent:GetWide( ) ) - 30 ); – Set it to the parent width - border and padding
textbox:SetTall( textbox:GetTall( ) * 5 ); – Set it 5 times default height[/lua]

All that was needed is to remove the dock FILL and replace it to dock TOP, like the rest of control panel elements.

So, here’s an example how to fix this for live version:

local test = CPanel:AddControl( "TextBox", 	{ Label = "#persistent_mode", Command = "sbox_persist", WaitForEnter = "1" } )
test:Dock( TOP )
test:SetTall( 200 )

I will be replacing the dock type to TOP by default.

Thanks all :wink:

Good :wink: