From 241d37afa59bb0af3f3a7505dc0a78c2922e22a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Wed, 20 Dec 2017 10:27:14 +0100 Subject: [PATCH] [poincare] Recompute baselines when needed. Change-Id: I4ec717402a4dfd287aa95f45189e1734e4f5e3ed --- apps/expression_editor/controller.cpp | 2 +- poincare/include/poincare/expression_layout.h | 6 ++++-- .../src/layout/baseline_relative_layout.cpp | 9 +++++++-- poincare/src/layout/baseline_relative_layout.h | 1 + poincare/src/layout/bracket_layout.cpp | 7 ++++++- poincare/src/layout/bracket_layout.h | 1 + .../src/layout/bracket_left_right_layout.cpp | 6 ++++++ .../src/layout/bracket_left_right_layout.h | 1 + poincare/src/layout/char_layout.cpp | 9 +++++++-- poincare/src/layout/char_layout.h | 1 + poincare/src/layout/condensed_sum_layout.cpp | 9 +++++++-- poincare/src/layout/condensed_sum_layout.h | 1 + poincare/src/layout/conjugate_layout.cpp | 7 ++++++- poincare/src/layout/conjugate_layout.h | 1 + poincare/src/layout/empty_layout.cpp | 5 +++++ poincare/src/layout/empty_layout.h | 1 + poincare/src/layout/empty_visible_layout.cpp | 7 ++++++- poincare/src/layout/empty_visible_layout.h | 1 + poincare/src/layout/expression_layout.cpp | 15 +++++++++++++-- poincare/src/layout/fraction_layout.cpp | 9 +++++++-- poincare/src/layout/fraction_layout.h | 1 + poincare/src/layout/grid_layout.cpp | 11 ++++++++--- poincare/src/layout/grid_layout.h | 1 + poincare/src/layout/horizontal_layout.cpp | 18 ++++++++++++------ poincare/src/layout/horizontal_layout.h | 1 + poincare/src/layout/integral_layout.cpp | 7 ++++++- poincare/src/layout/integral_layout.h | 1 + poincare/src/layout/nth_root_layout.cpp | 17 +++++++++++------ poincare/src/layout/nth_root_layout.h | 1 + poincare/src/layout/parenthesis_layout.cpp | 7 ++++++- poincare/src/layout/parenthesis_layout.h | 1 + .../layout/parenthesis_left_right_layout.cpp | 6 ++++++ .../src/layout/parenthesis_left_right_layout.h | 1 + poincare/src/layout/sequence_layout.cpp | 7 ++++++- poincare/src/layout/sequence_layout.h | 1 + poincare/src/layout/string_layout.cpp | 8 ++++++-- poincare/src/layout/string_layout.h | 1 + 37 files changed, 153 insertions(+), 36 deletions(-) diff --git a/apps/expression_editor/controller.cpp b/apps/expression_editor/controller.cpp index f82229f4e..0a83b28c7 100644 --- a/apps/expression_editor/controller.cpp +++ b/apps/expression_editor/controller.cpp @@ -38,7 +38,7 @@ bool Controller::handleEvent(Ion::Events::Event event) { else if (event.hasText()) { insertTextAtCursor(event.text()); returnValue = true; - m_expressionLayout->invalidAllSizesAndPositions(); + m_expressionLayout->invalidAllSizesPositionsAndBaselines(); m_view.layoutSubviews(); } m_view.cursorPositionChanged(); diff --git a/poincare/include/poincare/expression_layout.h b/poincare/include/poincare/expression_layout.h index a9c824f1d..1e48236df 100644 --- a/poincare/include/poincare/expression_layout.h +++ b/poincare/include/poincare/expression_layout.h @@ -30,8 +30,8 @@ public: KDPoint origin(); KDPoint absoluteOrigin(); KDSize size(); - KDCoordinate baseline() const { return m_baseline; } - void invalidAllSizesAndPositions(); + KDCoordinate baseline(); + void invalidAllSizesPositionsAndBaselines(); /* Hierarchy */ virtual const ExpressionLayout * const * children() const = 0; @@ -66,6 +66,7 @@ public: protected: virtual void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) = 0; virtual KDSize computeSize() = 0; + virtual void computeBaseline() = 0; virtual KDPoint positionOfChild(ExpressionLayout * child) = 0; void detachChildAtIndex(int i); virtual void moveCursorInsideAtDirection ( @@ -78,6 +79,7 @@ protected: KDCoordinate m_baseline; ExpressionLayout * m_parent; bool m_sized; + bool m_baselined; private: bool moveInside(VerticalDirection direction, ExpressionLayoutCursor * cursor); void replaceWithJuxtapositionOf(ExpressionLayout * firstLayout, ExpressionLayout * secondLayout); diff --git a/poincare/src/layout/baseline_relative_layout.cpp b/poincare/src/layout/baseline_relative_layout.cpp index 0e5b23439..39b0bac48 100644 --- a/poincare/src/layout/baseline_relative_layout.cpp +++ b/poincare/src/layout/baseline_relative_layout.cpp @@ -9,8 +9,7 @@ BaselineRelativeLayout::BaselineRelativeLayout(ExpressionLayout * base, Expressi StaticLayoutHierarchy(base, indice, cloneOperands), m_type(type) { - m_baseline = type == Type::Subscript ? baseLayout()->baseline() : - indiceLayout()->size().height() + baseLayout()->baseline() - k_indiceHeight; + computeBaseline(); } ExpressionLayout * BaselineRelativeLayout::clone() const { @@ -70,6 +69,12 @@ KDSize BaselineRelativeLayout::computeSize() { return KDSize(baseSize.width() + indiceSize.width(), baseSize.height() + indiceSize.height() - k_indiceHeight); } +void BaselineRelativeLayout::computeBaseline() { + m_baseline = m_type == Type::Subscript ? baseLayout()->baseline() : + indiceLayout()->size().height() + baseLayout()->baseline() - k_indiceHeight; + m_baselined = true; +} + KDPoint BaselineRelativeLayout::positionOfChild(ExpressionLayout * child) { KDCoordinate x = 0; KDCoordinate y = 0; diff --git a/poincare/src/layout/baseline_relative_layout.h b/poincare/src/layout/baseline_relative_layout.h index 8ef335015..1e72783a8 100644 --- a/poincare/src/layout/baseline_relative_layout.h +++ b/poincare/src/layout/baseline_relative_layout.h @@ -20,6 +20,7 @@ protected: ExpressionLayout * indiceLayout(); void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; KDSize computeSize() override; + void computeBaseline() override; KDPoint positionOfChild(ExpressionLayout * child) override; Type m_type; private: diff --git a/poincare/src/layout/bracket_layout.cpp b/poincare/src/layout/bracket_layout.cpp index 487d1e2b0..1ad946b87 100644 --- a/poincare/src/layout/bracket_layout.cpp +++ b/poincare/src/layout/bracket_layout.cpp @@ -10,7 +10,7 @@ namespace Poincare { BracketLayout::BracketLayout(ExpressionLayout * operandLayout, bool cloneOperands) : StaticLayoutHierarchy<1>(operandLayout, cloneOperands) { - m_baseline = operandLayout->baseline(); + computeBaseline(); } ExpressionLayout * BracketLayout::clone() const { @@ -100,6 +100,11 @@ KDSize BracketLayout::computeSize() { return KDSize(operandSize.width() + 2*k_externWidthMargin + 2*k_widthMargin + 2*k_lineThickness, operandSize.height()); } +void BracketLayout::computeBaseline() { + m_baseline = operandLayout()->baseline(); + m_baselined = true; +} + KDPoint BracketLayout::positionOfChild(ExpressionLayout * child) { const KDCoordinate k_widthMargin = widthMargin(); const KDCoordinate k_externWidthMargin = externWidthMargin(); diff --git a/poincare/src/layout/bracket_layout.h b/poincare/src/layout/bracket_layout.h index 977095632..b9beeb4c7 100644 --- a/poincare/src/layout/bracket_layout.h +++ b/poincare/src/layout/bracket_layout.h @@ -19,6 +19,7 @@ protected: virtual bool renderBottomBar() const { return true; } void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; KDSize computeSize() override; + void computeBaseline() override; KDPoint positionOfChild(ExpressionLayout * child) override; private: constexpr static KDCoordinate k_bracketWidth = 5; diff --git a/poincare/src/layout/bracket_left_right_layout.cpp b/poincare/src/layout/bracket_left_right_layout.cpp index 70701274d..98d01121e 100644 --- a/poincare/src/layout/bracket_left_right_layout.cpp +++ b/poincare/src/layout/bracket_left_right_layout.cpp @@ -53,6 +53,12 @@ KDSize BracketLeftRightLayout::computeSize() { return KDSize(k_externWidthMargin + k_lineThickness + k_bracketWidth + k_widthMargin, m_operandHeight); } +void BracketLeftRightLayout::computeBaseline() { + //TODO: compute the operandHeight according to the brothers + m_baseline = m_operandHeight; + m_baselined = true; +} + KDPoint BracketLeftRightLayout::positionOfChild(ExpressionLayout * child) { assert(false); return KDPointZero; diff --git a/poincare/src/layout/bracket_left_right_layout.h b/poincare/src/layout/bracket_left_right_layout.h index 1c9527e1b..838b9e00e 100644 --- a/poincare/src/layout/bracket_left_right_layout.h +++ b/poincare/src/layout/bracket_left_right_layout.h @@ -16,6 +16,7 @@ public: constexpr static KDCoordinate k_externWidthMargin = 2; protected: KDSize computeSize() override; + void computeBaseline() override; KDPoint positionOfChild(ExpressionLayout * child) override; uint16_t m_operandHeight; }; diff --git a/poincare/src/layout/char_layout.cpp b/poincare/src/layout/char_layout.cpp index b81762916..22357ddfc 100644 --- a/poincare/src/layout/char_layout.cpp +++ b/poincare/src/layout/char_layout.cpp @@ -10,8 +10,7 @@ CharLayout::CharLayout(char c, KDText::FontSize fontSize) : m_char(c), m_fontSize(fontSize) { - // Half height of the font. - m_baseline = (KDText::charSize(m_fontSize).height()+1)/2; + computeBaseline(); } ExpressionLayout * CharLayout::clone() const { @@ -65,4 +64,10 @@ KDSize CharLayout::computeSize() { return KDText::charSize(m_fontSize); } +void CharLayout::computeBaseline() { + // Half height of the font. + m_baseline = (KDText::charSize(m_fontSize).height()+1)/2; + m_baselined = true; +} + } diff --git a/poincare/src/layout/char_layout.h b/poincare/src/layout/char_layout.h index 37cedfb90..d00625c09 100644 --- a/poincare/src/layout/char_layout.h +++ b/poincare/src/layout/char_layout.h @@ -18,6 +18,7 @@ protected: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; KDPoint positionOfChild(ExpressionLayout * child) override; KDSize computeSize() override; + void computeBaseline() override; char m_char; KDText::FontSize m_fontSize; }; diff --git a/poincare/src/layout/condensed_sum_layout.cpp b/poincare/src/layout/condensed_sum_layout.cpp index d696cb170..04babee19 100644 --- a/poincare/src/layout/condensed_sum_layout.cpp +++ b/poincare/src/layout/condensed_sum_layout.cpp @@ -8,8 +8,7 @@ namespace Poincare { CondensedSumLayout::CondensedSumLayout(ExpressionLayout * base, ExpressionLayout * subscript, ExpressionLayout * superscript, bool cloneOperands) : StaticLayoutHierarchy<3>(base, subscript, superscript, cloneOperands) { - KDSize superscriptSize = superscriptLayout() == nullptr ? KDSizeZero : superscriptLayout()->size(); - m_baseline = baseLayout()->baseline() + max(0, superscriptSize.height() - baseLayout()->size().height()/2); + computeBaseline(); } ExpressionLayout * CondensedSumLayout::clone() const { @@ -142,6 +141,12 @@ KDSize CondensedSumLayout::computeSize() { return KDSize(baseSize.width() + max(subscriptSize.width(), superscriptSize.width()), max(baseSize.height()/2, subscriptSize.height()) + max(baseSize.height()/2, superscriptSize.height())); } +void CondensedSumLayout::computeBaseline() { + KDSize superscriptSize = superscriptLayout() == nullptr ? KDSizeZero : superscriptLayout()->size(); + m_baseline = baseLayout()->baseline() + max(0, superscriptSize.height() - baseLayout()->size().height()/2); + m_baselined = true; +} + KDPoint CondensedSumLayout::positionOfChild(ExpressionLayout * child) { KDCoordinate x = 0; KDCoordinate y = 0; diff --git a/poincare/src/layout/condensed_sum_layout.h b/poincare/src/layout/condensed_sum_layout.h index 16528e6c7..fa9179acd 100644 --- a/poincare/src/layout/condensed_sum_layout.h +++ b/poincare/src/layout/condensed_sum_layout.h @@ -16,6 +16,7 @@ public: protected: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; KDSize computeSize() override; + void computeBaseline() override; KDPoint positionOfChild(ExpressionLayout * child) override; private: ExpressionLayout * baseLayout(); diff --git a/poincare/src/layout/conjugate_layout.cpp b/poincare/src/layout/conjugate_layout.cpp index cfe653ab0..97317f5dc 100644 --- a/poincare/src/layout/conjugate_layout.cpp +++ b/poincare/src/layout/conjugate_layout.cpp @@ -11,7 +11,7 @@ namespace Poincare { ConjugateLayout::ConjugateLayout(ExpressionLayout * operand, bool cloneOperands) : StaticLayoutHierarchy<1>(operand, cloneOperands) { - m_baseline = operandLayout()->baseline()+k_overlineWidth+k_overlineVerticalMargin; + computeBaseline(); } ExpressionLayout * ConjugateLayout::clone() const { @@ -82,6 +82,11 @@ KDSize ConjugateLayout::computeSize() { return KDSize(Metric::FractionAndConjugateHorizontalMargin+Metric::FractionAndConjugateHorizontalOverflow+operandSize.width()+Metric::FractionAndConjugateHorizontalOverflow+Metric::FractionAndConjugateHorizontalMargin, operandSize.height()+k_overlineWidth+k_overlineVerticalMargin); } +void ConjugateLayout::computeBaseline() { + m_baseline = operandLayout()->baseline()+k_overlineWidth+k_overlineVerticalMargin; + m_baselined = true; +} + KDPoint ConjugateLayout::positionOfChild(ExpressionLayout * child) { return KDPoint(Metric::FractionAndConjugateHorizontalMargin+Metric::FractionAndConjugateHorizontalOverflow, k_overlineWidth+k_overlineVerticalMargin); } diff --git a/poincare/src/layout/conjugate_layout.h b/poincare/src/layout/conjugate_layout.h index 5bb16be5b..732e89e49 100644 --- a/poincare/src/layout/conjugate_layout.h +++ b/poincare/src/layout/conjugate_layout.h @@ -14,6 +14,7 @@ public: protected: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; KDSize computeSize() override; + void computeBaseline() override; KDPoint positionOfChild(ExpressionLayout * child) override; private: constexpr static KDCoordinate k_overlineWidth = 1; diff --git a/poincare/src/layout/empty_layout.cpp b/poincare/src/layout/empty_layout.cpp index 3823553e5..fe9a28222 100644 --- a/poincare/src/layout/empty_layout.cpp +++ b/poincare/src/layout/empty_layout.cpp @@ -35,4 +35,9 @@ bool EmptyLayout::moveRight(ExpressionLayoutCursor * cursor) { return false; } +void EmptyLayout::computeBaseline() { + m_baseline = 0; + m_baselined = true; +} + } diff --git a/poincare/src/layout/empty_layout.h b/poincare/src/layout/empty_layout.h index 9f1a61da7..5573b0207 100644 --- a/poincare/src/layout/empty_layout.h +++ b/poincare/src/layout/empty_layout.h @@ -15,6 +15,7 @@ public: protected: virtual void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override { return; } virtual KDSize computeSize() override { return KDSizeZero; } + void computeBaseline() override; KDPoint positionOfChild(ExpressionLayout * child) override { assert(false); return KDPointZero; diff --git a/poincare/src/layout/empty_visible_layout.cpp b/poincare/src/layout/empty_visible_layout.cpp index 3d8910572..f6cdaf7b4 100644 --- a/poincare/src/layout/empty_visible_layout.cpp +++ b/poincare/src/layout/empty_visible_layout.cpp @@ -8,7 +8,7 @@ EmptyVisibleLayout::EmptyVisibleLayout() : EmptyLayout(), m_fillRectColor(KDColor::RGB24(0xffd370)) //TODO make static or in Palette? { - m_baseline = k_height + 2*k_marginHeight; + computeBaseline(); } ExpressionLayout * EmptyVisibleLayout::clone() const { @@ -57,4 +57,9 @@ KDSize EmptyVisibleLayout::computeSize() { return KDSize(k_width + 2*k_marginWidth, k_height + 2*k_marginHeight); } +void EmptyVisibleLayout::computeBaseline() { + m_baseline = k_marginHeight + k_height/2; + m_baselined = true; +} + } diff --git a/poincare/src/layout/empty_visible_layout.h b/poincare/src/layout/empty_visible_layout.h index c595e9b02..7a88565b9 100644 --- a/poincare/src/layout/empty_visible_layout.h +++ b/poincare/src/layout/empty_visible_layout.h @@ -15,6 +15,7 @@ public: protected: virtual void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; virtual KDSize computeSize() override; + void computeBaseline() override; private: constexpr static KDCoordinate k_width = 7; constexpr static KDCoordinate k_height = 13; diff --git a/poincare/src/layout/expression_layout.cpp b/poincare/src/layout/expression_layout.cpp index f7b52bcf9..3a92820d7 100644 --- a/poincare/src/layout/expression_layout.cpp +++ b/poincare/src/layout/expression_layout.cpp @@ -11,6 +11,7 @@ ExpressionLayout::ExpressionLayout() : m_baseline(0), m_parent(nullptr), m_sized(false), + m_baselined(false), m_positioned(false), m_frame(KDRectZero) { } @@ -67,11 +68,21 @@ KDSize ExpressionLayout::size() { return m_frame.size(); } -void ExpressionLayout::invalidAllSizesAndPositions() { +KDCoordinate ExpressionLayout::baseline() { + if (!m_baselined) { + computeBaseline(); + m_baselined = true; + } + return m_baseline; +} + + +void ExpressionLayout::invalidAllSizesPositionsAndBaselines() { m_sized = false; m_positioned = false; + m_baselined = false; for (int i = 0; i < numberOfChildren(); i++) { - editableChild(i)->invalidAllSizesAndPositions(); + editableChild(i)->invalidAllSizesPositionsAndBaselines(); } } diff --git a/poincare/src/layout/fraction_layout.cpp b/poincare/src/layout/fraction_layout.cpp index 5d183530e..6fd6651b3 100644 --- a/poincare/src/layout/fraction_layout.cpp +++ b/poincare/src/layout/fraction_layout.cpp @@ -9,8 +9,7 @@ namespace Poincare { FractionLayout::FractionLayout(ExpressionLayout * numerator, ExpressionLayout * denominator, bool cloneOperands) : StaticLayoutHierarchy<2>(numerator, denominator, cloneOperands) { - m_baseline = numeratorLayout()->size().height() - + k_fractionLineMargin + k_fractionLineHeight; + computeBaseline(); } ExpressionLayout * FractionLayout::clone() const { @@ -114,6 +113,12 @@ KDSize FractionLayout::computeSize() { return KDSize(width, height); } +void FractionLayout::computeBaseline() { + m_baseline = numeratorLayout()->size().height() + + k_fractionLineMargin + k_fractionLineHeight; + m_baselined = true; +} + KDPoint FractionLayout::positionOfChild(ExpressionLayout * child) { KDCoordinate x = 0; KDCoordinate y = 0; diff --git a/poincare/src/layout/fraction_layout.h b/poincare/src/layout/fraction_layout.h index c2c93d275..670718879 100644 --- a/poincare/src/layout/fraction_layout.h +++ b/poincare/src/layout/fraction_layout.h @@ -16,6 +16,7 @@ public: protected: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; KDSize computeSize() override; + void computeBaseline() override; KDPoint positionOfChild(ExpressionLayout * child) override; private: constexpr static KDCoordinate k_fractionLineMargin = 2; diff --git a/poincare/src/layout/grid_layout.cpp b/poincare/src/layout/grid_layout.cpp index c379c5883..504a9c65d 100644 --- a/poincare/src/layout/grid_layout.cpp +++ b/poincare/src/layout/grid_layout.cpp @@ -12,7 +12,7 @@ GridLayout::GridLayout(ExpressionLayout ** entryLayouts, int numberOfRows, int n m_numberOfRows(numberOfRows), m_numberOfColumns(numberOfColumns) { - m_baseline = (height()+1)/2; + computeBaseline(); } ExpressionLayout * GridLayout::clone() const { @@ -116,7 +116,7 @@ bool GridLayout::moveDown(ExpressionLayoutCursor * cursor, ExpressionLayout * pr KDCoordinate GridLayout::rowBaseline(int i) { KDCoordinate rowBaseline = 0; for (int j = 0; j < m_numberOfColumns; j++) { - rowBaseline = max(rowBaseline, child(i*m_numberOfColumns+j)->baseline()); + rowBaseline = max(rowBaseline, editableChild(i*m_numberOfColumns+j)->baseline()); } return rowBaseline; } @@ -125,7 +125,7 @@ KDCoordinate GridLayout::rowHeight(int i) { KDCoordinate rowHeight = 0; KDCoordinate baseline = rowBaseline(i); for (int j = 0; j < m_numberOfColumns; j++) { - rowHeight = max(rowHeight, editableChild(i*m_numberOfColumns+j)->size().height() - child(i*m_numberOfColumns+j)->baseline()); + rowHeight = max(rowHeight, editableChild(i*m_numberOfColumns+j)->size().height() - editableChild(i*m_numberOfColumns+j)->baseline()); } return baseline+rowHeight; } @@ -164,6 +164,11 @@ KDSize GridLayout::computeSize() { return KDSize(width(), height()); } +void GridLayout::computeBaseline() { + m_baseline = (height()+1)/2; + m_baselined = true; +} + KDPoint GridLayout::positionOfChild(ExpressionLayout * child) { int rowIndex = 0; int columnIndex = 0; diff --git a/poincare/src/layout/grid_layout.h b/poincare/src/layout/grid_layout.h index ce48b66e6..379fd642f 100644 --- a/poincare/src/layout/grid_layout.h +++ b/poincare/src/layout/grid_layout.h @@ -19,6 +19,7 @@ public: protected: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; KDSize computeSize() override; + void computeBaseline() override; KDPoint positionOfChild(ExpressionLayout * child) override; private: constexpr static KDCoordinate k_gridEntryMargin = 6; diff --git a/poincare/src/layout/horizontal_layout.cpp b/poincare/src/layout/horizontal_layout.cpp index d025e9f8a..dc627bee9 100644 --- a/poincare/src/layout/horizontal_layout.cpp +++ b/poincare/src/layout/horizontal_layout.cpp @@ -18,11 +18,7 @@ HorizontalLayout::HorizontalLayout() : HorizontalLayout::HorizontalLayout(ExpressionLayout ** childrenLayouts, int childrenCount, bool cloneOperands) : DynamicLayoutHierarchy(childrenLayouts, childrenCount, cloneOperands) { - for (int i = 0; i < numberOfChildren(); i++) { - if (child(i)->baseline() > m_baseline) { - m_baseline = child(i)->baseline(); - } - } + computeBaseline(); } ExpressionLayout * HorizontalLayout::clone() const { @@ -159,6 +155,16 @@ KDSize HorizontalLayout::computeSize() { return KDSize(totalWidth, max_under_baseline + max_above_baseline); } +void HorizontalLayout::computeBaseline() { + m_baseline = 0; + for (int i = 0; i < numberOfChildren(); i++) { + if (editableChild(i)->baseline() > m_baseline) { + m_baseline = editableChild(i)->baseline(); + } + } + m_baselined = true; +} + KDPoint HorizontalLayout::positionOfChild(ExpressionLayout * child) { KDCoordinate x = 0; KDCoordinate y = 0; @@ -168,7 +174,7 @@ KDPoint HorizontalLayout::positionOfChild(ExpressionLayout * child) { assert(previousChild != nullptr); x = previousChild->origin().x() + previousChild->size().width(); } - y = m_baseline - child->baseline(); + y = baseline() - child->baseline(); return KDPoint(x, y); } diff --git a/poincare/src/layout/horizontal_layout.h b/poincare/src/layout/horizontal_layout.h index dfcd71a63..d6f8bba01 100644 --- a/poincare/src/layout/horizontal_layout.h +++ b/poincare/src/layout/horizontal_layout.h @@ -19,6 +19,7 @@ public: protected: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; KDSize computeSize() override; + void computeBaseline() override; KDPoint positionOfChild(ExpressionLayout * child) override; private: bool moveVertically(ExpressionLayout::VerticalDirection direction, ExpressionLayoutCursor * cursor, ExpressionLayout * previousLayout, ExpressionLayout * previousPreviousLayout); diff --git a/poincare/src/layout/integral_layout.cpp b/poincare/src/layout/integral_layout.cpp index 727e477f0..4e912dd91 100644 --- a/poincare/src/layout/integral_layout.cpp +++ b/poincare/src/layout/integral_layout.cpp @@ -22,7 +22,7 @@ const uint8_t bottomSymbolPixel[IntegralLayout::k_symbolHeight][IntegralLayout:: IntegralLayout::IntegralLayout(ExpressionLayout * lowerBound, ExpressionLayout * upperBound, ExpressionLayout * integrand, bool cloneOperands) : StaticLayoutHierarchy<3>(upperBound, lowerBound, integrand, cloneOperands) { - m_baseline = upperBoundLayout()->size().height() + k_integrandHeigthMargin + integrandLayout()->baseline(); + computeBaseline(); } ExpressionLayout * IntegralLayout::clone() const { @@ -168,6 +168,11 @@ KDSize IntegralLayout::computeSize() { upperBoundSize.height()+ 2*k_integrandHeigthMargin+integrandSize.height()+lowerBoundSize.height()); } +void IntegralLayout::computeBaseline() { + m_baseline = upperBoundLayout()->size().height() + k_integrandHeigthMargin + integrandLayout()->baseline(); + m_baselined = true; +} + KDPoint IntegralLayout::positionOfChild(ExpressionLayout * child) { KDSize integrandSize = integrandLayout()->size(); KDSize lowerBoundSize = lowerBoundLayout()->size(); diff --git a/poincare/src/layout/integral_layout.h b/poincare/src/layout/integral_layout.h index 067cc7cea..7390f644a 100644 --- a/poincare/src/layout/integral_layout.h +++ b/poincare/src/layout/integral_layout.h @@ -18,6 +18,7 @@ public: protected: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; KDSize computeSize() override; + void computeBaseline() override; KDPoint positionOfChild(ExpressionLayout * child) override; private: constexpr static KDCoordinate k_boundHeightMargin = 8; diff --git a/poincare/src/layout/nth_root_layout.cpp b/poincare/src/layout/nth_root_layout.cpp index 89a3c59a4..a52194a0f 100644 --- a/poincare/src/layout/nth_root_layout.cpp +++ b/poincare/src/layout/nth_root_layout.cpp @@ -19,12 +19,7 @@ const uint8_t radixPixel[NthRootLayout::k_leftRadixHeight][NthRootLayout::k_left NthRootLayout::NthRootLayout(ExpressionLayout * radicand, ExpressionLayout * index, bool cloneOperands) : StaticLayoutHierarchy<2>(radicand, index, cloneOperands) { - if (indexLayout() != nullptr) { - m_baseline = max(radicandLayout()->baseline() + k_radixLineThickness + k_heightMargin, - indexLayout()->size().height() + k_indexHeight); - } else { - m_baseline = radicandLayout()->baseline() + k_radixLineThickness + k_heightMargin; - } + computeBaseline(); } ExpressionLayout * NthRootLayout::clone() const { @@ -208,6 +203,16 @@ KDSize NthRootLayout::computeSize() { ); } +void NthRootLayout::computeBaseline() { + if (indexLayout() != nullptr) { + m_baseline = max(radicandLayout()->baseline() + k_radixLineThickness + k_heightMargin, + indexLayout()->size().height() + k_indexHeight); + } else { + m_baseline = radicandLayout()->baseline() + k_radixLineThickness + k_heightMargin; + } + m_baselined = true; +} + KDPoint NthRootLayout::positionOfChild(ExpressionLayout * child) { KDCoordinate x = 0; KDCoordinate y = 0; diff --git a/poincare/src/layout/nth_root_layout.h b/poincare/src/layout/nth_root_layout.h index d942b3863..aa7d81814 100644 --- a/poincare/src/layout/nth_root_layout.h +++ b/poincare/src/layout/nth_root_layout.h @@ -18,6 +18,7 @@ public: protected: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; KDSize computeSize() override; + void computeBaseline() override; KDPoint positionOfChild(ExpressionLayout * child) override; private: constexpr static KDCoordinate k_rightRadixHeight = 2; diff --git a/poincare/src/layout/parenthesis_layout.cpp b/poincare/src/layout/parenthesis_layout.cpp index eccab7030..b5b48641f 100644 --- a/poincare/src/layout/parenthesis_layout.cpp +++ b/poincare/src/layout/parenthesis_layout.cpp @@ -15,7 +15,7 @@ ParenthesisLayout::ParenthesisLayout(ExpressionLayout * operand, bool cloneOpera ExpressionLayout * leftParenthesis = new ParenthesisLeftLayout(); ExpressionLayout * rightParenthesis = new ParenthesisRightLayout(); build(ExpressionLayout::ExpressionLayoutArray3(leftParenthesis, operand, rightParenthesis), 3, cloneOperands); - m_baseline = operandLayout()->baseline(); + computeBaseline(); } ExpressionLayout * ParenthesisLayout::clone() const { @@ -130,6 +130,11 @@ KDSize ParenthesisLayout::computeSize() { return KDSize(operandSize.width() + 2*leftParenthesisLayout()->size().width(), operandSize.height()); } +void ParenthesisLayout::computeBaseline() { + m_baseline = operandLayout()->baseline(); + m_baselined = true; +} + KDPoint ParenthesisLayout::positionOfChild(ExpressionLayout * child) { if (child == leftParenthesisLayout()) { return KDPoint(0, 0); diff --git a/poincare/src/layout/parenthesis_layout.h b/poincare/src/layout/parenthesis_layout.h index 594d81a34..0757c6f5f 100644 --- a/poincare/src/layout/parenthesis_layout.h +++ b/poincare/src/layout/parenthesis_layout.h @@ -17,6 +17,7 @@ protected: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override { }; KDSize computeSize() override; + void computeBaseline() override; KDPoint positionOfChild(ExpressionLayout * child) override; private: constexpr static KDCoordinate k_externWidthMargin = 1; diff --git a/poincare/src/layout/parenthesis_left_right_layout.cpp b/poincare/src/layout/parenthesis_left_right_layout.cpp index 4f7e51e89..1baceff6b 100644 --- a/poincare/src/layout/parenthesis_left_right_layout.cpp +++ b/poincare/src/layout/parenthesis_left_right_layout.cpp @@ -11,6 +11,7 @@ ParenthesisLeftRightLayout::ParenthesisLeftRightLayout() : StaticLayoutHierarchy<0>(), m_operandHeight(36) //TODO { + computeBaseline(); } bool ParenthesisLeftRightLayout::moveLeft(ExpressionLayoutCursor * cursor) { @@ -52,6 +53,11 @@ KDSize ParenthesisLeftRightLayout::computeSize() { return KDSize(k_widthMargin + k_lineThickness + k_externWidthMargin, m_operandHeight); } +void ParenthesisLeftRightLayout::computeBaseline() { + m_baseline = m_operandHeight/2; //TODO + m_baselined = true; +} + KDPoint ParenthesisLeftRightLayout::positionOfChild(ExpressionLayout * child) { assert(false); return KDPointZero; diff --git a/poincare/src/layout/parenthesis_left_right_layout.h b/poincare/src/layout/parenthesis_left_right_layout.h index 92d63ef3c..67381f10a 100644 --- a/poincare/src/layout/parenthesis_left_right_layout.h +++ b/poincare/src/layout/parenthesis_left_right_layout.h @@ -19,6 +19,7 @@ public: protected: KDColor s_parenthesisWorkingBuffer[k_parenthesisCurveHeight*k_parenthesisCurveWidth]; KDSize computeSize() override; + void computeBaseline() override; KDPoint positionOfChild(ExpressionLayout * child) override; uint16_t m_operandHeight; }; diff --git a/poincare/src/layout/sequence_layout.cpp b/poincare/src/layout/sequence_layout.cpp index c810a91b6..3955f77b3 100644 --- a/poincare/src/layout/sequence_layout.cpp +++ b/poincare/src/layout/sequence_layout.cpp @@ -9,7 +9,7 @@ namespace Poincare { SequenceLayout::SequenceLayout(ExpressionLayout * lowerBound, ExpressionLayout * upperBound, ExpressionLayout * argument, bool cloneOperands) : StaticLayoutHierarchy<3>(upperBound, lowerBound, argument, cloneOperands) { - m_baseline = max(upperBoundLayout()->size().height()+k_boundHeightMargin+(k_symbolHeight+1)/2, argumentLayout()->baseline()); + computeBaseline(); } bool SequenceLayout::moveLeft(ExpressionLayoutCursor * cursor) { @@ -150,6 +150,11 @@ KDSize SequenceLayout::computeSize() { ); } +void SequenceLayout::computeBaseline() { + m_baseline = max(upperBoundLayout()->size().height()+k_boundHeightMargin+(k_symbolHeight+1)/2, argumentLayout()->baseline()); + m_baselined = true; +} + KDPoint SequenceLayout::positionOfChild(ExpressionLayout * child) { KDSize lowerBoundSize = lowerBoundLayout()->size(); KDSize upperBoundSize = upperBoundLayout()->size(); diff --git a/poincare/src/layout/sequence_layout.h b/poincare/src/layout/sequence_layout.h index b9e4735d3..6e186982d 100644 --- a/poincare/src/layout/sequence_layout.h +++ b/poincare/src/layout/sequence_layout.h @@ -21,6 +21,7 @@ protected: ExpressionLayout * argumentLayout(); private: KDSize computeSize() override; + void computeBaseline() override; KDPoint positionOfChild(ExpressionLayout * child) override; constexpr static KDCoordinate k_argumentWidthMargin = 2; }; diff --git a/poincare/src/layout/string_layout.cpp b/poincare/src/layout/string_layout.cpp index e9e93970d..43996cd7d 100644 --- a/poincare/src/layout/string_layout.cpp +++ b/poincare/src/layout/string_layout.cpp @@ -12,8 +12,6 @@ StringLayout::StringLayout(const char * string, size_t length, KDText::FontSize m_string = new char[length+1]; memcpy(m_string, string, length); m_string[length] = 0; - // Half height of the font. - m_baseline = (KDText::charSize(m_fontSize).height()+1)/2; } StringLayout::~StringLayout() { @@ -72,4 +70,10 @@ KDSize StringLayout::computeSize() { return KDText::stringSize(m_string, m_fontSize); } +void StringLayout::computeBaseline() { + // Half height of the font. + m_baseline = (KDText::charSize(m_fontSize).height()+1)/2; + m_baselined = true; +} + } diff --git a/poincare/src/layout/string_layout.h b/poincare/src/layout/string_layout.h index 60060efb3..0a3763811 100644 --- a/poincare/src/layout/string_layout.h +++ b/poincare/src/layout/string_layout.h @@ -23,6 +23,7 @@ protected: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; KDPoint positionOfChild(ExpressionLayout * child) override; KDSize computeSize() override; + void computeBaseline() override; char * m_string; KDText::FontSize m_fontSize; };