A Windowing System for Codea

I’ve written a tiny windowing system in Codea to support making GUIs for my games and other stuff. I’ve put it up on GitHub at https://github.com/npryce/codea-gui if anyone’s interested in playing with it.

It supports:

  • Axis aligned windows
  • Clip drawing to within windows
  • Automatic, declarative layout management with a few simple layout managers (row, column, anchor in parent window, add margins)
  • Relayout when the UI contents or device orientation changes
  • Dispatching touch events to windows
  • Drawing text and icons

Not implemented yet (but I want to…)

  • Dynamic modification of UIs (add/remove components, change widget config parameters)
  • Keyboard focus management and text input
  • GUI toolkit widgets (buttons, sliders)
  • … etc…

Here’s a simple example: https://github.com/npryce/codea-gui/blob/master/src/Main.lua

When I run it I get an error

error: [string "Screen = class()..."]:19: attempt to call method 'layout' (a nil value)

It looks like the Screen class is not able to get at the layout function defined by the widget class (which it should). Have you tried this in Codea version 1.3.1?

I was about to do this… Nice! Haven’t tried it yet though.

@Herwig - This is a class, not an app.

@Nat Thank you for your sharing. I like to code for GUI stuff. In the future, we might have a lot of widgets such as date picker, check box, etc.

Native GUI in codea wouldn’t be bad…

@Zoyt if you bother to try it you will see the code comes with a main() and a setup() as an example app.

@Herwig: I tested it in Codea 1.3.1. Maybe you have the files in the wrong order or are missing some files. You need to have the files in the same order as in the Plist file in the git repo.

I use iExplorer to import all files. For the first time, I got an error that is not the same as @Herwing found. I didn’t correct anything but I just ran it again. It worked.

Thanks @Nat! I wasn’t aware the order of the tabs was important in the inheritance of classes.

It probably means you can redefine a class after it has been used to inherit from, which opens up some interesting avenues…

Great class by the way! Well worth the trouble it took to copy and paste it into Codea!