|
TUI - Tiny User Interface Library
|
The TUI C library is a very small and lightweight library for
writing simple user interface applications that run under X11,
Mac OSX, and Windows. A basic widget set and user interface
builder are included.
|
|
TUI is designed to be simple to use and extremely lightweight. You
can use the TUI layout tool, tui_build, to create an interface
and then save out a header file. In your application you call
TUI_construct() to build the interface. Tui_build
includes all the widgets, but is only 44 KB under Linux and less on
Mac OSX and Windows.
|
|
#include "my_ui.h"
int
main(int argc, char *argv[])
{
TUI_APPLICATION *app;
MY_UI ui;
app = TUI_APPLICATION_create();
TUI_construct(app, &my_ui, my_ui_layout);
TUI_mainloop(ui.tui);
}
|
The header file created by tui_build includes a structure
containing the widgets that you can use in your application and a
layout string which is used to build the interface. Here is the one from the example program.
|
|
You can also call the library functions to build an
interface in your application dynamically, if you don't
want to use tui_build. You can even save out a header file
from dynamically created widgets, if you like.
Here is the entire API.
|
|
|
I wrote TUI so that I could learn about user interface programming
under different operating systems. The code is pretty clean and
should provide a good way for people to learn about basic things like
opening a window and creating widgets on these different
platforms.
Under Windows, TUI uses only WIN32 calls and under Mac OSX,
the basic Mac toolbox routines are uses. I think it would all
work on a regular Mac as well, but I haven't tried that yet.
|
|
I don't like to do "tricky" things in my code, but TUI does one
thing that I think was worth it. The layout code can contain the
name of a callback function in your code. Search for
"callback" in the example header file.
TUI_construct()then asks the OS to find that function in
your application and attaches the callback to the widget. Under
Linux, I use dlopen() & dlsym(), under
Windows, I use GetModuleHandle() &
GetProcAddress(), and under Mac OSX, I use
NSLookupAndBindSymbol() &
NSAddressOfSymbol().
Windows has a horrible compiler and linker, so I had to define a
special link tag, EXPORT that you need to use with your
callback functions. Like this:
|
EXPORT my_callback(TUI_WIDGET_INFO *info)
...
|
Under Linux and OSX, this does nothing, and under Windows, it does
"special stuff" to tell the compiler and linker to reveal these
symbols in the global symbol table. Anyway, it works, and it is
pretty simple to use, and it makes the interface much cleaner.
Otherwise you'd need to litter your code with functions to attach the
callbacks to the widgets (which you can still do manually, if you
like).
The upshot is that you can modify your UI layout, and even add
or remove widgets without having to change your application's code.
In addition to the basic widgets, I plan to include a special
OpenGL drawing region, which will handle the OS-specific parts of
attaching OpenGL to a window. As soon as this, and a bit of cleanup
is done, I'll release the code for TUI under some sort of Open Source
license.
Send me mail if you are
interested in using TUI, or have any questions.
|
|