From dae57c916315da9b88afed21edfc4ea94f930384 Mon Sep 17 00:00:00 2001 From: zhenyan121 <3367366583@qq.com> Date: Sun, 19 Jul 2026 19:43:59 +0800 Subject: [PATCH] feat(ui): add background to Label widget and refactor debug overlay --- include/Cubed/ui/label.hpp | 6 ++- src/debug_collector.cpp | 104 ++++++++++++++++--------------------- src/ui/label.cpp | 32 +++++++++++- 3 files changed, 81 insertions(+), 61 deletions(-) diff --git a/include/Cubed/ui/label.hpp b/include/Cubed/ui/label.hpp index 734fa8f..d348192 100644 --- a/include/Cubed/ui/label.hpp +++ b/include/Cubed/ui/label.hpp @@ -1,4 +1,5 @@ #pragma once +#include "Cubed/ui/rect.hpp" #include "Cubed/ui/text.hpp" #include "Cubed/ui/ui_vertex_data.hpp" #include "Cubed/ui/widget.hpp" @@ -17,7 +18,9 @@ public: Label& set_color(Color color); Label& set_scale(float scale); - + Label& enable_background(); + Label& set_background(Color color, float alpha); + Label& set_background_alpha(float alpha); const UIVertexData& data() const; const TextStyle& text_style() const; @@ -38,6 +41,7 @@ protected: private: TextStyle m_text; UIVertexData m_data; + std::unique_ptr m_background; float m_real_width = 0.0f; float m_real_height = 0.0f; float m_offset_x = 0.0f; diff --git a/src/debug_collector.cpp b/src/debug_collector.cpp index 493a1e0..d55bf4d 100644 --- a/src/debug_collector.cpp +++ b/src/debug_collector.cpp @@ -19,15 +19,34 @@ std::unique_ptr& DebugCollector::get_ptr() { } void DebugCollector::destory() { get_ptr().reset(); } void DebugCollector::init(int width, int height) { - constexpr float SCALE = 0.6f; + constexpr float SCALE = 0.7f; + constexpr Color COLOR = Color::GRAY; + constexpr float ALPHA = 0.6f; m_widget.set_window_size(width, height); m_widget.set_spacing(15); m_widget.set_anchor(Anchor::TOP_LEFT); m_widget.set_offset({0, 5}); m_widget.set_child_anchor(ColumnLayoutAnchor::LEFT); + + auto add_label = [&](std::string_view text, std::string_view key = "") { + auto& label = m_widget.add_child