[poincare] Check children when moving vertically in HorizontalLayout

Change-Id: Ib0fa5ef58b605c16079e46040a28c96695dcf3d5
This commit is contained in:
Léa Saviot
2018-04-17 10:59:06 +02:00
parent 3abb619283
commit b4be993d2f
2 changed files with 27 additions and 11 deletions

View File

@@ -1,6 +1,5 @@
#include "horizontal_layout.h"
#include "empty_layout.h"
#include <poincare/expression_layout_cursor.h>
extern "C" {
#include <assert.h>
#include <kandinsky.h>
@@ -424,18 +423,17 @@ bool HorizontalLayout::moveVertically(ExpressionLayout::VerticalDirection direct
newPosition = ExpressionLayoutCursor::Position::Left;
}
if (brother && cursor->positionIsEquivalentTo(brother, newPosition)) {
ExpressionLayout * previousPointedLayout = cursor->pointedExpressionLayout();
ExpressionLayoutCursor::Position previousPosition = cursor->position();
cursor->setPointedExpressionLayout(brother);
cursor->setPosition(newPosition);
if (direction == ExpressionLayout::VerticalDirection::Up && brother->moveUp(cursor, shouldRecomputeLayout, this, previousLayout)) {
if (tryMoveVerticallyFromAnotherLayout(brother, newPosition, direction, cursor, shouldRecomputeLayout, previousLayout)) {
return true;
}
if (direction == ExpressionLayout::VerticalDirection::Down && brother->moveDown(cursor, shouldRecomputeLayout, this, previousLayout)) {
return true;
}
cursor->setPointedExpressionLayout(previousPointedLayout);
cursor->setPosition(previousPosition);
}
}
/* If the cursor is Lefit or Right of the HorizontalLayout, try moving it up
* from its extremal child. */
if (cursor->pointedExpressionLayout() == this && previousLayout == nullptr) {
int indexOfChildToCheck = cursor->position() == ExpressionLayoutCursor::Position::Left ? 0 : numberOfChildren() - 1;
if (tryMoveVerticallyFromAnotherLayout(editableChild(indexOfChildToCheck), cursor->position(), direction, cursor, shouldRecomputeLayout, previousLayout)) {
return true;
}
}
if (direction == ExpressionLayout::VerticalDirection::Up) {
@@ -445,6 +443,22 @@ bool HorizontalLayout::moveVertically(ExpressionLayout::VerticalDirection direct
return ExpressionLayout::moveDown(cursor, shouldRecomputeLayout, previousLayout, previousPreviousLayout);
}
bool HorizontalLayout::tryMoveVerticallyFromAnotherLayout(ExpressionLayout * otherLayout, ExpressionLayoutCursor::Position otherPosition, ExpressionLayout::VerticalDirection direction, ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, ExpressionLayout * previousLayout) {
ExpressionLayout * previousPointedLayout = cursor->pointedExpressionLayout();
ExpressionLayoutCursor::Position previousPosition = cursor->position();
cursor->setPointedExpressionLayout(otherLayout);
cursor->setPosition(otherPosition);
if (direction == ExpressionLayout::VerticalDirection::Up && otherLayout->moveUp(cursor, shouldRecomputeLayout, this, previousLayout)) {
return true;
}
if (direction == ExpressionLayout::VerticalDirection::Down && otherLayout->moveDown(cursor, shouldRecomputeLayout, this, previousLayout)) {
return true;
}
cursor->setPointedExpressionLayout(previousPointedLayout);
cursor->setPosition(previousPosition);
return false;
}
void HorizontalLayout::privateRemoveChildAtIndex(int index, bool deleteAfterRemoval, bool forceRemove) {
// If the child to remove is at index 0 and its right brother must have a left
// brother (e.g. it is a VerticalOffsetLayout), replace the child with an

View File

@@ -3,6 +3,7 @@
#include <poincare/dynamic_layout_hierarchy.h>
#include <poincare/layout_engine.h>
#include <poincare/expression_layout_cursor.h>
namespace Poincare {
@@ -48,6 +49,7 @@ protected:
void privateAddBrother(ExpressionLayoutCursor * cursor, ExpressionLayout * brother, bool moveCursor) override;
private:
bool moveVertically(ExpressionLayout::VerticalDirection direction, ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, ExpressionLayout * previousLayout, ExpressionLayout * previousPreviousLayout);
bool tryMoveVerticallyFromAnotherLayout(ExpressionLayout * otherLayout, ExpressionLayoutCursor::Position otherPosition, ExpressionLayout::VerticalDirection direction, ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, ExpressionLayout * previousLayout);
void privateReplaceChild(const ExpressionLayout * oldChild, ExpressionLayout * newChild, bool deleteOldChild, ExpressionLayoutCursor * cursor);
void privateRemoveChildAtIndex(int index, bool deleteAfterRemoval, bool forceRemove);
int removeEmptyChildBeforeInsertionAtIndex(int index, bool shouldRemoveOnLeft);