diff --git a/es-core/src/GuiComponent.cpp b/es-core/src/GuiComponent.cpp index 351920b15..d66849627 100644 --- a/es-core/src/GuiComponent.cpp +++ b/es-core/src/GuiComponent.cpp @@ -336,9 +336,9 @@ void GuiComponent::applyTheme(const std::shared_ptr& theme, const std::string& element, unsigned int properties) { - glm::vec2 scale {getParent() ? - getParent()->getSize() : - glm::vec2 {Renderer::getScreenWidth(), Renderer::getScreenHeight()}}; + const glm::vec2 scale {getParent() ? + getParent()->getSize() : + glm::vec2 {Renderer::getScreenWidth(), Renderer::getScreenHeight()}}; const ThemeData::ThemeElement* elem {theme->getElement(view, element, "")}; if (!elem) diff --git a/es-core/src/components/TextComponent.cpp b/es-core/src/components/TextComponent.cpp index 6a6de9400..3d7f13b41 100644 --- a/es-core/src/components/TextComponent.cpp +++ b/es-core/src/components/TextComponent.cpp @@ -29,6 +29,7 @@ TextComponent::TextComponent() , mLineSpacing {1.5f} , mNoTopMargin {false} , mSelectable {false} + , mVerticalAutoSizing {false} { } @@ -55,6 +56,7 @@ TextComponent::TextComponent(const std::string& text, , mLineSpacing {1.5f} , mNoTopMargin {false} , mSelectable {false} + , mVerticalAutoSizing {false} { setFont(font); setColor(color); @@ -275,6 +277,9 @@ void TextComponent::calculateExtent() void TextComponent::onTextChanged() { + if (!mVerticalAutoSizing) + mVerticalAutoSizing = (mSize.x != 0.0f && mSize.y == 0.0f); + calculateExtent(); if (!mFont || mText.empty() || mSize.x == 0.0f || mSize.y == 0.0f) { @@ -325,15 +330,15 @@ void TextComponent::onTextChanged() text, glm::vec2 {}, mColor, mSize.x, mHorizontalAlignment, mLineSpacing, mNoTopMargin)); } else if (isMultiline && text.size() && !isScrollable) { - const std::string wrappedText { - f->wrapText(text, mSize.x, mSize.y - lineHeight, mLineSpacing)}; + const std::string wrappedText {f->wrapText( + text, mSize.x, (mVerticalAutoSizing ? 0.0f : mSize.y - lineHeight), mLineSpacing)}; mTextCache = std::shared_ptr(f->buildTextCache(wrappedText, glm::vec2 {}, mColor, mSize.x, mHorizontalAlignment, mLineSpacing, mNoTopMargin)); } else { mTextCache = std::shared_ptr( - f->buildTextCache(f->wrapText(text, mSize.x), glm::vec2 {}, mColor, mSize.x, + f->buildTextCache(f->wrapText(text, mSize.x), glm::vec2 {0.0f, 0.0f}, mColor, mSize.x, mHorizontalAlignment, mLineSpacing, mNoTopMargin)); } diff --git a/es-core/src/components/TextComponent.h b/es-core/src/components/TextComponent.h index 889413ae0..3aef17af1 100644 --- a/es-core/src/components/TextComponent.h +++ b/es-core/src/components/TextComponent.h @@ -29,8 +29,8 @@ public: const std::shared_ptr& font, unsigned int color = 0x000000FF, Alignment align = ALIGN_LEFT, - glm::vec3 pos = {}, - glm::vec2 size = {}, + glm::vec3 pos = {0.0f, 0.0f, 0.0f}, + glm::vec2 size = {0.0f, 0.0f}, unsigned int bgcolor = 0x00000000); void setFont(const std::shared_ptr& font); @@ -116,6 +116,7 @@ private: float mLineSpacing; bool mNoTopMargin; bool mSelectable; + bool mVerticalAutoSizing; }; #endif // ES_CORE_COMPONENTS_TEXT_COMPONENT_H