[escher] merge label view and text view in text view

Change-Id: Ia2422af03ebb79ba7450a1c8d220933cdd7a4586
This commit is contained in:
Émilie Feral
2016-09-21 18:29:00 +02:00
parent 0178a7fff9
commit f089ea8ddf
2 changed files with 24 additions and 6 deletions

View File

@@ -1,14 +1,17 @@
#include <escher/text_view.h>
TextView::TextView() : TextView(nullptr, 0.0f, 0.0f)
TextView::TextView() : TextView(nullptr, 0.0f, 0.0f, KDColorBlack, KDColorWhite)
{
}
TextView::TextView(const char * text, float horizontalAlignment, float verticalAlignment) :
TextView::TextView(const char * text, float horizontalAlignment, float verticalAlignment,
KDColor textColor, KDColor backgroundColor) :
ChildlessView(),
m_text(text),
m_horizontalAlignment(horizontalAlignment),
m_verticalAlignment(verticalAlignment)
m_verticalAlignment(verticalAlignment),
m_textColor(textColor),
m_backgroundColor(backgroundColor)
{
}
@@ -16,13 +19,23 @@ void TextView::setText(const char * text) {
m_text = text;
}
void TextView::setBackgroundColor(KDColor backgroundColor) {
m_backgroundColor = backgroundColor;
markRectAsDirty(bounds());
}
void TextView::setTextColor(KDColor textColor) {
m_textColor = textColor;
markRectAsDirty(bounds());
}
void TextView::drawRect(KDContext * ctx, KDRect rect) const {
KDSize textSize = KDText::stringSize(m_text);
KDPoint origin = {
(KDCoordinate)(m_horizontalAlignment*(m_frame.width() - textSize.width())),
(KDCoordinate)(m_verticalAlignment*(m_frame.height() - textSize.height()))
};
ctx->drawString(m_text, origin, 0);
ctx->drawString(m_text, origin, m_textColor, m_backgroundColor);
}
#if ESCHER_VIEW_LOGGING