get started on ui stuff (just types for now)
parent
62ec411a5d
commit
3e5d58fa72
13
src/main.c
13
src/main.c
|
@ -21,6 +21,11 @@
|
||||||
#define ARENA_IMPLEMENTATION
|
#define ARENA_IMPLEMENTATION
|
||||||
#include <tsoding/arena.h>
|
#include <tsoding/arena.h>
|
||||||
|
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
|
#define ED_UI_IMPLEMENTATION
|
||||||
|
#include "ui.h"
|
||||||
|
|
||||||
static Arena default_arena = {0};
|
static Arena default_arena = {0};
|
||||||
static Arena temporary_arena = {0};
|
static Arena temporary_arena = {0};
|
||||||
static Arena *context_arena = &default_arena;
|
static Arena *context_arena = &default_arena;
|
||||||
|
@ -91,13 +96,7 @@ static struct {
|
||||||
bool should_exit;
|
bool should_exit;
|
||||||
} state;
|
} state;
|
||||||
|
|
||||||
#define _String(text) ((String) { .data = text, .len = sizeof(text) })
|
void queue_text(string text, float position[2]) {
|
||||||
typedef struct {
|
|
||||||
char *data;
|
|
||||||
size_t len;
|
|
||||||
} String;
|
|
||||||
|
|
||||||
void queue_text(String text, float position[2]) {
|
|
||||||
float x = 0;
|
float x = 0;
|
||||||
for (size_t i=0; i < text.len; ++i) {
|
for (size_t i=0; i < text.len; ++i) {
|
||||||
if (text.data[i] >= 32 && text.data[i] <= 32+95) {
|
if (text.data[i] >= 32 && text.data[i] <= 32+95) {
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
#ifndef ED_STRING_INCLUDED
|
||||||
|
#define ED_STRING_INCLUDED
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#define _String(text) ((string) { .data = text, .len = sizeof(text) })
|
||||||
|
typedef struct {
|
||||||
|
char *data;
|
||||||
|
size_t len;
|
||||||
|
} string;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
// A naive implementation of an immediate mode gui.
|
||||||
|
|
||||||
|
#ifndef ED_UI_INCLUDED
|
||||||
|
#define ED_UI_INCLUDED
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
UI_AXIS_HORIZONTAL,
|
||||||
|
UI_AXIS_VERTICAL,
|
||||||
|
} ui_axis;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
UI_SEMANTIC_SIZE_FIT_TEXT,
|
||||||
|
UI_SEMANTIC_SIZE_CHILDREN_SUM,
|
||||||
|
UI_SEMANTIC_SIZE_FILL,
|
||||||
|
UI_SEMANTIC_SIZE_EXACT,
|
||||||
|
UI_SEMANTIC_SIZE_PERCENT_OF_PARENT,
|
||||||
|
} ui_semantic_size_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
ui_semantic_size_t type;
|
||||||
|
union {
|
||||||
|
uint32_t integer;
|
||||||
|
};
|
||||||
|
} ui_semantic_size;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
ui_axis axis;
|
||||||
|
ui_semantic_size semantic_size[2];
|
||||||
|
uint32_t computed_size[2];
|
||||||
|
uint32_t computed_pos[2];
|
||||||
|
} ui_size;
|
||||||
|
|
||||||
|
// UI Element data persisted across frames
|
||||||
|
typedef struct {
|
||||||
|
string label;
|
||||||
|
ui_size size;
|
||||||
|
size_t last_instantiated_index;
|
||||||
|
} ui_element_cache_data;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
UI_FLAG_CLICKABLE = 0b000000001,
|
||||||
|
UI_FLAG_HOVERABLE = 0b000000010,
|
||||||
|
UI_FLAG_SCROLLABLE = 0b000000100,
|
||||||
|
UI_FLAG_DRAW_TEXT = 0b000001000,
|
||||||
|
UI_FLAG_DRAW_BORDER = 0b000010000,
|
||||||
|
UI_FLAG_DRAW_BACKGROUND = 0b000100000,
|
||||||
|
UI_FLAG_ROUNDED_BORDER = 0b001000000,
|
||||||
|
UI_FLAG_FLOATING = 0b010000000,
|
||||||
|
UI_FLAG_CUSTOM_DRAW_FUNC = 0b100000000,
|
||||||
|
} ui_flags;
|
||||||
|
|
||||||
|
// Ephemeral frame only UI Element data
|
||||||
|
typedef struct {
|
||||||
|
size_t index;
|
||||||
|
string key;
|
||||||
|
string label;
|
||||||
|
|
||||||
|
ui_size size;
|
||||||
|
ui_flags flags;
|
||||||
|
|
||||||
|
// optional types
|
||||||
|
size_t first;
|
||||||
|
size_t last;
|
||||||
|
size_t next;
|
||||||
|
size_t prev;
|
||||||
|
size_t parent;
|
||||||
|
} ui_element_frame_data;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef ED_UI_IMPLEMENTATION
|
||||||
|
#endif
|
Loading…
Reference in New Issue