compositor-test/include/ui.h

68 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_elem_type ui_elem_type;
typedef struct ui_elem ui_elem;
typedef struct ui_ctx ui_ctx;
enum ui_elem_type {
UI_ELEM_NODE,
UI_ELEM_BUTTON,
COUNT_UI_ELEM,
};
struct ui_elem {
u64 id;
rect rect;
ui_elem_type type;
};
typedef struct ui_elem_colours ui_elem_colours;
struct ui_elem_colours {
colour fill;
colour border;
};
typedef struct ui_node_elem ui_node_elem;
struct ui_node_elem {
line noodle;
rect rec;
};
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);
ui_node_elem ui_node(const window *wnd, ui_ctx *ctx, ui_node_elem node,
ui_elem_colours colours);
#endif // !UI_H