summaryrefslogtreecommitdiff
path: root/bindings/minimgui.h
blob: 3d3c94c23695609699ad18204209599236342376 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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__ \
    })