Concept Overview
Widgets
All of the user-interface elements supported by the library are considered
to be "widgets". You can freely convert between a specific type and the abstract
type widget
, but no other conversions are allowed.
Widget objects are references
The most important thing to remember about the GUI library is that the objects you use are reference types. That means that if, for example, you make a copy of a window object, you don't get a whole new window. Instead, you get another reference to the first window.
Signals
Widgets that have meaningful events associated with them (such as a button being clicked) use boost::signals to represent those events. You can connect a signal to one or more functions, function objects or slots. See the signal documentation for more information.
No inheritance
One of the striking differences between this library and other GUI libraries
written in C++ is that this library does not use the reuse-is-inheritance model.
This means that you do window
type
in order to use it.
If you really, really want to extend the window type to create your own window type, you can always use aggregation to achieve this end.
Automatic layout
Widgets are automatically arranged in a sensible way, much as HTML elements are arranged on a page. Generally, you use container classes such as grids to line up your widgets. GTK users will be in familiar territory. If you really, really want to specify a pixel-perfect layout yourself, a "fixed_layout" widget can be provided.
Implicit message processing
The majority of current GUI toolkits use a message processing model, where the application must call a function called main_loop or GetMessage to process user events. This library is different in that there is no explicit message loop; where possible, messages are processed in the background. When the main function exits, the message loop terminates. The paradigm in cxxgui is to wait for a signal from a widget, or for a condition to be fulfilled:
int main() { window w("My Window"); wait_for_signal(w.delete_signal()); return 0; }
In this example, the window is created, and the main loop then waits for its "delete signal" (which is usually associated with pressing a "close" decoration - for example the X in the top right corner of a Microsoft Windows window). More commonly, of course, one would check whether the window was ready to close (have the files been saved, etc.):
int main() { window w("My Window"); do { wait_for_signal(w.delete_signal()); } while (!ready_to_exit()); return 0; }
Note that, unlike windows in other GUI toolkits, the window does not close automatically simply because the user pressed the X.