diff options
Diffstat (limited to 'bindings/minimgui.h')
| -rw-r--r-- | bindings/minimgui.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/bindings/minimgui.h b/bindings/minimgui.h new file mode 100644 index 0000000..3d3c94c --- /dev/null +++ b/bindings/minimgui.h @@ -0,0 +1,76 @@ +#include <stdbool.h> +#include <stdint.h> +#include <stdio.h> + +/*=== 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__ \ + }) + |
