mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare/matrix_layout] Delete rows in two steps
Row deletion is done when deleting the left empty layout of an empty row.
This commit is contained in:
committed by
RubenNumworks
parent
3831c66183
commit
6ef0b3b4ab
@@ -26,6 +26,7 @@ public:
|
||||
void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override;
|
||||
void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) override;
|
||||
void willAddSiblingToEmptyChildAtIndex(int childIndex) override;
|
||||
void deleteBeforeCursor(LayoutCursor * cursor) override;
|
||||
|
||||
// SerializableNode
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
@@ -92,6 +92,26 @@ void MatrixLayoutNode::willAddSiblingToEmptyChildAtIndex(int childIndex) {
|
||||
}
|
||||
}
|
||||
|
||||
void MatrixLayoutNode::deleteBeforeCursor(LayoutCursor * cursor) {
|
||||
// Deleting the left empty layout of an empty row deletes the row
|
||||
assert(cursor != nullptr);
|
||||
LayoutNode * pointedChild = cursor->layoutNode();
|
||||
if (pointedChild->isEmpty()) {
|
||||
int indexOfPointedLayout = indexOfChild(pointedChild);
|
||||
if (columnAtChildIndex(indexOfPointedLayout) == 0) {
|
||||
int rowIndex = rowAtChildIndex(indexOfPointedLayout);
|
||||
if (isRowEmpty(rowIndex) && m_numberOfRows > 2) {
|
||||
deleteRowAtIndex(rowIndex);
|
||||
assert(indexOfPointedLayout >= 0 && indexOfPointedLayout < m_numberOfColumns*m_numberOfRows);
|
||||
cursor->setLayoutNode(childAtIndex(indexOfPointedLayout));
|
||||
cursor->setPosition(LayoutCursor::Position::Right);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
GridLayoutNode::deleteBeforeCursor(cursor);
|
||||
}
|
||||
|
||||
// SerializableNode
|
||||
|
||||
int MatrixLayoutNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
@@ -273,10 +293,8 @@ void MatrixLayoutNode::didReplaceChildAtIndex(int index, LayoutCursor * cursor,
|
||||
bool rowIsEmpty = isRowEmpty(rowIndex);
|
||||
bool columnIsEmpty = isColumnEmpty(columnIndex);
|
||||
int newIndex = index;
|
||||
if (rowIsEmpty && m_numberOfRows > 2) {
|
||||
deleteRowAtIndex(rowIndex);
|
||||
}
|
||||
if (columnIsEmpty && m_numberOfColumns > 2) {
|
||||
// If the column is now empty, delete it
|
||||
deleteColumnAtIndex(columnIndex);
|
||||
newIndex -= rowIndex;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user