From 0b61b2a338cbdc527dfde8a16120dbb96aacf3fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Thu, 6 Sep 2018 14:21:51 +0200 Subject: [PATCH] [poincare] Clean inlines in LayoutCursor and LayoutReference --- poincare/include/poincare/layout_cursor.h | 33 +++++++++----------- poincare/include/poincare/layout_reference.h | 16 ++-------- poincare/src/layout_cursor.cpp | 28 +++++++---------- poincare/src/layout_reference.cpp | 9 ++++++ 4 files changed, 37 insertions(+), 49 deletions(-) diff --git a/poincare/include/poincare/layout_cursor.h b/poincare/include/poincare/layout_cursor.h index 67989e0df..7a15a590f 100644 --- a/poincare/include/poincare/layout_cursor.h +++ b/poincare/include/poincare/layout_cursor.h @@ -1,9 +1,8 @@ #ifndef POINCARE_LAYOUT_CURSOR_H #define POINCARE_LAYOUT_CURSOR_H -#include "layout_reference.h" -#include "layout_node.h" -#include +#include +#include namespace Poincare { @@ -82,23 +81,19 @@ public: KDPoint middleLeftPoint(); /* Move */ - void move(MoveDirection direction, bool * shouldRecomputeLayout) { - if (direction == MoveDirection::Left) { - moveLeft(shouldRecomputeLayout); - } else if (direction == MoveDirection::Right) { - moveRight(shouldRecomputeLayout); - } else if (direction == MoveDirection::Up) { - moveAbove(shouldRecomputeLayout); - } else if (direction == MoveDirection::Down) { - moveUnder(shouldRecomputeLayout); - } else { - assert(false); - } + void move(MoveDirection direction, bool * shouldRecomputeLayout); + void moveLeft(bool * shouldRecomputeLayout) { + layoutNode()->moveCursorLeft(this, shouldRecomputeLayout); + } + void moveRight(bool * shouldRecomputeLayout) { + layoutNode()->moveCursorRight(this, shouldRecomputeLayout); + } + void moveAbove(bool * shouldRecomputeLayout) { + layoutNode()->moveCursorUp(this, shouldRecomputeLayout); + } + void moveUnder(bool * shouldRecomputeLayout) { + layoutNode()->moveCursorDown(this, shouldRecomputeLayout); } - void moveLeft(bool * shouldRecomputeLayout); - void moveRight(bool * shouldRecomputeLayout); - void moveAbove(bool * shouldRecomputeLayout); - void moveUnder(bool * shouldRecomputeLayout); LayoutCursor cursorAtDirection(MoveDirection direction, bool * shouldRecomputeLayout) { LayoutCursor result = clone(); result.move(direction, shouldRecomputeLayout); diff --git a/poincare/include/poincare/layout_reference.h b/poincare/include/poincare/layout_reference.h index 22161ec51..86d6149f7 100644 --- a/poincare/include/poincare/layout_reference.h +++ b/poincare/include/poincare/layout_reference.h @@ -19,19 +19,8 @@ public: using TreeByReference::operator!=; LayoutReference() : TreeByReference() {} - LayoutReference(const LayoutNode * node) : - TreeByReference(node) {} - - LayoutReference clone() const { - if (isUninitialized()) { - return LayoutReference(); - } - TreeByReference c = TreeByReference::clone(); - LayoutReference cast = LayoutReference(static_cast(c.node())); - cast.invalidAllSizesPositionsAndBaselines(); - return cast; - } - + LayoutReference(const LayoutNode * node) : TreeByReference(node) {} + LayoutReference clone() const; LayoutNode * node() const { assert(isUninitialized() || !TreeByReference::node()->isGhost()); return static_cast(TreeByReference::node()); @@ -46,7 +35,6 @@ public: } //TODO: check these methods are needed here, not just in Node KDSize layoutSize() { return node()->layoutSize(); } - //KDPoint layoutOrigin() { return this->node()->origin(); } KDPoint absoluteOrigin() { return node()->absoluteOrigin(); } KDCoordinate baseline() { return node()->baseline(); } void invalidAllSizesPositionsAndBaselines() { return node()->invalidAllSizesPositionsAndBaselines(); } diff --git a/poincare/src/layout_cursor.cpp b/poincare/src/layout_cursor.cpp index 04d2a3a06..8d7ffcb1b 100644 --- a/poincare/src/layout_cursor.cpp +++ b/poincare/src/layout_cursor.cpp @@ -54,21 +54,18 @@ KDPoint LayoutCursor::middleLeftPoint() { } /* Move */ - -void LayoutCursor::moveLeft(bool * shouldRecomputeLayout) { - layoutNode()->moveCursorLeft(this, shouldRecomputeLayout); -} - -void LayoutCursor::moveRight(bool * shouldRecomputeLayout) { - layoutNode()->moveCursorRight(this, shouldRecomputeLayout); -} - -void LayoutCursor::moveAbove(bool * shouldRecomputeLayout) { - layoutNode()->moveCursorUp(this, shouldRecomputeLayout); -} - -void LayoutCursor::moveUnder(bool * shouldRecomputeLayout) { - layoutNode()->moveCursorDown(this, shouldRecomputeLayout); +void LayoutCursor::move(MoveDirection direction, bool * shouldRecomputeLayout) { + if (direction == MoveDirection::Left) { + moveLeft(shouldRecomputeLayout); + } else if (direction == MoveDirection::Right) { + moveRight(shouldRecomputeLayout); + } else if (direction == MoveDirection::Up) { + moveAbove(shouldRecomputeLayout); + } else if (direction == MoveDirection::Down) { + moveUnder(shouldRecomputeLayout); + } else { + assert(false); + } } /* Layout modification */ @@ -221,7 +218,6 @@ KDCoordinate LayoutCursor::layoutHeight() { + max(pointedLayoutHeight - pointedLayoutBaseline, equivalentLayoutHeight - equivalentLayoutBaseline); } return pointedLayoutHeight; - } void LayoutCursor::privateAddEmptyPowerLayout(VerticalOffsetLayoutRef v) { diff --git a/poincare/src/layout_reference.cpp b/poincare/src/layout_reference.cpp index 39a987473..dd0b0e56e 100644 --- a/poincare/src/layout_reference.cpp +++ b/poincare/src/layout_reference.cpp @@ -7,6 +7,15 @@ #include namespace Poincare { +LayoutReference LayoutReference::clone() const { + if (isUninitialized()) { + return LayoutReference(); + } + TreeByReference c = TreeByReference::clone(); + LayoutReference cast = LayoutReference(static_cast(c.node())); + cast.invalidAllSizesPositionsAndBaselines(); + return cast; +} // Cursor LayoutCursor LayoutReference::cursor() const {