From 4f757c2ea9958e8b695aaf193d6462c9bf23923a Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Fri, 16 Jun 2023 10:29:08 -0700 Subject: [PATCH] About to cleanup truetype and newtruetype --- src/dawn/scene/components/ui/text/UILabel.cpp | 12 ++++++++---- src/dawn/scene/components/ui/text/UILabel.hpp | 9 ++++----- src/dawnliminal/scenes/HelloWorldScene.hpp | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/dawn/scene/components/ui/text/UILabel.cpp b/src/dawn/scene/components/ui/text/UILabel.cpp index 696fbc11..12bd49dc 100644 --- a/src/dawn/scene/components/ui/text/UILabel.cpp +++ b/src/dawn/scene/components/ui/text/UILabel.cpp @@ -89,6 +89,9 @@ void UILabel::rebufferQuads(const std::vector newTexts) { struct FontShaderBufferData fontData; quadCountTotal = 0; std::vector realNewTexts; + + // Reset + lines.clear(); // Determine font dimensions. auto itText = newTexts.begin(); @@ -97,6 +100,10 @@ void UILabel::rebufferQuads(const std::vector newTexts) { ++itText; } + // Prepare values shared across all text parts/styles + float_t lineWidth = 0; + struct UILabelLine currentLine; + // Now generate quads itText = newTexts.begin(); while(itText != newTexts.end()) { @@ -133,12 +140,9 @@ void UILabel::rebufferQuads(const std::vector newTexts) { // Prepare loop properties and shorthands auto len = text.text.length(); - float_t lineWidth = 0; float_t wordWidth = 0; int32_t lastSpaceCharacter = -1; - struct UILabelLine currentLine; - std::function fnInsertNewline = [&](int32_t i){ if(i != len) { // Update text. @@ -150,13 +154,13 @@ void UILabel::rebufferQuads(const std::vector newTexts) { vertices.push_back(std::make_pair(vert, uvs)); fontData.fontQuadMappings[quadCountTotal] = partIndex; - currentLine.quadCount++; quadCountTotal++; } // Finalize current line lineWidth += wordWidth; currentLine.width = lineWidth; + currentLine.quadCount = quadCountTotal - currentLine.quadStart; // Move to next line position.x = 0; diff --git a/src/dawn/scene/components/ui/text/UILabel.hpp b/src/dawn/scene/components/ui/text/UILabel.hpp index 18f29b3c..e274c9e3 100644 --- a/src/dawn/scene/components/ui/text/UILabel.hpp +++ b/src/dawn/scene/components/ui/text/UILabel.hpp @@ -32,23 +32,22 @@ namespace Dawn { float_t width = 0.0f; int32_t quadStart = -1; int32_t quadCount = 0; - - std::vector texts; }; class UILabel : public UIComponentRenderable { private: Mesh mesh; FontShaderBuffer shaderBuffer; - std::vector texts; - std::vector textsBuffered; - std::vector lines; std::map textureMap; public: int32_t quadStart = 0; int32_t quadCount = -1; int32_t quadCountTotal = -1; + + std::vector texts; + std::vector textsBuffered; + std::vector lines; UILabel(SceneItem *item); diff --git a/src/dawnliminal/scenes/HelloWorldScene.hpp b/src/dawnliminal/scenes/HelloWorldScene.hpp index 3bb4951d..4482d7d0 100644 --- a/src/dawnliminal/scenes/HelloWorldScene.hpp +++ b/src/dawnliminal/scenes/HelloWorldScene.hpp @@ -34,7 +34,7 @@ namespace Dawn { // newLabel->maxWidth = 300.0f; newLabel->richText = std::string( "" - "Hello\nWorld" + "Hello World\nHow are you?" // "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " // "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " // "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "