[escher] In pointer text view (future message text view) implement

minimal size for optimal display to ensure to be able to display all
languages

Change-Id: Id3c81185fa44017bc4fcca5db0c8d0a6c115f6fb
This commit is contained in:
Émilie Feral
2017-03-15 16:26:31 +01:00
parent adc80cd71b
commit 9186792e40
7 changed files with 23 additions and 3 deletions

View File

@@ -356,4 +356,8 @@ const char * translate(Message m, Language l) {
return messages[(int)m][languageIndex-1];
}
int numberOfLanguages() {
return 3;
}
}

View File

@@ -7,6 +7,7 @@ namespace I18n {
enum class Message : uint16_t;
enum class Language : uint16_t;
const char * translate(Message m, Language l = (Language)0);
int numberOfLanguages();
}
#endif

View File

@@ -11,6 +11,7 @@ public:
void setText(const char * text) override;
void setMessage(I18n::Message message);
const char * text() const override;
KDSize minimalSizeForOptimalDisplay() const override;
private:
I18n::Message m_message;
};

View File

@@ -22,12 +22,12 @@ protected:
#if ESCHER_VIEW_LOGGING
const char * className() const override;
#endif
KDText::FontSize m_fontSize;
private:
float m_horizontalAlignment;
float m_verticalAlignment;
KDColor m_textColor;
KDColor m_backgroundColor;
KDText::FontSize m_fontSize;
};
#endif

View File

@@ -20,3 +20,13 @@ void PointerTextView::setMessage(I18n::Message message) {
m_message = message;
markRectAsDirty(bounds());
}
KDSize PointerTextView::minimalSizeForOptimalDisplay() const {
KDCoordinate width = 0;
for (int l = 0; l < I18n::numberOfLanguages(); l++) {
KDCoordinate newWidth = KDText::stringSize(I18n::translate(m_message, (I18n::Language)l), m_fontSize).width();
width = width > newWidth ? width : newWidth;
l++;
}
return KDSize(width, KDText::stringSize(text(), m_fontSize).height());
}

View File

@@ -3,11 +3,11 @@
TextView::TextView(KDText::FontSize size, float horizontalAlignment, float verticalAlignment,
KDColor textColor, KDColor backgroundColor) :
View(),
m_fontSize(size),
m_horizontalAlignment(horizontalAlignment),
m_verticalAlignment(verticalAlignment),
m_textColor(textColor),
m_backgroundColor(backgroundColor),
m_fontSize(size)
m_backgroundColor(backgroundColor)
{
}

View File

@@ -6,5 +6,9 @@ const char * translate(Message m, Language l) {
return nullptr;
}
int numberOfLanguages() {
return 0;
}
}