We will implement a minimal "Hello world" application with libagar.
If libagar is not yet installed on your system, refer to the Installation Guide for your particular platform. Compilation of a minimal "Hello world" is demonstrated at the end of each Installation Guide.
*** FIXME how to set monospace font in patreon text posts?
main(int argc, char *argv)
win = AG_WindowNew(0);
AG_LabelNew(win, 0, "Hello, world!");
We must initialize both core and gui libraries by calling AG_InitCore() followed by AG_InitGraphics(). We omit error checking in this example, but in a proper application both calls should be checked for a return value of -1, in which case the error string could be retrieved using AG_GetError().
Create an AG_Label widget by calling AG_LabelNew(), passing the AG_Window object as the parent argument. Another possibility for the parent argument would have been a different widget (for example an AG_Box) acting as a container widget, but here we attach the label to the window directly.
Newly created windows are not visible by default. To make a window visible we must call AG_WindowShow().
Finally, enter AG_EventLoop(). This is agar's standard event loop routine which waits on low-level events (such as activity on sockets / file descriptors, timer expirations and kernel-event notifications), and processes them.