From 0e27521bea7b083248b4e139ccf688c4f6dbff2b Mon Sep 17 00:00:00 2001 From: Vladislav Khorev Date: Fri, 5 Jun 2026 12:31:00 +0300 Subject: [PATCH] Minor bug fixing --- src/UiManager.cpp | 11 +++++++++-- src/UiManager.h | 9 +++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/UiManager.cpp b/src/UiManager.cpp index 05cb65c..4f9a9ad 100644 --- a/src/UiManager.cpp +++ b/src/UiManager.cpp @@ -844,9 +844,16 @@ namespace ZL { mesh.RefreshVBO(); } + float UiChatBubble::computeWidth() const { + if (!textRenderer) return MAX_WIDTH; + const float measuredTextW = textRenderer->measureTextWidth(text, 1.0f); + const float required = measuredTextW + CORNER_SIZE * 2.0f + PAD_X * 2.0f; + return min(required, MAX_WIDTH); + } + float UiChatBubble::computeHeight() const { if (!textRenderer) return CORNER_SIZE * 2 + PAD_Y * 2 + static_cast(fontSize); - const float textW = MAX_WIDTH - CORNER_SIZE * 2.0f - PAD_X * 2.0f; + const float textW = computeWidth() - CORNER_SIZE * 2.0f - PAD_X * 2.0f; const std::string wrapped = wrapTextByPixels(text, *textRenderer, textW, 1.0f); int lines = 1; for (char c : wrapped) if (c == '\n') ++lines; @@ -2152,7 +2159,7 @@ namespace ZL { // Build the UiNode auto node = std::make_shared(); node->name = nodeName; - node->width = UiChatBubble::MAX_WIDTH; + node->width = bubble->computeWidth(); node->height = bubble->computeHeight(); node->localX = 430.0f; node->localY = 0.0f; diff --git a/src/UiManager.h b/src/UiManager.h index 6be976c..936b69f 100644 --- a/src/UiManager.h +++ b/src/UiManager.h @@ -261,8 +261,8 @@ namespace ZL { static constexpr float MAX_WIDTH = 320.6f; //static constexpr float PAD_X = 7.0f; //static constexpr float PAD_Y = 5.0f; - static constexpr float PAD_X = -15.0f; - static constexpr float PAD_Y = -15.0f; + static constexpr float PAD_X = -10.0f; + static constexpr float PAD_Y = -10.0f; // 7 meshes: middle-center, top-strip, bottom-strip, LT, RT, LB, RB VertexRenderStruct meshMiddle; @@ -276,8 +276,9 @@ namespace ZL { std::unique_ptr textRenderer; int fontSize = 20; - // Must be called after rect is set and textRenderer is initialised - float computeHeight() const; + // Must be called after textRenderer is initialised + float computeWidth() const; // capped at MAX_WIDTH + float computeHeight() const; // depends on computeWidth() void buildMeshes(); // nodeScaleX/Y: the owning UiNode's current scale (for pop-in / animations). // Text position and glyph size are transformed to match the renderer's scale matrix.