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:
PBAppMainenters the standard app runloop, which processes events and dispatches app callbacks until thread exit.PBEventdescribes runtime events like clicks, pointer movement, keyboard, signals, timers etc.PBWindowMainretrieves the main UI window handle (PBWindow).PBObservesets signal subscriptions on a handle so relevant object signals are delivered as events.PBTimemonotonic timestamp type used for event timestamps and timer deadlines.PBTimeNowreturns the current monotonic high-resolution time (PBTime).PBTimeDurationsigned duration type used with constants likePB_TIME_MILLISECONDand timers.PBTimerStartschedules a timer to ring at deadline, with optional repetition.PBThreadStartstarts a new threadPBExitterminates the calling thread; if called on the main thread it ends the process.
Example
Save as hello.c and build & run with pb run hello.c
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.