[poincare] Simplify MatrixLayout code

Change-Id: I4bfcf3da94296b8314ff47a1a71dbc79150a4027
This commit is contained in:
Léa Saviot
2018-05-09 13:32:27 +02:00
parent 7e9bbe3aea
commit b5f4a7b3f0
3 changed files with 9 additions and 26 deletions

View File

@@ -89,8 +89,8 @@ public:
virtual ExpressionLayoutCursor cursorRightOf(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout) = 0;
virtual ExpressionLayoutCursor cursorAbove(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false);
virtual ExpressionLayoutCursor cursorUnder(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false);
virtual ExpressionLayoutCursor cursorInDescendantsAbove(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout);
virtual ExpressionLayoutCursor cursorInDescendantsUnder(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout);
ExpressionLayoutCursor cursorInDescendantsAbove(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout);
ExpressionLayoutCursor cursorInDescendantsUnder(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout);
/* Expression Engine */
virtual int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const = 0;
@@ -142,6 +142,7 @@ protected:
int * resultScore);
virtual void privateAddSibling(ExpressionLayoutCursor * cursor, ExpressionLayout * sibling, bool moveCursor);
void collapseOnDirection(HorizontalDirection direction, int absorbingChildIndex);
virtual ExpressionLayoutCursor cursorVerticalOf(VerticalDirection direction, ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited);
ExpressionLayout * m_parent;
KDCoordinate m_baseline;
/* m_baseline is the signed vertical distance from the top of the layout to
@@ -152,7 +153,6 @@ protected:
bool m_positioned;
private:
void detachChildAtIndex(int i);
ExpressionLayoutCursor cursorVerticalOf(VerticalDirection direction, ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited);
ExpressionLayoutCursor cursorInDescendantsVerticalOf(VerticalDirection direction, ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout);
ExpressionLayout * replaceWithJuxtapositionOf(ExpressionLayout * leftChild, ExpressionLayout * rightChild, bool deleteAfterReplace);
KDRect m_frame;

View File

@@ -73,34 +73,18 @@ ExpressionLayoutCursor MatrixLayout::cursorRightOf(ExpressionLayoutCursor cursor
return GridLayout::cursorRightOf(cursor, shouldRecomputeLayout);
}
ExpressionLayoutCursor MatrixLayout::cursorAbove(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) {
ExpressionLayoutCursor MatrixLayout::cursorVerticalOf(VerticalDirection direction, ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) {
bool shouldRemoveGreySquares = false;
for (int childIndex = 0; childIndex < m_numberOfColumns; childIndex++) {
int firstIndex = direction == VerticalDirection::Up ? 0 : numberOfChildren() - m_numberOfColumns;
int lastIndex = direction == VerticalDirection::Up ? m_numberOfColumns : numberOfChildren();
for (int childIndex = firstIndex; childIndex < lastIndex; childIndex++) {
if (cursor.pointedExpressionLayout()->hasAncestor(child(childIndex), true)) {
// The cursor is leaving the matrix, so remove the grey squares.
shouldRemoveGreySquares = true;
break;
}
}
ExpressionLayoutCursor resultCursor = GridLayout::cursorAbove(cursor, shouldRecomputeLayout, equivalentPositionVisited);
if (resultCursor.isDefined() && shouldRemoveGreySquares) {
assert(hasGreySquares());
removeGreySquares();
*shouldRecomputeLayout = true;
}
return resultCursor;
}
ExpressionLayoutCursor MatrixLayout::cursorUnder(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) {
bool shouldRemoveGreySquares = false;
for (int childIndex = numberOfChildren() - m_numberOfColumns; childIndex < m_numberOfChildren; childIndex++) {
if (cursor.pointedExpressionLayout()->hasAncestor(child(childIndex), true)) {
// The cursor is leaving the matrix, so remove the grey squares.
shouldRemoveGreySquares = true;
break;
}
}
ExpressionLayoutCursor resultCursor = GridLayout::cursorUnder(cursor, shouldRecomputeLayout, equivalentPositionVisited);
ExpressionLayoutCursor resultCursor = GridLayout::cursorVerticalOf(direction, cursor, shouldRecomputeLayout, equivalentPositionVisited);
if (resultCursor.isDefined() && shouldRemoveGreySquares) {
assert(hasGreySquares());
removeGreySquares();

View File

@@ -13,8 +13,6 @@ public:
/* Navigation */
ExpressionLayoutCursor cursorLeftOf(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout) override;
ExpressionLayoutCursor cursorRightOf(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout) override;
ExpressionLayoutCursor cursorAbove(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override;
ExpressionLayoutCursor cursorUnder(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override;
/* Dynamic layout */
void replaceChild(const ExpressionLayout * oldChild, ExpressionLayout * newChild, bool deleteOldChild) override;
@@ -35,6 +33,7 @@ protected:
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override;
KDSize computeSize() override;
KDPoint positionOfChild(ExpressionLayout * child) override;
ExpressionLayoutCursor cursorVerticalOf(VerticalDirection direction, ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) override;
private:
void childWasReplacedAtIndex(int index);
bool isRowEmpty(int index) const;