#include #include #include /*=== DEF START ===*/ typedef struct { float x, y; } V2; typedef struct { float x, y; float w, h; } Rect; typedef struct { float a, r, g, b; } Color; typedef void* Image; typedef bool(*const InitFn)(); typedef bool(*const LoopFn)(float dt); typedef void(*const DeinitFn)(); void run ( InitFn const init_fn, LoopFn const loop_fn, DeinitFn const deinit_fn ); typedef void* Context; Context context_init(void); void context_deinit(Context ctx); typedef struct { Color color; Image image; bool* hover; bool consume_hover; bool ignore_hover_if_consumed; bool begin_drag_if_hover_and; bool end_drag_if; V2** drag; } RectangleOptions_; bool rectangle_(Context ctx, Rect rect, RectangleOptions_ o); /*=== DEF END ===*/ #if defined(__GNUC__) || defined(__clang__) #define PURE __attribute__((pure)) #else #define PURE #endif PURE Color color_hex(uint64_t argb) { uint8_t* arr = (uint8_t*)&argb; return (Color){ .a = ((float)arr[0]) / 255.0f, .r = ((float)arr[1]) / 255.0f, .g = ((float)arr[2]) / 255.0f, .b = ((float)arr[3]) / 255.0f, }; } #define rectangle(ctx, rect, ...) \ rectangle_(ctx, rect, (RectangleOptions_){ \ .color = color_hex(0xffffffff), \ .image = NULL, \ .hover = NULL, \ .consume_hover = true, \ .ignore_hover_if_consumed = true, \ .begin_drag_if_hover_and = false, \ .end_drag_if = false, \ .drag = NULL, \ __VA_ARGS__ \ })