Skip to main content
The Draw namespace contains all primitive drawing functions for rendering basic shapes and graphics. These functions provide the foundation for all higher-level UI widgets and graphics operations. All drawing operations use 32-bit RGBA color values in the format 0xAABBGGRR.

Functions

fill()

void Draw::fill(uint32_t color)
Fills the entire canvas with a solid color.
color
uint32_t
required
32-bit RGBA color value (0xAABBGGRR format)
Draw::fill(Colors::Black);        // Fill with black
Draw::fill(0xFF0000FF);          // Fill with red
Draw::fill(0x80FFFFFF);          // Fill with semi-transparent white

rect()

void Draw::rect(int x, int y, int width, int height, uint32_t color)
Draws a filled rectangle.
x
int
required
Left edge x-coordinate
y
int
required
Top edge y-coordinate
width
int
required
Rectangle width in pixels
height
int
required
Rectangle height in pixels
color
uint32_t
required
32-bit RGBA color value
Draw::rect(100, 50, 200, 100, Colors::Blue);

roundedRect()

void Draw::roundedRect(int x, int y, int width, int height, int radius, uint32_t color)
Draws a filled rounded rectangle.
x
int
required
Left edge x-coordinate
y
int
required
Top edge y-coordinate
width
int
required
Rectangle width in pixels
height
int
required
Rectangle height in pixels
radius
int
required
Corner radius in pixels
color
uint32_t
required
32-bit RGBA color value
Draw::roundedRect(50, 50, 150, 75, 10, Colors::Green);

roundedRectBorder()

void Draw::roundedRectBorder(int x, int y, int width, int height, int radius, int borderWidth, uint32_t color)
Draws a rounded rectangle border/outline.
x
int
required
Left edge x-coordinate
y
int
required
Top edge y-coordinate
width
int
required
Rectangle width in pixels
height
int
required
Rectangle height in pixels
radius
int
required
Corner radius in pixels
borderWidth
int
required
Border thickness in pixels
color
uint32_t
required
32-bit RGBA color value
Draw::roundedRectBorder(10, 10, 100, 50, 5, 2, Colors::White);

circle()

void Draw::circle(int cx, int cy, int radius, uint32_t color)
Draws a filled circle.
cx
int
required
Center x-coordinate
cy
int
required
Center y-coordinate
radius
int
required
Circle radius in pixels
color
uint32_t
required
32-bit RGBA color value
Draw::circle(200, 150, 25, Colors::Red);

line()

void Draw::line(int x1, int y1, int x2, int y2, int thickness, uint32_t color)
Draws a line between two points.
x1
int
required
Start point x-coordinate
y1
int
required
Start point y-coordinate
x2
int
required
End point x-coordinate
y2
int
required
End point y-coordinate
thickness
int
required
Line thickness in pixels
color
uint32_t
required
32-bit RGBA color value
Draw::line(0, 0, 100, 100, 3, Colors::Yellow);

Example Usage

Basic Shapes

// Clear background
Draw::fill(Colors::Black);

// Draw a red rectangle
Draw::rect(50, 50, 200, 100, Colors::Red);

// Draw a blue circle
Draw::circle(150, 100, 30, Colors::Blue);

// Draw a yellow line
Draw::line(0, 0, 300, 300, 2, Colors::Yellow);

Rounded UI Elements

// Draw a button background
Draw::roundedRect(100, 50, 120, 40, 8, Colors::Primary);

// Draw a button border
Draw::roundedRectBorder(100, 50, 120, 40, 8, 2, Colors::White);

Custom Widget Drawing

class MyWidget : public Widget {
    void render() override {
        // Draw widget background
        Draw::roundedRect(x_, y_, width_, height_, 10, backgroundColor_);
        
        // Draw widget border
        Draw::roundedRectBorder(x_, y_, width_, height_, 10, 2, borderColor_);
        
        // Draw content
        Draw::circle(x_ + width_/2, y_ + height_/2, 15, Colors::White);
    }
};

Build docs developers (and LLMs) love