From 6736966974aea334e119cdb0b6c330066061bf91 Mon Sep 17 00:00:00 2001 From: quou Date: Fri, 27 Dec 2024 11:35:01 +1100 Subject: basic text rendering --- ui.hpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 ui.hpp (limited to 'ui.hpp') 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 -- cgit v1.2.3-54-g00ecf