With the news that a GUI update is on the cards for 0.14/0.15, would it be worth taking a step back and considering a different approach to the GUI?
Specifically, I'm thinking a generic 'panel' could form the basis of most aspects of GUI.
Panel would have properties such as:
* background image
* margin (outer spacing between panel and siblings/parent)
* padding (inner spacing between panel and children)
* clickable = when true, panel is clickable
* width, height, minWidth, minHeight, maxWith, maxHeight
* scroll properties
* flow properties (vertical, horizontal, etc. CSS-like
flexbox features would be ideal)
* sounds (or maybe better just a new sound API)
* etc.
Thus a frame is a panel with background image, containing a label and a flow. A flow is just a basic panel with no background image. A button is a clickable panel with a label, a glyph button with a sprite.
Thus, I could easily create a button with both a glyph and a label: a clickable panel, with two children (a glyph and a label). That also pretty much deals with checkbox and radio button - would we need dedicated elements for them any more?
When user clicks the UI, if the element they click on is not marked as clickable, the click ripples up through parent and ancestors until it finds a clickable panel. If it reaches LuaGui (top, left, center) the click is discarded.
If flexbox-like features are implemented (would be available on all gui elements, not just panels) then
grids could be implemented without the need for a special control (although specifying num columns might need some ponderage).
Almost all elements could have child elements, notable exceptions might be label and textbox. Speaking of textbox, a new .pattern field which would be a
pattern to constrain user input (eg. to numbers or specific chars).
Add a .draggable = LuaGuiElement property and now we have custom scrollers, sliders, etc. The LuaGuiElement specified must be parent or ancestor of the draggable element, and is used to constrain where the draggable element can be dragged to. Exposing properties like x,y (top, left) and width, height would mean we could easily keep track of where dragged things are.
Also, option to rotate an element (.rotate prop) with or without rotating its children. This, when use in conjunction with draggables or carefully styled sliders, would allow creation of dials, knobs, analog displays (think steampunk). Delta events or even remote calls would be required to make this sort of thing reality (we'd need events/calls to update our UI while something is being dragged, not just when the dragging is complete).
Ability to define composition and monolith images in their own right (like we can do with sprites), and then use them by named reference in prototypes. Ability to define GUI style sheets at runtime, eg. in control.lua, and "compile" them (get a handle to C object representing the style) for fast re-use and application. These two things combined would make it much easier to do GUI stuff - simply reloading a save after making changes, without needing to exit game to update prototypes.
Most element properties could be set to special 'inherit' value that causes them to get the value from parent (recursive, until found, up to and including to LuaGui top/left/center). This would allow, for example, me to set font or color at top-level of a dialog and have all text in that dialog inherit the setting from the dialog Panel.
Full list of GUI elements could therefore be:
* Panel
* Sprite
* Label / Textbox (a textbox is just an editable label?)
* Progress
* Grid (flexbox with specific number of columns)
* Monitor (shows live map view, similar to the train station UI) - can contain child elements so I can overlay UI on it
* Slider (could be created with draggable panel, but convenient to have dedicated element)
* Checkbox / Radio (again, just for convenience)
Sorry for huge post. :/