Make DateTimeComponent honor theme size values again.

This commit is contained in:
Aloshi 2015-03-05 17:43:38 -06:00
parent a6a9fff50f
commit 2b3080f90b
2 changed files with 18 additions and 10 deletions

View file

@ -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> font = getFont();
mTextCache = std::unique_ptr<TextCache>(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> font)
void DateTimeComponent::onSizeChanged()
{
mSizeSet = true;
updateTextCache();
}
@ -311,14 +313,20 @@ void DateTimeComponent::setUppercase(bool uppercase)
void DateTimeComponent::applyTheme(const std::shared_ptr<ThemeData>& 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<unsigned int>("color"));

View file

@ -62,5 +62,5 @@ private:
std::shared_ptr<Font> mFont;
bool mUppercase;
bool mSizeSet;
bool mAutoSize;
};