From 03446bc9d14b3b2becd840ec1bda6a6a6bbac2fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Wed, 23 Jan 2019 14:53:23 +0100 Subject: [PATCH] [escher] Clean TextView --- escher/include/escher/text_view.h | 19 +++++++++++++------ escher/src/text_view.cpp | 22 +++------------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/escher/include/escher/text_view.h b/escher/include/escher/text_view.h index 1677817e8..7c449e22a 100644 --- a/escher/include/escher/text_view.h +++ b/escher/include/escher/text_view.h @@ -4,13 +4,20 @@ #include #include +/* alignment = 0 -> align left or top + * alignment = 0.5 -> align center + * alignment = 1.0 -> align right or bottom */ + class TextView : public View { public: - // alignment = 0 -> align left or top - // alignment = 0.5 -> align center - // alignment = 1.0 -> align right or bottom - TextView(const KDFont * font = KDFont::LargeFont, float horizontalAlignment = 0.0f, float verticalAlignment = 0.0f, - KDColor textColor = KDColorBlack, KDColor backgroundColor = KDColorWhite); + TextView(const KDFont * font = KDFont::LargeFont, float horizontalAlignment = 0.0f, float verticalAlignment = 0.0f, KDColor textColor = KDColorBlack, KDColor backgroundColor = KDColorWhite) : + View(), + m_font(font), + m_horizontalAlignment(horizontalAlignment), + m_verticalAlignment(verticalAlignment), + m_textColor(textColor), + m_backgroundColor(backgroundColor) + {} void drawRect(KDContext * ctx, KDRect rect) const override; void setBackgroundColor(KDColor backgroundColor); void setTextColor(KDColor textColor); @@ -22,7 +29,7 @@ public: void setFont(const KDFont * font); protected: #if ESCHER_VIEW_LOGGING - const char * className() const override; + const char * className() const override { return "TextView"; } #endif const KDFont * m_font; float m_horizontalAlignment; diff --git a/escher/src/text_view.cpp b/escher/src/text_view.cpp index b799a8fe0..b8bc1b8e9 100644 --- a/escher/src/text_view.cpp +++ b/escher/src/text_view.cpp @@ -1,16 +1,5 @@ #include -TextView::TextView(const KDFont * font, float horizontalAlignment, float verticalAlignment, - KDColor textColor, KDColor backgroundColor) : - View(), - m_font(font), - m_horizontalAlignment(horizontalAlignment), - m_verticalAlignment(verticalAlignment), - m_textColor(textColor), - m_backgroundColor(backgroundColor) -{ -} - void TextView::setBackgroundColor(KDColor backgroundColor) { m_backgroundColor = backgroundColor; markRectAsDirty(bounds()); @@ -44,14 +33,9 @@ void TextView::drawRect(KDContext * ctx, KDRect rect) const { return; } KDSize textSize = m_font->stringSize(text()); - KDPoint origin(m_horizontalAlignment*(m_frame.width() - textSize.width()), - m_verticalAlignment*(m_frame.height() - textSize.height())); + KDPoint origin( + m_horizontalAlignment * (m_frame.width() - textSize.width()), + m_verticalAlignment * (m_frame.height() - textSize.height())); ctx->fillRect(bounds(), m_backgroundColor); ctx->drawString(text(), origin, m_font, m_textColor, m_backgroundColor); } - -#if ESCHER_VIEW_LOGGING -const char * TextView::className() const { - return "TextView"; -} -#endif