GUI Design
Just thinking out loud here, and I am considering designing the GUI like this:
The GUI class handles events, window clipping, widget layout, etc. Rather than having a bunch of C++ classes that extend a base Widget class, there would just be the Widget class with a Lua script attached to it. The Lua script would handle all events and drawing, so it would determine what kind of widget the C++ object is. For example, here's a script for a simple button:
function Script:Draw(x,y,width,height)
if self.pointerhovered==true then
self.widget.window:SetColor(self.background.r*1.2,self.background.g*1.2,self.background.b*1.2)
else
self.widget.window:SetColor(self.background.r,self.background.g,self.background.b)
end
self.widget.window:DrawRect(self.x,self.y,self.width,self.height)
self.widget.window:SetColor(self.background.r,self.background.g,self.background.b)
self.widget.window:DrawText(self.text,self.x,self.y,self.width,self.height,Text.Center+Text.VCenter)
end
function Script:MouseEnter(x,y)
self.pointerhovered=true
self:Draw(self.x,self.y,self.width,self.height)
end
function Script:MouseLeave(x,y)
self.pointerhovered=false
self:Draw(self.x,self.y,self.width,self.height)
end
function Script:MouseUp(x,y)
if self.pointerhovered==true then
self.widget.gui:EmitEvent(Widget.ActionEvent)
end
self.buttonpressed=false
end
function Script:MouseDown(x,y)
if self.pointerhovered==true then
self.buttonpressed=true
end
end
The upside:
- It's infinitely extensible and can be used to make literally any kind of widget.
The downside:
- The script needs to contains the logic and the drawing, so although skinning is possible, it's not as simple as choosing a couple of colors.
- Complexity in the interaction between C++ and Lua widget logic.
- Debugging editor scripts as they are running = not fun. If people modify the editor GUI scripts it could introduce crashes.
- Coding advanced widgets like a treeview will be quite complex in Lua.
Anyways, I'm just experimenting with it for now.

-
3
16 Comments
Recommended Comments