From 076c83525ff33a756bf1aac63fe202f5e02c86b0 Mon Sep 17 00:00:00 2001 From: quou Date: Wed, 1 Jan 2025 10:37:17 +1100 Subject: UI tree --- ui.cpp | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- ui.hpp | 29 ++++++++++++++------ 2 files changed, 113 insertions(+), 14 deletions(-) diff --git a/ui.cpp b/ui.cpp index 7b5128b..a3ed71b 100644 --- a/ui.cpp +++ b/ui.cpp @@ -706,6 +706,10 @@ void UI::Element::on_message(const Message& msg) { (void)msg; } +void UI::Element::on_add_child(Element* nch) { + (void)nch; +} + void UI::Element::on_render() { } @@ -734,6 +738,7 @@ void UI::Element::add_child(Element* ch) { } ch->parent = this; ui->layout_dirty = true; + on_add_child(ch); } void UI::Element::remove_child(Element* ch) { @@ -821,12 +826,7 @@ void UI::Toolbar::on_render() { } UI::Button::Button(UI* ui, Element* parent, const char* label): - Element(ui, parent) { - text = dup_stringh(ui->heap, label); -} - -UI::Button::~Button() { - heap_free(ui->heap, text); + Label(ui, parent, label) { } UI::Rect UI::Button::layout(const Rect& avail) { @@ -988,3 +988,89 @@ void UI::Modal::bring_to_front() { p->remove_child(this); p->add_child(this); } + +UI::Tree::Tree(UI* ui, Element* parent, const char* label): + Element(ui, parent), collapsed(0), expandbtn(0), text(0) { + text = ui->create_element