playbit / docs

Playbit C library

playbit-c is the general-purpose C programming library for Playbit, a layer on top of the Playbit runtime. Programs can include all headers with #include <playbit/playbit.h> or just what's needed, e.g. #include <playbit/time.h>. Examples use and assume #include <playbit/playbit.h> is included.

Here are some commonly-used APIs:

Example

Save as hello.c and build & run with pb run hello.c

#include <playbit/playbit.h>

f32 x = 0, y = 0;

void on_event(const PBEvent* eventHeader) {
    const PBEventAny* event = (const PBEventAny*)eventHeader;
    if (event->type == PBEventType_POINTER_MOVE) {
        x = event->pointer.x;
        y = event->pointer.y;
    }
}

void update_ui() {
    PBDrawRect(PBRectangleMake(x, y, x + 132, y + 132), PBColor_Red);
    PBDrawText(
        PBUIFontMake(PBStrLit("Inter"), 16, 500),
        PBStrLit("Hello world!"),
        PBColor_White,
        PBRectangleMake(x + 16, y + 16, x + 100, y + 100));
}

void timer_rang(PBTimer timer, u64 arg) {
    log("timer rang");
}

void main() {
    PBAppTimeout(100 * PB_TIME_MILLISECOND, timer_rang, 0);
    PBApp.onEvent = on_event;
    PBApp.onRender = update_ui;
    PBAppMain();
}

See Playbit Apps for more details about how to customize the app with an icon, name and embedded resources.