gui-kit

API Reference

Window

GLFW-based window management with OpenGL rendering support.

The guikit::Window class is the entry point of every gui-kit application. It creates a GLFW window with an OpenGL context and a Renderer, and it drives the render loop. A Window owns a RootElement (exposed via Window::rootElement) that all widgets are attached to.

This doc assumes using namespace guikit is set and #include <guikit/window.hpp> is included. Otherwise, use guikit::Window instead of Window.

Constructor

Window(std::string title, uint64_t width, uint64_t height)

Creates a hidden, resizable window with the given title and dimensions, initializes SDL_ttf, and creates a default RootElement sized to the window.

Window(std::string title, uint64_t width, uint64_t height);

Example:

Window window("My App", 800, 600);

Destructor

~Window()

Releases the renderer and destroys the GLFW window.

~Window();

Available methods

setTitle(std::string title)

Sets the window title.

Window &setTitle(std::string title);

Example:

Window window("My App", 800, 600);
window.setTitle("New Title");

setWindowSize(uint16_t width, uint16_t height)

Sets the window dimensions and updates the cached winW / winH.

Window &setWindowSize(uint16_t width, uint16_t height);

Example:

Window window("My App", 800, 600);
window.setWindowSize(1024, 768);

setRenderCallback(std::function<void()> callback)

Registers a callback that is invoked every frame, after the widget tree has been rendered.

Window &setRenderCallback(std::function<void()> callback);

setRootElement(const std::shared_ptr<RootElement> &widget)

Replaces the root widget of the scene. The window constructs its own RootElement automatically, so this is usually only needed for advanced setups.

void setRootElement(const std::shared_ptr<RootElement> &widget);

show()

Makes the window visible and starts the main render loop. The loop:

  • polls GLFW events, dispatching click, hover, and key callbacks,
  • re-lays out the widget tree when the window size changes,
  • renders the RootElement,
  • caps the frame rate to ~60 FPS and draws an FPS counter overlay.
void show();

Example:

Window window("My App", 800, 600);
window.show();

close()

Stops the render loop, destroys the window, and shuts down GLFW.

void close();

onResize()

Rebuilds the renderer when the window is resized. Called automatically by the internal framebuffer resize callback.

void onResize();

rebuildRenderer()

Destroys and recreates the renderer against the current framebuffer. Also called automatically on window size changes.

void rebuildRenderer();

Full Example

#include <guikit/window.hpp>

using namespace guikit;

int main() {
    Window window("My Application", 1024, 768);
    window.show();
    return 0;
}

On this page