HelloWorld

Creating your first LibSTK application is simple enough. There are three main steps involved:

  1. Create the application object
  2. Create the widgets
  3. Start the application event loop.

Download hello_world.cpp.

Preparation (lines 13-21)

Of course, before we can code anything, we need to include the appropriate header files. Line 14 includes the standard libstk widgets an objects. Lines 17-18 include files corresponding to the specific backend we wish to use for our application. Lastly, to simplify the code we use the namespace stk.

The Application Object (lines 30-34)

All LibSTK widgets are created using the named constructor "create" which returns the appropriate smart pointer. For more information on this construction method and smart pointers, see the introduction and smart pointers documentation. In order to create an application, we need to specify the surface and event system backends we wish to use. For this example we included the SDL backends, so we create a surface_sdl and an event_system_sdl and pass them as arguments to the application constructor.

Widget Creation (lines 37-39)

LibSTK applications are state based, you can think of states like tabs in other widget sets. Only one state is visible at a time and they are the top level container for widgets (like a window would be in other toolkits). Every widget requires a parent, an application must be passed as the parent for states. The label receives a state as its parent and requires a string and a rectangle as well. Note the string is not a std::string, but rather a std::wstring, and is created with an L preceding the quoted string (this is part of LibSTK's Überscript internationalization system). The rectangle is created with x, y, width, and height values which define its size and location on the screen.

The Application Event Loop (line 42)

Now that all the application and widgets have been created, the application is ready to run. Simply call application::run(). When the application exits, it returns an appropriate return value. Our application will now terminate and free all memory pointed to by the smart pointers. That't it!