mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 15:45:38 +00:00
Fixed an issue where text element vertical auto-sizing did not work correctly.
This commit is contained in:
parent
1839dfc31a
commit
00b71c7b27
|
@ -336,9 +336,9 @@ void GuiComponent::applyTheme(const std::shared_ptr<ThemeData>& 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)
|
||||
|
|
|
@ -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<TextCache>(f->buildTextCache(wrappedText, glm::vec2 {}, mColor,
|
||||
mSize.x, mHorizontalAlignment,
|
||||
mLineSpacing, mNoTopMargin));
|
||||
}
|
||||
else {
|
||||
mTextCache = std::shared_ptr<TextCache>(
|
||||
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));
|
||||
}
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ public:
|
|||
const std::shared_ptr<Font>& 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>& font);
|
||||
|
@ -116,6 +116,7 @@ private:
|
|||
float mLineSpacing;
|
||||
bool mNoTopMargin;
|
||||
bool mSelectable;
|
||||
bool mVerticalAutoSizing;
|
||||
};
|
||||
|
||||
#endif // ES_CORE_COMPONENTS_TEXT_COMPONENT_H
|
||||
|
|
Loading…
Reference in a new issue