Files
Upsilon/escher/src/text_view.cpp
Émilie Feral c0dc33cfbd [escher] Make one constructor only for views
Change-Id: I304a49995beb59071dd88fcfad8715bdb58e6685
2016-12-13 15:10:02 +01:00

48 lines
1.3 KiB
C++

#include <escher/text_view.h>
TextView::TextView(float horizontalAlignment, float verticalAlignment,
KDColor textColor, KDColor backgroundColor) :
View(),
m_horizontalAlignment(horizontalAlignment),
m_verticalAlignment(verticalAlignment),
m_textColor(textColor),
m_backgroundColor(backgroundColor)
{
}
void TextView::setBackgroundColor(KDColor backgroundColor) {
m_backgroundColor = backgroundColor;
markRectAsDirty(bounds());
}
void TextView::setTextColor(KDColor textColor) {
m_textColor = textColor;
markRectAsDirty(bounds());
}
void TextView::setAlignment(float horizontalAlignment, float verticalAlignment) {
m_horizontalAlignment = horizontalAlignment;
m_verticalAlignment = verticalAlignment;
markRectAsDirty(bounds());
}
KDSize TextView::minimalSizeForOptimalDisplay() {
return KDText::stringSize(text());
}
void TextView::drawRect(KDContext * ctx, KDRect rect) const {
if (text() == nullptr) {
return;
}
KDSize textSize = KDText::stringSize(text());
KDPoint origin(m_horizontalAlignment*(m_frame.width() - textSize.width()),
m_verticalAlignment*(m_frame.height() - textSize.height()));
ctx->drawString(text(), origin, m_textColor, m_backgroundColor);
}
#if ESCHER_VIEW_LOGGING
const char * TextView::className() const {
return "TextView";
}
#endif