mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-22 23:30:37 +01:00
[poincare] LayoutReference::addChildAtIndex needs current childrenCount
This commit is contained in:
@@ -73,7 +73,7 @@ public:
|
||||
|
||||
// Tree modification
|
||||
// Add
|
||||
void addChildAtIndex(LayoutReference l, int index, LayoutCursor * cursor);
|
||||
void addChildAtIndex(LayoutReference l, int index, int currentNumberOfChildren, LayoutCursor * cursor);
|
||||
void addSibling(LayoutCursor * cursor, LayoutReference sibling, bool moveCursor);
|
||||
// Replace
|
||||
//void replaceChildAtIndex(int oldChildIndex, LayoutReference newChild) { TreeReference::replaceTreeChildAtIndex(oldChildIndex, newChild); }
|
||||
|
||||
@@ -52,7 +52,7 @@ Expression * Equal::shallowReduce(Context& context, Preferences::AngleUnit angle
|
||||
LayoutRef Equal::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
HorizontalLayoutRef result;
|
||||
result.addOrMergeChildAtIndex(operand(0)->createLayout(floatDisplayMode, numberOfSignificantDigits), 0, false);
|
||||
result.addChildAtIndex(CharLayoutRef('='), result.numberOfChildren(), nullptr);
|
||||
result.addChildAtIndex(CharLayoutRef('='), result.numberOfChildren(), result.numberOfChildren(), nullptr);
|
||||
result.addOrMergeChildAtIndex(operand(1)->createLayout(floatDisplayMode, numberOfSignificantDigits), result.numberOfChildren(), false);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,8 @@ std::complex<T> Factorial::computeOnComplex(const std::complex<T> c, Preferences
|
||||
LayoutRef Factorial::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
HorizontalLayoutRef result;
|
||||
result.addOrMergeChildAtIndex(operand(0)->createLayout(floatDisplayMode, numberOfSignificantDigits), 0, false);
|
||||
result.addChildAtIndex(CharLayoutRef('!'), result.numberOfChildren(), nullptr);
|
||||
int childrenCount = result.numberOfChildren();
|
||||
result.addChildAtIndex(CharLayoutRef('!'), childrenCount, childrenCount, nullptr);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -94,18 +94,27 @@ void GridLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldRecomput
|
||||
//TODO
|
||||
void GridLayoutNode::addEmptyRow(EmptyLayoutNode::Color color) {
|
||||
LayoutRef thisRef = LayoutRef(this);
|
||||
int insertionIndex = numberOfChildren();
|
||||
int previousNumberOfChildren = numberOfChildren();
|
||||
for (int i = 0; i < m_numberOfColumns; i++) {
|
||||
thisRef.addChildAtIndex(EmptyLayoutRef(color), insertionIndex, nullptr);
|
||||
thisRef.addChildAtIndex(
|
||||
EmptyLayoutRef(color),
|
||||
previousNumberOfChildren,
|
||||
previousNumberOfChildren + i,
|
||||
nullptr);
|
||||
}
|
||||
m_numberOfRows++;
|
||||
}
|
||||
|
||||
void GridLayoutNode::addEmptyColumn(EmptyLayoutNode::Color color) {
|
||||
LayoutRef thisRef = LayoutRef(this);
|
||||
int previousNumberOfChildren = numberOfChildren();
|
||||
m_numberOfColumns++;
|
||||
for (int i = 0; i < m_numberOfRows; i++) {
|
||||
thisRef.addChildAtIndex(EmptyLayoutRef(color), i*m_numberOfColumns + m_numberOfColumns-1, nullptr);
|
||||
thisRef.addChildAtIndex(
|
||||
EmptyLayoutRef(color),
|
||||
i*m_numberOfColumns + m_numberOfColumns-1,
|
||||
previousNumberOfChildren + i,
|
||||
nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -248,7 +248,7 @@ void HorizontalLayoutNode::didRemoveChildAtIndex(int index, LayoutCursor * curso
|
||||
* sibling (e.g. a VerticalOffsetLayout), add an empty layout at index 0 */
|
||||
|
||||
if (!force && index == 0 && numberOfChildren() > 0 && childAtIndex(0)->mustHaveLeftSibling()) {
|
||||
HorizontalLayoutRef(this).addChildAtIndex(EmptyLayoutRef(), 0, cursor);
|
||||
HorizontalLayoutRef(this).addChildAtIndex(EmptyLayoutRef(), 0, numberOfChildren(), cursor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ void HorizontalLayoutRef::addOrMergeChildAtIndex(LayoutRef l, int index, bool re
|
||||
if (l.isHorizontal()) {
|
||||
mergeChildrenAtIndex(HorizontalLayoutRef(l.node()), index, removeEmptyChildren, cursor);
|
||||
} else {
|
||||
addChildAtIndex(l, index, cursor);
|
||||
addChildAtIndex(l, index, numberOfChildren(),cursor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ LayoutRef LayoutEngine::createPrefixLayout(const Expression * expression, Prefer
|
||||
if (numberOfOperands > 0) {
|
||||
args.addOrMergeChildAtIndex(expression->operand(0)->createLayout(floatDisplayMode, numberOfSignificantDigits), 0, true);
|
||||
for (int i = 1; i < numberOfOperands; i++) {
|
||||
args.addChildAtIndex(CharLayoutRef(','), args.numberOfChildren(), nullptr);
|
||||
args.addChildAtIndex(CharLayoutRef(','), args.numberOfChildren(), args.numberOfChildren(), nullptr);
|
||||
args.addOrMergeChildAtIndex(expression->operand(i)->createLayout(floatDisplayMode, numberOfSignificantDigits), args.numberOfChildren(), true);
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ LayoutRef LayoutEngine::createStringLayout(const char * buffer, int bufferSize,
|
||||
assert(bufferSize > 0);
|
||||
HorizontalLayoutRef resultLayout;
|
||||
for (int i = 0; i < bufferSize; i++) {
|
||||
resultLayout.addChildAtIndex(CharLayoutRef(buffer[i], fontSize), i, nullptr);
|
||||
resultLayout.addChildAtIndex(CharLayoutRef(buffer[i], fontSize), i, i, nullptr);
|
||||
}
|
||||
return resultLayout;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ LayoutRef LayoutEngine::createStringLayout(const char * buffer, int bufferSize,
|
||||
LayoutRef LayoutEngine::createLogLayout(LayoutRef argument, LayoutRef index) {
|
||||
HorizontalLayoutRef resultLayout = HorizontalLayoutRef(createStringLayout("log", 3));
|
||||
VerticalOffsetLayoutRef offsetLayout = VerticalOffsetLayoutRef(index, VerticalOffsetLayoutNode::Type::Subscript);
|
||||
resultLayout.addChildAtIndex(offsetLayout, resultLayout.numberOfChildren(), nullptr);
|
||||
resultLayout.addChildAtIndex(offsetLayout, resultLayout.numberOfChildren(), resultLayout.numberOfChildren(), nullptr);
|
||||
resultLayout.addOrMergeChildAtIndex(createParenthesedLayout(argument, false), resultLayout.numberOfChildren(), true);
|
||||
return resultLayout;
|
||||
}
|
||||
|
||||
@@ -80,9 +80,10 @@ void LayoutReference::replaceWithJuxtapositionOf(LayoutRef leftChild, LayoutRef
|
||||
p.removeChild(*this, cursor->layoutReference() == *this ? cursor : nullptr);
|
||||
}
|
||||
|
||||
void LayoutReference::addChildAtIndex(LayoutRef l, int index, LayoutCursor * cursor) {
|
||||
void LayoutReference::addChildAtIndex(LayoutRef l, int index, int currentNumberOfChildren, LayoutCursor * cursor) {
|
||||
int newIndex = index;
|
||||
if (!this->node()->willAddChildAtIndex(l.node(), &newIndex, cursor)) {
|
||||
int newCurrentNumberOfChildren = currentNumberOfChildren;
|
||||
if (!this->node()->willAddChildAtIndex(l.node(), &newIndex, /*&newCurrentNumberOfChildren /*TODO*/, cursor)) {
|
||||
return;
|
||||
}
|
||||
LayoutRef nextPointedLayout(nullptr);
|
||||
@@ -97,7 +98,7 @@ void LayoutReference::addChildAtIndex(LayoutRef l, int index, LayoutCursor * cur
|
||||
}
|
||||
}
|
||||
|
||||
this->addChildTreeAtIndex(l, newIndex, numberOfChildren());
|
||||
this->addChildTreeAtIndex(l, newIndex, newCurrentNumberOfChildren);
|
||||
|
||||
if (cursor != nullptr) {
|
||||
if (this->isAllocationFailure()) {
|
||||
|
||||
@@ -219,7 +219,7 @@ LayoutRef Matrix::createLayout(Preferences::PrintFloatMode floatDisplayMode, int
|
||||
MatrixLayoutRef layout;
|
||||
LayoutRef castedLayout(layout.node());
|
||||
for (int i = 0; i < numberOfOperands(); i++) {
|
||||
castedLayout.addChildAtIndex(operand(i)->createLayout(floatDisplayMode, numberOfSignificantDigits), i, nullptr);
|
||||
castedLayout.addChildAtIndex(operand(i)->createLayout(floatDisplayMode, numberOfSignificantDigits), i, i, nullptr);
|
||||
}
|
||||
layout.setNumberOfRows(numberOfRows());
|
||||
layout.setNumberOfColumns(numberOfColumns());
|
||||
|
||||
@@ -183,6 +183,7 @@ LayoutRef Power::createLayout(Preferences::PrintFloatMode floatDisplayMode, int
|
||||
indiceOperand->createLayout(floatDisplayMode, numberOfSignificantDigits),
|
||||
VerticalOffsetLayoutNode::Type::Superscript),
|
||||
result.numberOfChildren(),
|
||||
result.numberOfChildren(),
|
||||
nullptr);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ Expression * Store::shallowReduce(Context& context, Preferences::AngleUnit angle
|
||||
LayoutRef Store::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
HorizontalLayoutRef result = HorizontalLayoutRef();
|
||||
result.addOrMergeChildAtIndex(value()->createLayout(floatDisplayMode, numberOfSignificantDigits), 0, false);
|
||||
result.addChildAtIndex(CharLayoutRef(Ion::Charset::Sto), result.numberOfChildren(), nullptr);
|
||||
result.addChildAtIndex(CharLayoutRef(Ion::Charset::Sto), result.numberOfChildren(), result.numberOfChildren(), nullptr);
|
||||
result.addOrMergeChildAtIndex(symbol()->createLayout(floatDisplayMode, numberOfSignificantDigits), result.numberOfChildren(), false);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -255,16 +255,16 @@ bool VerticalOffsetLayoutNode::willAddSibling(LayoutCursor * cursor, LayoutNode
|
||||
{
|
||||
leftParenthesisIndex--;
|
||||
}
|
||||
parentRef.addChildAtIndex(leftParenthesis, leftParenthesisIndex, nullptr);
|
||||
parentRef.addChildAtIndex(leftParenthesis, leftParenthesisIndex, parentRef.numberOfChildren(), nullptr);
|
||||
idxInParent++;
|
||||
|
||||
// Add the Right parenthesis
|
||||
RightParenthesisLayoutRef rightParenthesis = RightParenthesisLayoutRef();
|
||||
if (cursor->position() == LayoutCursor::Position::Right) {
|
||||
parentRef.addChildAtIndex(rightParenthesis, idxInParent + 1, nullptr);
|
||||
parentRef.addChildAtIndex(rightParenthesis, idxInParent + 1, parentRef.numberOfChildren(), nullptr);
|
||||
} else {
|
||||
assert(cursor->position() == LayoutCursor::Position::Left);
|
||||
parentRef.addChildAtIndex(rightParenthesis, idxInParent, nullptr);
|
||||
parentRef.addChildAtIndex(rightParenthesis, idxInParent, parentRef.numberOfChildren(), nullptr);
|
||||
}
|
||||
if (rightParenthesis.parent().isDefined()) {
|
||||
cursor->setLayoutReference(rightParenthesis);
|
||||
|
||||
Reference in New Issue
Block a user