compositor-test/include/ui.h

64 lines
1.2 KiB
C

#ifndef UI_H
#define UI_H
#include "SDL_events.h"
#include "aliases/aliases.h"
#include "window.h"
#include <stdbool.h>
#define MAX_UI_ELEMENTS 8192
#define BUTTON_WIDTH 100
#define BUTTON_HEIGHT 40
#define NODE_WIDTH 70
#define NODE_HEIGHT 20
typedef enum ui_elemype ui_elemype;
typedef struct ui_elem ui_elem;
typedef struct ui_ctx ui_ctx;
enum ui_elemype {
UI_ELEM_NODE,
UI_ELEM_BUTTON,
COUNT_UI_ELEM,
};
struct ui_elem {
u64 id;
rect rect;
ui_elemype type;
};
typedef struct ui_elem_colours ui_elem_colours;
struct ui_elem_colours {
colour fill;
colour border;
};
struct ui_ctx {
u64 count;
i64 hovered;
i64 active;
i32 mouse_x;
i32 mouse_y;
i32 rel_x;
i32 rel_y;
bool mouse_down;
bool mouse_up;
const window *wnd;
};
void init_ui_ctx(ui_ctx *ctx);
void reset_ui_ctx(ui_ctx *ctx);
void handle_ui_events(const window *wnd, ui_ctx *ctx, const SDL_Event *event);
bool ui_button(const window *wnd, ui_ctx *ctx, rect rect,
ui_elem_colours colours);
rect ui_node(const window *wnd, ui_ctx *ctx, rect rect,
ui_elem_colours colours);
line ui_noodle(const window *wnd, ui_ctx *ctx, line ln,
ui_elem_colours colours);
#endif // !UI_H