#ifndef ui_hpp #define ui_hpp #include "maths.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, config_buf; Sampler_Id sampler; struct UI_CBuffer { m4f projection; }; struct { int vert_binding; int atlas_binding; int config_binding; } shader_info; 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