diff --git a/es-core/src/components/DateTimeComponent.cpp b/es-core/src/components/DateTimeComponent.cpp index 81775319e..ca12aef17 100644 --- a/es-core/src/components/DateTimeComponent.cpp +++ b/es-core/src/components/DateTimeComponent.cpp @@ -6,7 +6,7 @@ DateTimeComponent::DateTimeComponent(Window* window, DisplayMode dispMode) : GuiComponent(window), mEditing(false), mEditIndex(0), mDisplayMode(dispMode), mRelativeUpdateAccumulator(0), - mColor(0x777777FF), mFont(Font::get(FONT_SIZE_SMALL, FONT_PATH_LIGHT)), mUppercase(false), mSizeSet(false) + mColor(0x777777FF), mFont(Font::get(FONT_SIZE_SMALL, FONT_PATH_LIGHT)), mUppercase(false), mAutoSize(true) { updateTextCache(); } @@ -253,9 +253,12 @@ void DateTimeComponent::updateTextCache() std::shared_ptr font = getFont(); mTextCache = std::unique_ptr(font->buildTextCache(dispString, 0, 0, mColor)); - mSize = mTextCache->metrics.size; - if(getParent()) - getParent()->onSizeChanged(); + if(mAutoSize) + { + mSize = mTextCache->metrics.size; + if(getParent()) + getParent()->onSizeChanged(); + } //set up cursor positions mCursorBoxes.clear(); @@ -299,7 +302,6 @@ void DateTimeComponent::setFont(std::shared_ptr font) void DateTimeComponent::onSizeChanged() { - mSizeSet = true; updateTextCache(); } @@ -311,14 +313,20 @@ void DateTimeComponent::setUppercase(bool uppercase) void DateTimeComponent::applyTheme(const std::shared_ptr& theme, const std::string& view, const std::string& element, unsigned int properties) { - GuiComponent::applyTheme(theme, view, element, properties); - - using namespace ThemeFlags; - const ThemeData::ThemeElement* elem = theme->getElement(view, element, "datetime"); if(!elem) return; + // We set mAutoSize BEFORE calling GuiComponent::applyTheme because it calls + // setSize(), which will call updateTextCache(), which will reset mSize if + // mAutoSize == true, ignoring the theme's value. + if(properties & ThemeFlags::SIZE) + mAutoSize = !elem->has("size"); + + GuiComponent::applyTheme(theme, view, element, properties); + + using namespace ThemeFlags; + if(properties & COLOR && elem->has("color")) setColor(elem->get("color")); diff --git a/es-core/src/components/DateTimeComponent.h b/es-core/src/components/DateTimeComponent.h index 82cf38577..bc0083fd7 100644 --- a/es-core/src/components/DateTimeComponent.h +++ b/es-core/src/components/DateTimeComponent.h @@ -62,5 +62,5 @@ private: std::shared_ptr mFont; bool mUppercase; - bool mSizeSet; + bool mAutoSize; };