diff --git a/poincare/src/layout/empty_layout.cpp b/poincare/src/layout/empty_layout.cpp index 6d1acc880..867814b3c 100644 --- a/poincare/src/layout/empty_layout.cpp +++ b/poincare/src/layout/empty_layout.cpp @@ -45,23 +45,6 @@ ExpressionLayoutCursor EmptyLayout::cursorRightOf(ExpressionLayoutCursor cursor, return ExpressionLayoutCursor(); } -ExpressionLayoutCursor EmptyLayout::cursorVerticalOf(VerticalDirection direction, ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { - /* The two cursor positions around an EmptyLayout are equivalent, so both - * should be checked. */ - assert(cursor.pointedExpressionLayout() == this); - ExpressionLayoutCursor cursorResult = direction == VerticalDirection::Up ? - ExpressionLayout::cursorAbove(cursor, shouldRecomputeLayout, equivalentPositionVisited) : - ExpressionLayout::cursorUnder(cursor, shouldRecomputeLayout, equivalentPositionVisited); - if (cursorResult.isDefined()) { - return cursorResult; - } - ExpressionLayoutCursor::Position newPosition = cursor.position() == ExpressionLayoutCursor::Position::Left ? ExpressionLayoutCursor::Position::Right : ExpressionLayoutCursor::Position::Left; - cursor.setPosition(newPosition); - return direction == VerticalDirection::Up ? - ExpressionLayout::cursorAbove(cursor, shouldRecomputeLayout, equivalentPositionVisited) : - ExpressionLayout::cursorUnder(cursor, shouldRecomputeLayout, equivalentPositionVisited); -} - int EmptyLayout::writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits) const { if (bufferSize == 0) { return -1; @@ -108,4 +91,21 @@ void EmptyLayout::privateAddSibling(ExpressionLayoutCursor * cursor, ExpressionL } } +ExpressionLayoutCursor EmptyLayout::cursorVerticalOf(VerticalDirection direction, ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { + /* The two cursor positions around an EmptyLayout are equivalent, so both + * should be checked. */ + assert(cursor.pointedExpressionLayout() == this); + ExpressionLayoutCursor cursorResult = direction == VerticalDirection::Up ? + ExpressionLayout::cursorAbove(cursor, shouldRecomputeLayout, equivalentPositionVisited) : + ExpressionLayout::cursorUnder(cursor, shouldRecomputeLayout, equivalentPositionVisited); + if (cursorResult.isDefined()) { + return cursorResult; + } + ExpressionLayoutCursor::Position newPosition = cursor.position() == ExpressionLayoutCursor::Position::Left ? ExpressionLayoutCursor::Position::Right : ExpressionLayoutCursor::Position::Left; + cursor.setPosition(newPosition); + return direction == VerticalDirection::Up ? + ExpressionLayout::cursorAbove(cursor, shouldRecomputeLayout, equivalentPositionVisited) : + ExpressionLayout::cursorUnder(cursor, shouldRecomputeLayout, equivalentPositionVisited); +} + } diff --git a/poincare/src/layout/empty_layout.h b/poincare/src/layout/empty_layout.h index 4f72e5b7f..b141425f4 100644 --- a/poincare/src/layout/empty_layout.h +++ b/poincare/src/layout/empty_layout.h @@ -12,20 +12,32 @@ public: Yellow, Grey }; + // Constructor EmptyLayout(Color color = Color::Yellow, bool visible = true); ExpressionLayout * clone() const override; - void deleteBeforeCursor(ExpressionLayoutCursor * cursor) override; - ExpressionLayoutCursor cursorLeftOf(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout) override; - ExpressionLayoutCursor cursorRightOf(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout) override; - int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override; - bool isEmpty() const override { return true; } + + // EmptyLayout Color color() const { return m_color; } void setColor(Color color) { m_color = color; } bool isVisible() const { return m_isVisible; } void setVisible(bool visible) { m_isVisible = visible; } + + // User input + void deleteBeforeCursor(ExpressionLayoutCursor * cursor) override; + + // Tree navigation + ExpressionLayoutCursor cursorLeftOf(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout) override; + ExpressionLayoutCursor cursorRightOf(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout) override; + + // Serialization + int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override; + + // Other + bool isEmpty() const override { return true; } + protected: - virtual void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; - virtual KDSize computeSize() override; + void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; + KDSize computeSize() override; void computeBaseline() override; KDPoint positionOfChild(ExpressionLayout * child) override { assert(false);