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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
#ifndef gui_h
#define gui_h
#include "rect.h"
struct App;
struct Arena;
struct GUI;
struct Renderer;
typedef enum {
gui_el_type_btn,
gui_el_type_scrollable,
gui_el_type_scrollbar
} GUI_El_Type;
typedef struct GUI_El {
GUI_El_Type type;
struct GUI_El* next;
Rect r;
} GUI_El;
typedef struct {
GUI_El el;
char* text;
int hover, active;
} GUI_Btn;
typedef struct {
int x, y;
short grabbed[2];
short graboff[2];
} GUI_Scroll_State;
typedef struct {
GUI_El el;
GUI_Scroll_State* s;
Rect handle;
int h;
int hover, active;
} GUI_Scrollbar;
typedef void (*GUI_Scrollable_Draw_Fn)(
struct GUI*,
struct Renderer*,
const Rect*,
const GUI_Scroll_State*
);
typedef struct {
GUI_El el;
GUI_Scrollable_Draw_Fn draw;
GUI_Scroll_State* ss;
int cs[2];
int vp[2];
} GUI_Scrollable;
typedef struct GUI {
const struct App* app;
struct Arena* a;
GUI_El* first, * prev;
void* uptr;
int cursor[2], pad;
} GUI;
int gui_text_width(const char* text, int len);
int gui_text_height(void);
void gui_begin(GUI* g, const struct App* app, struct Arena* a);
void gui_end(GUI* g, struct Renderer* r);
Rect gui_viewport(GUI* g);
Rect gui_cut_left(Rect* a, int v);
Rect gui_cut_right(Rect* a, int v);
Rect gui_cut_down(Rect* a, int v);
Rect gui_cut_up(Rect* a, int v);
int gui_btn(GUI* g, Rect r, const char* text);
void gui_scrollable(
GUI* g,
Rect r,
const int* cs,
GUI_Scroll_State* state,
GUI_Scrollable_Draw_Fn fn
);
void gui_scrollbar(
GUI* g,
GUI_Scroll_State* state,
Rect r,
int diff,
int horizontal
);
#endif
|