From bfe7333a41ab1ea39bf17c8407e672be827a2c15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 26 Jan 2017 15:19:20 +0100 Subject: [PATCH] [poincare] In string layout, add a instance variable to decide the font size Change-Id: I2ef41531209e21db1e5d22dcf8c846e2a0e8fba7 --- poincare/src/layout/string_layout.cpp | 12 +++++++----- poincare/src/layout/string_layout.h | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/poincare/src/layout/string_layout.cpp b/poincare/src/layout/string_layout.cpp index 86bcf4b70..fdc3d376c 100644 --- a/poincare/src/layout/string_layout.cpp +++ b/poincare/src/layout/string_layout.cpp @@ -2,13 +2,15 @@ #include #include "string_layout.h" -StringLayout::StringLayout(const char * string, size_t length) : -ExpressionLayout() { +StringLayout::StringLayout(const char * string, size_t length, KDText::FontSize fontSize) : + ExpressionLayout(), + m_fontSize(fontSize) +{ m_string = (char *)malloc(sizeof(char)*(length+1)); memcpy(m_string, string, length); m_string[length] = 0; // Height of the font. - m_baseline = KDText::stringSize(" ", KDText::FontSize::Large).height(); + m_baseline = KDText::stringSize(" ", m_fontSize).height(); } StringLayout::~StringLayout() { @@ -20,7 +22,7 @@ ExpressionLayout * StringLayout::child(uint16_t index) { } void StringLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) { - ctx->drawString(m_string, KDText::FontSize::Large, p, expressionColor, backgroundColor); + ctx->drawString(m_string, m_fontSize, p, expressionColor, backgroundColor); } KDPoint StringLayout::positionOfChild(ExpressionLayout * child) { @@ -29,5 +31,5 @@ KDPoint StringLayout::positionOfChild(ExpressionLayout * child) { } KDSize StringLayout::computeSize() { - return KDText::stringSize(m_string, KDText::FontSize::Large); + return KDText::stringSize(m_string, m_fontSize); } diff --git a/poincare/src/layout/string_layout.h b/poincare/src/layout/string_layout.h index c943326b9..97cea6afc 100644 --- a/poincare/src/layout/string_layout.h +++ b/poincare/src/layout/string_layout.h @@ -9,7 +9,7 @@ class StringLayout : public ExpressionLayout { // Here the inverse is a uint8_t instead of a bool, because the size of a bool is // not standardized, thus since we call a foreign C function with this value we want to be // sure about compatibility. - StringLayout(const char * string, size_t length); + StringLayout(const char * string, size_t length, KDText::FontSize fontSize = KDText::FontSize::Large); ~StringLayout(); protected: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; @@ -18,6 +18,7 @@ class StringLayout : public ExpressionLayout { KDPoint positionOfChild(ExpressionLayout * child) override; private: char * m_string; + KDText::FontSize m_fontSize; }; #endif