ugui.c3l/ugui.h

94 lines
1.9 KiB
C
Raw Normal View History

2023-12-29 12:44:53 +01:00
#ifndef _UGUI_H
#define _UGUI_H
#include <stdint.h>
typedef struct {
int32_t x, y, w, h;
} UgRect;
typedef struct {
int32_t x, y;
} UgPoint;
typedef struct {
uint8_t r, g, b, a;
} UgColor;
2024-01-01 20:43:19 +01:00
typedef uint64_t UgId;
2023-12-29 12:44:53 +01:00
typedef enum {
ETYPE_NONE = 0,
2024-01-01 20:43:19 +01:00
ETYPE_DIV,
2024-01-09 16:00:03 +01:00
ETYPE_BUTTON,
2023-12-29 12:44:53 +01:00
} UgElemType;
2024-01-09 16:00:03 +01:00
enum UgElemFlags {
ELEM_UPDATED = 1 << 0,
};
2023-12-29 12:44:53 +01:00
typedef struct {
2024-01-11 18:53:20 +01:00
UgId id;
uint32_t flags;
UgRect rect;
UgElemType type;
2024-01-09 16:00:03 +01:00
// type-specific fields
union {
2024-01-11 18:53:20 +01:00
struct UgDiv {
2024-01-09 16:00:03 +01:00
enum {
DIV_LAYOUT_ROW = 0,
DIV_LAYOUT_COLUMN,
DIV_LAYOUT_FLOATING,
} layout;
2024-01-11 18:53:20 +01:00
2024-01-09 16:00:03 +01:00
UgPoint origin_r, origin_c;
UgColor color_bg;
} div; // Div
};
2023-12-29 12:44:53 +01:00
} UgElem;
// TODO: add a packed flag
// TODO: add a fill index to skip some searching for free spots
typedef struct {
2024-01-09 16:00:03 +01:00
int size, elements;
2024-01-01 20:43:19 +01:00
UgId *vector; // vector of element ids
2024-01-09 16:00:03 +01:00
int *refs, *ordered_refs;
2023-12-29 12:44:53 +01:00
} UgTree;
typedef struct {
2024-01-09 16:00:03 +01:00
struct _IdTable *table;
UgElem *array;
uint64_t *present, *used;
int cycles;
2024-01-01 20:43:19 +01:00
} UgElemCache;
typedef struct _UgCtx UgCtx;
2023-12-29 12:44:53 +01:00
// tree implementation
2024-01-11 18:53:20 +01:00
int ug_tree_init(UgTree *tree, unsigned int size);
int ug_tree_pack(UgTree *tree);
int ug_tree_resize(UgTree *tree, unsigned int newsize);
int ug_tree_add(UgTree *tree, UgId elem, int parent);
int ug_tree_prune(UgTree *tree, int ref);
int ug_tree_subtree_size(UgTree *tree, int ref);
int ug_tree_children_it(UgTree *tree, int parent, int *cursor);
int ug_tree_level_order_it(UgTree *tree, int ref, int *cursor);
int ug_tree_parentof(UgTree *tree, int node);
int ug_tree_destroy(UgTree *tree);
UgId ug_tree_get(UgTree *tree, int node);
2023-12-29 12:44:53 +01:00
2024-01-01 20:43:19 +01:00
// cache implementation
UgElemCache ug_cache_init(void);
2024-01-09 16:00:03 +01:00
void ug_cache_free(UgElemCache *cache);
UgElem *ug_cache_search(UgElemCache *cache, UgId id);
2024-01-11 18:53:20 +01:00
UgElem *ug_cache_insert_new(UgElemCache *cache, const UgElem *g, uint32_t *index);
2024-01-01 20:43:19 +01:00
2023-12-29 12:44:53 +01:00
int ug_init(UgCtx *ctx);
int ug_destroy(UgCtx *ctx);
2024-01-01 20:43:19 +01:00
int ug_frame_begin(UgCtx *ctx);
int ug_frame_end(UgCtx *ctx);
2023-12-29 12:44:53 +01:00
#endif // _UGUI_H