diff --git a/es-core/src/GuiComponent.cpp b/es-core/src/GuiComponent.cpp index 5075fc311..d4d605ec9 100644 --- a/es-core/src/GuiComponent.cpp +++ b/es-core/src/GuiComponent.cpp @@ -95,18 +95,27 @@ void GuiComponent::renderChildren(const glm::mat4& transform) const void GuiComponent::setPosition(float x, float y, float z) { + if (mPosition.x == x && mPosition.y == y && mPosition.z == z) + return; + mPosition = glm::vec3{x, y, z}; onPositionChanged(); } void GuiComponent::setOrigin(float x, float y) { + if (mOrigin.x == x && mOrigin.y == y) + return; + mOrigin = glm::vec2{x, y}; onOriginChanged(); } void GuiComponent::setSize(float w, float h) { + if (mSize.x == w && mSize.y == h) + return; + mSize = glm::vec2{w, h}; onSizeChanged(); } @@ -166,6 +175,9 @@ int GuiComponent::getChildIndex() const void GuiComponent::setOpacity(unsigned char opacity) { + if (mOpacity == opacity) + return; + mOpacity = opacity; for (auto it = mChildren.cbegin(); it != mChildren.cend(); it++) (*it)->setOpacity(opacity); diff --git a/es-core/src/components/ComponentGrid.cpp b/es-core/src/components/ComponentGrid.cpp index bd6012d12..fd87cd10d 100644 --- a/es-core/src/components/ComponentGrid.cpp +++ b/es-core/src/components/ComponentGrid.cpp @@ -138,7 +138,7 @@ void ComponentGrid::updateCellComponent(const GridEntry& cell) for (int y = cell.pos.y; y < cell.pos.y + cell.dim.y; y++) size.y += getRowHeight(y); - if (cell.resize) + if (cell.resize && size != glm::vec2{} && cell.component->getSize() != size) cell.component->setSize(size); // Find top left corner. diff --git a/es-core/src/components/OptionListComponent.h b/es-core/src/components/OptionListComponent.h index 25df35e61..3549eafb4 100644 --- a/es-core/src/components/OptionListComponent.h +++ b/es-core/src/components/OptionListComponent.h @@ -156,12 +156,14 @@ public: e.selected = selected; mEntries.push_back(e); - onSelectedChanged(); + + if (selected) + onSelectedChanged(); } bool selectEntry(unsigned int entry) { - if (entry > mEntries.size()) { + if (mEntries.empty() || entry > mEntries.size()) { return false; } else { @@ -258,6 +260,10 @@ private: mParent->onSizeChanged(); } else { + // Make a size update so the text for the first entry is properly aligned. + if (mText.getSize().x > 0.0f && mText.getSize().y > 0.0f) + setSize(mText.getSize()); + // Display the selected entry and left/right option arrows. for (auto it = mEntries.cbegin(); it != mEntries.cend(); it++) { if (it->selected) { diff --git a/es-core/src/components/TextComponent.cpp b/es-core/src/components/TextComponent.cpp index 2af422b19..ad4dda89f 100644 --- a/es-core/src/components/TextComponent.cpp +++ b/es-core/src/components/TextComponent.cpp @@ -53,7 +53,7 @@ TextComponent::TextComponent(Window* window, setFont(font); setColor(color); setBackgroundColor(bgcolor); - setText(text); + setText(text, false); setPosition(pos); setSize(size); } @@ -66,6 +66,9 @@ void TextComponent::onSizeChanged() void TextComponent::setFont(const std::shared_ptr& font) { + if (mFont == font) + return; + mFont = font; onTextChanged(); } @@ -103,10 +106,15 @@ void TextComponent::setOpacity(unsigned char opacity) GuiComponent::setOpacity(opacity); } -void TextComponent::setText(const std::string& text) +void TextComponent::setText(const std::string& text, bool update) { + if (mText == text) + return; + mText = text; - onTextChanged(); + + if (update) + onTextChanged(); } void TextComponent::setUppercase(bool uppercase) @@ -262,8 +270,6 @@ void TextComponent::setHorizontalAlignment(Alignment align) onTextChanged(); } -void TextComponent::setVerticalAlignment(Alignment align) { mVerticalAlignment = align; } - void TextComponent::setLineSpacing(float spacing) { mLineSpacing = spacing; diff --git a/es-core/src/components/TextComponent.h b/es-core/src/components/TextComponent.h index 58ac31f69..a0b357ae6 100644 --- a/es-core/src/components/TextComponent.h +++ b/es-core/src/components/TextComponent.h @@ -38,11 +38,11 @@ public: void setFont(const std::shared_ptr& font); void setUppercase(bool uppercase); void onSizeChanged() override; - void setText(const std::string& text); + void setText(const std::string& text, bool update = true); void setHiddenText(const std::string& text) { mHiddenText = text; } void setColor(unsigned int color) override; void setHorizontalAlignment(Alignment align); - void setVerticalAlignment(Alignment align); + void setVerticalAlignment(Alignment align) { mVerticalAlignment = align; } void setLineSpacing(float spacing); void setNoTopMargin(bool margin); void setBackgroundColor(unsigned int color);