From 076c83525ff33a756bf1aac63fe202f5e02c86b0 Mon Sep 17 00:00:00 2001 From: quou Date: Wed, 1 Jan 2025 10:37:17 +1100 Subject: UI tree --- ui.hpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'ui.hpp') diff --git a/ui.hpp b/ui.hpp index adb1ba8..abb4f69 100644 --- a/ui.hpp +++ b/ui.hpp @@ -177,6 +177,7 @@ struct UI { void update(); virtual void on_update(); virtual void on_render(); + virtual void on_add_child(Element* nch); virtual void on_message(const Message& msg); void add_child(Element* ch); @@ -204,14 +205,6 @@ struct UI { void on_render() override; }; - 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); @@ -222,6 +215,12 @@ struct UI { void set_text(const char* s); }; + struct Button : Label { + Button(UI* ui, Element* parent, const char* label); + Rect layout(const Rect& avail) override; + void on_render() override; + }; + struct Modal : Element { Container* contents; Toolbar* title_bar; @@ -236,6 +235,20 @@ struct UI { void on_update() override; void bring_to_front(); }; + + struct Tree : Element { + Element* collapsed; /* <- children are moved here when it's collapsed so they stop layout'ing and rendering! */ + Button* expandbtn; + Label* text; + Tree(UI* ui, Element* parent, const char* text); + Rect layout(const Rect& avail) override; + void on_render() override; + void on_update() override; + void on_add_child(Element* child) override; + void expand(); + void collapse(); + bool is_leaf() const; + }; }; #endif -- cgit v1.2.3-54-g00ecf