mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-29 09:35:39 +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,
|
const std::string& element,
|
||||||
unsigned int properties)
|
unsigned int properties)
|
||||||
{
|
{
|
||||||
glm::vec2 scale {getParent() ?
|
const glm::vec2 scale {getParent() ?
|
||||||
getParent()->getSize() :
|
getParent()->getSize() :
|
||||||
glm::vec2 {Renderer::getScreenWidth(), Renderer::getScreenHeight()}};
|
glm::vec2 {Renderer::getScreenWidth(), Renderer::getScreenHeight()}};
|
||||||
|
|
||||||
const ThemeData::ThemeElement* elem {theme->getElement(view, element, "")};
|
const ThemeData::ThemeElement* elem {theme->getElement(view, element, "")};
|
||||||
if (!elem)
|
if (!elem)
|
||||||
|
|
|
@ -29,6 +29,7 @@ TextComponent::TextComponent()
|
||||||
, mLineSpacing {1.5f}
|
, mLineSpacing {1.5f}
|
||||||
, mNoTopMargin {false}
|
, mNoTopMargin {false}
|
||||||
, mSelectable {false}
|
, mSelectable {false}
|
||||||
|
, mVerticalAutoSizing {false}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +56,7 @@ TextComponent::TextComponent(const std::string& text,
|
||||||
, mLineSpacing {1.5f}
|
, mLineSpacing {1.5f}
|
||||||
, mNoTopMargin {false}
|
, mNoTopMargin {false}
|
||||||
, mSelectable {false}
|
, mSelectable {false}
|
||||||
|
, mVerticalAutoSizing {false}
|
||||||
{
|
{
|
||||||
setFont(font);
|
setFont(font);
|
||||||
setColor(color);
|
setColor(color);
|
||||||
|
@ -275,6 +277,9 @@ void TextComponent::calculateExtent()
|
||||||
|
|
||||||
void TextComponent::onTextChanged()
|
void TextComponent::onTextChanged()
|
||||||
{
|
{
|
||||||
|
if (!mVerticalAutoSizing)
|
||||||
|
mVerticalAutoSizing = (mSize.x != 0.0f && mSize.y == 0.0f);
|
||||||
|
|
||||||
calculateExtent();
|
calculateExtent();
|
||||||
|
|
||||||
if (!mFont || mText.empty() || mSize.x == 0.0f || mSize.y == 0.0f) {
|
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));
|
text, glm::vec2 {}, mColor, mSize.x, mHorizontalAlignment, mLineSpacing, mNoTopMargin));
|
||||||
}
|
}
|
||||||
else if (isMultiline && text.size() && !isScrollable) {
|
else if (isMultiline && text.size() && !isScrollable) {
|
||||||
const std::string wrappedText {
|
const std::string wrappedText {f->wrapText(
|
||||||
f->wrapText(text, mSize.x, mSize.y - lineHeight, mLineSpacing)};
|
text, mSize.x, (mVerticalAutoSizing ? 0.0f : mSize.y - lineHeight), mLineSpacing)};
|
||||||
mTextCache = std::shared_ptr<TextCache>(f->buildTextCache(wrappedText, glm::vec2 {}, mColor,
|
mTextCache = std::shared_ptr<TextCache>(f->buildTextCache(wrappedText, glm::vec2 {}, mColor,
|
||||||
mSize.x, mHorizontalAlignment,
|
mSize.x, mHorizontalAlignment,
|
||||||
mLineSpacing, mNoTopMargin));
|
mLineSpacing, mNoTopMargin));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mTextCache = std::shared_ptr<TextCache>(
|
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));
|
mHorizontalAlignment, mLineSpacing, mNoTopMargin));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,8 @@ public:
|
||||||
const std::shared_ptr<Font>& font,
|
const std::shared_ptr<Font>& font,
|
||||||
unsigned int color = 0x000000FF,
|
unsigned int color = 0x000000FF,
|
||||||
Alignment align = ALIGN_LEFT,
|
Alignment align = ALIGN_LEFT,
|
||||||
glm::vec3 pos = {},
|
glm::vec3 pos = {0.0f, 0.0f, 0.0f},
|
||||||
glm::vec2 size = {},
|
glm::vec2 size = {0.0f, 0.0f},
|
||||||
unsigned int bgcolor = 0x00000000);
|
unsigned int bgcolor = 0x00000000);
|
||||||
|
|
||||||
void setFont(const std::shared_ptr<Font>& font);
|
void setFont(const std::shared_ptr<Font>& font);
|
||||||
|
@ -116,6 +116,7 @@ private:
|
||||||
float mLineSpacing;
|
float mLineSpacing;
|
||||||
bool mNoTopMargin;
|
bool mNoTopMargin;
|
||||||
bool mSelectable;
|
bool mSelectable;
|
||||||
|
bool mVerticalAutoSizing;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ES_CORE_COMPONENTS_TEXT_COMPONENT_H
|
#endif // ES_CORE_COMPONENTS_TEXT_COMPONENT_H
|
||||||
|
|
Loading…
Reference in a new issue