summaryrefslogtreecommitdiff
path: root/ui.hpp
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-12-27 11:35:01 +1100
committerquou <quou@disroot.org>2024-12-27 11:36:20 +1100
commit6736966974aea334e119cdb0b6c330066061bf91 (patch)
treea16cc9a3d12e6f9468dbb8fe30146acd78f4af64 /ui.hpp
parent5f9100b935a27bbb6d5ac8ab2050b19ba2894087 (diff)
basic text rendering
Diffstat (limited to 'ui.hpp')
-rw-r--r--ui.hpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/ui.hpp b/ui.hpp
new file mode 100644
index 0000000..a181afe
--- /dev/null
+++ b/ui.hpp
@@ -0,0 +1,60 @@
+#ifndef ui_hpp
+#define ui_hpp
+
+#include "video.hpp"
+
+struct Arena;
+struct UI {
+ struct Rect {
+ int x, y, w, h;
+ };
+
+ struct Element : Rect {
+ enum class Type {
+ label
+ } type;
+ Element* next;
+ static int size(Type t);
+ };
+
+ struct Label : Element {
+ char* text;
+ int len;
+ int x, y;
+ };
+
+ struct Vertex {
+ float x, y, u, v, r, g, b, a;
+ };
+
+ Arena* arena;
+ Device* device;
+ Element* tree;
+ Texture_Id atlas;
+ Shader_Id shader;
+ Vertex_Format_Id vertex_format;
+ Buffer_Id mesh;
+ Sampler_Id sampler;
+ struct {
+ int vert_binding;
+ int atlas_binding;
+ } shader_info;
+ float ndc[2];
+
+ static int text_width(const char* t);
+ static int text_height(const char* t);
+
+ static UI* create(Device* dev, Arena* a, Shader_Id sh);
+
+ Element* create_element(Element::Type t);
+ Label* create_label(const char* t, int x, int y);
+
+ void init(Device* dev, Arena* a, Texture_Id atlas, Shader_Id sh);
+ void destroy();
+ void update(Arena* s);
+ void render(Arena* s, Texture_Id target);
+
+ int render_label(const Label* l, int off);
+};
+
+#endif