[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: What is your favorite Lua GUI toolkit?
- From: David Given <dg@...>
- Date: Wed, 09 Feb 2011 11:44:35 +0000
On 02/09/11 00:37, Rob Kendrick wrote:
[...]
> It would be ncurses, but nobody's written a binding for it yet that
> doesn't make me want to spurt poisonous bile from my nipples.
You might want to get that looked into...
I'm quite happy with the curses-based GUI wot I wrote for WordGrinder,
although it's very simple. To run a dialogue you just do:
local dialogue = {
title = "Title goes here"
width = Form.Large, -- just smaller than screen
height = 12, -- or absolute value,
-- Arbitrary keybindings
["KEY_RETURN"] = function() return "confirm" end,
["KEY_ENTER"] = "confirm",
["KEY_^C"] = "cancel",
-- Widgets:
Form.Label {
-- bounding box. Negative numbers go from
-- opposite side of dialogue
x1 = 1, y1 = 2,
x2 = -1, y2 = 2,
align = Form.Left,
text = "Hello, world!"
},
Form.TextField {
x1 = 1, y1 = 5,
x2 = -1, y2 = 5,
value = "Initial value of text field"
}
}
Then you do:
local result = Form.Run(dialogue, RedrawScreen)
RedrawScreen is a function that draws what's behind the dialogue, and it
returns a value indicating whether the dialogue was confirmed or
cancelled. Typically I call this in a loop that validates the values the
user put into the dialogue.
The whole thing's about 600 lines of code, not including the curses
drawing routines. Widgets can be customised by overriding methods on the
widget instantiation. I'm fairly pleased with the general Lua-ness of it.
There's a bunch of stuff wrong with it, mainly in that it handles
screens too small for the dialogue rather ungracefully, and of course
the total lack of documentation, polish, and the fact that it's
integrated into WordGrinder and intended for dialogues only; I have
other stuff I want to write using it, and so have vague plans to
abstract it into a proper library at some point.
Code here:
http://wordgrinder.hg.sourceforge.net/hgweb/wordgrinder/wordgrinder/file/f658d1e8f1f3/src/lua/forms.lua
Example here (starting at line 100):
http://wordgrinder.hg.sourceforge.net/hgweb/wordgrinder/wordgrinder/file/f658d1e8f1f3/src/lua/addons/autosave.lua
--
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "Thou who might be our Father, who perhaps may be in Heaven, hallowed
│ be Thy Name, if Name Thou hast and any desire to see it hallowed..."
│ --- _Creatures of Light and Darkness_, Roger Zelazny