From c70feb9a46d4aa78868ef09b0dc6588f7e1309bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 15 May 2018 11:33:51 +0200 Subject: [PATCH] [poincare] Fix SumGraphController CondensSumLayout size on second step Change-Id: Ia9608ccf6b556183ed8def852d35a9096aeaac19 --- apps/shared/sum_graph_controller.cpp | 2 +- poincare/src/layout/empty_layout.cpp | 18 ++++++++++-------- poincare/src/layout/empty_layout.h | 9 ++++++--- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/apps/shared/sum_graph_controller.cpp b/apps/shared/sum_graph_controller.cpp index c7db7491e..49a31a458 100644 --- a/apps/shared/sum_graph_controller.cpp +++ b/apps/shared/sum_graph_controller.cpp @@ -251,7 +251,7 @@ void SumGraphController::LegendView::setSumSymbol(Step step, double start, doubl m_sumLayout = new CondensedSumLayout( LayoutEngine::createStringLayout(sigma, sizeof(sigma)), LayoutEngine::createStringLayout(buffer, strlen(buffer), KDText::FontSize::Small), - new EmptyLayout(EmptyLayout::Color::Yellow, false), + new EmptyLayout(EmptyLayout::Color::Yellow, false, KDText::FontSize::Small, false), false); } else { char buffer[2+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)]; diff --git a/poincare/src/layout/empty_layout.cpp b/poincare/src/layout/empty_layout.cpp index 6744aec61..535599ec5 100644 --- a/poincare/src/layout/empty_layout.cpp +++ b/poincare/src/layout/empty_layout.cpp @@ -6,15 +6,17 @@ namespace Poincare { -EmptyLayout::EmptyLayout(Color color, bool visible) : +EmptyLayout::EmptyLayout(Color color, bool visible, KDText::FontSize size, bool margins) : StaticLayoutHierarchy(), m_isVisible(visible), - m_color(color) + m_color(color), + m_size(size), + m_margins(margins) { } ExpressionLayout * EmptyLayout::clone() const { - EmptyLayout * layout = new EmptyLayout(m_color, m_isVisible); + EmptyLayout * layout = new EmptyLayout(m_color, m_isVisible, m_size, m_margins); return layout; } @@ -56,18 +58,18 @@ int EmptyLayout::writeTextInBuffer(char * buffer, int bufferSize, int numberOfSi void EmptyLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) { if (m_isVisible) { KDColor fillColor = m_color == Color::Yellow ? Palette::YellowDark : Palette::GreyBright; - ctx->fillRect(KDRect(p.x()+k_marginWidth, p.y()+k_marginHeight, k_width, k_height), fillColor); - ctx->fillRect(KDRect(p.x()+k_marginWidth, p.y()+k_marginHeight, k_width, k_height), fillColor); + ctx->fillRect(KDRect(p.x()+(m_margins ? k_marginWidth : 0), p.y()+(m_margins ? k_marginHeight : 0), width(), height()), fillColor); + ctx->fillRect(KDRect(p.x()+(m_margins ? k_marginWidth : 0), p.y()+(m_margins ? k_marginHeight : 0), width(), height()), fillColor); } } KDSize EmptyLayout::computeSize() { - KDCoordinate width = m_isVisible ? k_width + 2*k_marginWidth : 0; - return KDSize(width, k_height + 2*k_marginHeight); + KDCoordinate sizeWidth = m_isVisible ? width() + 2*(m_margins ? k_marginWidth : 0) : 0; + return KDSize(sizeWidth, height() + 2*(m_margins ? k_marginHeight : 0)); } void EmptyLayout::computeBaseline() { - m_baseline = k_marginHeight + k_height/2; + m_baseline = (m_margins ? k_marginHeight : 0) + height()/2; m_baselined = true; } diff --git a/poincare/src/layout/empty_layout.h b/poincare/src/layout/empty_layout.h index 16d98a9fc..77ce71b3a 100644 --- a/poincare/src/layout/empty_layout.h +++ b/poincare/src/layout/empty_layout.h @@ -2,6 +2,7 @@ #define POINCARE_empty_layout_H #include +#include #include namespace Poincare { @@ -12,7 +13,7 @@ public: Yellow, Grey }; - EmptyLayout(Color color = Color::Yellow, bool visible = true); + EmptyLayout(Color color = Color::Yellow, bool visible = true, KDText::FontSize size = KDText::FontSize::Large, bool margins = true); ExpressionLayout * clone() const override; // EmptyLayout @@ -44,14 +45,16 @@ protected: } void privateAddSibling(ExpressionLayoutCursor * cursor, ExpressionLayout * sibling, bool moveCursor) override; private: - constexpr static KDCoordinate k_width = 7; - constexpr static KDCoordinate k_height = 12; constexpr static KDCoordinate k_marginWidth = 1; constexpr static KDCoordinate k_marginHeight = 3; constexpr static KDCoordinate k_lineThickness = 1; ExpressionLayoutCursor cursorVerticalOf(VerticalDirection direction, ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) override; + KDCoordinate height() const { return KDText::charSize(m_size).height() - 2*k_marginHeight; } + KDCoordinate width() const { return KDText::charSize(m_size).width() - 2*k_marginWidth; } bool m_isVisible; Color m_color; + KDText::FontSize m_size; + bool m_margins; }; }