gui-kit

API Reference

Box

A solid, rounded, colored rectangle widget.

guikit::Box is the simplest visual widget: a solid, rounded rectangle that can be filled with any color. It also acts as a layout container for child elements.

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

It inherits from Element, so everything in the Element reference is available.

Fields

color

The fill color. Defaults to Colors::White().

Color color = guikit::Colors::White();

radiusTL / radiusTR / radiusBR / radiusBL

The per-corner border radius of the box. Each defaults to 0.

float radiusTL = 0, radiusTR = 0, radiusBR = 0, radiusBL = 0;

Available methods

setBackgroundColor(Color color)

Sets the fill color of the box.

Box &setBackgroundColor(Color color);

Example:

box.setBackgroundColor(Color(255, 0, 0, 255)); // Red box

setBorderRadius(float radius)

Sets the same border radius on all four corners.

Box &setBorderRadius(float radius);

setBorderRadius(float topLeft, float topRight, float bottomRight, float bottomLeft)

Sets each corner's border radius independently.

Box &setBorderRadius(float topLeft, float topRight, float bottomRight, float bottomLeft);

setBorderTopLeftRadius(float radius)

Sets the top-left corner radius.

Box &setBorderTopLeftRadius(float radius);

setBorderTopRightRadius(float radius)

Sets the top-right corner radius.

Box &setBorderTopRightRadius(float radius);

setBorderBottomRightRadius(float radius)

Sets the bottom-right corner radius.

Box &setBorderBottomRightRadius(float radius);

setBorderBottomLeftRadius(float radius)

Sets the bottom-left corner radius.

Box &setBorderBottomLeftRadius(float radius);

Overrides

render()

Draws the box as a rounded rectangle using its current color, then renders all children. Called automatically by the render loop.

void render();

interSect(int x, int y)

Returns true if the point falls within the box's bounds.

bool interSect(int x, int y) override;

Example

#include <guikit/window.hpp>
#include <guikit/box.hpp>
#include <guikit/colors.hpp>

using namespace guikit;

int main() {
    Window window("Box Demo", 800, 600);

    window.rootElement->addChild<Box>()
        .setWidth(240)
        .setHeight(120)
        .setBackgroundColor(Colors::Violet600())
        .setBorderRadius(12);

    window.show();
    return 0;
}

On this page