mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[apps,escher,kandinsky,poincare,python] Replace every "grey" with "gray"
Change-Id: I60a232849dce90f70e6977b6024d6e9b1ce1b731
This commit is contained in:
committed by
Émilie Feral
parent
4331686818
commit
e27c668c40
@@ -10,7 +10,7 @@ class EmptyLayoutNode /*final*/ : public LayoutNode {
|
||||
public:
|
||||
enum class Color {
|
||||
Yellow,
|
||||
Grey
|
||||
Gray
|
||||
};
|
||||
|
||||
// Layout
|
||||
|
||||
@@ -60,9 +60,9 @@ public:
|
||||
|
||||
// Layout modification
|
||||
void deleteBeforeCursor(LayoutCursor * cursor) { return node()->deleteBeforeCursor(cursor); }
|
||||
bool removeGreySquaresFromAllMatrixAncestors() { return node()->removeGreySquaresFromAllMatrixAncestors(); }
|
||||
bool removeGreySquaresFromAllMatrixChildren() { return node()->removeGreySquaresFromAllMatrixChildren(); }
|
||||
bool addGreySquaresToAllMatrixAncestors() { return node()->addGreySquaresToAllMatrixAncestors(); }
|
||||
bool removeGraySquaresFromAllMatrixAncestors() { return node()->removeGraySquaresFromAllMatrixAncestors(); }
|
||||
bool removeGraySquaresFromAllMatrixChildren() { return node()->removeGraySquaresFromAllMatrixChildren(); }
|
||||
bool addGraySquaresToAllMatrixAncestors() { return node()->addGraySquaresToAllMatrixAncestors(); }
|
||||
Layout layoutToPointWhenInserting(Expression * correspondingExpression) {
|
||||
// Pointer to correspondingExpr because expression.h includes layout.h
|
||||
assert(correspondingExpression != nullptr);
|
||||
|
||||
@@ -103,9 +103,9 @@ public:
|
||||
|
||||
// Other
|
||||
virtual LayoutNode * layoutToPointWhenInserting(Expression * correspondingExpression);
|
||||
bool removeGreySquaresFromAllMatrixAncestors();
|
||||
bool removeGreySquaresFromAllMatrixChildren();
|
||||
bool addGreySquaresToAllMatrixAncestors();
|
||||
bool removeGraySquaresFromAllMatrixAncestors();
|
||||
bool removeGraySquaresFromAllMatrixChildren();
|
||||
bool addGraySquaresToAllMatrixAncestors();
|
||||
/* A layout has text if it is not empty and it is not an horizontal layout
|
||||
* with no child or with one child with no text. */
|
||||
virtual bool hasText() const { return true; }
|
||||
@@ -173,7 +173,7 @@ private:
|
||||
int * resultScore,
|
||||
bool forSelection);
|
||||
virtual void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor, Layout * selectionStart = nullptr, Layout * selectionEnd = nullptr, KDColor selectionColor = KDColorRed) = 0;
|
||||
void changeGreySquaresOfAllMatrixRelatives(bool add, bool ancestors, bool * changedSquares);
|
||||
void changeGraySquaresOfAllMatrixRelatives(bool add, bool ancestors, bool * changedSquares);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ public:
|
||||
Type type() const override { return Type::MatrixLayout; }
|
||||
|
||||
// MatrixLayoutNode
|
||||
void addGreySquares();
|
||||
void removeGreySquares();
|
||||
void addGraySquares();
|
||||
void removeGraySquares();
|
||||
|
||||
// LayoutNode
|
||||
void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override;
|
||||
@@ -50,7 +50,7 @@ private:
|
||||
void newRowOrColumnAtIndex(int index);
|
||||
bool isRowEmpty(int index) const;
|
||||
bool isColumnEmpty(int index) const;
|
||||
bool hasGreySquares() const;
|
||||
bool hasGraySquares() const;
|
||||
|
||||
// LayoutNode
|
||||
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor, Layout * selectionStart = nullptr, Layout * selectionEnd = nullptr, KDColor selectionColor = KDColorRed) override;
|
||||
@@ -64,9 +64,9 @@ public:
|
||||
static MatrixLayout Builder() { return TreeHandle::NAryBuilder<MatrixLayout, MatrixLayoutNode>(); }
|
||||
static MatrixLayout Builder(Layout l1, Layout l2, Layout l3, Layout l4);
|
||||
|
||||
bool hasGreySquares() const { return node()->hasGreySquares(); }
|
||||
void addGreySquares() { node()->addGreySquares(); }
|
||||
void removeGreySquares() { node()->removeGreySquares(); }
|
||||
bool hasGraySquares() const { return node()->hasGraySquares(); }
|
||||
void addGraySquares() { node()->addGraySquares(); }
|
||||
void removeGraySquares() { node()->removeGraySquares(); }
|
||||
private:
|
||||
MatrixLayoutNode * node() const { return static_cast<MatrixLayoutNode *>(Layout::node()); }
|
||||
};
|
||||
|
||||
@@ -68,7 +68,7 @@ void EmptyLayoutNode::moveCursorVertically(VerticalDirection direction, LayoutCu
|
||||
bool EmptyLayoutNode::willAddSibling(LayoutCursor * cursor, LayoutNode * sibling, bool moveCursor) {
|
||||
EmptyLayout thisRef(this);
|
||||
Layout siblingRef(sibling); // Create the reference now, as the node might be moved
|
||||
if (m_color == Color::Grey) {
|
||||
if (m_color == Color::Gray) {
|
||||
/* The parent is a MatrixLayout, and the current empty row or column is
|
||||
* being filled in, so add a new empty row or column. */
|
||||
LayoutNode * parentNode = parent();
|
||||
@@ -88,7 +88,7 @@ bool EmptyLayoutNode::willAddSibling(LayoutCursor * cursor, LayoutNode * sibling
|
||||
|
||||
void EmptyLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor, Layout * selectionStart, Layout * selectionEnd, KDColor selectionColor) {
|
||||
if (m_isVisible) {
|
||||
KDColor fillColor = m_color == Color::Yellow ? Palette::YellowDark : Palette::GreyBright;
|
||||
KDColor fillColor = m_color == Color::Yellow ? Palette::YellowDark : Palette::GrayBright;
|
||||
ctx->fillRect(KDRect(p.x()+(m_margins ? k_marginWidth : 0), p.y()+(m_margins ? k_marginHeight : 0), width(), height()), fillColor);
|
||||
ctx->fillRect(KDRect(p.x()+(m_margins ? k_marginWidth : 0), p.y()+(m_margins ? k_marginHeight : 0), width(), height()), fillColor);
|
||||
}
|
||||
|
||||
@@ -150,9 +150,9 @@ void LayoutCursor::addEmptyExponentialLayout() {
|
||||
void LayoutCursor::addEmptyMatrixLayout() {
|
||||
MatrixLayout matrixLayout = MatrixLayout::Builder(
|
||||
EmptyLayout::Builder(EmptyLayoutNode::Color::Yellow),
|
||||
EmptyLayout::Builder(EmptyLayoutNode::Color::Grey),
|
||||
EmptyLayout::Builder(EmptyLayoutNode::Color::Grey),
|
||||
EmptyLayout::Builder(EmptyLayoutNode::Color::Grey));
|
||||
EmptyLayout::Builder(EmptyLayoutNode::Color::Gray),
|
||||
EmptyLayout::Builder(EmptyLayoutNode::Color::Gray),
|
||||
EmptyLayout::Builder(EmptyLayoutNode::Color::Gray));
|
||||
m_layout.addSibling(this, matrixLayout, false);
|
||||
m_layout = matrixLayout.childAtIndex(0);
|
||||
m_position = Position::Right;
|
||||
@@ -432,7 +432,7 @@ void LayoutCursor::selectUpDown(bool up, bool * shouldRecomputeLayout, Layout *
|
||||
* position). This ancestor will be the added selection.
|
||||
*
|
||||
* The current layout might have been detached from its parent, for instance
|
||||
* if it was a grey empty layout of a matrix and the cursor move exited this
|
||||
* if it was a gray empty layout of a matrix and the cursor move exited this
|
||||
* matrix. In this case, use the layout parent (it should still be attached to
|
||||
* the main layout). */
|
||||
|
||||
|
||||
@@ -118,21 +118,21 @@ LayoutNode * LayoutNode::layoutToPointWhenInserting(Expression * correspondingEx
|
||||
return numberOfChildren() > 0 ? childAtIndex(0) : this;
|
||||
}
|
||||
|
||||
bool LayoutNode::removeGreySquaresFromAllMatrixAncestors() {
|
||||
bool LayoutNode::removeGraySquaresFromAllMatrixAncestors() {
|
||||
bool result = false;
|
||||
changeGreySquaresOfAllMatrixRelatives(false, true, &result);
|
||||
changeGraySquaresOfAllMatrixRelatives(false, true, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool LayoutNode::removeGreySquaresFromAllMatrixChildren() {
|
||||
bool LayoutNode::removeGraySquaresFromAllMatrixChildren() {
|
||||
bool result = false;
|
||||
changeGreySquaresOfAllMatrixRelatives(false, false, &result);
|
||||
changeGraySquaresOfAllMatrixRelatives(false, false, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool LayoutNode::addGreySquaresToAllMatrixAncestors() {
|
||||
bool LayoutNode::addGraySquaresToAllMatrixAncestors() {
|
||||
bool result = false;
|
||||
changeGreySquaresOfAllMatrixRelatives(true, true, &result);
|
||||
changeGraySquaresOfAllMatrixRelatives(true, true, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ void LayoutNode::moveCursorInDescendantsVertically(VerticalDirection direction,
|
||||
// If there is a valid result
|
||||
Layout resultRef(childResult);
|
||||
if ((*childResultPtr) != nullptr) {
|
||||
*shouldRecomputeLayout = childResult->addGreySquaresToAllMatrixAncestors();
|
||||
*shouldRecomputeLayout = childResult->addGraySquaresToAllMatrixAncestors();
|
||||
// WARNING: Do not use "this" afterwards
|
||||
}
|
||||
cursor->setLayout(resultRef);
|
||||
@@ -260,36 +260,36 @@ void LayoutNode::scoreCursorInDescendantsVertically (
|
||||
}
|
||||
}
|
||||
|
||||
bool addRemoveGreySquaresInLayoutIfNeeded(bool add, Layout * l) {
|
||||
bool addRemoveGraySquaresInLayoutIfNeeded(bool add, Layout * l) {
|
||||
if (l->type() != LayoutNode::Type::MatrixLayout) {
|
||||
return false;
|
||||
}
|
||||
if (add) {
|
||||
static_cast<MatrixLayoutNode *>(l->node())->addGreySquares();
|
||||
static_cast<MatrixLayoutNode *>(l->node())->addGraySquares();
|
||||
} else {
|
||||
static_cast<MatrixLayoutNode *>(l->node())->removeGreySquares();
|
||||
static_cast<MatrixLayoutNode *>(l->node())->removeGraySquares();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void LayoutNode::changeGreySquaresOfAllMatrixRelatives(bool add, bool ancestors, bool * changedSquares) {
|
||||
void LayoutNode::changeGraySquaresOfAllMatrixRelatives(bool add, bool ancestors, bool * changedSquares) {
|
||||
if (!ancestors) {
|
||||
// If in children, we also change the squares for this
|
||||
{
|
||||
Layout thisLayout = Layout(this);
|
||||
if (addRemoveGreySquaresInLayoutIfNeeded(add, &thisLayout)) {
|
||||
if (addRemoveGraySquaresInLayoutIfNeeded(add, &thisLayout)) {
|
||||
*changedSquares = true;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < numberOfChildren(); i++) {
|
||||
/* We cannot use "for l : children()", as the node addresses might change,
|
||||
* especially the iterator stopping address. */
|
||||
childAtIndex(i)->changeGreySquaresOfAllMatrixRelatives(add, false, changedSquares);
|
||||
childAtIndex(i)->changeGraySquaresOfAllMatrixRelatives(add, false, changedSquares);
|
||||
}
|
||||
} else {
|
||||
Layout currentAncestor = Layout(parent());
|
||||
while (!currentAncestor.isUninitialized()) {
|
||||
if (addRemoveGreySquaresInLayoutIfNeeded(add, ¤tAncestor)) {
|
||||
if (addRemoveGraySquaresInLayoutIfNeeded(add, ¤tAncestor)) {
|
||||
*changedSquares = true;
|
||||
}
|
||||
currentAncestor = currentAncestor.parent();
|
||||
|
||||
@@ -10,16 +10,16 @@ namespace Poincare {
|
||||
|
||||
// MatrixLayoutNode
|
||||
|
||||
void MatrixLayoutNode::addGreySquares() {
|
||||
if (!hasGreySquares()) {
|
||||
void MatrixLayoutNode::addGraySquares() {
|
||||
if (!hasGraySquares()) {
|
||||
Layout thisRef(this);
|
||||
addEmptyRow(EmptyLayoutNode::Color::Grey);
|
||||
addEmptyColumn(EmptyLayoutNode::Color::Grey);
|
||||
addEmptyRow(EmptyLayoutNode::Color::Gray);
|
||||
addEmptyColumn(EmptyLayoutNode::Color::Gray);
|
||||
}
|
||||
}
|
||||
|
||||
void MatrixLayoutNode::removeGreySquares() {
|
||||
if (hasGreySquares()) {
|
||||
void MatrixLayoutNode::removeGraySquares() {
|
||||
if (hasGraySquares()) {
|
||||
deleteRowAtIndex(m_numberOfRows - 1);
|
||||
deleteColumnAtIndex(m_numberOfColumns - 1);
|
||||
}
|
||||
@@ -33,10 +33,10 @@ void MatrixLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomp
|
||||
&& cursor->position() == LayoutCursor::Position::Left
|
||||
&& childIsLeftOfGrid(childIndex))
|
||||
{
|
||||
/* Case: Left of a child on the left of the grid. Remove the grey squares of
|
||||
/* Case: Left of a child on the left of the grid. Remove the gray squares of
|
||||
* the grid, then go left of the grid. */
|
||||
assert(hasGreySquares());
|
||||
removeGreySquares();
|
||||
assert(hasGraySquares());
|
||||
removeGraySquares();
|
||||
*shouldRecomputeLayout = true;
|
||||
cursor->setLayoutNode(this);
|
||||
return;
|
||||
@@ -44,10 +44,10 @@ void MatrixLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomp
|
||||
if (cursor->layoutNode() == this
|
||||
&& cursor->position() == LayoutCursor::Position::Right)
|
||||
{
|
||||
/* Case: Right. Add the grey squares to the matrix, then move to the bottom
|
||||
* right non empty nor grey child. */
|
||||
assert(!hasGreySquares());
|
||||
addGreySquares();
|
||||
/* Case: Right. Add the gray squares to the matrix, then move to the bottom
|
||||
* right non empty nor gray child. */
|
||||
assert(!hasGraySquares());
|
||||
addGraySquares();
|
||||
*shouldRecomputeLayout = true;
|
||||
LayoutNode * lastChild = childAtIndex((m_numberOfColumns-1)*(m_numberOfRows-1));
|
||||
cursor->setLayoutNode(lastChild);
|
||||
@@ -60,9 +60,9 @@ void MatrixLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecom
|
||||
if (cursor->layoutNode() == this
|
||||
&& cursor->position() == LayoutCursor::Position::Left)
|
||||
{
|
||||
// Case: Left. Add grey squares to the matrix, then go to its first entry.
|
||||
assert(!hasGreySquares());
|
||||
addGreySquares();
|
||||
// Case: Left. Add gray squares to the matrix, then go to its first entry.
|
||||
assert(!hasGraySquares());
|
||||
addGraySquares();
|
||||
*shouldRecomputeLayout = true;
|
||||
assert(m_numberOfColumns*m_numberOfRows >= 1);
|
||||
cursor->setLayoutNode(childAtIndex(0));
|
||||
@@ -73,10 +73,10 @@ void MatrixLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecom
|
||||
&& cursor->position() == LayoutCursor::Position::Right
|
||||
&& childIsRightOfGrid(childIndex))
|
||||
{
|
||||
/* Case: Right of a child on the right of the grid. Remove the grey squares
|
||||
/* Case: Right of a child on the right of the grid. Remove the gray squares
|
||||
* of the grid, then go right of the grid. */
|
||||
assert(hasGreySquares());
|
||||
removeGreySquares();
|
||||
assert(hasGraySquares());
|
||||
removeGraySquares();
|
||||
*shouldRecomputeLayout = true;
|
||||
cursor->setLayoutNode(this);
|
||||
return;
|
||||
@@ -149,7 +149,7 @@ int MatrixLayoutNode::serialize(char * buffer, int bufferSize, Preferences::Prin
|
||||
}
|
||||
|
||||
// Serialize the vectors
|
||||
int maxColumnIndex = hasGreySquares() ? m_numberOfColumns - 2 : m_numberOfColumns - 1;
|
||||
int maxColumnIndex = hasGraySquares() ? m_numberOfColumns - 2 : m_numberOfColumns - 1;
|
||||
for (int i = minRowIndex; i <= maxRowIndex; i++) {
|
||||
numberOfChar += SerializationHelper::CodePoint(buffer + numberOfChar, bufferSize - numberOfChar, '[');
|
||||
if (numberOfChar >= bufferSize-1) { return bufferSize-1;}
|
||||
@@ -183,7 +183,7 @@ KDPoint MatrixLayoutNode::positionOfChild(LayoutNode * l) {
|
||||
|
||||
void MatrixLayoutNode::moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) {
|
||||
MatrixLayout thisRef = MatrixLayout(this);
|
||||
bool shouldRemoveGreySquares = false;
|
||||
bool shouldRemoveGraySquares = false;
|
||||
int firstIndex = direction == VerticalDirection::Up ? 0 : numberOfChildren() - m_numberOfColumns;
|
||||
int lastIndex = direction == VerticalDirection::Up ? m_numberOfColumns : numberOfChildren();
|
||||
int i = firstIndex;
|
||||
@@ -192,16 +192,16 @@ void MatrixLayoutNode::moveCursorVertically(VerticalDirection direction, LayoutC
|
||||
break;
|
||||
}
|
||||
if (cursor->layout().node()->hasAncestor(l, true)) {
|
||||
// The cursor is leaving the matrix, so remove the grey squares.
|
||||
shouldRemoveGreySquares = true;
|
||||
// The cursor is leaving the matrix, so remove the gray squares.
|
||||
shouldRemoveGraySquares = true;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
GridLayoutNode::moveCursorVertically(direction, cursor, shouldRecomputeLayout, equivalentPositionVisited, forSelection);
|
||||
if (cursor->isDefined() && shouldRemoveGreySquares) {
|
||||
assert(thisRef.hasGreySquares());
|
||||
thisRef.removeGreySquares();
|
||||
if (cursor->isDefined() && shouldRemoveGraySquares) {
|
||||
assert(thisRef.hasGraySquares());
|
||||
thisRef.removeGraySquares();
|
||||
*shouldRecomputeLayout = true;
|
||||
}
|
||||
}
|
||||
@@ -214,7 +214,7 @@ void MatrixLayoutNode::newRowOrColumnAtIndex(int index) {
|
||||
int correspondingRow = rowAtChildIndex(index);
|
||||
if (childIsRightOfGrid(index)) {
|
||||
assert(m_numberOfRows >= 2);
|
||||
// Color the grey EmptyLayouts of the column in yellow.
|
||||
// Color the gray EmptyLayouts of the column in yellow.
|
||||
int correspondingColumn = m_numberOfColumns - 1;
|
||||
int childIndex = correspondingColumn;
|
||||
int maxIndex = (m_numberOfRows - 2)*m_numberOfColumns+correspondingColumn;
|
||||
@@ -234,12 +234,12 @@ void MatrixLayoutNode::newRowOrColumnAtIndex(int index) {
|
||||
}
|
||||
childIndex++;
|
||||
}
|
||||
// Add a column of grey EmptyLayouts on the right.
|
||||
addEmptyColumn(EmptyLayoutNode::Color::Grey);
|
||||
// Add a column of gray EmptyLayouts on the right.
|
||||
addEmptyColumn(EmptyLayoutNode::Color::Gray);
|
||||
}
|
||||
if (shouldAddNewRow) {
|
||||
assert(m_numberOfColumns >= 2);
|
||||
// Color the grey EmptyLayouts of the row in yellow.
|
||||
// Color the gray EmptyLayouts of the row in yellow.
|
||||
int childIndex = correspondingRow * m_numberOfColumns;
|
||||
int maxIndex = correspondingRow * m_numberOfColumns + m_numberOfColumns - 2;
|
||||
for (LayoutNode * lastLayoutOfColumn : childrenFromIndex(correspondingRow*m_numberOfColumns)) {
|
||||
@@ -256,8 +256,8 @@ void MatrixLayoutNode::newRowOrColumnAtIndex(int index) {
|
||||
}
|
||||
childIndex++;
|
||||
}
|
||||
// Add a row of grey EmptyLayouts at the bottom.
|
||||
addEmptyRow(EmptyLayoutNode::Color::Grey);
|
||||
// Add a row of gray EmptyLayouts at the bottom.
|
||||
addEmptyRow(EmptyLayoutNode::Color::Gray);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,14 +291,14 @@ bool MatrixLayoutNode::isColumnEmpty(int index) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MatrixLayoutNode::hasGreySquares() const {
|
||||
bool MatrixLayoutNode::hasGraySquares() const {
|
||||
if (numberOfChildren() == 0) {
|
||||
return false;
|
||||
}
|
||||
LayoutNode * lastChild = const_cast<MatrixLayoutNode *>(this)->childAtIndex(m_numberOfRows * m_numberOfColumns - 1);
|
||||
if (lastChild->isEmpty()
|
||||
&& lastChild->type() != Type::HorizontalLayout
|
||||
&& (static_cast<EmptyLayoutNode *>(lastChild))->color() == EmptyLayoutNode::Color::Grey)
|
||||
&& (static_cast<EmptyLayoutNode *>(lastChild))->color() == EmptyLayoutNode::Color::Gray)
|
||||
{
|
||||
assert(isRowEmpty(m_numberOfRows - 1));
|
||||
assert(isColumnEmpty(m_numberOfColumns - 1));
|
||||
|
||||
Reference in New Issue
Block a user