diff --git a/escher/include/escher/text_view.h b/escher/include/escher/text_view.h index 243b681f8..bb742452a 100644 --- a/escher/include/escher/text_view.h +++ b/escher/include/escher/text_view.h @@ -2,6 +2,7 @@ #define ESCHER_TEXT_VIEW_H #include +#include class TextView : public ChildlessView { public: @@ -10,10 +11,12 @@ public: // alignment = 0.5 -> align center // alignment = 1.0 -> align right or bottom TextView(const char * text, - float horizontalAlignment, - float verticalAlignment); + float horizontalAlignment, float verticalAlignment, + KDColor textColor = KDColorBlack, KDColor backgroundColor = KDColorWhite); void drawRect(KDContext * ctx, KDRect rect) const override; void setText(const char * text); + void setBackgroundColor(KDColor backgroundColor); + void setTextColor(KDColor textColor); protected: #if ESCHER_VIEW_LOGGING const char * className() const override; @@ -22,6 +25,8 @@ private: const char * m_text; float m_horizontalAlignment; float m_verticalAlignment; + KDColor m_textColor; + KDColor m_backgroundColor; }; #endif diff --git a/escher/src/text_view.cpp b/escher/src/text_view.cpp index bdd24fc56..7f25250b0 100644 --- a/escher/src/text_view.cpp +++ b/escher/src/text_view.cpp @@ -1,14 +1,17 @@ #include -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