Minor bug fixing

This commit is contained in:
Vladislav Khorev 2026-06-05 12:31:00 +03:00
parent 1fc8120ee0
commit 0e27521bea
2 changed files with 14 additions and 6 deletions

View File

@ -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<float>(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<UiNode>();
node->name = nodeName;
node->width = UiChatBubble::MAX_WIDTH;
node->width = bubble->computeWidth();
node->height = bubble->computeHeight();
node->localX = 430.0f;
node->localY = 0.0f;

View File

@ -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> 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.