From 021d98da7c5b461c92ce5ce3fba865c44f2be792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 17 Apr 2018 17:29:56 +0200 Subject: [PATCH] [poincare] More beautiful separation of exponential and root indexes Exponent Layout (VerticalOffsetLayout of Superscript type) now add a margin to their layout only when they are next to a layout that has an upper left index. Change-Id: I670e8aefc7c6bcace8f61bbe4a4b6cea0936d96c --- poincare/include/poincare/expression_layout.h | 1 + poincare/src/layout/nth_root_layout.h | 1 + poincare/src/layout/vertical_offset_layout.cpp | 7 ++++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/poincare/include/poincare/expression_layout.h b/poincare/include/poincare/expression_layout.h index 1694204e8..9dff32dfb 100644 --- a/poincare/include/poincare/expression_layout.h +++ b/poincare/include/poincare/expression_layout.h @@ -125,6 +125,7 @@ public: virtual bool isRightBracket() const { return false; } virtual bool isEmpty() const { return false; } virtual bool isMatrix() const { return false; } + virtual bool hasUpperLeftIndex() const { return false; } virtual char XNTChar() const; protected: diff --git a/poincare/src/layout/nth_root_layout.h b/poincare/src/layout/nth_root_layout.h index f5d31c723..c62b896e0 100644 --- a/poincare/src/layout/nth_root_layout.h +++ b/poincare/src/layout/nth_root_layout.h @@ -26,6 +26,7 @@ public: /* Expression Engine */ int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override; + bool hasUpperLeftIndex() const override { return numberOfChildren() > 1; } protected: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; KDSize computeSize() override; diff --git a/poincare/src/layout/vertical_offset_layout.cpp b/poincare/src/layout/vertical_offset_layout.cpp index 14bb1da9f..f921efa76 100644 --- a/poincare/src/layout/vertical_offset_layout.cpp +++ b/poincare/src/layout/vertical_offset_layout.cpp @@ -246,7 +246,12 @@ KDSize VerticalOffsetLayout::computeSize() { KDSize indiceSize = indiceLayout()->size(); KDCoordinate width = indiceSize.width(); if (m_type == Type::Superscript) { - width += 5; + assert(m_parent != nullptr); + assert(m_parent->isHorizontal()); + int indexInParent = m_parent->indexOfChild(this); + if (indexInParent < m_parent-> numberOfChildren() - 1 && m_parent->editableChild(indexInParent + 1)->hasUpperLeftIndex()) { + width += 5; + } } KDCoordinate height = 0; if (m_type == Type::Subscript) {