Skip to content

Widgets

Generated from engine/ui/widget.h at f525bc6. The text under each declaration is the header's own comment, word for word. About the reference says how these pages are made.

Browse the ui module

Audience: game code.

#include "engine/ui/widget.h" · namespace labrador

class UiObject : public GameObject

A named, hideable thing in a user interface.

Geometry stays in the game's authored space. The game owns layout (T1) and maps the menu to screen space through DrawList::set_camera in engine/render/renderer.h; widgets do not recursively rescale themselves.

UiObject() = default;
explicit UiObject(const std::string& name, bool hidden = false);
const std::string& name() const;
void set_hidden(bool hidden);
bool hidden() const;
void update(float dt) override = 0;
void draw(DrawList& draw_list) const override = 0;
RectangleF bounds() const override = 0;
virtual void set_colour(const Colour& colour);

No-op for an object without colour. Containers can forward colour to all their children without testing each child's type.

class UiWidget : public UiObject

A colourable UiObject accepted by FocusGroup in engine/ui/focus.h.

UiWidget() = default;
explicit UiWidget(const std::string& name, bool hidden = false);
~UiWidget() override = default;
void update(float dt) override = 0;
void draw(DrawList& draw_list) const override = 0;
RectangleF bounds() const override = 0;
void set_colour(const Colour& colour) override = 0;

Widgets implement colouring rather than inheriting UiObject's no-op.

class UiContainer : public UiWidget

A compound widget that updates, draws and colours its children in insertion order. It can be focused as one row and derived from to own its parts (docs/design/PHILOSOPHY.md, UI).

Child pointers are borrowed and must remain alive while operations can reach them. A derived class can own child members and add them from its constructor body; container destruction drops pointers without reading children, so those members may be destroyed before the base container.

UiContainer() = default;
explicit UiContainer(const std::string& name);
void add_child(UiObject* child);

Stores the child's name and borrows the pointer. Throws std::invalid_argument for a null child.

void remove_child(const std::string& name);
void remove_child(const UiObject* child);
size_t child_count() const;

Remove the first matching child, without destroying it. No-op if absent.

const std::vector<std::pair<std::string, UiObject*>>& children() const;

The children's names and pointers in insertion order; the pointers remain borrowed. The reference is invalidated by add_child and remove_child.

void update(float dt) override;
void draw(DrawList& draw_list) const override;

Hidden children still update; hiding a container suppresses its draw.

RectangleF bounds() const override;
RectangleF cull_bounds(float units_per_pixel) const override;

Union of child bounds, skipping width or height <= 0. Returns RectangleF::zero when no child contributes.

void set_colour(const Colour& colour) override;

Forwarded to every child, including hidden ones, in insertion order. Nested containers forward it; children without colour ignore it.

class UiTexture : public UiWidget, public TextureObject

Leaf widgets are open to derivation (docs/design/PHILOSOPHY.md, UI) and safe to delete through UiWidget*. An overriding draw() must check hidden() itself: it replaces the leaf's check rather than running after it.

UiTexture() = default;
UiTexture(const std::string& name,
const std::string& sheet_name,
const std::string& frame_name,
const RectangleF& rectangle,
RenderResources* render_resources,
const Colour& color = Colour::white,
bool hidden = false,
float rotation = 0.0f,
const Vector2F& origin = Vector2F::zero,
SpriteFlip flip = SpriteFlip::none,
float layer_depth = 0.0f);
void update(float dt) override;
void draw(DrawList& draw_list) const override;
RectangleF bounds() const override;
RectangleF cull_bounds(float units_per_pixel) const override;

set_sprite_frame · set_colour · set_position · set_position_at_center · set_width · set_height · set_size

Section titled “set_sprite_frame · set_colour · set_position · set_position_at_center · set_width · set_height · set_size”
void set_sprite_frame(const std::string& frame_name);
void set_colour(const Colour& colour) override;
void set_position(const Vector2F& position);
void set_position_at_center(const Vector2F& position);
void set_width(float width);
void set_height(float height);
void set_size(const Vector2F& size);
const RectangleF& rectangle() const;
class UiText : public UiWidget, public Text
UiText() = default;
UiText(const std::string& name,
const std::wstring& text,
const std::string& font_name,
const Vector2F& position,
RenderResources* render_resources,
const Colour& color = Colour::white,
bool hidden = false,
float scale = 1.0f,
float rotation = 0.0f,
const Vector2F& origin = Vector2F::zero,
float layer_depth = 0.0f);
void update(float dt) override;
void draw(DrawList& draw_list) const override;
RectangleF bounds() const override;
void set_colour(const Colour& colour) override;

Named in the public declarations above: Colour, DrawList, GameObject, RectangleF, RenderResources, SpriteFlip, Text, TextureObject, Vector2F.

The files that include this header directly. A file can also reach it through another header.

Documentation for Labrador v0.4.0. Built from Labrador f525bc6 of 2026-11-17.

All documentation versions