DGUI (dragon-gui): runtime GUI library for rapid panel building, with a real textarea widget

Hi everyone,

I built a small GUI library for my own game and wanted to share it in case it’s useful to anyone else. It’s called dragon-gui (DGUI).

Why I made it:
I wanted to build UI panels fast, without placing dozens of nodes in the GUI editor. With DGUI the only thing you need in the editor is one root box node. You describe the panel as Lua tables, and DGUI builds the nodes, lays them out and handles input.

lua

local dgui = require("dragon-gui.dgui")

self.ui = dgui.new(self, "panel", { title = "My Panel" })
self.ui:add({ type = "button", id = "go", text = "Go", x = 10, y = 10,
              on_click = function(id) print("clicked", id) end })

What’s in it:

  • Widgets: label, button, slider, checkbox, radio, buttongroup, scrollview, accordion, tabview (including adding and removing tabs at runtime)
  • Layout: vstack and hstack, with automatic reflow when widgets are hidden or shown
  • Header bar with title, extra buttons and dragging
  • A value API (get_value, set_value, get_values, global on_change) that makes saving and restoring UI state easy
  • Rich text through Defold’s native markup (needs a 1.14.2+ engine, otherwise the markup is stripped)

The textarea widget:
This is the main reason I wrote it. I needed proper text editing, which I couldn’t find in a ready-made form. It has a real blinking caret, tap and click to place the caret, drag-select, double-tap for a word, triple-tap for a line, keyboard navigation, and a method API (insert, copy, cut, paste, get_selection and so on) that you can wire to your own buttons. It works as an editor, a read-only log or a selectable text view.

Being honest about the state of it:
It’s not perfect. It works for my project right now, and I’m sharing it as is.

  • The built-in header close button isn’t wired up yet (there’s a workaround in the README).
  • Layout has some rough edges. For example, I’m still tracking down an hstack alignment problem with buttons.
  • The rich text and textarea code was mostly tested against a mock of the gui API, so it needs more testing on real engine builds.
  • Icons and textures need an atlas named ui_assets in your GUI Textures list.

The repo has a large demo script that shows most widgets. If you try it, I’d love bug reports, ideas or PRs. If you’ve built something similar, I’d be interested to hear how you approached it.

Thanks for reading!

4 Likes