From b5e0bb92907224b35287fa56f77793f6845d9b96 Mon Sep 17 00:00:00 2001 From: zhenyan121 <3367366583@qq.com> Date: Mon, 13 Jul 2026 11:32:52 +0800 Subject: [PATCH] refactor(font): return TextMesh from Font::vertices to include bounding box Replace the plain vertex vector with a TextMesh struct that carries width, height, and min coordinates. Update Label to compute and store these values immediately on text change (removing lazy dirty update). Fix Button's width/height to factor in scale and use concrete widget types for background and foreground. --- include/Cubed/tools/font.hpp | 12 +++++++++++- include/Cubed/ui/button.hpp | 6 ++++-- include/Cubed/ui/label.hpp | 10 +++++++++- src/tools/font.cpp | 20 ++++++++++++++++++-- src/ui/button.cpp | 12 ++++++------ src/ui/label.cpp | 23 ++++++++++++++--------- 6 files changed, 62 insertions(+), 21 deletions(-) diff --git a/include/Cubed/tools/font.hpp b/include/Cubed/tools/font.hpp index 263bfa0..2566c77 100644 --- a/include/Cubed/tools/font.hpp +++ b/include/Cubed/tools/font.hpp @@ -22,6 +22,16 @@ struct Character { GLuint advance; }; +struct TextMesh { + std::vector vertices; + + float width; + float height; + + float min_x; + float min_y; +}; + class Shader; class Font { @@ -29,7 +39,7 @@ public: Font(); ~Font(); - static std::vector vertices(const std::string& text); + static TextMesh vertices(const std::string& text); static const Texture* text_texture(); static const std::string& font_path(); diff --git a/include/Cubed/ui/button.hpp b/include/Cubed/ui/button.hpp index 5f550e3..2b34a28 100644 --- a/include/Cubed/ui/button.hpp +++ b/include/Cubed/ui/button.hpp @@ -1,5 +1,7 @@ #pragma once +#include "Cubed/ui/image.hpp" +#include "Cubed/ui/label.hpp" #include "Cubed/ui/widget.hpp" #include @@ -47,8 +49,8 @@ public: private: std::function m_clicked; - std::unique_ptr m_background; - std::unique_ptr m_foreground; + std::unique_ptr m_background; + std::unique_ptr