dermatables

i was getting really tired of the code messiness that derma programming generates, so i made a layer for derma that doesn’t make my code horribly repetitious and ugly as fuck.

for example:
[lua]local someFrame = vgui.Create(“DFrame”, nil)
someFrame:SetPos(64, 64)
someFrame:SetSize(512, 512)
someFrame:SetTitle(“DermaTables”)

local someCBL = vgui.Create(“DCheckBoxLabel”, someFrame)
someCBL:SetPos(32, 32)
someCBL:SetText(“Test”)
someCBL:SizeToContents()

someFrame:MakePopup()
[/lua]

this is ugly, let’s turn it into ~dermatables~:
[lua]local dtable = {
type = “DFrame”, name = “someFrame”, title = “DermaTables”, pos = { 64, 64 }, size = { 512, 512 },
children = {
{ type = “DCheckBoxLabel”, name = “someCBL”, pos = { 32, 32 }, size = 1, text = “Test” }
}
}
dt.process(dtable)
someFrame:MakePopup()[/lua]
it also works with glon (by Deco Da Man)

and the end result (from the sexy dermatable of course):

http://upl.luahelp.com/uploads/hDpBOCd3/gmt_pvp_frostbite0005.jpg

right now, it is very incomplete. also, if it has been done before, i haven’t heard of it and i really don’t give a shit.

post what you think.

Instead of arbitrary names, use the method names as parameters, so that you could add custom panels very easily and without modifying the core. So this…

[lua]local dtable = { type = “MyControl”, Value = “abc” };[/lua]

Would translate into…

[lua]
local panel = vgui.Create( “MyControl” );
panel:SetValue( “abc” );
[/lua]

The ‘Value’ param would translate into the ‘SetValue’ method.

one of my irc bros suggested this (if you mean something like frame[“Set”…capitalize(key)]). i might do that but it may require a bit of a rewrite, no biggie though.

I’d suggest you go with Nevec’s method.

How do you overwrite functions?

Since lua is case sensitive, you can’t bluntly capitalize the names.

Why not just make better constructors?

[lua]vgui.Create( “DFrame”, nil, “Title”, Vector( P, o, s ), Vector( S, i, ze ) )[/lua] ?

what

[editline]08:19AM[/editline]

i also noticed this (in the case of “ConVar”)

[editline]08:20AM[/editline]

dt.process{ type = “DFrame”, name = “someFrame”, title = “DermaTables”, pos = { 64, 64 }, size = { 512, 512 } }

This would be nice.

Something like Dr Magnusson suggested would look and be much better than dt.process style.

I assume the name field in the table indicates the global variable name in which to store the panel? Could you make it so that if the name field is nil, it will not store it in a global but instead simply return the new panel?

Why does no one use the PANEL method?

[lua]
local PANEL = {}

function PANEL:Init()
self:SetSize(128,128)
end

vgui.Register(“a_panel”, PANEL, “DFrame”)
[/lua]

It is so much nicer.

Not when you’re dealing with a lot of them.

What? Its structured properly. When making complex menus with many parts you can split it all up into different panels, you can derive from panels, it is a far better way of coding Derma IMO.

I do… it’s much better from an OOP perspective.

I do as well! Much easier to use in my opinion…

I only use it when I need to create a new object.

That code def looks better. Thanks Rambo.

Rambo hasnt posted here?

phor are you retarded

lmbo