diff options
author | quou <quou@disroot.org> | 2024-12-31 13:44:32 +1100 |
---|---|---|
committer | quou <quou@disroot.org> | 2024-12-31 13:44:32 +1100 |
commit | a9a0d1ee84397621b6172693330b48e9474b0a91 (patch) | |
tree | dadae19cdd20d09903438ee07af69b7694af6fef /ui.hpp | |
parent | 0c7b8be8e7d257f2f584121d97bfb899085aa350 (diff) |
UI modal windows
Diffstat (limited to 'ui.hpp')
-rw-r--r-- | ui.hpp | 65 |
1 files changed, 57 insertions, 8 deletions
@@ -88,6 +88,7 @@ struct UI { Heap* heap; Device* device; + const App* app; Texture_Id atlas; Shader_Id shader; Vertex_Format_Id vertex_format; @@ -97,6 +98,8 @@ struct UI { Pipeline* pipeline; Render_Pass* render_pass; Element* root, * hot, * hovered; + int area_w, area_h; + bool layout_dirty; struct UI_CBuffer { m4f projection; @@ -110,20 +113,27 @@ struct UI { static int text_width(const char* t); static int text_height(const char* t); - static UI* create(Device* dev, Arena* a, Shader_Id sh); + static UI* create( + Device* dev, + const App* app, + Arena* a, + Shader_Id sh + ); void init( Device* dev, + const App* app, Heap* h, Texture_Id atlas, Shader_Id sh ); void destroy(); - void update(Arena* s, const App& app); + void layout(int w, int h); + void update(Arena* s); void render(Arena* s, Texture_Id target); - void draw_container(const Rect& r); - void draw_containeri(const Rect& r); + void draw_container(const Rect& r, Colour c); + void draw_containeri(const Rect& r, Colour c); Element* alloc_element(size_t size); template <typename T, typename... Args> @@ -135,31 +145,48 @@ struct UI { struct Message { enum class Type { - click + click, + destroy, + activate, + deactivate } type; }; typedef int (*Message_Handler)(Element* e, const Message& m); struct Element { + struct Flags { + enum { + disabled = 1 << 0 + }; + }; + UI* ui; Element* parent; - Element** children; + Element* children, * next; Message_Handler handler; Rect bound, clip; - int child_count; + int flags; Element(UI* ui, Element* parent); virtual ~Element(); + void destroy(); + virtual Rect layout(const Rect& avail); - void update(const App& app); + void update(); + virtual void on_update(); virtual void on_render(); virtual void on_message(const Message& msg); void add_child(Element* ch); + void remove_child(Element* ch); void message(const Message& msg); void render(); + + bool enabled(); + void disable(); + void enable(); }; struct Container : Element { @@ -179,8 +206,30 @@ struct UI { struct Button : Element { char* text; Button(UI* ui, Element* parent, const char* label); + ~Button(); + Rect layout(const Rect& avail) override; + void on_render() override; + }; + + struct Label : Element { + char* text; + Label(UI* ui, Element* parent, const char* label); + ~Label(); + Rect layout(const Rect& avail) override; + void on_render() override; + }; + + struct Modal : Element { + Container* contents; + Toolbar* title_bar; + Label* title; + Button* close; + int drag_offset[2]; + bool dragging; + Modal(UI* ui, Element* parent, const char* title); Rect layout(const Rect& avail) override; void on_render() override; + void on_update() override; }; }; |