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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
#ifndef PKE_STATIC_UI_HPP
#define PKE_STATIC_UI_HPP
#include "components-vk.hpp"
#include "font.hpp"
#include "pk.h"
#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;
};
TypeSafeInt_H(PKE_UI_BOX_TYPE, uint8_t, 0xFF);
TypeSafeInt_H(PKE_UI_BOX_FLAG, uint64_t, 0xFFFFFFFFFFFFFFFF);
// layouts
constexpr PKE_UI_BOX_TYPE PKE_UI_BOX_TYPE_STANDARD
= PKE_UI_BOX_TYPE(000);
// TODO columns, rows, tabs, etc
// special (content)
constexpr PKE_UI_BOX_TYPE PKE_UI_BOX_TYPE_TEXT
= PKE_UI_BOX_TYPE(050);
// TODO image, render target, etc
// inputs
constexpr PKE_UI_BOX_TYPE PKE_UI_BOX_TYPE_INPUT_TEXT
= PKE_UI_BOX_TYPE(100);
// TODO multi-line text, scalar, float, slider, button, etc
constexpr PKE_UI_BOX_FLAG PKE_UI_BOX_FLAG_NONE
= PKE_UI_BOX_FLAG(0);
// [00-04] position type
// exact screen coordinates
constexpr PKE_UI_BOX_FLAG PKE_UI_BOX_FLAG_POSITION_TYPE_FLEX
= PKE_UI_BOX_FLAG((1 << 0));
constexpr PKE_UI_BOX_FLAG PKE_UI_BOX_FLAG_POSITION_TYPE_STATIC
= PKE_UI_BOX_FLAG((1 << 1));
constexpr PKE_UI_BOX_FLAG PKE_UI_BOX_FLAG_POSITION_TYPE_DYNAMIC
= PKE_UI_BOX_FLAG((1 << 2));
constexpr PKE_UI_BOX_FLAG PKE_UI_BOX_FLAG_POSITION_TYPE_ALL
= PKE_UI_BOX_FLAG((1 << 0) | (1 << 1) | (1 << 2));
// [05-06] center
constexpr PKE_UI_BOX_FLAG PKE_UI_BOX_FLAG_CENTER_HORIZONTAL
= PKE_UI_BOX_FLAG((1 << 5));
constexpr PKE_UI_BOX_FLAG PKE_UI_BOX_FLAG_CENTER_VERTICAL
= PKE_UI_BOX_FLAG((1 << 6));
constexpr PKE_UI_BOX_FLAG PKE_UI_BOX_FLAG_CENTER_BOTH
= PKE_UI_BOX_FLAG((1 << 5) | (1 << 6));
// [07-09] visibility
constexpr PKE_UI_BOX_FLAG PKE_UI_BOX_FLAG_VISIBILITY_INVISIBLE
= PKE_UI_BOX_FLAG((1 << 7));
// [10-??]
typedef uint16_t pke_ui_box_count_T;
struct pke_ui_box;
struct pke_ui_box {
PKE_UI_BOX_FLAG flags;
float pos_top_left_x, pos_top_left_y;
float min_width, min_height;
float max_width, max_height;
float flex_weight;
PKE_UI_BOX_TYPE type;
uint8_t flex_direction;
uint8_t layer;
void *type_data;
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_box_type_data_text {
FontRenderHandle font_render_handle;
FontRenderSettings font_render_settings;
};
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(const PKE_UI_BOX_TYPE type = PKE_UI_BOX_TYPE_STANDARD);
pke_ui_box *pke_ui_box_new_child(pke_ui_box *parent, const PKE_UI_BOX_TYPE type = PKE_UI_BOX_TYPE_STANDARD);
#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 */
|