summaryrefslogtreecommitdiff
path: root/src/static-ui.hpp
blob: 6586a0259d4e6e082fce5342786d447bd903d763 (plain)
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
#ifndef PKE_STATIC_UI_HPP
#define PKE_STATIC_UI_HPP

#include "components-vk.hpp"
#include "vendor-glm-include.hpp"

#include <cstdint>

#define built_in_offset 2.0

struct MSDFGlyphSettings {
	float width;
	float height;
	float scale;
	float translate_em;
	float range_em;
};

enum PKE_UI_BOX_FLAGS : uint64_t {
	PKE_UI_BOX_FLAG_NONE    = 0,
	// [00-04] position type
	// exact screen coordinates
	PKE_UI_BOX_FLAG_POSITION_TYPE_FLEX                  = (1 <<  0),
	PKE_UI_BOX_FLAG_POSITION_TYPE_STATIC                = (1 <<  1),
	PKE_UI_BOX_FLAG_POSITION_TYPE_DYNAMIC               = (1 <<  2),
	PKE_UI_BOX_FLAG_POSITION_TYPE_ALL                   = (1 <<  0) | (1 <<  1) | (1 <<  2),
	// [05-06] center
	PKE_UI_BOX_FLAG_CENTER_HORIZONTAL                   = (1 <<  5),
	PKE_UI_BOX_FLAG_CENTER_VERTICAL                     = (1 <<  6),
	PKE_UI_BOX_FLAG_CENTER_BOTH                         = (1 <<  5) | (1 <<  6),
	// [07-09] visibility
	PKE_UI_BOX_FLAG_VISIBILITY_INVISIBLE                = (1 <<  7),
	// [10-??]
};

typedef uint16_t pke_ui_box_count_T;

struct pke_ui_box;

struct pke_ui_box {
	PKE_UI_BOX_FLAGS flags;
	float pos_top_left_x, pos_top_left_y;
	float min_width, min_height;
	float max_width, max_height;
	float flex_weight;
	uint8_t flex_direction;
	uint8_t layer;
	struct pke_ui_box_internals {
		// the exact px to translate (shader)
		glm::vec2 px_corner;
		// the exact px for scaling (shader)
		glm::vec2 px_size;
		// internal padding + running offset for adding children
		// glm::vec4 px_padding;
		float px_padding_l, px_padding_b, px_padding_r, px_padding_t;
		pke_ui_box *parent;
		pke_ui_box **children;
		pke_ui_box_count_T h_children;
		pke_ui_box_count_T r_children;
	} internal;
};

struct pke_ui_graphics_bindings {
	VkDeviceMemory deviceMemoryVert = VK_NULL_HANDLE;
	VkDeviceMemory deviceMemoryInst = VK_NULL_HANDLE;
	BufferBindingDetails bd_vertex;
	BufferBindingDetails bd_uv;
	BufferBindingDetails bd_index;
	BufferBindingDetails bd_instance;
	uint32_t index_count;
	uint32_t instance_counter;
	uint32_t instance_buffer_max_count;
};

void pke_ui_init();
void pke_ui_init_bindings();
void pke_ui_tick(double delta);
void pke_ui_teardown();

pke_ui_box *pke_ui_box_new_root();
pke_ui_box *pke_ui_box_new_child(pke_ui_box *parent);

#ifdef PKE_TEST_EXPOSE
void pke_ui_calc_px(DynArray<pke_ui_box_instance_buffer_item> &buffer, pke_ui_flex_params *flex_params, pke_ui_box *box);
void pke_ui_recalc_sizes_recursive(DynArray<pke_ui_box_instance_buffer_item> &arr, pke_ui_box *box, uint8_t depth = 0);
#endif

pke_ui_graphics_bindings *pke_ui_get_graphics_bindings();

#endif /* PKE_STATIC_UI_HPP */