mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-24 16:20:49 +01:00
[poincare] Cleaned the dynamic methods for layouts.
Change-Id: I17db05b01c75a638a56fe2c197a175fd1b04840d
This commit is contained in:
@@ -23,8 +23,10 @@ public:
|
||||
int numberOfChildren() const override { return m_numberOfChildren; }
|
||||
const ExpressionLayout * const * children() const override { return m_children; };
|
||||
|
||||
void addNonEmptyChildrenAtIndex(const ExpressionLayout * const * operands, int numberOfOperands, int indexForInsertion);
|
||||
bool addChildAtIndex(ExpressionLayout * operand, int index) override;
|
||||
void removeChildAtIndex(int index, bool deleteAfterRemoval) override;
|
||||
void mergeChildrenAtIndex(DynamicLayoutHierarchy * eL, int index); // WITHOUT delete.
|
||||
|
||||
bool isEmpty() const override;
|
||||
protected:
|
||||
|
||||
@@ -50,6 +50,8 @@ public:
|
||||
ExpressionLayout * replaceWithJuxtapositionOf(ExpressionLayout * leftChild, ExpressionLayout * rightChild, bool deleteAfterReplace);
|
||||
virtual void replaceChild(const ExpressionLayout * oldChild, ExpressionLayout * newChild, bool deleteOldChild = true);
|
||||
void detachChild(const ExpressionLayout * e); // Removes a child WITHOUT deleting it
|
||||
void detachChildren(); //Removes all children WITHOUT deleting them
|
||||
|
||||
|
||||
/* Dynamic Layout*/
|
||||
virtual bool addChildAtIndex(ExpressionLayout * child, int index) { return false; }
|
||||
|
||||
@@ -42,6 +42,40 @@ DynamicLayoutHierarchy::~DynamicLayoutHierarchy() {
|
||||
delete[] m_children;
|
||||
}
|
||||
|
||||
void DynamicLayoutHierarchy::mergeChildrenAtIndex(DynamicLayoutHierarchy * eL, int index) {
|
||||
int indexOfEL = indexOfChild(eL);
|
||||
if (indexOfEL >= 0) {
|
||||
removeChildAtIndex(indexOfEL, false);
|
||||
}
|
||||
addNonEmptyChildrenAtIndex(eL->children(), eL->numberOfChildren(), index);
|
||||
eL->detachChildren();
|
||||
delete eL;
|
||||
}
|
||||
|
||||
void DynamicLayoutHierarchy::addNonEmptyChildrenAtIndex(const ExpressionLayout * const * operands, int numberOfOperands, int indexForInsertion) {
|
||||
assert(numberOfOperands > 0);
|
||||
const ExpressionLayout ** newOperands = new const ExpressionLayout * [m_numberOfChildren+numberOfOperands];
|
||||
int currentIndex = 0;
|
||||
assert(indexForInsertion <= m_numberOfChildren);
|
||||
for (int i=0; i<indexForInsertion; i++) {
|
||||
newOperands[currentIndex++] = m_children[i];
|
||||
}
|
||||
for (int i=0; i<numberOfOperands; i++) {
|
||||
if (!operands[i]->isEmpty()
|
||||
|| (i < numberOfOperands-1 && operands[i+1]->mustHaveLeftBrother()))
|
||||
{
|
||||
const_cast<ExpressionLayout *>(operands[i])->setParent(this);
|
||||
newOperands[currentIndex++] = operands[i];
|
||||
}
|
||||
}
|
||||
for (int i=indexForInsertion; i<m_numberOfChildren; i++) {
|
||||
newOperands[currentIndex++] = m_children[i];
|
||||
}
|
||||
delete[] m_children;
|
||||
m_children = newOperands;
|
||||
m_numberOfChildren = currentIndex;
|
||||
}
|
||||
|
||||
bool DynamicLayoutHierarchy::addChildAtIndex(ExpressionLayout * child, int index) {
|
||||
assert(index >= 0 && index <= m_numberOfChildren);
|
||||
const ExpressionLayout ** newChildren = new const ExpressionLayout * [m_numberOfChildren+1];
|
||||
|
||||
@@ -197,6 +197,12 @@ void ExpressionLayout::detachChild(const ExpressionLayout * e) {
|
||||
}
|
||||
}
|
||||
|
||||
void ExpressionLayout::detachChildren() {
|
||||
for (int i = 0; i <numberOfChildren(); i++) {
|
||||
detachChildAtIndex(i);
|
||||
}
|
||||
}
|
||||
|
||||
void ExpressionLayout::removeChildAtIndex(int index, bool deleteAfterRemoval) {
|
||||
assert(index >= 0 && index < numberOfChildren());
|
||||
replaceChild(editableChild(index), new EmptyVisibleLayout(), deleteAfterRemoval);
|
||||
|
||||
@@ -50,7 +50,7 @@ void HorizontalLayout::replaceChild(const ExpressionLayout * oldChild, Expressio
|
||||
// new layout then destroy it.
|
||||
if (newChild->isHorizontal()) {
|
||||
int indexForInsertion = indexOfChild(const_cast<ExpressionLayout *>(oldChild));
|
||||
mergeChildrenAtIndex(newChild, indexForInsertion + 1);
|
||||
mergeChildrenAtIndex(static_cast<HorizontalLayout *>(newChild), indexForInsertion + 1);
|
||||
removeChildAtIndex(indexForInsertion, deleteOldChild);
|
||||
return;
|
||||
}
|
||||
@@ -65,11 +65,10 @@ void HorizontalLayout::addOrMergeChildAtIndex(ExpressionLayout * eL, int index)
|
||||
newIndex = index == 0 ? 0 : index - 1;
|
||||
}
|
||||
if (eL->isHorizontal()) {
|
||||
mergeChildrenAtIndex(eL, newIndex);
|
||||
mergeChildrenAtIndex(static_cast<HorizontalLayout *>(eL), newIndex);
|
||||
return;
|
||||
}
|
||||
addChildAtIndex(eL, newIndex);
|
||||
|
||||
}
|
||||
|
||||
bool HorizontalLayout::moveLeft(ExpressionLayoutCursor * cursor) {
|
||||
@@ -228,27 +227,6 @@ KDPoint HorizontalLayout::positionOfChild(ExpressionLayout * child) {
|
||||
return KDPoint(x, y);
|
||||
}
|
||||
|
||||
void HorizontalLayout::mergeChildrenAtIndex(ExpressionLayout * eL, int index) {
|
||||
int indexOfEL = indexOfChild(eL);
|
||||
if (indexOfEL >= 0) {
|
||||
removeChildAtIndex(indexOfEL, false);
|
||||
}
|
||||
int numChildren = eL->numberOfChildren();
|
||||
int currentAdditionIndex = index;
|
||||
for (int i = 0; i < numChildren; i++) {
|
||||
ExpressionLayout * currentChild = eL->editableChild(i);
|
||||
// Do not add empty children if we can
|
||||
if (!currentChild->isEmpty()
|
||||
|| i == numChildren - 1
|
||||
|| (i < numChildren - 1 && eL->editableChild(i+1)->mustHaveLeftBrother()))
|
||||
{
|
||||
addChildAtIndex(currentChild, currentAdditionIndex++);
|
||||
eL->detachChild(currentChild);
|
||||
}
|
||||
}
|
||||
delete eL;
|
||||
}
|
||||
|
||||
bool HorizontalLayout::moveVertically(ExpressionLayout::VerticalDirection direction, ExpressionLayoutCursor * cursor, ExpressionLayout * previousLayout, ExpressionLayout * previousPreviousLayout) {
|
||||
// Prevent looping fom child to parent
|
||||
if (previousPreviousLayout == this) {
|
||||
|
||||
@@ -38,7 +38,6 @@ protected:
|
||||
KDSize computeSize() override;
|
||||
void computeBaseline() override;
|
||||
KDPoint positionOfChild(ExpressionLayout * child) override;
|
||||
void mergeChildrenAtIndex(ExpressionLayout * eL, int index); // WITHOUT delete.
|
||||
private:
|
||||
bool moveVertically(ExpressionLayout::VerticalDirection direction, ExpressionLayoutCursor * cursor, ExpressionLayout * previousLayout, ExpressionLayout * previousPreviousLayout);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user