diff --git a/apps/calculation/calculation.cpp b/apps/calculation/calculation.cpp index 523c82591..f056918b1 100644 --- a/apps/calculation/calculation.cpp +++ b/apps/calculation/calculation.cpp @@ -42,14 +42,14 @@ void Calculation::setContent(const char * c, Context * context, Expression ansEx KDCoordinate Calculation::height(Context * context) { if (m_height < 0) { - LayoutReference inputLayout = createInputLayout(); + Layout inputLayout = createInputLayout(); KDCoordinate inputHeight = inputLayout.layoutSize().height(); - LayoutReference approximateLayout = createApproximateOutputLayout(context); + Layout approximateLayout = createApproximateOutputLayout(context); KDCoordinate approximateOutputHeight = approximateLayout.layoutSize().height(); if (shouldOnlyDisplayApproximateOutput(context)) { m_height = inputHeight+approximateOutputHeight; } else { - LayoutReference exactLayout = createExactOutputLayout(context); + Layout exactLayout = createExactOutputLayout(context); KDCoordinate exactOutputHeight = exactLayout.layoutSize().height(); KDCoordinate outputHeight = max(exactLayout.baseline(), approximateLayout.baseline()) + max(exactOutputHeight-exactLayout.baseline(), approximateOutputHeight-approximateLayout.baseline()); m_height = inputHeight + outputHeight; @@ -77,7 +77,7 @@ Expression Calculation::input() { return m_input; } -LayoutReference Calculation::createInputLayout() { +Layout Calculation::createInputLayout() { return input().createLayout(Preferences::PrintFloatMode::Decimal, PrintFloat::k_numberOfStoredSignificantDigits); } @@ -118,7 +118,7 @@ Expression Calculation::exactOutput(Context * context) { return m_exactOutput; } -LayoutReference Calculation::createExactOutputLayout(Context * context) { +Layout Calculation::createExactOutputLayout(Context * context) { return PoincareHelpers::CreateLayout(exactOutput(context)); } @@ -132,7 +132,7 @@ Expression Calculation::approximateOutput(Context * context) { return m_approximateOutput; } -LayoutReference Calculation::createApproximateOutputLayout(Context * context) { +Layout Calculation::createApproximateOutputLayout(Context * context) { return PoincareHelpers::CreateLayout(approximateOutput(context)); } diff --git a/apps/calculation/calculation.h b/apps/calculation/calculation.h index 7d7c61215..1f9b112ea 100644 --- a/apps/calculation/calculation.h +++ b/apps/calculation/calculation.h @@ -24,11 +24,11 @@ public: const char * exactOutputText(); const char * approximateOutputText(); Poincare::Expression input(); - Poincare::LayoutReference createInputLayout(); + Poincare::Layout createInputLayout(); Poincare::Expression approximateOutput(Poincare::Context * context); Poincare::Expression exactOutput(Poincare::Context * context); - Poincare::LayoutReference createExactOutputLayout(Poincare::Context * context); - Poincare::LayoutReference createApproximateOutputLayout(Poincare::Context * context); + Poincare::Layout createExactOutputLayout(Poincare::Context * context); + Poincare::Layout createApproximateOutputLayout(Poincare::Context * context); bool isEmpty(); void tidy(); bool shouldOnlyDisplayApproximateOutput(Poincare::Context * context); diff --git a/apps/calculation/edit_expression_controller.cpp b/apps/calculation/edit_expression_controller.cpp index 99cad5fc5..b44d6b1d1 100644 --- a/apps/calculation/edit_expression_controller.cpp +++ b/apps/calculation/edit_expression_controller.cpp @@ -99,7 +99,7 @@ bool EditExpressionController::layoutFieldDidReceiveEvent(::LayoutField * layout return expressionFieldDelegateApp()->layoutFieldDidReceiveEvent(layoutField, event); } -bool EditExpressionController::layoutFieldDidFinishEditing(::LayoutField * layoutField, LayoutReference layoutR, Ion::Events::Event event) { +bool EditExpressionController::layoutFieldDidFinishEditing(::LayoutField * layoutField, Layout layoutR, Ion::Events::Event event) { return inputViewDidFinishEditing(nullptr, layoutR); } @@ -149,7 +149,7 @@ bool EditExpressionController::inputViewDidReceiveEvent(Ion::Events::Event event } -bool EditExpressionController::inputViewDidFinishEditing(const char * text, LayoutReference layoutR) { +bool EditExpressionController::inputViewDidFinishEditing(const char * text, Layout layoutR) { App * calculationApp = (App *)app(); if (layoutR.isUninitialized()) { assert(text); diff --git a/apps/calculation/edit_expression_controller.h b/apps/calculation/edit_expression_controller.h index a36afefeb..6032868f1 100644 --- a/apps/calculation/edit_expression_controller.h +++ b/apps/calculation/edit_expression_controller.h @@ -2,7 +2,7 @@ #define CALCULATION_EDIT_EXPRESSION_CONTROLLER_H #include -#include +#include #include "expression_field.h" #include "../shared/text_field_delegate.h" #include "../shared/layout_field_delegate.h" @@ -29,7 +29,7 @@ public: /* LayoutFieldDelegate */ bool layoutFieldDidReceiveEvent(::LayoutField * layoutField, Ion::Events::Event event) override; - bool layoutFieldDidFinishEditing(::LayoutField * layoutField, Poincare::LayoutReference layoutR, Ion::Events::Event event) override; + bool layoutFieldDidFinishEditing(::LayoutField * layoutField, Poincare::Layout layoutR, Ion::Events::Event event) override; bool layoutFieldDidAbortEditing(::LayoutField * layoutField) override; void layoutFieldDidChangeSize(::LayoutField * layoutField) override; @@ -52,7 +52,7 @@ private: }; void reloadView(); bool inputViewDidReceiveEvent(Ion::Events::Event event); - bool inputViewDidFinishEditing(const char * text, Poincare::LayoutReference layoutR); + bool inputViewDidFinishEditing(const char * text, Poincare::Layout layoutR); bool inputViewDidAbortEditing(const char * text); Shared::TextFieldDelegateApp * textFieldDelegateApp() override; Shared::ExpressionFieldDelegateApp * expressionFieldDelegateApp() override; diff --git a/apps/calculation/history_view_cell.cpp b/apps/calculation/history_view_cell.cpp index fa61321f0..2162786b5 100644 --- a/apps/calculation/history_view_cell.cpp +++ b/apps/calculation/history_view_cell.cpp @@ -42,11 +42,11 @@ void HistoryViewCell::setHighlighted(bool highlight) { reloadScroll(); } -Poincare::LayoutReference HistoryViewCell::layoutRef() const { +Poincare::Layout HistoryViewCell::layout() const { if (m_selectedSubviewType == SubviewType::Input) { return m_inputLayout; } else { - return m_scrollableOutputView.layoutRef(); + return m_scrollableOutputView.layout(); } } @@ -95,13 +95,13 @@ void HistoryViewCell::layoutSubviews() { void HistoryViewCell::setCalculation(Calculation * calculation) { m_inputLayout = calculation->createInputLayout(); - m_inputView.setLayoutReference(m_inputLayout); + m_inputView.setLayout(m_inputLayout); App * calculationApp = (App *)app(); /* Both output expressions have to be updated at the same time. Otherwise, * when updating one layout, if the second one still points to a deleted * layout, calling to layoutSubviews() would fail. */ if (!m_exactOutputLayout.isUninitialized()) { - m_exactOutputLayout = Poincare::LayoutReference(); + m_exactOutputLayout = Poincare::Layout(); } if (!calculation->shouldOnlyDisplayApproximateOutput(calculationApp->localContext())) { m_exactOutputLayout = calculation->createExactOutputLayout(calculationApp->localContext()); diff --git a/apps/calculation/history_view_cell.h b/apps/calculation/history_view_cell.h index 24e652b81..401c3ebf4 100644 --- a/apps/calculation/history_view_cell.h +++ b/apps/calculation/history_view_cell.h @@ -22,7 +22,7 @@ public: Responder * responder() override { return this; } - Poincare::LayoutReference layoutRef() const override; + Poincare::Layout layout() const override; KDColor backgroundColor() const override; void setCalculation(Calculation * calculation); int numberOfSubviews() const override; @@ -36,9 +36,9 @@ public: Shared::ScrollableExactApproximateExpressionsView * outputView(); private: constexpr static KDCoordinate k_resultWidth = 80; - Poincare::LayoutReference m_inputLayout; - Poincare::LayoutReference m_exactOutputLayout; - Poincare::LayoutReference m_approximateOutputLayout; + Poincare::Layout m_inputLayout; + Poincare::Layout m_exactOutputLayout; + Poincare::Layout m_approximateOutputLayout; ScrollableExpressionView m_inputView; Shared::ScrollableExactApproximateExpressionsView m_scrollableOutputView; SubviewType m_selectedSubviewType; diff --git a/apps/calculation/scrollable_expression_view.cpp b/apps/calculation/scrollable_expression_view.cpp index fb524203f..35cfe08de 100644 --- a/apps/calculation/scrollable_expression_view.cpp +++ b/apps/calculation/scrollable_expression_view.cpp @@ -10,8 +10,8 @@ ScrollableExpressionView::ScrollableExpressionView(Responder * parentResponder) { } -void ScrollableExpressionView::setLayoutReference(LayoutReference layoutRef) { - m_expressionView.setLayoutReference(layoutRef); +void ScrollableExpressionView::setLayout(Layout layout) { + m_expressionView.setLayout(layout); layoutSubviews(); } diff --git a/apps/calculation/scrollable_expression_view.h b/apps/calculation/scrollable_expression_view.h index c680e6f88..d4ac8e330 100644 --- a/apps/calculation/scrollable_expression_view.h +++ b/apps/calculation/scrollable_expression_view.h @@ -8,7 +8,7 @@ namespace Calculation { class ScrollableExpressionView : public ScrollableView, public ScrollViewDataSource { public: ScrollableExpressionView(Responder * parentResponder); - void setLayoutReference(Poincare::LayoutReference layoutRef); + void setLayout(Poincare::Layout layout); void setBackgroundColor(KDColor backgroundColor) override; KDSize minimalSizeForOptimalDisplay() const override; private: diff --git a/apps/graph/graph/integral_graph_controller.cpp b/apps/graph/graph/integral_graph_controller.cpp index 1e49258f2..29b09df61 100644 --- a/apps/graph/graph/integral_graph_controller.cpp +++ b/apps/graph/graph/integral_graph_controller.cpp @@ -36,7 +36,7 @@ double IntegralGraphController::cursorNextStep(double x, int direction) { return (direction > 0 ? x + m_graphRange->xGridUnit()/k_numberOfCursorStepsInGradUnit : x - m_graphRange->xGridUnit()/k_numberOfCursorStepsInGradUnit); } -LayoutReference IntegralGraphController::createFunctionLayout(const char * functionName) { +Layout IntegralGraphController::createFunctionLayout(const char * functionName) { char buffer[7] = "0(x)dx"; buffer[0] = functionName[0]; return LayoutHelper::String(buffer, strlen(buffer), KDText::FontSize::Small); diff --git a/apps/graph/graph/integral_graph_controller.h b/apps/graph/graph/integral_graph_controller.h index 685b8d1d1..42cdae043 100644 --- a/apps/graph/graph/integral_graph_controller.h +++ b/apps/graph/graph/integral_graph_controller.h @@ -14,7 +14,7 @@ public: private: I18n::Message legendMessageAtStep(Step step) override; double cursorNextStep(double position, int direction) override; - Poincare::LayoutReference createFunctionLayout(const char * functionName) override; + Poincare::Layout createFunctionLayout(const char * functionName) override; }; } diff --git a/apps/regression/calculation_controller.cpp b/apps/regression/calculation_controller.cpp index 789eeed7d..3993a0a4d 100644 --- a/apps/regression/calculation_controller.cpp +++ b/apps/regression/calculation_controller.cpp @@ -25,7 +25,7 @@ CalculationController::CalculationController(Responder * parentResponder, Button m_hideableCell(), m_store(store) { - m_r2Layout = HorizontalLayoutReference(CharLayoutReference('r', KDText::FontSize::Small), VerticalOffsetLayoutReference(CharLayoutReference('2', KDText::FontSize::Small), VerticalOffsetLayoutNode::Type::Superscript)); + m_r2Layout = HorizontalLayout(CharLayout('r', KDText::FontSize::Small), VerticalOffsetLayout(CharLayout('2', KDText::FontSize::Small), VerticalOffsetLayoutNode::Type::Superscript)); m_selectableTableView.setVerticalCellOverlap(0); m_selectableTableView.setBackgroundColor(Palette::WallScreenDark); m_selectableTableView.setMargins(k_margin, k_scrollBarMargin, k_scrollBarMargin, k_margin); @@ -125,7 +125,7 @@ void CalculationController::willDisplayCellAtLocation(HighlightCell * cell, int int numberRows = numberOfRows(); if (shouldDisplayRAndR2 && j == numberRows-1) { EvenOddExpressionCell * myCell = (EvenOddExpressionCell *)cell; - myCell->setLayoutReference(m_r2Layout); + myCell->setLayout(m_r2Layout); return; } MarginEvenOddMessageTextCell * myCell = (MarginEvenOddMessageTextCell *)cell; diff --git a/apps/regression/calculation_controller.h b/apps/regression/calculation_controller.h index 0164f76d9..bbec0ca66 100644 --- a/apps/regression/calculation_controller.h +++ b/apps/regression/calculation_controller.h @@ -69,7 +69,7 @@ private: SelectableTableView * selectableTableView() override { return &m_selectableTableView; } bool hasLinearRegression() const; int maxNumberOfCoefficients() const; - Poincare::LayoutReference m_r2Layout; + Poincare::Layout m_r2Layout; SelectableTableView m_selectableTableView; Shared::MarginEvenOddMessageTextCell m_titleCells[k_maxNumberOfDisplayableRows]; EvenOddExpressionCell m_r2TitleCell; diff --git a/apps/regression/graph_options_controller.cpp b/apps/regression/graph_options_controller.cpp index 192e87902..fb66c69e9 100644 --- a/apps/regression/graph_options_controller.cpp +++ b/apps/regression/graph_options_controller.cpp @@ -116,7 +116,7 @@ int GraphOptionsController::typeAtLocation(int i, int j) { void GraphOptionsController::willDisplayCellForIndex(HighlightCell * cell, int index) { if (index == numberOfRows() - 1) { - m_changeRegressionCell.setLayoutReference(static_cast(m_store)->modelForSeries(m_graphController->selectedSeriesIndex())->layout()); + m_changeRegressionCell.setLayout(static_cast(m_store)->modelForSeries(m_graphController->selectedSeriesIndex())->layout()); return; } assert(index >=0 && index < k_numberOfParameterCells); diff --git a/apps/regression/model/cubic_model.cpp b/apps/regression/model/cubic_model.cpp index 89be34f56..e95b45ddb 100644 --- a/apps/regression/model/cubic_model.cpp +++ b/apps/regression/model/cubic_model.cpp @@ -8,32 +8,32 @@ using namespace Shared; namespace Regression { -LayoutReference CubicModel::layout() { +Layout CubicModel::layout() { if (m_layout.isUninitialized()) { - const LayoutReference layoutChildren[] = { - CharLayoutReference('a', KDText::FontSize::Small), - CharLayoutReference(Ion::Charset::MiddleDot, KDText::FontSize::Small), - CharLayoutReference('X', KDText::FontSize::Small), - VerticalOffsetLayoutReference( - CharLayoutReference('3', KDText::FontSize::Small), + const Layout layoutChildren[] = { + CharLayout('a', KDText::FontSize::Small), + CharLayout(Ion::Charset::MiddleDot, KDText::FontSize::Small), + CharLayout('X', KDText::FontSize::Small), + VerticalOffsetLayout( + CharLayout('3', KDText::FontSize::Small), VerticalOffsetLayoutNode::Type::Superscript ), - CharLayoutReference('+', KDText::FontSize::Small), - CharLayoutReference('b', KDText::FontSize::Small), - CharLayoutReference(Ion::Charset::MiddleDot, KDText::FontSize::Small), - CharLayoutReference('X', KDText::FontSize::Small), - VerticalOffsetLayoutReference( - CharLayoutReference('2', KDText::FontSize::Small), + CharLayout('+', KDText::FontSize::Small), + CharLayout('b', KDText::FontSize::Small), + CharLayout(Ion::Charset::MiddleDot, KDText::FontSize::Small), + CharLayout('X', KDText::FontSize::Small), + VerticalOffsetLayout( + CharLayout('2', KDText::FontSize::Small), VerticalOffsetLayoutNode::Type::Superscript ), - CharLayoutReference('+', KDText::FontSize::Small), - CharLayoutReference('c', KDText::FontSize::Small), - CharLayoutReference(Ion::Charset::MiddleDot, KDText::FontSize::Small), - CharLayoutReference('X', KDText::FontSize::Small), - CharLayoutReference('+', KDText::FontSize::Small), - CharLayoutReference('d', KDText::FontSize::Small), + CharLayout('+', KDText::FontSize::Small), + CharLayout('c', KDText::FontSize::Small), + CharLayout(Ion::Charset::MiddleDot, KDText::FontSize::Small), + CharLayout('X', KDText::FontSize::Small), + CharLayout('+', KDText::FontSize::Small), + CharLayout('d', KDText::FontSize::Small), }; - m_layout = HorizontalLayoutReference(layoutChildren, 15); + m_layout = HorizontalLayout(layoutChildren, 15); } return m_layout; } diff --git a/apps/regression/model/cubic_model.h b/apps/regression/model/cubic_model.h index 6d600e9cf..833f26060 100644 --- a/apps/regression/model/cubic_model.h +++ b/apps/regression/model/cubic_model.h @@ -8,7 +8,7 @@ namespace Regression { class CubicModel : public Model { public: using Model::Model; - Poincare::LayoutReference layout() override; + Poincare::Layout layout() override; Poincare::Expression simplifiedExpression(double * modelCoefficients, Poincare::Context * context) override; I18n::Message formulaMessage() const override { return I18n::Message::CubicRegressionFormula; } double evaluate(double * modelCoefficients, double x) const override; diff --git a/apps/regression/model/exponential_model.cpp b/apps/regression/model/exponential_model.cpp index a4d4ae3dc..6ad999c6f 100644 --- a/apps/regression/model/exponential_model.cpp +++ b/apps/regression/model/exponential_model.cpp @@ -6,22 +6,22 @@ using namespace Poincare; namespace Regression { -LayoutReference ExponentialModel::layout() { +Layout ExponentialModel::layout() { if (m_layout.isUninitialized()) { - const LayoutReference layoutChildren[] = { - CharLayoutReference('a', KDText::FontSize::Small), - CharLayoutReference(Ion::Charset::MiddleDot, KDText::FontSize::Small), - CharLayoutReference('e', KDText::FontSize::Small), - VerticalOffsetLayoutReference( - HorizontalLayoutReference( - CharLayoutReference('b', KDText::FontSize::Small), - CharLayoutReference(Ion::Charset::MiddleDot, KDText::FontSize::Small), - CharLayoutReference('X', KDText::FontSize::Small) + const Layout layoutChildren[] = { + CharLayout('a', KDText::FontSize::Small), + CharLayout(Ion::Charset::MiddleDot, KDText::FontSize::Small), + CharLayout('e', KDText::FontSize::Small), + VerticalOffsetLayout( + HorizontalLayout( + CharLayout('b', KDText::FontSize::Small), + CharLayout(Ion::Charset::MiddleDot, KDText::FontSize::Small), + CharLayout('X', KDText::FontSize::Small) ), VerticalOffsetLayoutNode::Type::Superscript ) }; - m_layout = HorizontalLayoutReference(layoutChildren, 4); + m_layout = HorizontalLayout(layoutChildren, 4); } return m_layout; } diff --git a/apps/regression/model/exponential_model.h b/apps/regression/model/exponential_model.h index 2a3732295..7d373b473 100644 --- a/apps/regression/model/exponential_model.h +++ b/apps/regression/model/exponential_model.h @@ -8,7 +8,7 @@ namespace Regression { class ExponentialModel : public Model { public: using Model::Model; - Poincare::LayoutReference layout() override; + Poincare::Layout layout() override; I18n::Message formulaMessage() const override { return I18n::Message::ExponentialRegressionFormula; } double evaluate(double * modelCoefficients, double x) const override; double levelSet(double * modelCoefficients, double xMin, double step, double xMax, double y, Poincare::Context * context) override; diff --git a/apps/regression/model/linear_model.cpp b/apps/regression/model/linear_model.cpp index 31b7970d9..a88bdf567 100644 --- a/apps/regression/model/linear_model.cpp +++ b/apps/regression/model/linear_model.cpp @@ -7,16 +7,16 @@ using namespace Poincare; namespace Regression { -LayoutReference LinearModel::layout() { +Layout LinearModel::layout() { if (m_layout.isUninitialized()) { - const LayoutReference layoutChildren[] = { - CharLayoutReference('a', KDText::FontSize::Small), - CharLayoutReference(Ion::Charset::MiddleDot, KDText::FontSize::Small), - CharLayoutReference('X', KDText::FontSize::Small), - CharLayoutReference('+', KDText::FontSize::Small), - CharLayoutReference('b', KDText::FontSize::Small), + const Layout layoutChildren[] = { + CharLayout('a', KDText::FontSize::Small), + CharLayout(Ion::Charset::MiddleDot, KDText::FontSize::Small), + CharLayout('X', KDText::FontSize::Small), + CharLayout('+', KDText::FontSize::Small), + CharLayout('b', KDText::FontSize::Small), }; - m_layout = HorizontalLayoutReference(layoutChildren, 5); + m_layout = HorizontalLayout(layoutChildren, 5); } return m_layout; } diff --git a/apps/regression/model/linear_model.h b/apps/regression/model/linear_model.h index f1efb8651..6f1c91153 100644 --- a/apps/regression/model/linear_model.h +++ b/apps/regression/model/linear_model.h @@ -8,7 +8,7 @@ namespace Regression { class LinearModel : public Model { public: using Model::Model; - Poincare::LayoutReference layout() override; + Poincare::Layout layout() override; I18n::Message formulaMessage() const override { return I18n::Message::LinearRegressionFormula; } double evaluate(double * modelCoefficients, double x) const override; double levelSet(double * modelCoefficients, double xMin, double step, double xMax, double y, Poincare::Context * context) override; diff --git a/apps/regression/model/logarithmic_model.cpp b/apps/regression/model/logarithmic_model.cpp index b2d9152d7..2471474ad 100644 --- a/apps/regression/model/logarithmic_model.cpp +++ b/apps/regression/model/logarithmic_model.cpp @@ -7,20 +7,20 @@ using namespace Poincare; namespace Regression { -LayoutReference LogarithmicModel::layout() { +Layout LogarithmicModel::layout() { if (m_layout.isUninitialized()) { - const LayoutReference layoutChildren[] = { - CharLayoutReference('a', KDText::FontSize::Small), - CharLayoutReference(Ion::Charset::MiddleDot, KDText::FontSize::Small), - CharLayoutReference('l', KDText::FontSize::Small), - CharLayoutReference('n', KDText::FontSize::Small), - CharLayoutReference('(', KDText::FontSize::Small), - CharLayoutReference('X', KDText::FontSize::Small), - CharLayoutReference(')', KDText::FontSize::Small), - CharLayoutReference('+', KDText::FontSize::Small), - CharLayoutReference('b', KDText::FontSize::Small) + const Layout layoutChildren[] = { + CharLayout('a', KDText::FontSize::Small), + CharLayout(Ion::Charset::MiddleDot, KDText::FontSize::Small), + CharLayout('l', KDText::FontSize::Small), + CharLayout('n', KDText::FontSize::Small), + CharLayout('(', KDText::FontSize::Small), + CharLayout('X', KDText::FontSize::Small), + CharLayout(')', KDText::FontSize::Small), + CharLayout('+', KDText::FontSize::Small), + CharLayout('b', KDText::FontSize::Small) }; - m_layout = HorizontalLayoutReference(layoutChildren, 9); + m_layout = HorizontalLayout(layoutChildren, 9); } return m_layout; } diff --git a/apps/regression/model/logarithmic_model.h b/apps/regression/model/logarithmic_model.h index 6cfbb5541..a541b571d 100644 --- a/apps/regression/model/logarithmic_model.h +++ b/apps/regression/model/logarithmic_model.h @@ -8,7 +8,7 @@ namespace Regression { class LogarithmicModel : public Model { public: using Model::Model; - Poincare::LayoutReference layout() override; + Poincare::Layout layout() override; I18n::Message formulaMessage() const override { return I18n::Message::LogarithmicRegressionFormula; } double evaluate(double * modelCoefficients, double x) const override; double levelSet(double * modelCoefficients, double xMin, double step, double xMax, double y, Poincare::Context * context) override; diff --git a/apps/regression/model/logistic_model.cpp b/apps/regression/model/logistic_model.cpp index 49c930e1b..53a3151c4 100644 --- a/apps/regression/model/logistic_model.cpp +++ b/apps/regression/model/logistic_model.cpp @@ -6,28 +6,28 @@ using namespace Poincare; namespace Regression { -LayoutReference LogisticModel::layout() { +Layout LogisticModel::layout() { if (m_layout.isUninitialized()) { - const LayoutReference exponentLayoutChildren[] = { - CharLayoutReference('-', KDText::FontSize::Small), - CharLayoutReference('b', KDText::FontSize::Small), - CharLayoutReference(Ion::Charset::MiddleDot, KDText::FontSize::Small), - CharLayoutReference('X', KDText::FontSize::Small) + const Layout exponentLayoutChildren[] = { + CharLayout('-', KDText::FontSize::Small), + CharLayout('b', KDText::FontSize::Small), + CharLayout(Ion::Charset::MiddleDot, KDText::FontSize::Small), + CharLayout('X', KDText::FontSize::Small) }; - const LayoutReference layoutChildren[] = { - CharLayoutReference('1', KDText::FontSize::Small), - CharLayoutReference('+', KDText::FontSize::Small), - CharLayoutReference('a', KDText::FontSize::Small), - CharLayoutReference(Ion::Charset::MiddleDot, KDText::FontSize::Small), - CharLayoutReference('e', KDText::FontSize::Small), - VerticalOffsetLayoutReference( - HorizontalLayoutReference(exponentLayoutChildren, 4), + const Layout layoutChildren[] = { + CharLayout('1', KDText::FontSize::Small), + CharLayout('+', KDText::FontSize::Small), + CharLayout('a', KDText::FontSize::Small), + CharLayout(Ion::Charset::MiddleDot, KDText::FontSize::Small), + CharLayout('e', KDText::FontSize::Small), + VerticalOffsetLayout( + HorizontalLayout(exponentLayoutChildren, 4), VerticalOffsetLayoutNode::Type::Superscript ) }; - m_layout = FractionLayoutReference( - CharLayoutReference('c', KDText::FontSize::Small), - HorizontalLayoutReference(layoutChildren, 6) + m_layout = FractionLayout( + CharLayout('c', KDText::FontSize::Small), + HorizontalLayout(layoutChildren, 6) ); } return m_layout; diff --git a/apps/regression/model/logistic_model.h b/apps/regression/model/logistic_model.h index 97264e0c5..aa338e88e 100644 --- a/apps/regression/model/logistic_model.h +++ b/apps/regression/model/logistic_model.h @@ -8,7 +8,7 @@ namespace Regression { class LogisticModel : public Model { public: using Model::Model; - Poincare::LayoutReference layout() override; + Poincare::Layout layout() override; I18n::Message formulaMessage() const override { return I18n::Message::LogisticRegressionFormula; } double evaluate(double * modelCoefficients, double x) const override; double levelSet(double * modelCoefficients, double xMin, double step, double xMax, double y, Poincare::Context * context) override; diff --git a/apps/regression/model/model.cpp b/apps/regression/model/model.cpp index 0015e6e27..af87b1a3d 100644 --- a/apps/regression/model/model.cpp +++ b/apps/regression/model/model.cpp @@ -12,7 +12,7 @@ using namespace Shared; namespace Regression { void Model::tidy() { - m_layout = LayoutReference(); + m_layout = Layout(); } double Model::levelSet(double * modelCoefficients, double xMin, double step, double xMax, double y, Poincare::Context * context) { diff --git a/apps/regression/model/model.h b/apps/regression/model/model.h index d9dfcde59..ddda88e1b 100644 --- a/apps/regression/model/model.h +++ b/apps/regression/model/model.h @@ -25,7 +25,7 @@ public: static constexpr int k_numberOfModels = 9; static constexpr int k_maxNumberOfCoefficients = 5; // This has to verify: k_maxNumberOfCoefficients < Matrix::k_maxNumberOfCoefficients virtual ~Model() = default; - virtual Poincare::LayoutReference layout() = 0; + virtual Poincare::Layout layout() = 0; // Reinitialize m_layout to empty the pool void tidy(); // simplifiedExpression is overrided only by Models that override levelSet @@ -39,7 +39,7 @@ public: protected: // Fit virtual bool dataSuitableForFit(Store * store, int series) const; - Poincare::LayoutReference m_layout; + Poincare::Layout m_layout; private: // Model attributes virtual double partialDerivate(double * modelCoefficients, int derivateCoefficientIndex, double x) const = 0; diff --git a/apps/regression/model/power_model.cpp b/apps/regression/model/power_model.cpp index 87ec74b36..62e6b02f9 100644 --- a/apps/regression/model/power_model.cpp +++ b/apps/regression/model/power_model.cpp @@ -7,18 +7,18 @@ using namespace Poincare; namespace Regression { -LayoutReference PowerModel::layout() { +Layout PowerModel::layout() { if (m_layout.isUninitialized()) { - const LayoutReference layoutChildren[] = { - CharLayoutReference('a', KDText::FontSize::Small), - CharLayoutReference(Ion::Charset::MiddleDot, KDText::FontSize::Small), - CharLayoutReference('X', KDText::FontSize::Small), - VerticalOffsetLayoutReference( - CharLayoutReference('b', KDText::FontSize::Small), + const Layout layoutChildren[] = { + CharLayout('a', KDText::FontSize::Small), + CharLayout(Ion::Charset::MiddleDot, KDText::FontSize::Small), + CharLayout('X', KDText::FontSize::Small), + VerticalOffsetLayout( + CharLayout('b', KDText::FontSize::Small), VerticalOffsetLayoutNode::Type::Superscript ), }; - m_layout = HorizontalLayoutReference(layoutChildren, 4); + m_layout = HorizontalLayout(layoutChildren, 4); } return m_layout; } diff --git a/apps/regression/model/power_model.h b/apps/regression/model/power_model.h index 034d07e6d..ac544e5c1 100644 --- a/apps/regression/model/power_model.h +++ b/apps/regression/model/power_model.h @@ -8,7 +8,7 @@ namespace Regression { class PowerModel : public Model { public: using Model::Model; - Poincare::LayoutReference layout() override; + Poincare::Layout layout() override; I18n::Message formulaMessage() const override { return I18n::Message::PowerRegressionFormula; } double evaluate(double * modelCoefficients, double x) const override; double levelSet(double * modelCoefficients, double xMin, double step, double xMax, double y, Poincare::Context * context) override; diff --git a/apps/regression/model/quadratic_model.cpp b/apps/regression/model/quadratic_model.cpp index 9cdc841a6..407d10f4f 100644 --- a/apps/regression/model/quadratic_model.cpp +++ b/apps/regression/model/quadratic_model.cpp @@ -8,24 +8,24 @@ using namespace Shared; namespace Regression { -LayoutReference QuadraticModel::layout() { +Layout QuadraticModel::layout() { if (m_layout.isUninitialized()) { - const LayoutReference layoutChildren[] = { - CharLayoutReference('a', KDText::FontSize::Small), - CharLayoutReference(Ion::Charset::MiddleDot, KDText::FontSize::Small), - CharLayoutReference('X', KDText::FontSize::Small), - VerticalOffsetLayoutReference( - CharLayoutReference('2', KDText::FontSize::Small), + const Layout layoutChildren[] = { + CharLayout('a', KDText::FontSize::Small), + CharLayout(Ion::Charset::MiddleDot, KDText::FontSize::Small), + CharLayout('X', KDText::FontSize::Small), + VerticalOffsetLayout( + CharLayout('2', KDText::FontSize::Small), VerticalOffsetLayoutNode::Type::Superscript ), - CharLayoutReference('+', KDText::FontSize::Small), - CharLayoutReference('b', KDText::FontSize::Small), - CharLayoutReference(Ion::Charset::MiddleDot, KDText::FontSize::Small), - CharLayoutReference('X', KDText::FontSize::Small), - CharLayoutReference('+', KDText::FontSize::Small), - CharLayoutReference('c', KDText::FontSize::Small), + CharLayout('+', KDText::FontSize::Small), + CharLayout('b', KDText::FontSize::Small), + CharLayout(Ion::Charset::MiddleDot, KDText::FontSize::Small), + CharLayout('X', KDText::FontSize::Small), + CharLayout('+', KDText::FontSize::Small), + CharLayout('c', KDText::FontSize::Small), }; - m_layout = HorizontalLayoutReference(layoutChildren, 10); + m_layout = HorizontalLayout(layoutChildren, 10); } return m_layout; } diff --git a/apps/regression/model/quadratic_model.h b/apps/regression/model/quadratic_model.h index 0a7ce94d1..c56894498 100644 --- a/apps/regression/model/quadratic_model.h +++ b/apps/regression/model/quadratic_model.h @@ -8,7 +8,7 @@ namespace Regression { class QuadraticModel : public Model { public: using Model::Model; - Poincare::LayoutReference layout() override; + Poincare::Layout layout() override; Poincare::Expression simplifiedExpression(double * modelCoefficients, Poincare::Context * context) override; I18n::Message formulaMessage() const override { return I18n::Message::QuadraticRegressionFormula; } double evaluate(double * modelCoefficients, double x) const override; diff --git a/apps/regression/model/quartic_model.cpp b/apps/regression/model/quartic_model.cpp index f9f8dd976..004e301c2 100644 --- a/apps/regression/model/quartic_model.cpp +++ b/apps/regression/model/quartic_model.cpp @@ -8,40 +8,40 @@ using namespace Shared; namespace Regression { -LayoutReference QuarticModel::layout() { +Layout QuarticModel::layout() { if (m_layout.isUninitialized()) { - const LayoutReference layoutChildren[] = { - CharLayoutReference('a', KDText::FontSize::Small), - CharLayoutReference(Ion::Charset::MiddleDot, KDText::FontSize::Small), - CharLayoutReference('X', KDText::FontSize::Small), - VerticalOffsetLayoutReference( - CharLayoutReference('4', KDText::FontSize::Small), + const Layout layoutChildren[] = { + CharLayout('a', KDText::FontSize::Small), + CharLayout(Ion::Charset::MiddleDot, KDText::FontSize::Small), + CharLayout('X', KDText::FontSize::Small), + VerticalOffsetLayout( + CharLayout('4', KDText::FontSize::Small), VerticalOffsetLayoutNode::Type::Superscript ), - CharLayoutReference('+', KDText::FontSize::Small), - CharLayoutReference('b', KDText::FontSize::Small), - CharLayoutReference(Ion::Charset::MiddleDot, KDText::FontSize::Small), - CharLayoutReference('X', KDText::FontSize::Small), - VerticalOffsetLayoutReference( - CharLayoutReference('3', KDText::FontSize::Small), + CharLayout('+', KDText::FontSize::Small), + CharLayout('b', KDText::FontSize::Small), + CharLayout(Ion::Charset::MiddleDot, KDText::FontSize::Small), + CharLayout('X', KDText::FontSize::Small), + VerticalOffsetLayout( + CharLayout('3', KDText::FontSize::Small), VerticalOffsetLayoutNode::Type::Superscript ), - CharLayoutReference('+', KDText::FontSize::Small), - CharLayoutReference('c', KDText::FontSize::Small), - CharLayoutReference(Ion::Charset::MiddleDot, KDText::FontSize::Small), - CharLayoutReference('X', KDText::FontSize::Small), - VerticalOffsetLayoutReference( - CharLayoutReference('2', KDText::FontSize::Small), + CharLayout('+', KDText::FontSize::Small), + CharLayout('c', KDText::FontSize::Small), + CharLayout(Ion::Charset::MiddleDot, KDText::FontSize::Small), + CharLayout('X', KDText::FontSize::Small), + VerticalOffsetLayout( + CharLayout('2', KDText::FontSize::Small), VerticalOffsetLayoutNode::Type::Superscript ), - CharLayoutReference('+', KDText::FontSize::Small), - CharLayoutReference('d', KDText::FontSize::Small), - CharLayoutReference(Ion::Charset::MiddleDot, KDText::FontSize::Small), - CharLayoutReference('X', KDText::FontSize::Small), - CharLayoutReference('+', KDText::FontSize::Small), - CharLayoutReference('e', KDText::FontSize::Small), + CharLayout('+', KDText::FontSize::Small), + CharLayout('d', KDText::FontSize::Small), + CharLayout(Ion::Charset::MiddleDot, KDText::FontSize::Small), + CharLayout('X', KDText::FontSize::Small), + CharLayout('+', KDText::FontSize::Small), + CharLayout('e', KDText::FontSize::Small), }; - m_layout = HorizontalLayoutReference(layoutChildren, 20); + m_layout = HorizontalLayout(layoutChildren, 20); } return m_layout; } diff --git a/apps/regression/model/quartic_model.h b/apps/regression/model/quartic_model.h index 9d5184df5..a5aadd965 100644 --- a/apps/regression/model/quartic_model.h +++ b/apps/regression/model/quartic_model.h @@ -8,7 +8,7 @@ namespace Regression { class QuarticModel : public Model { public: using Model::Model; - Poincare::LayoutReference layout() override; + Poincare::Layout layout() override; Poincare::Expression simplifiedExpression(double * modelCoefficients, Poincare::Context * context) override; I18n::Message formulaMessage() const override { return I18n::Message::QuarticRegressionFormula; } double evaluate(double * modelCoefficients, double x) const override; diff --git a/apps/regression/model/trigonometric_model.cpp b/apps/regression/model/trigonometric_model.cpp index c7b476cb2..69f9b8421 100644 --- a/apps/regression/model/trigonometric_model.cpp +++ b/apps/regression/model/trigonometric_model.cpp @@ -9,25 +9,25 @@ using namespace Shared; namespace Regression { -LayoutReference TrigonometricModel::layout() { +Layout TrigonometricModel::layout() { if (m_layout.isUninitialized()) { - const LayoutReference layoutChildren[] = { - CharLayoutReference('a', KDText::FontSize::Small), - CharLayoutReference(Ion::Charset::MiddleDot, KDText::FontSize::Small), - CharLayoutReference('s', KDText::FontSize::Small), - CharLayoutReference('i', KDText::FontSize::Small), - CharLayoutReference('n', KDText::FontSize::Small), - CharLayoutReference('(', KDText::FontSize::Small), - CharLayoutReference('b', KDText::FontSize::Small), - CharLayoutReference(Ion::Charset::MiddleDot, KDText::FontSize::Small), - CharLayoutReference('X', KDText::FontSize::Small), - CharLayoutReference('+', KDText::FontSize::Small), - CharLayoutReference('c', KDText::FontSize::Small), - CharLayoutReference(')', KDText::FontSize::Small), - CharLayoutReference('+', KDText::FontSize::Small), - CharLayoutReference('d', KDText::FontSize::Small) + const Layout layoutChildren[] = { + CharLayout('a', KDText::FontSize::Small), + CharLayout(Ion::Charset::MiddleDot, KDText::FontSize::Small), + CharLayout('s', KDText::FontSize::Small), + CharLayout('i', KDText::FontSize::Small), + CharLayout('n', KDText::FontSize::Small), + CharLayout('(', KDText::FontSize::Small), + CharLayout('b', KDText::FontSize::Small), + CharLayout(Ion::Charset::MiddleDot, KDText::FontSize::Small), + CharLayout('X', KDText::FontSize::Small), + CharLayout('+', KDText::FontSize::Small), + CharLayout('c', KDText::FontSize::Small), + CharLayout(')', KDText::FontSize::Small), + CharLayout('+', KDText::FontSize::Small), + CharLayout('d', KDText::FontSize::Small) }; - m_layout = HorizontalLayoutReference(layoutChildren, 14); + m_layout = HorizontalLayout(layoutChildren, 14); } return m_layout; } diff --git a/apps/regression/model/trigonometric_model.h b/apps/regression/model/trigonometric_model.h index af56e6ebe..b328286f5 100644 --- a/apps/regression/model/trigonometric_model.h +++ b/apps/regression/model/trigonometric_model.h @@ -8,7 +8,7 @@ namespace Regression { class TrigonometricModel : public Model { public: using Model::Model; - Poincare::LayoutReference layout() override; + Poincare::Layout layout() override; Poincare::Expression simplifiedExpression(double * modelCoefficients, Poincare::Context * context) override; I18n::Message formulaMessage() const override { return I18n::Message::TrigonometricRegressionFormula; } double evaluate(double * modelCoefficients, double x) const override; diff --git a/apps/regression/regression_controller.cpp b/apps/regression/regression_controller.cpp index a338c8a27..0376701c9 100644 --- a/apps/regression/regression_controller.cpp +++ b/apps/regression/regression_controller.cpp @@ -85,7 +85,7 @@ void RegressionController::willDisplayCellAtLocation(HighlightCell * cell, int i I18n::Message messages[k_numberOfRows] = {I18n::Message::Linear, I18n::Message::Quadratic, I18n::Message::Cubic, I18n::Message::Quartic, I18n::Message::Logarithmic, I18n::Message::Exponential, I18n::Message::Power, I18n::Message::Trigonometrical, I18n::Message::Logistic}; MessageTableCellWithExpression * castedCell = static_cast(cell); castedCell->setMessage(messages[j]); - castedCell->setLayoutReference(m_store->regressionModel((Model::Type) j)->layout()); + castedCell->setLayout(m_store->regressionModel((Model::Type) j)->layout()); } } diff --git a/apps/regression/store_parameter_controller.cpp b/apps/regression/store_parameter_controller.cpp index e1ff15460..285ddd7df 100644 --- a/apps/regression/store_parameter_controller.cpp +++ b/apps/regression/store_parameter_controller.cpp @@ -76,7 +76,7 @@ int StoreParameterController::typeAtLocation(int i, int j) { void StoreParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) { if (index == numberOfRows() -1) { - m_changeRegressionCell.setLayoutReference(static_cast(m_store)->modelForSeries(m_series)->layout()); + m_changeRegressionCell.setLayout(static_cast(m_store)->modelForSeries(m_series)->layout()); } Shared::StoreParameterController::willDisplayCellForIndex(cell, index); } diff --git a/apps/sequence/graph/term_sum_controller.cpp b/apps/sequence/graph/term_sum_controller.cpp index fdb9a250b..264d748b8 100644 --- a/apps/sequence/graph/term_sum_controller.cpp +++ b/apps/sequence/graph/term_sum_controller.cpp @@ -46,11 +46,11 @@ double TermSumController::cursorNextStep(double x, int direction) { return std::round(m_cursor->x()+delta); } -LayoutReference TermSumController::createFunctionLayout(const char * functionName) { - return HorizontalLayoutReference( - CharLayoutReference(functionName[0], KDText::FontSize::Small), - VerticalOffsetLayoutReference( - CharLayoutReference('n', KDText::FontSize::Small), +Layout TermSumController::createFunctionLayout(const char * functionName) { + return HorizontalLayout( + CharLayout(functionName[0], KDText::FontSize::Small), + VerticalOffsetLayout( + CharLayout('n', KDText::FontSize::Small), VerticalOffsetLayoutNode::Type::Subscript ) ); diff --git a/apps/sequence/graph/term_sum_controller.h b/apps/sequence/graph/term_sum_controller.h index 507922498..8af30f309 100644 --- a/apps/sequence/graph/term_sum_controller.h +++ b/apps/sequence/graph/term_sum_controller.h @@ -16,7 +16,7 @@ private: bool moveCursorHorizontallyToPosition(double position) override; I18n::Message legendMessageAtStep(Step step) override; double cursorNextStep(double position, int direction) override; - Poincare::LayoutReference createFunctionLayout(const char * functionName) override; + Poincare::Layout createFunctionLayout(const char * functionName) override; }; } diff --git a/apps/sequence/list/list_controller.cpp b/apps/sequence/list/list_controller.cpp index feb19b590..591c56ed4 100644 --- a/apps/sequence/list/list_controller.cpp +++ b/apps/sequence/list/list_controller.cpp @@ -62,7 +62,7 @@ KDCoordinate ListController::expressionRowHeight(int j) { } Sequence * sequence = m_sequenceStore->modelAtIndex(modelIndexForRow(j)); KDCoordinate defaultHeight = 2*k_expressionCellVerticalMargin + (sequence->type() == Sequence::Type::Explicit ? Metric::StoreRowHeight : k_emptySubRowHeight); - LayoutReference layout = sequence->layoutRef(); + Layout layout = sequence->layout(); if (sequenceDefinitionForRow(j) == 1) { layout = sequence->firstInitialConditionLayout(); } @@ -204,13 +204,13 @@ void ListController::willDisplayExpressionCellAtIndex(HighlightCell * cell, int FunctionExpressionCell * myCell = (FunctionExpressionCell *)cell; Sequence * sequence = m_sequenceStore->modelAtIndex(modelIndexForRow(j)); if (sequenceDefinitionForRow(j) == 0) { - myCell->setLayoutReference(sequence->layoutRef()); + myCell->setLayout(sequence->layout()); } if (sequenceDefinitionForRow(j) == 1) { - myCell->setLayoutReference(sequence->firstInitialConditionLayout()); + myCell->setLayout(sequence->firstInitialConditionLayout()); } if (sequenceDefinitionForRow(j) == 2) { - myCell->setLayoutReference(sequence->secondInitialConditionLayout()); + myCell->setLayout(sequence->secondInitialConditionLayout()); } bool active = sequence->isActive(); KDColor textColor = active ? KDColorBlack : Palette::GreyDark; diff --git a/apps/sequence/list/list_parameter_controller.cpp b/apps/sequence/list/list_parameter_controller.cpp index 1871c3ff0..0ea587d1d 100644 --- a/apps/sequence/list/list_parameter_controller.cpp +++ b/apps/sequence/list/list_parameter_controller.cpp @@ -104,7 +104,7 @@ void ListParameterController::willDisplayCellForIndex(HighlightCell * cell, int cell->setHighlighted(index == selectedRow()); // See FIXME in SelectableTableView::reloadData() Shared::ListParameterController::willDisplayCellForIndex(cell, index); if (cell == &m_typeCell && m_sequence != nullptr) { - m_typeCell.setLayoutReference(m_sequence->definitionName()); + m_typeCell.setLayout(m_sequence->definitionName()); } if (cell == &m_initialRankCell && m_sequence != nullptr) { MessageTableCellWithEditableText * myCell = (MessageTableCellWithEditableText *) cell; diff --git a/apps/sequence/list/sequence_toolbox.cpp b/apps/sequence/list/sequence_toolbox.cpp index ad7089d88..4c6197078 100644 --- a/apps/sequence/list/sequence_toolbox.cpp +++ b/apps/sequence/list/sequence_toolbox.cpp @@ -43,7 +43,7 @@ HighlightCell * SequenceToolbox::reusableCell(int index, int type) { void SequenceToolbox::willDisplayCellForIndex(HighlightCell * cell, int index) { if (typeAtLocation(0, index) == 2) { - static_cast(cell)->setLayoutReference(m_addedCellLayout[index]); + static_cast(cell)->setLayout(m_addedCellLayout[index]); return; } MathToolbox::willDisplayCellForIndex(cell, mathToolboxIndex(index)); @@ -73,20 +73,20 @@ void SequenceToolbox::buildExtraCellsLayouts(const char * sequenceName, int recu const char * otherSequenceName = SequenceStore::k_sequenceNames[1-sequenceIndex]; for (int j = 0; j < recurrenceDepth; j++) { const char * indice = j == 0 ? "n" : "n+1"; - m_addedCellLayout[j] = HorizontalLayoutReference( - CharLayoutReference(sequenceName[0], KDText::FontSize::Large), - VerticalOffsetLayoutReference(LayoutHelper::String(indice, strlen(indice), KDText::FontSize::Large), VerticalOffsetLayoutNode::Type::Subscript) + m_addedCellLayout[j] = HorizontalLayout( + CharLayout(sequenceName[0], KDText::FontSize::Large), + VerticalOffsetLayout(LayoutHelper::String(indice, strlen(indice), KDText::FontSize::Large), VerticalOffsetLayoutNode::Type::Subscript) ); - m_addedCellLayout[j+recurrenceDepth] = HorizontalLayoutReference( - CharLayoutReference(otherSequenceName[0], KDText::FontSize::Large), - VerticalOffsetLayoutReference(LayoutHelper::String(indice, strlen(indice), KDText::FontSize::Large), VerticalOffsetLayoutNode::Type::Subscript) + m_addedCellLayout[j+recurrenceDepth] = HorizontalLayout( + CharLayout(otherSequenceName[0], KDText::FontSize::Large), + VerticalOffsetLayout(LayoutHelper::String(indice, strlen(indice), KDText::FontSize::Large), VerticalOffsetLayoutNode::Type::Subscript) ); } if (recurrenceDepth < 2) { const char * indice = recurrenceDepth == 0 ? "n" : (recurrenceDepth == 1 ? "n+1" : "n+2"); - m_addedCellLayout[2*recurrenceDepth] = HorizontalLayoutReference( - CharLayoutReference(otherSequenceName[0], KDText::FontSize::Large), - VerticalOffsetLayoutReference(LayoutHelper::String(indice, strlen(indice), KDText::FontSize::Large), VerticalOffsetLayoutNode::Type::Subscript) + m_addedCellLayout[2*recurrenceDepth] = HorizontalLayout( + CharLayout(otherSequenceName[0], KDText::FontSize::Large), + VerticalOffsetLayout(LayoutHelper::String(indice, strlen(indice), KDText::FontSize::Large), VerticalOffsetLayoutNode::Type::Subscript) ); } } diff --git a/apps/sequence/list/sequence_toolbox.h b/apps/sequence/list/sequence_toolbox.h index f4ef36fa0..1be99fb88 100644 --- a/apps/sequence/list/sequence_toolbox.h +++ b/apps/sequence/list/sequence_toolbox.h @@ -18,7 +18,7 @@ private: bool selectAddedCell(int selectedRow); int mathToolboxIndex(int index); ExpressionTableCell m_addedCells[k_maxNumberOfDisplayedRows]; - Poincare::LayoutReference m_addedCellLayout[k_maxNumberOfDisplayedRows]; + Poincare::Layout m_addedCellLayout[k_maxNumberOfDisplayedRows]; int m_numberOfAddedCells; }; diff --git a/apps/sequence/list/type_parameter_controller.cpp b/apps/sequence/list/type_parameter_controller.cpp index 5dafbe300..554c5197c 100644 --- a/apps/sequence/list/type_parameter_controller.cpp +++ b/apps/sequence/list/type_parameter_controller.cpp @@ -113,12 +113,12 @@ void TypeParameterController::willDisplayCellAtLocation(HighlightCell * cell, in size = KDText::FontSize::Small; } const char * subscripts[3] = {"n", "n+1", "n+2"}; - m_layouts[j] = HorizontalLayoutReference( - CharLayoutReference(nextName[0], size), - VerticalOffsetLayoutReference(LayoutHelper::String(subscripts[j], strlen(subscripts[j]), size), VerticalOffsetLayoutNode::Type::Subscript) + m_layouts[j] = HorizontalLayout( + CharLayout(nextName[0], size), + VerticalOffsetLayout(LayoutHelper::String(subscripts[j], strlen(subscripts[j]), size), VerticalOffsetLayoutNode::Type::Subscript) ); ExpressionTableCellWithPointer * myCell = (ExpressionTableCellWithPointer *)cell; - myCell->setLayoutReference(m_layouts[j]); + myCell->setLayout(m_layouts[j]); } void TypeParameterController::setSequence(Sequence * sequence) { diff --git a/apps/sequence/list/type_parameter_controller.h b/apps/sequence/list/type_parameter_controller.h index 3155a5f13..83c3f762c 100644 --- a/apps/sequence/list/type_parameter_controller.h +++ b/apps/sequence/list/type_parameter_controller.h @@ -31,7 +31,7 @@ private: ExpressionTableCellWithPointer m_expliciteCell; ExpressionTableCellWithPointer m_singleRecurrenceCell; ExpressionTableCellWithPointer m_doubleRecurenceCell; - Poincare::LayoutReference m_layouts[k_totalNumberOfCell]; + Poincare::Layout m_layouts[k_totalNumberOfCell]; SelectableTableView m_selectableTableView; SequenceStore * m_sequenceStore; Sequence * m_sequence; diff --git a/apps/sequence/sequence.cpp b/apps/sequence/sequence.cpp index 210481f2d..e8745caf1 100644 --- a/apps/sequence/sequence.cpp +++ b/apps/sequence/sequence.cpp @@ -86,8 +86,8 @@ void Sequence::setType(Type type) { void Sequence::setInitialRank(int rank) { m_initialRank = rank; - m_firstInitialConditionName = LayoutReference(); - m_secondInitialConditionName = LayoutReference(); + m_firstInitialConditionName = Layout(); + m_secondInitialConditionName = Layout(); } Poincare::Expression Sequence::firstInitialConditionExpression(Context * context) const { @@ -104,7 +104,7 @@ Poincare::Expression Sequence::secondInitialConditionExpression(Context * contex return m_secondInitialConditionExpression; } -Poincare::LayoutReference Sequence::firstInitialConditionLayout() { +Poincare::Layout Sequence::firstInitialConditionLayout() { if (m_firstInitialConditionLayout.isUninitialized()) { Expression nonSimplifedExpression = Expression::parse(m_firstInitialConditionText); if (!nonSimplifedExpression.isUninitialized()) { @@ -114,7 +114,7 @@ Poincare::LayoutReference Sequence::firstInitialConditionLayout() { return m_firstInitialConditionLayout; } -Poincare::LayoutReference Sequence::secondInitialConditionLayout() { +Poincare::Layout Sequence::secondInitialConditionLayout() { if (m_secondInitialConditionLayout.isUninitialized()) { Expression nonSimplifedExpression = Expression::parse(m_secondInitialConditionText); if (!nonSimplifedExpression.isUninitialized()) { @@ -127,13 +127,13 @@ Poincare::LayoutReference Sequence::secondInitialConditionLayout() { void Sequence::setFirstInitialConditionContent(const char * c) { strlcpy(m_firstInitialConditionText, c, sizeof(m_firstInitialConditionText)); m_firstInitialConditionExpression = Expression(); - m_firstInitialConditionLayout = LayoutReference(); + m_firstInitialConditionLayout = Layout(); } void Sequence::setSecondInitialConditionContent(const char * c) { strlcpy(m_secondInitialConditionText, c, sizeof(m_secondInitialConditionText)); m_secondInitialConditionExpression = Expression(); - m_secondInitialConditionLayout = LayoutReference(); + m_secondInitialConditionLayout = Layout(); } char Sequence::symbol() const { @@ -144,65 +144,65 @@ int Sequence::numberOfElements() { return (int)m_type + 1; } -Poincare::LayoutReference Sequence::nameLayout() { +Poincare::Layout Sequence::nameLayout() { if (m_nameLayout.isUninitialized()) { - m_nameLayout = HorizontalLayoutReference( - CharLayoutReference(name()[0], KDText::FontSize::Small), - VerticalOffsetLayoutReference(CharLayoutReference('n', KDText::FontSize::Small), VerticalOffsetLayoutNode::Type::Subscript) + m_nameLayout = HorizontalLayout( + CharLayout(name()[0], KDText::FontSize::Small), + VerticalOffsetLayout(CharLayout('n', KDText::FontSize::Small), VerticalOffsetLayoutNode::Type::Subscript) ); } return m_nameLayout; } -Poincare::LayoutReference Sequence::definitionName() { +Poincare::Layout Sequence::definitionName() { if (m_definitionName.isUninitialized()) { if (m_type == Type::Explicit) { - m_definitionName = HorizontalLayoutReference( - CharLayoutReference(name()[0], KDText::FontSize::Large), - VerticalOffsetLayoutReference(LayoutHelper::String("n", 1, KDText::FontSize::Large), VerticalOffsetLayoutNode::Type::Subscript) + m_definitionName = HorizontalLayout( + CharLayout(name()[0], KDText::FontSize::Large), + VerticalOffsetLayout(LayoutHelper::String("n", 1, KDText::FontSize::Large), VerticalOffsetLayoutNode::Type::Subscript) ); } if (m_type == Type::SingleRecurrence) { - m_definitionName = HorizontalLayoutReference( - CharLayoutReference(name()[0], KDText::FontSize::Large), - VerticalOffsetLayoutReference(LayoutHelper::String("n+1", 3, KDText::FontSize::Large), VerticalOffsetLayoutNode::Type::Subscript) + m_definitionName = HorizontalLayout( + CharLayout(name()[0], KDText::FontSize::Large), + VerticalOffsetLayout(LayoutHelper::String("n+1", 3, KDText::FontSize::Large), VerticalOffsetLayoutNode::Type::Subscript) ); } if (m_type == Type::DoubleRecurrence) { - m_definitionName = HorizontalLayoutReference( - CharLayoutReference(name()[0], KDText::FontSize::Large), - VerticalOffsetLayoutReference(LayoutHelper::String("n+2", 3, KDText::FontSize::Large), VerticalOffsetLayoutNode::Type::Subscript) + m_definitionName = HorizontalLayout( + CharLayout(name()[0], KDText::FontSize::Large), + VerticalOffsetLayout(LayoutHelper::String("n+2", 3, KDText::FontSize::Large), VerticalOffsetLayoutNode::Type::Subscript) ); } } return m_definitionName; } -Poincare::LayoutReference Sequence::firstInitialConditionName() { +Poincare::Layout Sequence::firstInitialConditionName() { char buffer[k_initialRankNumberOfDigits+1]; Integer(m_initialRank).serialize(buffer, k_initialRankNumberOfDigits+1); if (m_firstInitialConditionName.isUninitialized() && (m_type == Type::SingleRecurrence || m_type == Type::DoubleRecurrence)) { - LayoutReference indexLayout = LayoutHelper::String(buffer, strlen(buffer), KDText::FontSize::Large); - m_firstInitialConditionName = HorizontalLayoutReference( - CharLayoutReference(name()[0], KDText::FontSize::Large), - VerticalOffsetLayoutReference(indexLayout, VerticalOffsetLayoutNode::Type::Subscript) + Layout indexLayout = LayoutHelper::String(buffer, strlen(buffer), KDText::FontSize::Large); + m_firstInitialConditionName = HorizontalLayout( + CharLayout(name()[0], KDText::FontSize::Large), + VerticalOffsetLayout(indexLayout, VerticalOffsetLayoutNode::Type::Subscript) ); } return m_firstInitialConditionName; } -Poincare::LayoutReference Sequence::secondInitialConditionName() { +Poincare::Layout Sequence::secondInitialConditionName() { char buffer[k_initialRankNumberOfDigits+1]; Integer(m_initialRank+1).serialize(buffer, k_initialRankNumberOfDigits+1); if (m_secondInitialConditionName.isUninitialized()) { if (m_type == Type::DoubleRecurrence) { - LayoutReference indexLayout = LayoutHelper::String(buffer, strlen(buffer), KDText::FontSize::Large); - m_secondInitialConditionName = HorizontalLayoutReference( - CharLayoutReference(name()[0], KDText::FontSize::Large), - VerticalOffsetLayoutReference(indexLayout, VerticalOffsetLayoutNode::Type::Subscript) + Layout indexLayout = LayoutHelper::String(buffer, strlen(buffer), KDText::FontSize::Large); + m_secondInitialConditionName = HorizontalLayout( + CharLayout(name()[0], KDText::FontSize::Large), + VerticalOffsetLayout(indexLayout, VerticalOffsetLayoutNode::Type::Subscript) ); } } @@ -310,14 +310,14 @@ double Sequence::sumBetweenBounds(double start, double end, Context * context) c void Sequence::tidy() { Function::tidy(); - m_firstInitialConditionLayout = LayoutReference(); - m_secondInitialConditionLayout = LayoutReference(); + m_firstInitialConditionLayout = Layout(); + m_secondInitialConditionLayout = Layout(); m_firstInitialConditionExpression = Expression(); m_secondInitialConditionExpression = Expression(); - m_nameLayout = LayoutReference(); - m_definitionName = LayoutReference(); - m_firstInitialConditionName = LayoutReference(); - m_secondInitialConditionName = LayoutReference(); + m_nameLayout = Layout(); + m_definitionName = Layout(); + m_firstInitialConditionName = Layout(); + m_secondInitialConditionName = Layout(); } template double Sequence::templatedApproximateAtAbscissa(double, SequenceContext*) const; diff --git a/apps/sequence/sequence.h b/apps/sequence/sequence.h index b13687e63..1f6416e85 100644 --- a/apps/sequence/sequence.h +++ b/apps/sequence/sequence.h @@ -24,8 +24,8 @@ public: const char * secondInitialConditionText(); Poincare::Expression firstInitialConditionExpression(Poincare::Context * context) const; Poincare::Expression secondInitialConditionExpression(Poincare::Context * context) const; - Poincare::LayoutReference firstInitialConditionLayout(); - Poincare::LayoutReference secondInitialConditionLayout(); + Poincare::Layout firstInitialConditionLayout(); + Poincare::Layout secondInitialConditionLayout(); /* WARNING: after calling setType, setContent, setFirstInitialConditionContent * or setSecondInitialConditionContent, the sequence context needs to * invalidate the cache because the sequences evaluations might have changed. */ @@ -34,10 +34,10 @@ public: void setFirstInitialConditionContent(const char * c); void setSecondInitialConditionContent(const char * c); int numberOfElements(); - Poincare::LayoutReference nameLayout(); - Poincare::LayoutReference definitionName(); - Poincare::LayoutReference firstInitialConditionName(); - Poincare::LayoutReference secondInitialConditionName(); + Poincare::Layout nameLayout(); + Poincare::Layout definitionName(); + Poincare::Layout firstInitialConditionName(); + Poincare::Layout secondInitialConditionName(); bool isDefined() override; bool isEmpty() override; float evaluateAtAbscissa(float x, Poincare::Context * context) const override { @@ -61,12 +61,12 @@ private: char m_secondInitialConditionText[TextField::maxBufferSize()]; mutable Poincare::Expression m_firstInitialConditionExpression; mutable Poincare::Expression m_secondInitialConditionExpression; - Poincare::LayoutReference m_firstInitialConditionLayout; - Poincare::LayoutReference m_secondInitialConditionLayout; - Poincare::LayoutReference m_nameLayout; - Poincare::LayoutReference m_definitionName; - Poincare::LayoutReference m_firstInitialConditionName; - Poincare::LayoutReference m_secondInitialConditionName; + Poincare::Layout m_firstInitialConditionLayout; + Poincare::Layout m_secondInitialConditionLayout; + Poincare::Layout m_nameLayout; + Poincare::Layout m_definitionName; + Poincare::Layout m_firstInitialConditionName; + Poincare::Layout m_secondInitialConditionName; int m_initialRank; }; diff --git a/apps/sequence/sequence_title_cell.cpp b/apps/sequence/sequence_title_cell.cpp index 4581f6e4b..0bb1d9bb9 100644 --- a/apps/sequence/sequence_title_cell.cpp +++ b/apps/sequence/sequence_title_cell.cpp @@ -12,8 +12,8 @@ SequenceTitleCell::SequenceTitleCell() : { } -void SequenceTitleCell::setLayout(Poincare::LayoutReference layout) { - m_titleTextView.setLayoutReference(layout); +void SequenceTitleCell::setLayout(Poincare::Layout layout) { + m_titleTextView.setLayout(layout); } void SequenceTitleCell::setHighlighted(bool highlight) { diff --git a/apps/sequence/sequence_title_cell.h b/apps/sequence/sequence_title_cell.h index c4d9ec2d6..b1b59f241 100644 --- a/apps/sequence/sequence_title_cell.h +++ b/apps/sequence/sequence_title_cell.h @@ -8,12 +8,12 @@ namespace Sequence { class SequenceTitleCell : public Shared::FunctionTitleCell { public: SequenceTitleCell(); - void setLayout(Poincare::LayoutReference layout); + void setLayout(Poincare::Layout layout); void setEven(bool even) override; void setHighlighted(bool highlight) override; void setColor(KDColor color) override; - Poincare::LayoutReference layoutRef() const override { - return m_titleTextView.layoutRef(); + Poincare::Layout layout() const override { + return m_titleTextView.layout(); } private: int numberOfSubviews() const override; diff --git a/apps/settings/helpers.cpp b/apps/settings/helpers.cpp index dac563e08..0f8cb8d7b 100644 --- a/apps/settings/helpers.cpp +++ b/apps/settings/helpers.cpp @@ -7,17 +7,17 @@ using namespace Poincare; namespace Settings { namespace Helpers { -LayoutReference CartesianComplexFormat(KDText::FontSize fontSize) { +Layout CartesianComplexFormat(KDText::FontSize fontSize) { const char text[] = {'a','+', Ion::Charset::IComplex, 'b', ' '}; return LayoutHelper::String(text, sizeof(text), fontSize); } -LayoutReference PolarComplexFormat(KDText::FontSize fontSize) { +Layout PolarComplexFormat(KDText::FontSize fontSize) { const char base[] = {'r', Ion::Charset::Exponential}; const char superscript[] = {Ion::Charset::IComplex, Ion::Charset::SmallTheta, ' '}; - return HorizontalLayoutReference( + return HorizontalLayout( LayoutHelper::String(base, sizeof(base), fontSize), - VerticalOffsetLayoutReference(LayoutHelper::String(superscript, sizeof(superscript), fontSize), VerticalOffsetLayoutNode::Type::Superscript) + VerticalOffsetLayout(LayoutHelper::String(superscript, sizeof(superscript), fontSize), VerticalOffsetLayoutNode::Type::Superscript) ); } diff --git a/apps/settings/helpers.h b/apps/settings/helpers.h index ed0f8c9a8..dc1b2fc3b 100644 --- a/apps/settings/helpers.h +++ b/apps/settings/helpers.h @@ -6,8 +6,8 @@ namespace Settings { namespace Helpers { -Poincare::LayoutReference CartesianComplexFormat(KDText::FontSize fontSize); -Poincare::LayoutReference PolarComplexFormat(KDText::FontSize fontSize); +Poincare::Layout CartesianComplexFormat(KDText::FontSize fontSize); +Poincare::Layout PolarComplexFormat(KDText::FontSize fontSize); } } diff --git a/apps/settings/main_controller.cpp b/apps/settings/main_controller.cpp index 726833885..43ded3bd5 100644 --- a/apps/settings/main_controller.cpp +++ b/apps/settings/main_controller.cpp @@ -172,7 +172,7 @@ void MainController::willDisplayCellForIndex(HighlightCell * cell, int index) { m_complexFormatLayout = Helpers::PolarComplexFormat(KDText::FontSize::Small); } MessageTableCellWithChevronAndExpression * myExpCell = (MessageTableCellWithChevronAndExpression *)cell; - myExpCell->setLayoutReference(m_complexFormatLayout); + myExpCell->setLayout(m_complexFormatLayout); return; } if (index == 4) { diff --git a/apps/settings/main_controller.h b/apps/settings/main_controller.h index c446e8a9f..997b627f3 100644 --- a/apps/settings/main_controller.h +++ b/apps/settings/main_controller.h @@ -35,7 +35,7 @@ private: MessageTableCellWithChevronAndMessage m_cells[k_numberOfSimpleChevronCells]; MessageTableCellWithChevronAndExpression m_complexFormatCell; MessageTableCellWithGauge m_brightnessCell; - Poincare::LayoutReference m_complexFormatLayout; + Poincare::Layout m_complexFormatLayout; SelectableTableView m_selectableTableView; MessageTree * m_messageTreeModel; SubController m_subController; diff --git a/apps/settings/sub_controller.cpp b/apps/settings/sub_controller.cpp index 0803304b6..cd7f8934a 100644 --- a/apps/settings/sub_controller.cpp +++ b/apps/settings/sub_controller.cpp @@ -27,7 +27,7 @@ SubController::SubController(Responder * parentResponder) : m_complexFormatLayout[0] = Helpers::CartesianComplexFormat(KDText::FontSize::Large); m_complexFormatLayout[1] = Helpers::PolarComplexFormat(KDText::FontSize::Large); for (int i = 0; i < 2; i++) { - m_complexFormatCells[i].setLayoutReference(m_complexFormatLayout[i]); + m_complexFormatCells[i].setLayout(m_complexFormatLayout[i]); } m_editableCell.setMessage(I18n::Message::SignificantFigures); m_editableCell.setMessageFontSize(KDText::FontSize::Large); diff --git a/apps/settings/sub_controller.h b/apps/settings/sub_controller.h index fed8b3054..50d758836 100644 --- a/apps/settings/sub_controller.h +++ b/apps/settings/sub_controller.h @@ -38,7 +38,7 @@ private: constexpr static int k_totalNumberOfCell = (Ion::Display::Height-2*k_topBottomMargin-Metric::TitleBarHeight-Metric::StackTitleHeight)/Metric::ParameterCellHeight; MessageTableCellWithBuffer m_cells[k_totalNumberOfCell]; ExpressionTableCell m_complexFormatCells[2]; - Poincare::LayoutReference m_complexFormatLayout[2]; + Poincare::Layout m_complexFormatLayout[2]; MessageTableCellWithEditableText m_editableCell; char m_draftTextBuffer[MessageTableCellWithEditableText::k_bufferLength]; SelectableTableView m_selectableTableView; diff --git a/apps/shared/expression_model.cpp b/apps/shared/expression_model.cpp index 959370143..ea2ef122a 100644 --- a/apps/shared/expression_model.cpp +++ b/apps/shared/expression_model.cpp @@ -11,7 +11,7 @@ namespace Shared { ExpressionModel::ExpressionModel() : m_text{0}, m_expression(), - m_layoutRef() + m_layout() { } @@ -26,12 +26,12 @@ Poincare::Expression ExpressionModel::expression(Poincare::Context * context) co return m_expression; } -LayoutReference ExpressionModel::layoutRef() { - if (m_layoutRef.isUninitialized()) { +Layout ExpressionModel::layout() { + if (m_layout.isUninitialized()) { Expression nonSimplifiedExpression = Expression::parse(m_text); - m_layoutRef = PoincareHelpers::CreateLayout(nonSimplifiedExpression); + m_layout = PoincareHelpers::CreateLayout(nonSimplifiedExpression); } - return m_layoutRef; + return m_layout; } bool ExpressionModel::isDefined() { @@ -47,12 +47,12 @@ void ExpressionModel::setContent(const char * c) { /* We cannot call tidy here because tidy is a virtual function and does not * do the same thing for all children class. And here we want to delete only * the m_layout and m_expression. */ - m_layoutRef = LayoutReference(); + m_layout = Layout(); m_expression = Expression(); } void ExpressionModel::tidy() { - m_layoutRef = LayoutReference(); + m_layout = Layout(); m_expression = Expression(); } diff --git a/apps/shared/expression_model.h b/apps/shared/expression_model.h index 9718ce232..237fea5bd 100644 --- a/apps/shared/expression_model.h +++ b/apps/shared/expression_model.h @@ -12,7 +12,7 @@ public: ExpressionModel(); const char * text() const; Poincare::Expression expression(Poincare::Context * context) const; - Poincare::LayoutReference layoutRef(); + Poincare::Layout layout(); /* Here, isDefined is the exact contrary of isEmpty. However, for Sequence * inheriting from ExpressionModel, isEmpty and isDefined have not exactly * opposite meaning. For instance, u(n+1)=u(n) & u(0) = ... is not empty and @@ -30,7 +30,7 @@ private: static_assert((k_dataLengthInBytes & 0x3) == 0, "The expression model data size is not a multiple of 4 bytes (cannot compute crc)"); // Assert that dataLengthInBytes is a multiple of 4 char m_text[k_expressionBufferSize]; mutable Poincare::Expression m_expression; - mutable Poincare::LayoutReference m_layoutRef; + mutable Poincare::Layout m_layout; }; } diff --git a/apps/shared/expression_model_list_controller.cpp b/apps/shared/expression_model_list_controller.cpp index c5836877e..2300a9d67 100644 --- a/apps/shared/expression_model_list_controller.cpp +++ b/apps/shared/expression_model_list_controller.cpp @@ -23,17 +23,17 @@ KDCoordinate ExpressionModelListController::expressionRowHeight(int j) { return Metric::StoreRowHeight; } ExpressionModel * m = modelStore()->modelAtIndex(j); - if (m->layoutRef().isUninitialized()) { + if (m->layout().isUninitialized()) { return Metric::StoreRowHeight; } - KDCoordinate modelSize = m->layoutRef().layoutSize().height(); + KDCoordinate modelSize = m->layout().layoutSize().height(); return modelSize + Metric::StoreRowHeight - KDText::charSize().height(); } void ExpressionModelListController::willDisplayExpressionCellAtIndex(HighlightCell * cell, int j) { EvenOddExpressionCell * myCell = (EvenOddExpressionCell *)cell; ExpressionModel * m = modelStore()->modelAtIndex(j); - myCell->setLayoutReference(m->layoutRef()); + myCell->setLayout(m->layout()); } /* Responder */ diff --git a/apps/shared/layout_field_delegate.cpp b/apps/shared/layout_field_delegate.cpp index a27448b56..c9a7215bc 100644 --- a/apps/shared/layout_field_delegate.cpp +++ b/apps/shared/layout_field_delegate.cpp @@ -12,7 +12,7 @@ bool LayoutFieldDelegate::layoutFieldDidReceiveEvent(LayoutField * layoutField, return expressionFieldDelegateApp()->layoutFieldDidReceiveEvent(layoutField, event); } -bool LayoutFieldDelegate::layoutFieldDidFinishEditing(LayoutField * layoutField, LayoutReference layoutR, Ion::Events::Event event) { +bool LayoutFieldDelegate::layoutFieldDidFinishEditing(LayoutField * layoutField, Layout layoutR, Ion::Events::Event event) { return expressionFieldDelegateApp()->layoutFieldDidFinishEditing(layoutField, layoutR, event); } diff --git a/apps/shared/layout_field_delegate.h b/apps/shared/layout_field_delegate.h index e20e6aaaa..a4338613f 100644 --- a/apps/shared/layout_field_delegate.h +++ b/apps/shared/layout_field_delegate.h @@ -10,7 +10,7 @@ class LayoutFieldDelegate : public ::LayoutFieldDelegate { public: bool layoutFieldShouldFinishEditing(LayoutField * layoutField, Ion::Events::Event event) override; bool layoutFieldDidReceiveEvent(LayoutField * layoutField, Ion::Events::Event event) override; - bool layoutFieldDidFinishEditing(LayoutField * layoutField, Poincare::LayoutReference layoutR, Ion::Events::Event event) override; + bool layoutFieldDidFinishEditing(LayoutField * layoutField, Poincare::Layout layoutR, Ion::Events::Event event) override; bool layoutFieldDidAbortEditing(LayoutField * layoutField) override; void layoutFieldDidChangeSize(LayoutField * layoutField) override; Toolbox * toolboxForLayoutField(LayoutField * layoutField) override; diff --git a/apps/shared/poincare_helpers.h b/apps/shared/poincare_helpers.h index 1f4980fcf..90a2c9133 100644 --- a/apps/shared/poincare_helpers.h +++ b/apps/shared/poincare_helpers.h @@ -7,7 +7,7 @@ namespace Shared { namespace PoincareHelpers { -inline Poincare::LayoutReference CreateLayout(const Poincare::Expression e) { +inline Poincare::Layout CreateLayout(const Poincare::Expression e) { return e.createLayout(Poincare::Preferences::sharedPreferences()->displayMode(), Poincare::Preferences::sharedPreferences()->numberOfSignificantDigits()); } diff --git a/apps/shared/scrollable_exact_approximate_expressions_cell.h b/apps/shared/scrollable_exact_approximate_expressions_cell.h index 90891f9da..f74f77091 100644 --- a/apps/shared/scrollable_exact_approximate_expressions_cell.h +++ b/apps/shared/scrollable_exact_approximate_expressions_cell.h @@ -9,7 +9,7 @@ namespace Shared { class ScrollableExactApproximateExpressionsCell : public ::EvenOddCell, public Responder { public: ScrollableExactApproximateExpressionsCell(Responder * parentResponder = nullptr); - void setLayouts(Poincare::LayoutReference approximateLayout, Poincare::LayoutReference exactLayout) { + void setLayouts(Poincare::Layout approximateLayout, Poincare::Layout exactLayout) { return m_view.setLayouts(approximateLayout, exactLayout); } void setEqualMessage(I18n::Message equalSignMessage) { @@ -22,7 +22,7 @@ public: Responder * responder() override { return this; } - Poincare::LayoutReference layoutRef() const override { return m_view.layoutRef(); } + Poincare::Layout layout() const override { return m_view.layout(); } void didBecomeFirstResponder() override; constexpr static KDCoordinate k_margin = 5; private: diff --git a/apps/shared/scrollable_exact_approximate_expressions_view.cpp b/apps/shared/scrollable_exact_approximate_expressions_view.cpp index b295363c6..6362f941b 100644 --- a/apps/shared/scrollable_exact_approximate_expressions_view.cpp +++ b/apps/shared/scrollable_exact_approximate_expressions_view.cpp @@ -49,8 +49,8 @@ KDSize ScrollableExactApproximateExpressionsView::ContentCell::minimalSizeForOpt return approximateExpressionSize; } KDSize exactExpressionSize = m_exactExpressionView.minimalSizeForOptimalDisplay(); - KDCoordinate exactBaseline = m_exactExpressionView.layoutRef().baseline(); - KDCoordinate approximateBaseline = m_approximateExpressionView.layoutRef().baseline(); + KDCoordinate exactBaseline = m_exactExpressionView.layout().baseline(); + KDCoordinate approximateBaseline = m_approximateExpressionView.layout().baseline(); KDCoordinate height = max(exactBaseline, approximateBaseline) + max(exactExpressionSize.height()-exactBaseline, approximateExpressionSize.height()-approximateBaseline); KDSize approximateSignSize = m_approximateSign.minimalSizeForOptimalDisplay(); return KDSize(exactExpressionSize.width()+approximateSignSize.width()+approximateExpressionSize.width()+2*k_digitHorizontalMargin, height); @@ -61,16 +61,16 @@ void ScrollableExactApproximateExpressionsView::ContentCell::setSelectedSubviewT setHighlighted(isHighlighted()); } -Poincare::LayoutReference ScrollableExactApproximateExpressionsView::ContentCell::layoutRef() const { +Poincare::Layout ScrollableExactApproximateExpressionsView::ContentCell::layout() const { if (m_selectedSubviewType == SubviewType::ExactOutput) { - return m_exactExpressionView.layoutRef(); + return m_exactExpressionView.layout(); } else { - return m_approximateExpressionView.layoutRef(); + return m_approximateExpressionView.layout(); } } int ScrollableExactApproximateExpressionsView::ContentCell::numberOfSubviews() const { - if (m_exactExpressionView.layoutRef().isUninitialized()) { + if (m_exactExpressionView.layout().isUninitialized()) { return 1; } return 3; @@ -88,8 +88,8 @@ void ScrollableExactApproximateExpressionsView::ContentCell::layoutSubviews() { m_approximateExpressionView.setFrame(KDRect(0, 0, approximateExpressionSize.width(), height)); return; } - KDCoordinate exactBaseline = m_exactExpressionView.layoutRef().baseline(); - KDCoordinate approximateBaseline = m_approximateExpressionView.layoutRef().baseline(); + KDCoordinate exactBaseline = m_exactExpressionView.layout().baseline(); + KDCoordinate approximateBaseline = m_approximateExpressionView.layout().baseline(); KDCoordinate baseline = max(exactBaseline, approximateBaseline); KDSize exactExpressionSize = m_exactExpressionView.minimalSizeForOptimalDisplay(); KDSize approximateSignSize = m_approximateSign.minimalSizeForOptimalDisplay(); @@ -104,9 +104,9 @@ ScrollableExactApproximateExpressionsView::ScrollableExactApproximateExpressions { } -void ScrollableExactApproximateExpressionsView::setLayouts(Poincare::LayoutReference approximateLayout, Poincare::LayoutReference exactLayout) { - m_contentCell.approximateExpressionView()->setLayoutReference(approximateLayout); - m_contentCell.exactExpressionView()->setLayoutReference(exactLayout); +void ScrollableExactApproximateExpressionsView::setLayouts(Poincare::Layout approximateLayout, Poincare::Layout exactLayout) { + m_contentCell.approximateExpressionView()->setLayout(approximateLayout); + m_contentCell.exactExpressionView()->setLayout(exactLayout); m_contentCell.layoutSubviews(); } @@ -115,7 +115,7 @@ void ScrollableExactApproximateExpressionsView::setEqualMessage(I18n::Message eq } void ScrollableExactApproximateExpressionsView::didBecomeFirstResponder() { - if (m_contentCell.exactExpressionView()->layoutRef().isUninitialized()) { + if (m_contentCell.exactExpressionView()->layout().isUninitialized()) { setSelectedSubviewType(SubviewType::ApproximativeOutput); } else { setSelectedSubviewType(SubviewType::ExactOutput); @@ -123,7 +123,7 @@ void ScrollableExactApproximateExpressionsView::didBecomeFirstResponder() { } bool ScrollableExactApproximateExpressionsView::handleEvent(Ion::Events::Event event) { - if (m_contentCell.exactExpressionView()->layoutRef().isUninitialized()) { + if (m_contentCell.exactExpressionView()->layout().isUninitialized()) { return ScrollableView::handleEvent(event); } bool rightExpressionIsVisible = minimalSizeForOptimalDisplay().width() - m_contentCell.approximateExpressionView()->minimalSizeForOptimalDisplay().width() - m_manualScrollingOffset.x() < bounds().width() diff --git a/apps/shared/scrollable_exact_approximate_expressions_view.h b/apps/shared/scrollable_exact_approximate_expressions_view.h index d87d4acba..29731503e 100644 --- a/apps/shared/scrollable_exact_approximate_expressions_view.h +++ b/apps/shared/scrollable_exact_approximate_expressions_view.h @@ -15,7 +15,7 @@ public: ::EvenOddCell * evenOddCell() { return &m_contentCell; } - void setLayouts(Poincare::LayoutReference approximatelayout, Poincare::LayoutReference exactLayout); + void setLayouts(Poincare::Layout approximatelayout, Poincare::Layout exactLayout); void setEqualMessage(I18n::Message equalSignMessage); SubviewType selectedSubviewType() { return m_contentCell.selectedSubviewType(); @@ -26,8 +26,8 @@ public: void didBecomeFirstResponder() override; bool handleEvent(Ion::Events::Event event) override; KDSize minimalSizeForOptimalDisplay() const override; - Poincare::LayoutReference layoutRef() const { - return m_contentCell.layoutRef(); + Poincare::Layout layout() const { + return m_contentCell.layout(); } private: class ContentCell : public ::EvenOddCell { @@ -52,7 +52,7 @@ private: void setSelectedSubviewType(SubviewType subviewType); void layoutSubviews() override; int numberOfSubviews() const override; - Poincare::LayoutReference layoutRef() const override; + Poincare::Layout layout() const override; private: View * subviewAtIndex(int index) override; constexpr static KDCoordinate k_digitHorizontalMargin = 10; diff --git a/apps/shared/sum_graph_controller.cpp b/apps/shared/sum_graph_controller.cpp index 20d214715..67354d31b 100644 --- a/apps/shared/sum_graph_controller.cpp +++ b/apps/shared/sum_graph_controller.cpp @@ -202,7 +202,7 @@ bool SumGraphController::handleEnter() { SumGraphController::LegendView::LegendView(SumGraphController * controller, char sumSymbol) : m_sum(0.0f, 0.5f, KDColorBlack, Palette::GreyMiddle), - m_sumLayoutReference(), + m_sumLayout(), m_legend(KDText::FontSize::Small, I18n::Message::Default, 0.0f, 0.5f, KDColorBlack, Palette::GreyMiddle), m_editableZone(controller, m_draftText, m_draftText, TextField::maxBufferSize(), controller, false, KDText::FontSize::Small, 0.0f, 0.5f, KDColorBlack, Palette::GreyMiddle), m_sumSymbol(sumSymbol) @@ -229,37 +229,37 @@ void SumGraphController::LegendView::setEditableZone(double d) { m_editableZone.setText(buffer); } -void SumGraphController::LegendView::setSumSymbol(Step step, double start, double end, double result, LayoutReference functionLayout) { +void SumGraphController::LegendView::setSumSymbol(Step step, double start, double end, double result, Layout functionLayout) { assert(step == Step::Result || functionLayout.isUninitialized()); const char sigma[] = {' ', m_sumSymbol}; if (step == Step::FirstParameter) { - m_sumLayoutReference = LayoutHelper::String(sigma, sizeof(sigma)); + m_sumLayout = LayoutHelper::String(sigma, sizeof(sigma)); } else if (step == Step::SecondParameter) { char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits)]; PrintFloat::convertFloatToText(start, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal); - m_sumLayoutReference = CondensedSumLayoutReference( + m_sumLayout = CondensedSumLayout( LayoutHelper::String(sigma, sizeof(sigma)), LayoutHelper::String(buffer, strlen(buffer), KDText::FontSize::Small), - EmptyLayoutReference(EmptyLayoutNode::Color::Yellow, false, KDText::FontSize::Small, false)); + EmptyLayout(EmptyLayoutNode::Color::Yellow, false, KDText::FontSize::Small, false)); } else { - m_sumLayoutReference = LayoutHelper::String(sigma, sizeof(sigma)); + m_sumLayout = LayoutHelper::String(sigma, sizeof(sigma)); char buffer[2+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)]; PrintFloat::convertFloatToText(start, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal); - LayoutReference start = LayoutHelper::String(buffer, strlen(buffer), KDText::FontSize::Small); + Layout start = LayoutHelper::String(buffer, strlen(buffer), KDText::FontSize::Small); PrintFloat::convertFloatToText(end, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal); - LayoutReference end = LayoutHelper::String(buffer, strlen(buffer), KDText::FontSize::Small); - m_sumLayoutReference = CondensedSumLayoutReference( + Layout end = LayoutHelper::String(buffer, strlen(buffer), KDText::FontSize::Small); + m_sumLayout = CondensedSumLayout( LayoutHelper::String(sigma, sizeof(sigma)), start, end); strlcpy(buffer, "= ", 3); PoincareHelpers::ConvertFloatToText(result, buffer+2, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); - m_sumLayoutReference = HorizontalLayoutReference( - m_sumLayoutReference, + m_sumLayout = HorizontalLayout( + m_sumLayout, functionLayout, LayoutHelper::String(buffer, strlen(buffer), KDText::FontSize::Small)); } - m_sum.setLayoutReference(m_sumLayoutReference); + m_sum.setLayout(m_sumLayout); if (step == Step::Result) { m_sum.setAlignment(0.5f, 0.5f); } else { diff --git a/apps/shared/sum_graph_controller.h b/apps/shared/sum_graph_controller.h index 87b41c5e2..0b1327577 100644 --- a/apps/shared/sum_graph_controller.h +++ b/apps/shared/sum_graph_controller.h @@ -39,7 +39,7 @@ private: constexpr static float k_cursorBottomMarginRatio = 0.28f; // (cursorHeight/2+bannerHeigh)/graphViewHeight virtual I18n::Message legendMessageAtStep(Step step) = 0; virtual double cursorNextStep(double position, int direction) = 0; - virtual Poincare::LayoutReference createFunctionLayout(const char * functionName) = 0; + virtual Poincare::Layout createFunctionLayout(const char * functionName) = 0; Shared::InteractiveCurveViewRange * interactiveCurveViewRange() override { return m_graphRange; } Shared::CurveView * curveView() override { return m_graphView; } TextFieldDelegateApp * textFieldDelegateApp() override { @@ -58,7 +58,7 @@ private: void drawRect(KDContext * ctx, KDRect rect) const override; void setLegendMessage(I18n::Message message, Step step); void setEditableZone(double d); - void setSumSymbol(Step step, double start = NAN, double end = NAN, double result = NAN, Poincare::LayoutReference sequenceName = Poincare::LayoutReference()); + void setSumSymbol(Step step, double start = NAN, double end = NAN, double result = NAN, Poincare::Layout sequenceName = Poincare::Layout()); private: constexpr static KDCoordinate k_legendHeight = 35; constexpr static KDCoordinate k_editableZoneWidth = 12*KDText::charSize(KDText::FontSize::Small).width(); @@ -70,7 +70,7 @@ private: void layoutSubviews() override; void layoutSubviews(Step step); ExpressionView m_sum; - Poincare::LayoutReference m_sumLayoutReference; + Poincare::Layout m_sumLayout; MessageTextView m_legend; TextField m_editableZone; char m_draftText[TextField::maxBufferSize()]; diff --git a/apps/solver/equation_models_parameter_controller.cpp b/apps/solver/equation_models_parameter_controller.cpp index e32d4c60b..12548a91c 100644 --- a/apps/solver/equation_models_parameter_controller.cpp +++ b/apps/solver/equation_models_parameter_controller.cpp @@ -24,7 +24,7 @@ EquationModelsParameterController::EquationModelsParameterController(Responder * for (int i = 0; i < k_numberOfExpressionCells; i++) { Poincare::Expression e = Expression::parse(k_models[i+1]); m_layouts[i] = e.createLayout(Poincare::Preferences::PrintFloatMode::Decimal, Constant::ShortNumberOfSignificantDigits); - m_modelCells[i].setLayoutReference(m_layouts[i]); + m_modelCells[i].setLayout(m_layouts[i]); } } diff --git a/apps/solver/equation_models_parameter_controller.h b/apps/solver/equation_models_parameter_controller.h index 94b91f2ff..ecf57f315 100644 --- a/apps/solver/equation_models_parameter_controller.h +++ b/apps/solver/equation_models_parameter_controller.h @@ -32,7 +32,7 @@ private: constexpr static int k_numberOfExpressionCells = k_numberOfModels-1; MessageTableCell m_emptyModelCell; ExpressionTableCell m_modelCells[k_numberOfExpressionCells]; - Poincare::LayoutReference m_layouts[k_numberOfExpressionCells]; + Poincare::Layout m_layouts[k_numberOfExpressionCells]; SelectableTableView m_selectableTableView; EquationStore * m_equationStore; ListController * m_listController; diff --git a/apps/solver/equation_store.cpp b/apps/solver/equation_store.cpp index a035479cc..1e1912ebb 100644 --- a/apps/solver/equation_store.cpp +++ b/apps/solver/equation_store.cpp @@ -29,7 +29,7 @@ void EquationStore::tidy() { tidySolution(); } -Poincare::LayoutReference EquationStore::exactSolutionLayoutAtIndex(int i, bool exactLayout) { +Poincare::Layout EquationStore::exactSolutionLayoutAtIndex(int i, bool exactLayout) { assert(m_type != Type::Monovariable && i >= 0 && (i < m_numberOfSolutions || (i == m_numberOfSolutions && m_type == Type::PolynomialMonovariable))); if (exactLayout) { return m_exactSolutionExactLayouts[i]; @@ -311,8 +311,8 @@ EquationStore::Error EquationStore::oneDimensialPolynomialSolve(Expression exact void EquationStore::tidySolution() { for (int i = 0; i < k_maxNumberOfExactSolutions; i++) { - m_exactSolutionExactLayouts[i] = LayoutReference(); - m_exactSolutionApproximateLayouts[i] = LayoutReference(); + m_exactSolutionExactLayouts[i] = Layout(); + m_exactSolutionApproximateLayouts[i] = Layout(); } } diff --git a/apps/solver/equation_store.h b/apps/solver/equation_store.h index 510743afc..7917b5a02 100644 --- a/apps/solver/equation_store.h +++ b/apps/solver/equation_store.h @@ -45,7 +45,7 @@ public: * Layout and an approximate layout. For example, 'sqrt(2)' and '1.414213'. * The boolean exactLayout indicates if we want the exact layout or the * approximate one. */ - Poincare::LayoutReference exactSolutionLayoutAtIndex(int i, bool exactLayout); + Poincare::Layout exactSolutionLayoutAtIndex(int i, bool exactLayout); /* Exact layout and approximate layout of an exact solution can be: * - identical: for instance, 5 and 5 * - equal: for instance 1/2 and 0.5 @@ -86,8 +86,8 @@ private: Type m_type; char m_variables[Poincare::Expression::k_maxNumberOfVariables+1]; int m_numberOfSolutions; - Poincare::LayoutReference m_exactSolutionExactLayouts[k_maxNumberOfApproximateSolutions]; - Poincare::LayoutReference m_exactSolutionApproximateLayouts[k_maxNumberOfExactSolutions]; + Poincare::Layout m_exactSolutionExactLayouts[k_maxNumberOfApproximateSolutions]; + Poincare::Layout m_exactSolutionApproximateLayouts[k_maxNumberOfExactSolutions]; bool m_exactSolutionIdentity[k_maxNumberOfExactSolutions]; bool m_exactSolutionEquality[k_maxNumberOfExactSolutions]; double m_intervalApproximateSolutions[2]; diff --git a/apps/solver/list_controller.cpp b/apps/solver/list_controller.cpp index e41f150c4..9258d1250 100644 --- a/apps/solver/list_controller.cpp +++ b/apps/solver/list_controller.cpp @@ -161,7 +161,7 @@ bool ListController::textFieldDidFinishEditing(TextField * textField, const char return true; } -bool ListController::layoutFieldDidFinishEditing(LayoutField * layoutField, Poincare::LayoutReference layout, Ion::Events::Event event) { +bool ListController::layoutFieldDidFinishEditing(LayoutField * layoutField, Poincare::Layout layout, Ion::Events::Event event) { reloadButtonMessage(); return true; } diff --git a/apps/solver/list_controller.h b/apps/solver/list_controller.h index 2a30df8fd..9355e9f37 100644 --- a/apps/solver/list_controller.h +++ b/apps/solver/list_controller.h @@ -42,7 +42,7 @@ public: bool textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) override; bool layoutFieldDidReceiveEvent(LayoutField * layoutField, Ion::Events::Event event) override; bool textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) override; - bool layoutFieldDidFinishEditing(LayoutField * layoutField, Poincare::LayoutReference layout, Ion::Events::Event event) override; + bool layoutFieldDidFinishEditing(LayoutField * layoutField, Poincare::Layout layout, Ion::Events::Event event) override; /* Specific to Solver */ void resolveEquations(); private: diff --git a/apps/solver/solutions_controller.cpp b/apps/solver/solutions_controller.cpp index 662bcd82d..576447e15 100644 --- a/apps/solver/solutions_controller.cpp +++ b/apps/solver/solutions_controller.cpp @@ -66,9 +66,9 @@ SolutionsController::SolutionsController(Responder * parentResponder, EquationSt m_delta2Layout(), m_contentView(this) { - m_delta2Layout = HorizontalLayoutReference(VerticalOffsetLayoutReference(CharLayoutReference('2', KDText::FontSize::Small), VerticalOffsetLayoutNode::Type::Superscript), LayoutHelper::String("-4ac", 4, KDText::FontSize::Small)); + m_delta2Layout = HorizontalLayout(VerticalOffsetLayout(CharLayout('2', KDText::FontSize::Small), VerticalOffsetLayoutNode::Type::Superscript), LayoutHelper::String("-4ac", 4, KDText::FontSize::Small)); char deltaB[] = {Ion::Charset::CapitalDelta, '=', 'b'}; - static_cast(m_delta2Layout).addOrMergeChildAtIndex(LayoutHelper::String(deltaB, 3, KDText::FontSize::Small), 0, false); + static_cast(m_delta2Layout).addOrMergeChildAtIndex(LayoutHelper::String(deltaB, 3, KDText::FontSize::Small), 0, false); for (int i = 0; i < EquationStore::k_maxNumberOfExactSolutions; i++) { m_exactValueCells[i].setParentResponder(m_contentView.selectableTableView()); } @@ -145,7 +145,7 @@ void SolutionsController::willDisplayCellAtLocation(HighlightCell * cell, int i, if (i == 0) { if (m_equationStore->type() == EquationStore::Type::PolynomialMonovariable && j == m_equationStore->numberOfSolutions()) { EvenOddExpressionCell * deltaCell = static_cast(cell); - deltaCell->setLayoutReference(m_delta2Layout); + deltaCell->setLayout(m_delta2Layout); } else { EvenOddBufferTextCell * symbolCell = static_cast(cell); symbolCell->setFontSize(KDText::FontSize::Large); @@ -171,7 +171,7 @@ void SolutionsController::willDisplayCellAtLocation(HighlightCell * cell, int i, valueCell->setText(bufferValue); } else { Shared::ScrollableExactApproximateExpressionsCell * valueCell = static_cast(cell); - Poincare::LayoutReference exactLayout = m_equationStore->exactSolutionLayoutsAtIndexAreIdentical(j) ? Poincare::LayoutReference() : m_equationStore->exactSolutionLayoutAtIndex(j, true); + Poincare::Layout exactLayout = m_equationStore->exactSolutionLayoutsAtIndexAreIdentical(j) ? Poincare::Layout() : m_equationStore->exactSolutionLayoutAtIndex(j, true); valueCell->setLayouts(m_equationStore->exactSolutionLayoutAtIndex(j, false), exactLayout); if (!exactLayout.isUninitialized()) { valueCell->setEqualMessage(m_equationStore->exactSolutionLayoutsAtIndexAreEqual(j) ? I18n::Message::Equal : I18n::Message::AlmostEqual); @@ -194,8 +194,8 @@ KDCoordinate SolutionsController::rowHeight(int j) { if (m_equationStore->type() == EquationStore::Type::Monovariable) { return k_defaultCellHeight; } - Poincare::LayoutReference exactLayout = m_equationStore->exactSolutionLayoutAtIndex(j, true); - Poincare::LayoutReference approximateLayout = m_equationStore->exactSolutionLayoutAtIndex(j, false); + Poincare::Layout exactLayout = m_equationStore->exactSolutionLayoutAtIndex(j, true); + Poincare::Layout approximateLayout = m_equationStore->exactSolutionLayoutAtIndex(j, false); KDCoordinate exactLayoutHeight = exactLayout.layoutSize().height(); KDCoordinate approximateLayoutHeight = approximateLayout.layoutSize().height(); KDCoordinate layoutHeight = max(exactLayout.baseline(), approximateLayout.baseline()) + max(exactLayoutHeight-exactLayout.baseline(), approximateLayoutHeight-approximateLayout.baseline()); diff --git a/apps/solver/solutions_controller.h b/apps/solver/solutions_controller.h index 28b2b45fa..5e4cc418e 100644 --- a/apps/solver/solutions_controller.h +++ b/apps/solver/solutions_controller.h @@ -58,7 +58,7 @@ private: EquationStore * m_equationStore; EvenOddBufferTextCell m_symbolCells[EquationStore::k_maxNumberOfSolutions]; EvenOddExpressionCell m_deltaCell; - Poincare::LayoutReference m_delta2Layout; + Poincare::Layout m_delta2Layout; Shared::ScrollableExactApproximateExpressionsCell m_exactValueCells[EquationStore::k_maxNumberOfExactSolutions]; EvenOddBufferTextCell m_approximateValueCells[EquationStore::k_maxNumberOfApproximateSolutions]; ContentView m_contentView; diff --git a/apps/variable_box_controller.cpp b/apps/variable_box_controller.cpp index 6ee54332b..982f71729 100644 --- a/apps/variable_box_controller.cpp +++ b/apps/variable_box_controller.cpp @@ -150,16 +150,16 @@ void VariableBoxController::ContentViewController::willDisplayCellForIndex(Highl if (!evaluation.isUninitialized()) { /* TODO: implement list contexts */ // TODO: handle matrix and scalar! - LayoutReference layoutR = layoutRefForIndex(index); + Layout layoutR = layoutForIndex(index); const Matrix matrixEvaluation = static_cast(evaluation); - myCell->setLayoutReference(layoutR); + myCell->setLayout(layoutR); char buffer[2*PrintFloat::bufferSizeForFloatsWithPrecision(2)+1]; int numberOfChars = PrintFloat::convertFloatToText(matrixEvaluation.numberOfRows(), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(2), 2, Preferences::PrintFloatMode::Decimal); buffer[numberOfChars++] = 'x'; PrintFloat::convertFloatToText(matrixEvaluation.numberOfColumns(), buffer+numberOfChars, PrintFloat::bufferSizeForFloatsWithPrecision(2), 2, Preferences::PrintFloatMode::Decimal); myCell->setSubtitle(buffer); } else { - myCell->setLayoutReference(LayoutReference()); + myCell->setLayout(Layout()); myCell->setSubtitle(I18n::translate(I18n::Message::Empty)); } } @@ -168,7 +168,7 @@ KDCoordinate VariableBoxController::ContentViewController::rowHeight(int index) if (m_currentPage == Page::RootMenu || m_currentPage == Page::Scalar) { return Metric::ToolboxRowHeight; } - LayoutReference layoutR = layoutRefForIndex(index); + Layout layoutR = layoutForIndex(index); if (!layoutR.isUninitialized()) { return max(layoutR.layoutSize().height()+k_leafMargin, Metric::ToolboxRowHeight); } @@ -198,7 +198,7 @@ void VariableBoxController::ContentViewController::viewDidDisappear() { m_selectableTableView.deselectTable(); // Tidy the layouts used to display the VariableBoxController to clean TreePool for (int i = 0; i < k_maxNumberOfDisplayedRows; i++) { - m_leafCells[i].setLayoutReference(LayoutReference()); + m_leafCells[i].setLayout(Layout()); } ViewController::viewDidDisappear(); } @@ -258,17 +258,17 @@ const Expression VariableBoxController::ContentViewController::expressionForInde return Expression(); } -LayoutReference VariableBoxController::ContentViewController::layoutRefForIndex(int index) { +Layout VariableBoxController::ContentViewController::layoutForIndex(int index) { if (m_currentPage == Page::Matrix) { const Symbol symbol = Symbol::matrixSymbol('0'+(char)index); return m_context->layoutForSymbol(symbol, Constant::ShortNumberOfSignificantDigits); } #if LIST_VARIABLES if (m_currentPage == Page::List) { - return LayoutReference(); + return Layout(); } #endif - return LayoutReference(); + return Layout(); } VariableBoxController::VariableBoxController(GlobalContext * context) : diff --git a/apps/variable_box_controller.h b/apps/variable_box_controller.h index 81cff2610..77580d4db 100644 --- a/apps/variable_box_controller.h +++ b/apps/variable_box_controller.h @@ -53,7 +53,7 @@ private: void putLabelAtIndexInBuffer(int index, char * buffer); I18n::Message nodeLabelAtIndex(int index); const Poincare::Expression expressionForIndex(int index); - Poincare::LayoutReference layoutRefForIndex(int index); + Poincare::Layout layoutForIndex(int index); Poincare::GlobalContext * m_context; Responder * m_sender; int m_firstSelectedRow; diff --git a/apps/variable_box_leaf_cell.cpp b/apps/variable_box_leaf_cell.cpp index d7bafac4b..fdb943d96 100644 --- a/apps/variable_box_leaf_cell.cpp +++ b/apps/variable_box_leaf_cell.cpp @@ -76,8 +76,8 @@ void VariableBoxLeafCell::setSubtitle(const char * text) { layoutSubviews(); } -void VariableBoxLeafCell::setLayoutReference(LayoutReference layoutRef) { - m_expressionView.setLayoutReference(layoutRef); +void VariableBoxLeafCell::setLayout(Layout layout) { + m_expressionView.setLayout(layout); } void VariableBoxLeafCell::drawRect(KDContext * ctx, KDRect rect) const { diff --git a/apps/variable_box_leaf_cell.h b/apps/variable_box_leaf_cell.h index 899455e75..4733eb0e0 100644 --- a/apps/variable_box_leaf_cell.h +++ b/apps/variable_box_leaf_cell.h @@ -11,7 +11,7 @@ public: void reloadCell() override; void setLabel(const char * text); void setSubtitle(const char * text); - void setLayoutReference(Poincare::LayoutReference layoutRef); + void setLayout(Poincare::Layout layout); void drawRect(KDContext * ctx, KDRect rect) const override; const char * text() const override { return m_labelView.text(); diff --git a/escher/include/escher/clipboard.h b/escher/include/escher/clipboard.h index 1e457a5a8..57f14638b 100644 --- a/escher/include/escher/clipboard.h +++ b/escher/include/escher/clipboard.h @@ -8,7 +8,7 @@ class Clipboard { public: static Clipboard * sharedClipboard(); void store(const char * storedText); - void store(Poincare::LayoutReference layoutR); + void store(Poincare::Layout layoutR); const char * storedText(); void reset(); private: diff --git a/escher/include/escher/even_odd_expression_cell.h b/escher/include/escher/even_odd_expression_cell.h index a1f0a662e..5978cfca8 100644 --- a/escher/include/escher/even_odd_expression_cell.h +++ b/escher/include/escher/even_odd_expression_cell.h @@ -10,14 +10,14 @@ public: KDColor textColor = KDColorBlack, KDColor backgroundColor = KDColorWhite); void setEven(bool even) override; void setHighlighted(bool highlight) override; - void setLayoutReference(Poincare::LayoutReference layoutRef); + void setLayout(Poincare::Layout layout); void setBackgroundColor(KDColor backgroundColor); void setTextColor(KDColor textColor); KDSize minimalSizeForOptimalDisplay() const override; void setAlignment(float horizontalAlignment, float verticalAlignment) { m_expressionView.setAlignment(horizontalAlignment, verticalAlignment); } void setLeftMargin(KDCoordinate margin); void setRightMargin(KDCoordinate margin); - Poincare::LayoutReference layoutRef() const override { return m_expressionView.layoutRef(); } + Poincare::Layout layout() const override { return m_expressionView.layout(); } void drawRect(KDContext * ctx, KDRect rect) const override; protected: int numberOfSubviews() const override; diff --git a/escher/include/escher/expression_field.h b/escher/include/escher/expression_field.h index 572c1945a..f7c039a5f 100644 --- a/escher/include/escher/expression_field.h +++ b/escher/include/escher/expression_field.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include class ExpressionField : public Responder, public View { public: diff --git a/escher/include/escher/expression_table_cell.h b/escher/include/escher/expression_table_cell.h index 450688e24..cb0719ba0 100644 --- a/escher/include/escher/expression_table_cell.h +++ b/escher/include/escher/expression_table_cell.h @@ -9,8 +9,8 @@ public: ExpressionTableCell(Layout layout = Layout::Horizontal); View * labelView() const override; void setHighlighted(bool highlight) override; - void setLayoutReference(Poincare::LayoutReference layoutR); - Poincare::LayoutReference layoutRef() const override { return m_labelExpressionView.layoutRef(); } + void setLayout(Poincare::Layout layoutR); + Poincare::Layout layout() const override { return m_labelExpressionView.layout(); } private: ExpressionView m_labelExpressionView; }; diff --git a/escher/include/escher/expression_view.h b/escher/include/escher/expression_view.h index e267d5628..0a1bdb7fe 100644 --- a/escher/include/escher/expression_view.h +++ b/escher/include/escher/expression_view.h @@ -3,7 +3,7 @@ #include #include -#include +#include /* This class does not handle the expression layout as the size of the layout is * needed to compute the size of table cells hosting the expression. As the size @@ -15,8 +15,8 @@ class ExpressionView : public View { public: ExpressionView(float horizontalAlignment = 0.0f, float verticalAlignment = 0.5f, KDColor textColor = KDColorBlack, KDColor backgroundColor = KDColorWhite); - Poincare::LayoutReference layoutRef() const { return m_layoutRef; } - void setLayoutReference(Poincare::LayoutReference layoutRef); + Poincare::Layout layout() const { return m_layout; } + void setLayout(Poincare::Layout layout); void drawRect(KDContext * ctx, KDRect rect) const override; void setBackgroundColor(KDColor backgroundColor); void setTextColor(KDColor textColor); @@ -32,7 +32,7 @@ private: * layout is always possessed by a controller which only gives a pointer to * the expression view (without cloning it). The named controller is then * responsible for freeing the expression layout when required. */ - mutable Poincare::LayoutReference m_layoutRef; // TODO find better way to have minimalSizeForOptimalDisplay const + mutable Poincare::Layout m_layout; // TODO find better way to have minimalSizeForOptimalDisplay const float m_horizontalAlignment; float m_verticalAlignment; KDColor m_textColor; diff --git a/escher/include/escher/highlight_cell.h b/escher/include/escher/highlight_cell.h index 416240b70..10436c329 100644 --- a/escher/include/escher/highlight_cell.h +++ b/escher/include/escher/highlight_cell.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include class HighlightCell : public View { public: @@ -18,8 +18,8 @@ public: virtual const char * text() const { return nullptr; } - virtual Poincare::LayoutReference layoutRef() const { - return Poincare::LayoutReference(); + virtual Poincare::Layout layout() const { + return Poincare::Layout(); } protected: bool m_highlighted; diff --git a/escher/include/escher/input_view_controller.h b/escher/include/escher/input_view_controller.h index 00138b32e..f9977cb35 100644 --- a/escher/include/escher/input_view_controller.h +++ b/escher/include/escher/input_view_controller.h @@ -29,7 +29,7 @@ public: /* LayoutFieldDelegate */ bool layoutFieldShouldFinishEditing(LayoutField * layoutField, Ion::Events::Event event) override; bool layoutFieldDidReceiveEvent(LayoutField * layoutField, Ion::Events::Event event) override; - bool layoutFieldDidFinishEditing(LayoutField * layoutField, Poincare::LayoutReference layoutR, Ion::Events::Event event) override; + bool layoutFieldDidFinishEditing(LayoutField * layoutField, Poincare::Layout layoutR, Ion::Events::Event event) override; bool layoutFieldDidAbortEditing(LayoutField * layoutField) override; void layoutFieldDidChangeSize(LayoutField * layoutField) override; Toolbox * toolboxForLayoutField(LayoutField * layoutField) override; diff --git a/escher/include/escher/layout_field.h b/escher/include/escher/layout_field.h index 2f8da33d6..0deb38204 100644 --- a/escher/include/escher/layout_field.h +++ b/escher/include/escher/layout_field.h @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include class LayoutField : public ScrollableView, public ScrollViewDataSource { @@ -25,10 +25,10 @@ public: scrollToBaselinedRect(m_contentView.cursorRect(), m_contentView.cursor()->baseline()); } void reload(); - bool hasText() const { return layoutRef().hasText(); } - int serialize(char * buffer, int bufferLength) { return layoutRef().serialize(buffer, bufferLength); } - Poincare::LayoutReference layoutRef() const { return m_contentView.expressionView()->layoutRef(); } - char XNTChar() { return m_contentView.cursor()->layoutReference().XNTChar(); } + bool hasText() const { return layout().hasText(); } + int serialize(char * buffer, int bufferLength) { return layout().serialize(buffer, bufferLength); } + Poincare::Layout layout() const { return m_contentView.expressionView()->layout(); } + char XNTChar() { return m_contentView.cursor()->layouterence().XNTChar(); } // ScrollableView void setBackgroundColor(KDColor c) override { @@ -59,9 +59,9 @@ protected: private: constexpr static int k_maxNumberOfLayouts = 152; static_assert(k_maxNumberOfLayouts == TextField::maxBufferSize(), "Maximal number of layouts in a layout field should be equal to max number of char in text field"); - void scrollRightOfLayout(Poincare::LayoutReference layoutR); + void scrollRightOfLayout(Poincare::Layout layoutR); void scrollToBaselinedRect(KDRect rect, KDCoordinate baseline); - void insertLayoutAtCursor(Poincare::LayoutReference layoutR, Poincare::LayoutReference pointedLayoutReference, bool forceCursorRightOfLayout = false); + void insertLayoutAtCursor(Poincare::Layout layoutR, Poincare::Layout pointedLayout, bool forceCursorRightOfLayout = false); class ContentView : public View { public: diff --git a/escher/include/escher/layout_field_delegate.h b/escher/include/escher/layout_field_delegate.h index a40698b3a..eb98b886f 100644 --- a/escher/include/escher/layout_field_delegate.h +++ b/escher/include/escher/layout_field_delegate.h @@ -10,7 +10,7 @@ class LayoutFieldDelegate { public: virtual bool layoutFieldShouldFinishEditing(LayoutField * layoutField, Ion::Events::Event event) = 0; virtual bool layoutFieldDidReceiveEvent(LayoutField * layoutField, Ion::Events::Event event) = 0; - virtual bool layoutFieldDidFinishEditing(LayoutField * layoutField, Poincare::LayoutReference layoutR, Ion::Events::Event event) { return false; } + virtual bool layoutFieldDidFinishEditing(LayoutField * layoutField, Poincare::Layout layoutR, Ion::Events::Event event) { return false; } virtual bool layoutFieldDidAbortEditing(LayoutField * layoutField) { return false; } virtual void layoutFieldDidChangeSize(LayoutField * layoutField) {} virtual Toolbox * toolboxForLayoutField(LayoutField * layoutField) = 0; diff --git a/escher/include/escher/message_table_cell_with_chevron_and_expression.h b/escher/include/escher/message_table_cell_with_chevron_and_expression.h index 035c85f36..d6d196df0 100644 --- a/escher/include/escher/message_table_cell_with_chevron_and_expression.h +++ b/escher/include/escher/message_table_cell_with_chevron_and_expression.h @@ -9,7 +9,7 @@ public: MessageTableCellWithChevronAndExpression(I18n::Message message = (I18n::Message)0, KDText::FontSize size = KDText::FontSize::Small); View * subAccessoryView() const override; void setHighlighted(bool highlight) override; - void setLayoutReference(Poincare::LayoutReference layoutR); + void setLayout(Poincare::Layout layoutR); private: ExpressionView m_subtitleView; }; diff --git a/escher/include/escher/message_table_cell_with_expression.h b/escher/include/escher/message_table_cell_with_expression.h index dfbc06a22..369b4180d 100644 --- a/escher/include/escher/message_table_cell_with_expression.h +++ b/escher/include/escher/message_table_cell_with_expression.h @@ -9,7 +9,7 @@ public: MessageTableCellWithExpression(I18n::Message message = (I18n::Message)0, KDText::FontSize size = KDText::FontSize::Small); View * accessoryView() const override; void setHighlighted(bool highlight) override; - void setLayoutReference(Poincare::LayoutReference layout); + void setLayout(Poincare::Layout layout); private: ExpressionView m_subtitleView; }; diff --git a/escher/src/clipboard.cpp b/escher/src/clipboard.cpp index fc4e0ec72..a2d5bd12f 100644 --- a/escher/src/clipboard.cpp +++ b/escher/src/clipboard.cpp @@ -10,7 +10,7 @@ void Clipboard::store(const char * storedText) { strlcpy(m_textBuffer, storedText, TextField::maxBufferSize()); } -void Clipboard::store(Poincare::LayoutReference layoutR) { +void Clipboard::store(Poincare::Layout layoutR) { layoutR.serialize(m_textBuffer, TextField::maxBufferSize()); } diff --git a/escher/src/even_odd_expression_cell.cpp b/escher/src/even_odd_expression_cell.cpp index c14d40c2d..8709cc829 100644 --- a/escher/src/even_odd_expression_cell.cpp +++ b/escher/src/even_odd_expression_cell.cpp @@ -23,8 +23,8 @@ void EvenOddExpressionCell::setEven(bool even) { m_expressionView.setBackgroundColor(backgroundColor()); } -void EvenOddExpressionCell::setLayoutReference(LayoutReference layoutR) { - m_expressionView.setLayoutReference(layoutR); +void EvenOddExpressionCell::setLayout(Layout layoutR) { + m_expressionView.setLayout(layoutR); } void EvenOddExpressionCell::setBackgroundColor(KDColor backgroundColor) { diff --git a/escher/src/expression_table_cell.cpp b/escher/src/expression_table_cell.cpp index 7a220982d..59012100d 100644 --- a/escher/src/expression_table_cell.cpp +++ b/escher/src/expression_table_cell.cpp @@ -18,7 +18,7 @@ void ExpressionTableCell::setHighlighted(bool highlight) { m_labelExpressionView.setBackgroundColor(backgroundColor); } -void ExpressionTableCell::setLayoutReference(Poincare::LayoutReference layoutR) { - m_labelExpressionView.setLayoutReference(layoutR); +void ExpressionTableCell::setLayout(Poincare::Layout layoutR) { + m_labelExpressionView.setLayout(layoutR); layoutSubviews(); } diff --git a/escher/src/expression_view.cpp b/escher/src/expression_view.cpp index dfe2c183f..8203333b5 100644 --- a/escher/src/expression_view.cpp +++ b/escher/src/expression_view.cpp @@ -3,7 +3,7 @@ using namespace Poincare; ExpressionView::ExpressionView(float horizontalAlignment, float verticalAlignment, KDColor textColor, KDColor backgroundColor) : - m_layoutRef(), + m_layout(), m_horizontalAlignment(horizontalAlignment), m_verticalAlignment(verticalAlignment), m_textColor(textColor), @@ -12,8 +12,8 @@ ExpressionView::ExpressionView(float horizontalAlignment, float verticalAlignmen { } -void ExpressionView::setLayoutReference(LayoutReference layoutR) { - m_layoutRef = layoutR; +void ExpressionView::setLayout(Layout layoutR) { + m_layout = layoutR; markRectAsDirty(bounds()); } @@ -38,19 +38,19 @@ void ExpressionView::setAlignment(float horizontalAlignment, float verticalAlign } int ExpressionView::numberOfLayouts() const { - return m_layoutRef.numberOfDescendants(true); + return m_layout.numberOfDescendants(true); } KDSize ExpressionView::minimalSizeForOptimalDisplay() const { - if (m_layoutRef.isUninitialized()) { + if (m_layout.isUninitialized()) { return KDSizeZero; } - KDSize expressionSize = m_layoutRef.layoutSize(); + KDSize expressionSize = m_layout.layoutSize(); return KDSize(expressionSize.width() + 2*m_horizontalMargin, expressionSize.height()); } KDPoint ExpressionView::drawingOrigin() const { - KDSize expressionSize = m_layoutRef.layoutSize(); + KDSize expressionSize = m_layout.layoutSize(); return KDPoint(m_horizontalMargin + m_horizontalAlignment*(m_frame.width() - 2*m_horizontalMargin - expressionSize.width()), max(0, (m_frame.height() - expressionSize.height())/2)); } @@ -60,7 +60,7 @@ KDPoint ExpressionView::absoluteDrawingOrigin() const { void ExpressionView::drawRect(KDContext * ctx, KDRect rect) const { ctx->fillRect(rect, m_backgroundColor); - if (!m_layoutRef.isUninitialized()) { - m_layoutRef.draw(ctx, drawingOrigin(), m_textColor, m_backgroundColor); + if (!m_layout.isUninitialized()) { + m_layout.draw(ctx, drawingOrigin(), m_textColor, m_backgroundColor); } } diff --git a/escher/src/input_view_controller.cpp b/escher/src/input_view_controller.cpp index 8e105e079..41aba11c9 100644 --- a/escher/src/input_view_controller.cpp +++ b/escher/src/input_view_controller.cpp @@ -76,7 +76,7 @@ bool InputViewController::layoutFieldDidReceiveEvent(LayoutField * layoutField, return m_layoutFieldDelegate->layoutFieldDidReceiveEvent(layoutField, event); } -bool InputViewController::layoutFieldDidFinishEditing(LayoutField * layoutField, Poincare::LayoutReference layoutR, Ion::Events::Event event) { +bool InputViewController::layoutFieldDidFinishEditing(LayoutField * layoutField, Poincare::Layout layoutR, Ion::Events::Event event) { inputViewDidFinishEditing(); m_layoutFieldDelegate->layoutFieldDidFinishEditing(layoutField, layoutR, event); return true; diff --git a/escher/src/layout_field.cpp b/escher/src/layout_field.cpp index 98f2d5c11..048a4d1d0 100644 --- a/escher/src/layout_field.cpp +++ b/escher/src/layout_field.cpp @@ -25,9 +25,9 @@ void LayoutField::ContentView::setEditing(bool isEditing) { } void LayoutField::ContentView::clearLayout() { - HorizontalLayoutReference h; - m_expressionView.setLayoutReference(h); - m_cursor.setLayoutReference(h); + HorizontalLayout h; + m_expressionView.setLayout(h); + m_cursor.setLayout(h); } KDSize LayoutField::ContentView::minimalSizeForOptimalDisplay() const { @@ -52,11 +52,11 @@ void LayoutField::ContentView::layoutCursorSubview() { return; } KDPoint expressionViewOrigin = m_expressionView.absoluteDrawingOrigin(); - LayoutReference pointedLayoutR = m_cursor.layoutReference(); + Layout pointedLayoutR = m_cursor.layouterence(); LayoutCursor::Position cursorPosition = m_cursor.position(); LayoutCursor eqCursor = pointedLayoutR.equivalentCursor(&m_cursor); - if (eqCursor.isDefined() && pointedLayoutR.hasChild(eqCursor.layoutReference())) { - pointedLayoutR = eqCursor.layoutReference(); + if (eqCursor.isDefined() && pointedLayoutR.hasChild(eqCursor.layouterence())) { + pointedLayoutR = eqCursor.layouterence(); cursorPosition = eqCursor.position(); } KDPoint cursoredExpressionViewOrigin = pointedLayoutR.absoluteOrigin(); @@ -70,7 +70,7 @@ void LayoutField::ContentView::layoutCursorSubview() { void LayoutField::reload() { KDSize previousSize = minimalSizeForOptimalDisplay(); - layoutRef().invalidAllSizesPositionsAndBaselines(); + layout().invalidAllSizesPositionsAndBaselines(); KDSize newSize = minimalSizeForOptimalDisplay(); if (m_delegate && previousSize.height() != newSize.height()) { m_delegate->layoutFieldDidChangeSize(this); @@ -114,30 +114,30 @@ bool LayoutField::handleEventWithText(const char * text, bool indentation, bool if (resultExpression.isUninitialized()) { m_contentView.cursor()->insertText(text); } else { - LayoutReference resultLayoutReference = resultExpression.createLayout(Poincare::Preferences::sharedPreferences()->displayMode(), Poincare::PrintFloat::k_numberOfStoredSignificantDigits); - if (currentNumberOfLayouts + resultLayoutReference.numberOfDescendants(true) >= k_maxNumberOfLayouts) { + Layout resultLayout = resultExpression.createLayout(Poincare::Preferences::sharedPreferences()->displayMode(), Poincare::PrintFloat::k_numberOfStoredSignificantDigits); + if (currentNumberOfLayouts + resultLayout.numberOfDescendants(true) >= k_maxNumberOfLayouts) { return true; } // Find the pointed layout. - LayoutReference pointedLayoutReference; + Layout pointedLayout; if (strcmp(text, I18n::translate(I18n::Message::RandomCommandWithArg)) == 0) { /* Special case: if the text is "random()", the cursor should not be set * inside the parentheses. */ - pointedLayoutReference = resultLayoutReference; - } else if (resultLayoutReference.isHorizontal()) { + pointedLayout = resultLayout; + } else if (resultLayout.isHorizontal()) { /* If the layout is horizontal, pick the first open parenthesis. For now, * all horizontal layouts in MathToolbox have parentheses. */ - for (int i = 0; i < resultLayoutReference.numberOfChildren(); i++) { - LayoutReference l = resultLayoutReference.childAtIndex(i); + for (int i = 0; i < resultLayout.numberOfChildren(); i++) { + Layout l = resultLayout.childAtIndex(i); if (l.isLeftParenthesis()) { - pointedLayoutReference = l; + pointedLayout = l; break; } } } /* Insert the layout. If pointedLayout is uninitialized, the cursor will * be on the right of the inserted layout. */ - insertLayoutAtCursor(resultLayoutReference, pointedLayoutReference, forceCursorRightOfText); + insertLayoutAtCursor(resultLayout, pointedLayout, forceCursorRightOfText); } } return true; @@ -185,14 +185,14 @@ bool LayoutField::privateHandleEvent(Ion::Events::Event event) { } if (isEditing() && m_delegate->layoutFieldShouldFinishEditing(this, event)) { //TODO use class method? setEditing(false); - if (m_delegate->layoutFieldDidFinishEditing(this, layoutRef(), event)) { + if (m_delegate->layoutFieldDidFinishEditing(this, layout(), event)) { clearLayout(); } return true; } if ((event == Ion::Events::OK || event == Ion::Events::EXE) && !isEditing()) { setEditing(true); - m_contentView.cursor()->setLayoutReference(layoutRef()); + m_contentView.cursor()->setLayout(layout()); m_contentView.cursor()->setPosition(LayoutCursor::Position::Right); return true; } @@ -235,16 +235,16 @@ bool LayoutField::privateHandleMoveEvent(Ion::Events::Event event, bool * should result = m_contentView.cursor()->cursorAtDirection(LayoutCursor::MoveDirection::Down, shouldRecomputeLayout); } else if (event == Ion::Events::ShiftLeft) { *shouldRecomputeLayout = true; - if (m_contentView.cursor()->layoutReference().removeGreySquaresFromAllMatrixAncestors()) { + if (m_contentView.cursor()->layouterence().removeGreySquaresFromAllMatrixAncestors()) { *shouldRecomputeLayout = true; } - result.setLayoutReference(layoutRef()); + result.setLayout(layout()); result.setPosition(LayoutCursor::Position::Left); } else if (event == Ion::Events::ShiftRight) { - if (m_contentView.cursor()->layoutReference().removeGreySquaresFromAllMatrixAncestors()) { + if (m_contentView.cursor()->layouterence().removeGreySquaresFromAllMatrixAncestors()) { *shouldRecomputeLayout = true; } - result.setLayoutReference(layoutRef()); + result.setLayout(layout()); result.setPosition(LayoutCursor::Position::Right); } if (result.isDefined()) { @@ -254,7 +254,7 @@ bool LayoutField::privateHandleMoveEvent(Ion::Events::Event event, bool * should return false; } -void LayoutField::scrollRightOfLayout(LayoutReference layoutR) { +void LayoutField::scrollRightOfLayout(Layout layoutR) { KDRect layoutRect(layoutR.absoluteOrigin().translatedBy(m_contentView.expressionView()->drawingOrigin()), layoutR.layoutSize()); scrollToBaselinedRect(layoutRect, layoutR.baseline()); } @@ -269,7 +269,7 @@ void LayoutField::scrollToBaselinedRect(KDRect rect, KDCoordinate baseline) { scrollToContentRect(balancedRect, true); } -void LayoutField::insertLayoutAtCursor(LayoutReference layoutR, LayoutReference pointedLayoutR, bool forceCursorRightOfLayout) { +void LayoutField::insertLayoutAtCursor(Layout layoutR, Layout pointedLayoutR, bool forceCursorRightOfLayout) { if (layoutR.isUninitialized()) { return; } @@ -278,7 +278,7 @@ void LayoutField::insertLayoutAtCursor(LayoutReference layoutR, LayoutReference m_contentView.cursor()->showEmptyLayoutIfNeeded(); bool layoutWillBeMerged = layoutR.isHorizontal(); - LayoutReference lastMergedLayoutChild = layoutWillBeMerged ? layoutR.childAtIndex(layoutR.numberOfChildren()-1) : LayoutReference(); + Layout lastMergedLayoutChild = layoutWillBeMerged ? layoutR.childAtIndex(layoutR.numberOfChildren()-1) : Layout(); // Add the layout m_contentView.cursor()->addLayoutAndMoveCursor(layoutR); @@ -287,19 +287,19 @@ void LayoutField::insertLayoutAtCursor(LayoutReference layoutR, LayoutReference if(!forceCursorRightOfLayout) { if (!pointedLayoutR.isUninitialized() && (!layoutWillBeMerged || pointedLayoutR != layoutR)) { // Make sure the layout was inserted (its parent is not uninitialized) - m_contentView.cursor()->setLayoutReference(pointedLayoutR); + m_contentView.cursor()->setLayout(pointedLayoutR); m_contentView.cursor()->setPosition(LayoutCursor::Position::Right); } else if (!layoutWillBeMerged) { - m_contentView.cursor()->setLayoutReference(layoutR.layoutToPointWhenInserting()); + m_contentView.cursor()->setLayout(layoutR.layoutToPointWhenInserting()); m_contentView.cursor()->setPosition(LayoutCursor::Position::Right); } } else if (!layoutWillBeMerged) { - m_contentView.cursor()->setLayoutReference(layoutR); + m_contentView.cursor()->setLayout(layoutR); m_contentView.cursor()->setPosition(LayoutCursor::Position::Right); } // Handle matrices - m_contentView.cursor()->layoutReference().addGreySquaresToAllMatrixAncestors(); + m_contentView.cursor()->layouterence().addGreySquaresToAllMatrixAncestors(); // Handle empty layouts m_contentView.cursor()->hideEmptyLayoutIfNeeded(); diff --git a/escher/src/message_table_cell_with_chevron_and_expression.cpp b/escher/src/message_table_cell_with_chevron_and_expression.cpp index ca1591520..f568fc4a3 100644 --- a/escher/src/message_table_cell_with_chevron_and_expression.cpp +++ b/escher/src/message_table_cell_with_chevron_and_expression.cpp @@ -17,8 +17,8 @@ void MessageTableCellWithChevronAndExpression::setHighlighted(bool highlight) { m_subtitleView.setBackgroundColor(backgroundColor); } -void MessageTableCellWithChevronAndExpression::setLayoutReference(Poincare::LayoutReference layoutR) { - m_subtitleView.setLayoutReference(layoutR); +void MessageTableCellWithChevronAndExpression::setLayout(Poincare::Layout layoutR) { + m_subtitleView.setLayout(layoutR); reloadCell(); layoutSubviews(); } diff --git a/escher/src/message_table_cell_with_expression.cpp b/escher/src/message_table_cell_with_expression.cpp index 181c24997..345a3e9f8 100644 --- a/escher/src/message_table_cell_with_expression.cpp +++ b/escher/src/message_table_cell_with_expression.cpp @@ -17,8 +17,8 @@ void MessageTableCellWithExpression::setHighlighted(bool highlight) { m_subtitleView.setBackgroundColor(backgroundColor); } -void MessageTableCellWithExpression::setLayoutReference(Poincare::LayoutReference layout) { - m_subtitleView.setLayoutReference(layout); +void MessageTableCellWithExpression::setLayout(Poincare::Layout layout) { + m_subtitleView.setLayout(layout); reloadCell(); layoutSubviews(); } diff --git a/escher/src/selectable_table_view.cpp b/escher/src/selectable_table_view.cpp index de021a8dd..e869b21cc 100644 --- a/escher/src/selectable_table_view.cpp +++ b/escher/src/selectable_table_view.cpp @@ -128,7 +128,7 @@ bool SelectableTableView::handleEvent(Ion::Events::Event event) { Clipboard::sharedClipboard()->store(text); return true; } - Poincare::LayoutReference layoutR = cell->layoutRef(); + Poincare::Layout layoutR = cell->layout(); if (!layoutR.isUninitialized()) { Clipboard::sharedClipboard()->store(layoutR); return true; diff --git a/poincare/Makefile b/poincare/Makefile index d09a2bcff..e73262464 100644 --- a/poincare/Makefile +++ b/poincare/Makefile @@ -17,7 +17,7 @@ objs += $(addprefix poincare/src/,\ integral_layout.o\ layout_cursor.o\ layout.o\ - layout_reference.o\ + layout_node.o\ left_parenthesis_layout.o\ left_square_bracket_layout.o\ matrix_layout.o\ diff --git a/poincare/include/poincare.h b/poincare/include/poincare.h index bdf3afea4..d02af80f1 100644 --- a/poincare/include/poincare.h +++ b/poincare/include/poincare.h @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include diff --git a/poincare/include/poincare/absolute_value.h b/poincare/include/poincare/absolute_value.h index 5428f8eda..806243adc 100644 --- a/poincare/include/poincare/absolute_value.h +++ b/poincare/include/poincare/absolute_value.h @@ -34,7 +34,7 @@ public: } // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "abs"); } diff --git a/poincare/include/poincare/absolute_value_layout.h b/poincare/include/poincare/absolute_value_layout.h index 35ecc8e2f..7c7280fb1 100644 --- a/poincare/include/poincare/absolute_value_layout.h +++ b/poincare/include/poincare/absolute_value_layout.h @@ -30,10 +30,10 @@ private: bool renderBottomBar() const override { return false; } }; -class AbsoluteValueLayoutReference : public LayoutReference { +class AbsoluteValueLayout : public Layout { public: - explicit AbsoluteValueLayoutReference(LayoutReference l) : - LayoutReference(TreePool::sharedPool()->createTreeNode()) + explicit AbsoluteValueLayout(Layout l) : + Layout(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, l); } diff --git a/poincare/include/poincare/addition.h b/poincare/include/poincare/addition.h index 0efed869e..a8c3a490c 100644 --- a/poincare/include/poincare/addition.h +++ b/poincare/include/poincare/addition.h @@ -40,7 +40,7 @@ public: private: // Layout bool childNeedsParenthesis(const SerializationHelperInterface * child) const override; - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Infix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/include/poincare/arc_cosine.h b/poincare/include/poincare/arc_cosine.h index ebb989411..9db975d2b 100644 --- a/poincare/include/poincare/arc_cosine.h +++ b/poincare/include/poincare/arc_cosine.h @@ -24,7 +24,7 @@ public: Type type() const override { return Type::ArcCosine; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/include/poincare/arc_sine.h b/poincare/include/poincare/arc_sine.h index 73acbe250..1cf0a2fa1 100644 --- a/poincare/include/poincare/arc_sine.h +++ b/poincare/include/poincare/arc_sine.h @@ -24,7 +24,7 @@ public: Type type() const override { return Type::ArcSine; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/include/poincare/arc_tangent.h b/poincare/include/poincare/arc_tangent.h index 5c08a6044..221c05294 100644 --- a/poincare/include/poincare/arc_tangent.h +++ b/poincare/include/poincare/arc_tangent.h @@ -24,7 +24,7 @@ public: Type type() const override { return Type::ArcTangent; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/include/poincare/binomial_coefficient.h b/poincare/include/poincare/binomial_coefficient.h index 87206c51e..f88fc91b6 100644 --- a/poincare/include/poincare/binomial_coefficient.h +++ b/poincare/include/poincare/binomial_coefficient.h @@ -26,7 +26,7 @@ public: template static T compute(T k, T n); private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; diff --git a/poincare/include/poincare/binomial_coefficient_layout.h b/poincare/include/poincare/binomial_coefficient_layout.h index 4396951b2..39e8bd236 100644 --- a/poincare/include/poincare/binomial_coefficient_layout.h +++ b/poincare/include/poincare/binomial_coefficient_layout.h @@ -3,7 +3,6 @@ #include #include -#include #include namespace Poincare { @@ -42,10 +41,10 @@ private: LayoutNode * kLayout() { return childAtIndex(1); } }; -class BinomialCoefficientLayoutReference : public LayoutReference { +class BinomialCoefficientLayout : public Layout { public: - BinomialCoefficientLayoutReference(LayoutReference n, LayoutReference k) : - LayoutReference(TreePool::sharedPool()->createTreeNode()) + BinomialCoefficientLayout(Layout n, Layout k) : + Layout(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, n); replaceChildAtIndexInPlace(1, k); diff --git a/poincare/include/poincare/bracket_layout.h b/poincare/include/poincare/bracket_layout.h index 5134f9c48..3a1e4d329 100644 --- a/poincare/include/poincare/bracket_layout.h +++ b/poincare/include/poincare/bracket_layout.h @@ -3,7 +3,6 @@ #include #include -#include namespace Poincare { diff --git a/poincare/include/poincare/bracket_pair_layout.h b/poincare/include/poincare/bracket_pair_layout.h index 01e75fc43..c3e33309b 100644 --- a/poincare/include/poincare/bracket_pair_layout.h +++ b/poincare/include/poincare/bracket_pair_layout.h @@ -3,7 +3,6 @@ #include #include -#include namespace Poincare { diff --git a/poincare/include/poincare/ceiling.h b/poincare/include/poincare/ceiling.h index 182d95a85..aa24b8dac 100644 --- a/poincare/include/poincare/ceiling.h +++ b/poincare/include/poincare/ceiling.h @@ -22,7 +22,7 @@ public: Type type() const override { return Type::Ceiling; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; const char * name() const { return "ceil"; } // Simplification diff --git a/poincare/include/poincare/ceiling_layout.h b/poincare/include/poincare/ceiling_layout.h index 1c905d85e..5fecb2038 100644 --- a/poincare/include/poincare/ceiling_layout.h +++ b/poincare/include/poincare/ceiling_layout.h @@ -27,9 +27,9 @@ protected: bool renderBottomBar() const override { return false; } }; -class CeilingLayoutReference : public LayoutReference { +class CeilingLayout : public Layout { public: - explicit CeilingLayoutReference(LayoutReference l) : LayoutReference(TreePool::sharedPool()->createTreeNode()) { + explicit CeilingLayout(Layout l) : Layout(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, l); } }; diff --git a/poincare/include/poincare/char_layout.h b/poincare/include/poincare/char_layout.h index 8245a88eb..a258c6709 100644 --- a/poincare/include/poincare/char_layout.h +++ b/poincare/include/poincare/char_layout.h @@ -3,7 +3,6 @@ #include #include -#include #include namespace Poincare { @@ -54,13 +53,13 @@ private: KDText::FontSize m_fontSize; }; -class CharLayoutReference : public LayoutReference { +class CharLayout : public Layout { public: - CharLayoutReference(char c, KDText::FontSize fontSize = KDText::FontSize::Large); - KDText::FontSize fontSize() const { return const_cast(this)->node()->fontSize(); } + CharLayout(char c, KDText::FontSize fontSize = KDText::FontSize::Large); + KDText::FontSize fontSize() const { return const_cast(this)->node()->fontSize(); } private: - using LayoutReference::node; - CharLayoutNode * node() { return static_cast(LayoutReference::node());} + using Layout::node; + CharLayoutNode * node() { return static_cast(Layout::node());} }; } diff --git a/poincare/include/poincare/complex_argument.h b/poincare/include/poincare/complex_argument.h index 353b5004e..97ce58c45 100644 --- a/poincare/include/poincare/complex_argument.h +++ b/poincare/include/poincare/complex_argument.h @@ -22,7 +22,7 @@ public: Type type() const override { return Type::ComplexArgument; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; const char * name() const { return "arg"; } // Simplification Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; diff --git a/poincare/include/poincare/condensed_sum_layout.h b/poincare/include/poincare/condensed_sum_layout.h index 9840c121e..f19d423ac 100644 --- a/poincare/include/poincare/condensed_sum_layout.h +++ b/poincare/include/poincare/condensed_sum_layout.h @@ -2,9 +2,8 @@ #define POINCARE_CONDENSED_SUM_LAYOUT_NODE_H #include -#include #include -#include +#include #include namespace Poincare { @@ -49,9 +48,9 @@ private: LayoutNode * superscriptLayout() { return childAtIndex(2); } }; -class CondensedSumLayoutReference : public LayoutReference { +class CondensedSumLayout : public Layout { public: - CondensedSumLayoutReference(LayoutReference base, LayoutReference subscript, LayoutReference superscript); + CondensedSumLayout(Layout base, Layout subscript, Layout superscript); }; } diff --git a/poincare/include/poincare/confidence_interval.h b/poincare/include/poincare/confidence_interval.h index f50110940..ad4f7bd94 100644 --- a/poincare/include/poincare/confidence_interval.h +++ b/poincare/include/poincare/confidence_interval.h @@ -24,7 +24,7 @@ public: int polynomialDegree(char symbolName) const override { return -1; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; virtual const char * name() const { return "confidence"; } // Simplification diff --git a/poincare/include/poincare/conjugate.h b/poincare/include/poincare/conjugate.h index c83cb310a..fecd6375a 100644 --- a/poincare/include/poincare/conjugate.h +++ b/poincare/include/poincare/conjugate.h @@ -22,7 +22,7 @@ public: Type type() const override { return Type::Conjugate; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; diff --git a/poincare/include/poincare/conjugate_layout.h b/poincare/include/poincare/conjugate_layout.h index 666acca82..79e368aed 100644 --- a/poincare/include/poincare/conjugate_layout.h +++ b/poincare/include/poincare/conjugate_layout.h @@ -3,7 +3,6 @@ #include #include -#include namespace Poincare { @@ -39,9 +38,9 @@ private: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; }; -class ConjugateLayoutReference : public LayoutReference { +class ConjugateLayout : public Layout { public: - explicit ConjugateLayoutReference(LayoutReference l) : LayoutReference(TreePool::sharedPool()->createTreeNode()) { + explicit ConjugateLayout(Layout l) : Layout(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, l); } }; diff --git a/poincare/include/poincare/cosine.h b/poincare/include/poincare/cosine.h index 41c4d79ad..aa95f0249 100644 --- a/poincare/include/poincare/cosine.h +++ b/poincare/include/poincare/cosine.h @@ -28,7 +28,7 @@ public: private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/include/poincare/decimal.h b/poincare/include/poincare/decimal.h index bc6ef7647..697b1a74b 100644 --- a/poincare/include/poincare/decimal.h +++ b/poincare/include/poincare/decimal.h @@ -68,7 +68,7 @@ public: int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode = Preferences::PrintFloatMode::Decimal, int numberOfSignificantDigits = 0) const override; // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; private: // Worst case is -1.2345678901234E-1000 constexpr static int k_maxBufferSize = PrintFloat::k_numberOfStoredSignificantDigits+1+1+1+1+4+1; diff --git a/poincare/include/poincare/derivative.h b/poincare/include/poincare/derivative.h index adcefc466..0f99cd486 100644 --- a/poincare/include/poincare/derivative.h +++ b/poincare/include/poincare/derivative.h @@ -26,7 +26,7 @@ public: private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return LayoutHelper::Prefix(this, floatDisplayMode, numberOfSignificantDigits, name()); } int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { diff --git a/poincare/include/poincare/determinant.h b/poincare/include/poincare/determinant.h index 07257199b..e6920b2b5 100644 --- a/poincare/include/poincare/determinant.h +++ b/poincare/include/poincare/determinant.h @@ -21,7 +21,7 @@ public: Type type() const override { return Type::Determinant; } private: /* Layout */ - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; /* Serialization */ int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); diff --git a/poincare/include/poincare/division.h b/poincare/include/poincare/division.h index 9a3ce4b5a..bf3044a25 100644 --- a/poincare/include/poincare/division.h +++ b/poincare/include/poincare/division.h @@ -43,7 +43,7 @@ public: // Layout bool childNeedsParenthesis(const SerializationHelperInterface * child) const override; - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Infix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "/"); } diff --git a/poincare/include/poincare/division_quotient.h b/poincare/include/poincare/division_quotient.h index 075ebc368..02ec0fac0 100644 --- a/poincare/include/poincare/division_quotient.h +++ b/poincare/include/poincare/division_quotient.h @@ -21,7 +21,7 @@ public: Type type() const override { return Type::DivisionQuotient; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; const char * name() const { return "quo"; } // Simplification diff --git a/poincare/include/poincare/division_remainder.h b/poincare/include/poincare/division_remainder.h index 928a19448..f88c441c7 100644 --- a/poincare/include/poincare/division_remainder.h +++ b/poincare/include/poincare/division_remainder.h @@ -22,7 +22,7 @@ public: Type type() const override { return Type::DivisionRemainder; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; const char * name() const { return "rem"; } // Simplification diff --git a/poincare/include/poincare/empty_expression.h b/poincare/include/poincare/empty_expression.h index c30565993..3d9855f08 100644 --- a/poincare/include/poincare/empty_expression.h +++ b/poincare/include/poincare/empty_expression.h @@ -24,7 +24,7 @@ public: int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Evaluation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } diff --git a/poincare/include/poincare/empty_layout.h b/poincare/include/poincare/empty_layout.h index 8c0054741..ebe705dbe 100644 --- a/poincare/include/poincare/empty_layout.h +++ b/poincare/include/poincare/empty_layout.h @@ -3,7 +3,6 @@ #include #include -#include namespace Poincare { @@ -73,10 +72,10 @@ private: bool m_margins; }; -class EmptyLayoutReference : public LayoutReference { +class EmptyLayout : public Layout { public: - EmptyLayoutReference(const EmptyLayoutNode * n); - EmptyLayoutReference(EmptyLayoutNode::Color color = EmptyLayoutNode::Color::Yellow, bool visible = true, KDText::FontSize fontSize = KDText::FontSize::Large, bool margins = true); + EmptyLayout(const EmptyLayoutNode * n); + EmptyLayout(EmptyLayoutNode::Color color = EmptyLayoutNode::Color::Yellow, bool visible = true, KDText::FontSize fontSize = KDText::FontSize::Large, bool margins = true); void setVisible(bool visible) { node()->setVisible(visible); } @@ -85,7 +84,7 @@ public: node()->setColor(color); } private: - EmptyLayoutNode * node() const { return static_cast(LayoutReference::node()); } + EmptyLayoutNode * node() const { return static_cast(Layout::node()); } }; } diff --git a/poincare/include/poincare/equal.h b/poincare/include/poincare/equal.h index e3f2b9dfe..842a75102 100644 --- a/poincare/include/poincare/equal.h +++ b/poincare/include/poincare/equal.h @@ -24,7 +24,7 @@ private: // Simplification Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Evalutation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } diff --git a/poincare/include/poincare/expression.h b/poincare/include/poincare/expression.h index ac98d143f..f1ee109b2 100644 --- a/poincare/include/poincare/expression.h +++ b/poincare/include/poincare/expression.h @@ -154,7 +154,7 @@ public: bool isEqualToItsApproximationLayout(Expression approximation, char * buffer, int bufferSize, Preferences::AngleUnit angleUnit, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, Context & context); /* Layout Helper */ - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode = Preferences::PrintFloatMode::Decimal, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const; /* Simplification */ diff --git a/poincare/include/poincare/expression_node.h b/poincare/include/poincare/expression_node.h index 3056a1af6..6ff5c1134 100644 --- a/poincare/include/poincare/expression_node.h +++ b/poincare/include/poincare/expression_node.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include #include @@ -136,7 +136,7 @@ public: virtual int simplificationOrderSameType(const ExpressionNode * e, bool canBeInterrupted) const; /* Layout Helper */ - virtual LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const = 0; + virtual Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const = 0; /* Evaluation Helper */ typedef float SinglePrecision; diff --git a/poincare/include/poincare/factor.h b/poincare/include/poincare/factor.h index e15a893b9..631d36913 100644 --- a/poincare/include/poincare/factor.h +++ b/poincare/include/poincare/factor.h @@ -23,7 +23,7 @@ public: Type type() const override { return Type::Factor; } private: /* Layout */ - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; /* Serialization */ int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); diff --git a/poincare/include/poincare/factorial.h b/poincare/include/poincare/factorial.h index 389283ae2..6affcfd0e 100644 --- a/poincare/include/poincare/factorial.h +++ b/poincare/include/poincare/factorial.h @@ -24,7 +24,7 @@ public: private: // Layout bool childNeedsParenthesis(const SerializationHelperInterface * child) const override; - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplication Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; diff --git a/poincare/include/poincare/float.h b/poincare/include/poincare/float.h index ff7052c04..12f2a8055 100644 --- a/poincare/include/poincare/float.h +++ b/poincare/include/poincare/float.h @@ -49,7 +49,7 @@ public: return 0; } /* Layout */ - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { assert(false); return nullptr; } diff --git a/poincare/include/poincare/floor.h b/poincare/include/poincare/floor.h index 2df9b91e1..a3f20c013 100644 --- a/poincare/include/poincare/floor.h +++ b/poincare/include/poincare/floor.h @@ -22,7 +22,7 @@ public: Type type() const override { return Type::Floor; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; const char * name() const { return "floor"; } // Simplification diff --git a/poincare/include/poincare/floor_layout.h b/poincare/include/poincare/floor_layout.h index c3a50434b..5df6ba62e 100644 --- a/poincare/include/poincare/floor_layout.h +++ b/poincare/include/poincare/floor_layout.h @@ -26,9 +26,9 @@ protected: bool renderTopBar() const override { return false; } }; -class FloorLayoutReference : public LayoutReference { +class FloorLayout : public Layout { public: - explicit FloorLayoutReference(LayoutReference l) : LayoutReference(TreePool::sharedPool()->createTreeNode()) { + explicit FloorLayout(Layout l) : Layout(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, l); } }; diff --git a/poincare/include/poincare/frac_part.h b/poincare/include/poincare/frac_part.h index dfadb4c90..9a0ae1740 100644 --- a/poincare/include/poincare/frac_part.h +++ b/poincare/include/poincare/frac_part.h @@ -22,7 +22,7 @@ public: Type type() const override { return Type::FracPart; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; const char * name() const { return "frac"; } // Simplification diff --git a/poincare/include/poincare/fraction_layout.h b/poincare/include/poincare/fraction_layout.h index b1a26be44..a0712bf67 100644 --- a/poincare/include/poincare/fraction_layout.h +++ b/poincare/include/poincare/fraction_layout.h @@ -3,7 +3,6 @@ #include #include -#include namespace Poincare { @@ -57,9 +56,9 @@ private: LayoutNode * denominatorLayout() { return childAtIndex(1); } }; -class FractionLayoutReference : public LayoutReference { +class FractionLayout : public Layout { public: - FractionLayoutReference(LayoutReference numerator, LayoutReference denominator); + FractionLayout(Layout numerator, Layout denominator); }; } diff --git a/poincare/include/poincare/global_context.h b/poincare/include/poincare/global_context.h index 67e3bf260..e9200ea97 100644 --- a/poincare/include/poincare/global_context.h +++ b/poincare/include/poincare/global_context.h @@ -18,7 +18,7 @@ public: /* The expression recorded in global context is already a expression. * Otherwise, we would need the context and the angle unit to evaluate it */ const Expression expressionForSymbol(const Symbol & symbol) override; - LayoutReference layoutForSymbol(const Symbol & symbol, int numberOfSignificantDigits); + Layout layoutForSymbol(const Symbol & symbol, int numberOfSignificantDigits); void setExpressionForSymbolName(const Expression & expression, const Symbol & symbol, Context & context) override; static constexpr uint16_t k_maxNumberOfScalarExpressions = 26; //static constexpr uint16_t k_maxNumberOfListExpressions = 10; diff --git a/poincare/include/poincare/great_common_divisor.h b/poincare/include/poincare/great_common_divisor.h index 335525621..98a636efe 100644 --- a/poincare/include/poincare/great_common_divisor.h +++ b/poincare/include/poincare/great_common_divisor.h @@ -21,7 +21,7 @@ public: Type type() const override { return Type::GreatCommonDivisor; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; const char * name() const { return "gcd"; } // Simplification diff --git a/poincare/include/poincare/grid_layout.h b/poincare/include/poincare/grid_layout.h index 332f2ea0a..d067a536a 100644 --- a/poincare/include/poincare/grid_layout.h +++ b/poincare/include/poincare/grid_layout.h @@ -1,21 +1,20 @@ #ifndef POINCARE_GRID_LAYOUT_NODE_H #define POINCARE_GRID_LAYOUT_NODE_H -#include #include #include #include namespace Poincare { -class GridLayoutReference; +class GridLayout; class MatrixLayoutNode; class GridLayoutNode : public LayoutNode { friend class MatrixLayoutNode; friend class BinomialCoefficientLayoutNode; - friend class BinomialCoefficientLayoutReference; - friend class GridLayoutReference; + friend class BinomialCoefficientLayout; + friend class GridLayout; public: GridLayoutNode() : LayoutNode(), @@ -85,16 +84,16 @@ private: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override {} }; -class GridLayoutReference : public LayoutReference { +class GridLayout : public Layout { public: - GridLayoutReference(const GridLayoutNode * n) : LayoutReference(n) {} - GridLayoutReference() : LayoutReference(TreePool::sharedPool()->createTreeNode()) {} + GridLayout(const GridLayoutNode * n) : Layout(n) {} + GridLayout() : Layout(TreePool::sharedPool()->createTreeNode()) {} void setDimensions(int rows, int columns); - void addChildAtIndex(LayoutReference l, int index, int currentNumberOfChildren, LayoutCursor * cursor) { - LayoutReference::addChildAtIndex(l, index, currentNumberOfChildren, cursor); + void addChildAtIndex(Layout l, int index, int currentNumberOfChildren, LayoutCursor * cursor) { + Layout::addChildAtIndex(l, index, currentNumberOfChildren, cursor); } private: - virtual GridLayoutNode * node() const { return static_cast(LayoutReference::node()); } + virtual GridLayoutNode * node() const { return static_cast(Layout::node()); } void setNumberOfRows(int rows) { assert(rows >= 0); node()->setNumberOfRows(rows); diff --git a/poincare/include/poincare/horizontal_layout.h b/poincare/include/poincare/horizontal_layout.h index af37b0fe6..089c94a69 100644 --- a/poincare/include/poincare/horizontal_layout.h +++ b/poincare/include/poincare/horizontal_layout.h @@ -1,7 +1,6 @@ #ifndef POINCARE_HORIZONTAL_LAYOUT_NODE_H #define POINCARE_HORIZONTAL_LAYOUT_NODE_H -#include #include #include @@ -11,7 +10,7 @@ namespace Poincare { * instance, use addOrMergeChildAtIndex to add a LayoutNode safely. */ class HorizontalLayoutNode : public LayoutNode { - friend class LayoutReference; + friend class Layout; public: HorizontalLayoutNode() : @@ -63,26 +62,26 @@ private: uint16_t m_numberOfChildren; }; -class HorizontalLayoutReference : public LayoutReference { +class HorizontalLayout : public Layout { friend class HorizontalLayoutNode; public: - HorizontalLayoutReference(HorizontalLayoutNode * n) : LayoutReference(n) {} - HorizontalLayoutReference(); - explicit HorizontalLayoutReference(LayoutReference l); - HorizontalLayoutReference(LayoutReference l1, LayoutReference l2); - HorizontalLayoutReference(LayoutReference l1, LayoutReference l2, LayoutReference l3); - HorizontalLayoutReference(LayoutReference l1, LayoutReference l2, LayoutReference l3, LayoutReference l4); - HorizontalLayoutReference(const LayoutReference * children, size_t numberOfChildren); - void addChildAtIndex(LayoutReference l, int index, int currentNumberOfChildren, LayoutCursor * cursor, bool removeEmptyChildren = false); + HorizontalLayout(HorizontalLayoutNode * n) : Layout(n) {} + HorizontalLayout(); + explicit HorizontalLayout(Layout l); + HorizontalLayout(Layout l1, Layout l2); + HorizontalLayout(Layout l1, Layout l2, Layout l3); + HorizontalLayout(Layout l1, Layout l2, Layout l3, Layout l4); + HorizontalLayout(const Layout * children, size_t numberOfChildren); + void addChildAtIndex(Layout l, int index, int currentNumberOfChildren, LayoutCursor * cursor, bool removeEmptyChildren = false); // Remove puts a child at the end of the pool - void removeChild(LayoutReference l, LayoutCursor * cursor, bool force = false) { - LayoutReference::removeChild(l, cursor, force); + void removeChild(Layout l, LayoutCursor * cursor, bool force = false) { + Layout::removeChild(l, cursor, force); } void removeChildAtIndex(int index, LayoutCursor * cursor, bool force = false) { - LayoutReference::removeChildAtIndex(index, cursor, force); + Layout::removeChildAtIndex(index, cursor, force); } - void addOrMergeChildAtIndex(LayoutReference l, int index, bool removeEmptyChildren, LayoutCursor * cursor = nullptr); - void mergeChildrenAtIndex(HorizontalLayoutReference h, int index, bool removeEmptyChildren, LayoutCursor * cursor = nullptr); + void addOrMergeChildAtIndex(Layout l, int index, bool removeEmptyChildren, LayoutCursor * cursor = nullptr); + void mergeChildrenAtIndex(HorizontalLayout h, int index, bool removeEmptyChildren, LayoutCursor * cursor = nullptr); private: void removeEmptyChildBeforeInsertionAtIndex(int * index, int * currentNumberOfChildren, bool shouldRemoveOnLeft, LayoutCursor * cursor = nullptr); }; diff --git a/poincare/include/poincare/hyperbolic_trigonometric_function.h b/poincare/include/poincare/hyperbolic_trigonometric_function.h index 97fb4d870..d006b0b2f 100644 --- a/poincare/include/poincare/hyperbolic_trigonometric_function.h +++ b/poincare/include/poincare/hyperbolic_trigonometric_function.h @@ -13,7 +13,7 @@ public: int numberOfChildren() const override { return 1; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/include/poincare/imaginary_part.h b/poincare/include/poincare/imaginary_part.h index 0e6ca99a9..62c8715de 100644 --- a/poincare/include/poincare/imaginary_part.h +++ b/poincare/include/poincare/imaginary_part.h @@ -22,7 +22,7 @@ public: Type type() const override { return Type::ImaginaryPart; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; const char * name() const { return "im"; } // Simplification Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; diff --git a/poincare/include/poincare/infinity.h b/poincare/include/poincare/infinity.h index 4081808aa..af4ba27f5 100644 --- a/poincare/include/poincare/infinity.h +++ b/poincare/include/poincare/infinity.h @@ -35,7 +35,7 @@ public: } // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode = Preferences::PrintFloatMode::Decimal, int numberOfSignificantDigits = 0) const override; private: template Evaluation templatedApproximate() const; diff --git a/poincare/include/poincare/integer.h b/poincare/include/poincare/integer.h index 1c873b428..8dd3f997e 100644 --- a/poincare/include/poincare/integer.h +++ b/poincare/include/poincare/integer.h @@ -8,7 +8,7 @@ namespace Poincare { class ExpressionLayout; -class LayoutReference; +class Layout; class LayoutNode; class Integer; struct IntegerDivision; @@ -58,7 +58,7 @@ public: int serialize(char * buffer, int bufferSize) const; //Layout - HorizontalLayoutReference createLayout() const; + HorizontalLayout createLayout() const; // Approximation template T approximate() const; diff --git a/poincare/include/poincare/integral.h b/poincare/include/poincare/integral.h index 1ce16f3d5..53b7fffd0 100644 --- a/poincare/include/poincare/integral.h +++ b/poincare/include/poincare/integral.h @@ -22,7 +22,7 @@ public: int polynomialDegree(char symbolName) const override; private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; diff --git a/poincare/include/poincare/integral_layout.h b/poincare/include/poincare/integral_layout.h index 1dd5509d0..3c00cf228 100644 --- a/poincare/include/poincare/integral_layout.h +++ b/poincare/include/poincare/integral_layout.h @@ -3,7 +3,6 @@ #include #include -#include #include namespace Poincare { @@ -52,10 +51,10 @@ private: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; }; -class IntegralLayoutReference : public LayoutReference { +class IntegralLayout : public Layout { public: - IntegralLayoutReference(LayoutReference integrand, LayoutReference lowerBound, LayoutReference upperBound) : - LayoutReference(TreePool::sharedPool()->createTreeNode()) + IntegralLayout(Layout integrand, Layout lowerBound, Layout upperBound) : + Layout(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, integrand); replaceChildAtIndexInPlace(1, lowerBound); diff --git a/poincare/include/poincare/layout.h b/poincare/include/poincare/layout.h index 5d257db6d..fb5450c27 100644 --- a/poincare/include/poincare/layout.h +++ b/poincare/include/poincare/layout.h @@ -1,158 +1,102 @@ -#ifndef POINCARE_LAYOUT_NODE_H -#define POINCARE_LAYOUT_NODE_H +#ifndef POINCARE_LAYOUT_REFERENCE_H +#define POINCARE_LAYOUT_REFERENCE_H -#include -#include -#include -#include +#include +#include namespace Poincare { class LayoutCursor; -class LayoutReference; -class LayoutNode : public TreeNode, public SerializationHelperInterface { - friend class LayoutReference; +class Layout : public TreeHandle { + friend class GridLayoutNode; + friend class HorizontalLayoutNode; + friend class LayoutNode; + friend class LayoutCursor; + friend class VerticalOffsetLayoutNode; public: - enum class VerticalDirection { - Up, - Down - }; - - // Constructor - LayoutNode() : - TreeNode(), - m_baseline(0), - m_frame(KDRectZero), - m_baselined(false), - m_positioned(false), - m_sized(false) - { + Layout() : TreeHandle() {} + Layout(const LayoutNode * node) : TreeHandle(node) {} + Layout clone() const; + LayoutNode * node() const { + assert(isUninitialized() || !TreeHandle::node()->isGhost()); + return static_cast(TreeHandle::node()); } // Rendering - void draw(KDContext * ctx, KDPoint p, KDColor expressionColor = KDColorBlack, KDColor backgroundColor = KDColorWhite); - KDPoint origin(); - KDPoint absoluteOrigin(); - KDSize layoutSize(); - KDCoordinate baseline(); - virtual void invalidAllSizesPositionsAndBaselines(); + void draw(KDContext * ctx, KDPoint p, KDColor expressionColor = KDColorBlack, KDColor backgroundColor = KDColorWhite) { + return node()->draw(ctx, p, expressionColor, backgroundColor); + } + void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) { + return node()->render(ctx, p, expressionColor, backgroundColor); + } + //TODO: check these methods are needed here, not just in Node + KDSize layoutSize() { return node()->layoutSize(); } + KDPoint absoluteOrigin() { return node()->absoluteOrigin(); } + KDCoordinate baseline() { return node()->baseline(); } + void invalidAllSizesPositionsAndBaselines() { return node()->invalidAllSizesPositionsAndBaselines(); } - // SerializationHelperInterface - SerializationHelperInterface * serializableChildAtIndex(int i) const override { return childAtIndex(i); } - int numberOfSerializableChildren() const override { return numberOfChildren(); } + // Serialization + int serialize(char * buffer, int bufferSize) const { return node()->serialize(buffer, bufferSize); } + + // Layout properties + KDPoint positionOfChild(Layout child) { return node()->positionOfChild(child.node()); } + bool mustHaveLeftSibling() const { return const_cast(this)->node()->mustHaveLeftSibling(); } + bool isEmpty() const { return const_cast(this)->node()->isEmpty(); } + bool isHorizontal() const { return const_cast(this)->node()->isHorizontal(); } + bool isMatrix() const { return const_cast(this)->node()->isMatrix(); } + bool isVerticalOffset() const { return const_cast(this)->node()->isVerticalOffset(); } + bool isLeftParenthesis() const { return const_cast(this)->node()->isLeftParenthesis(); } + bool isCollapsable(int * numberOfOpenParenthesis, bool goingLeft) const { return const_cast(this)->node()->isCollapsable(numberOfOpenParenthesis, goingLeft); } + int leftCollapsingAbsorbingChildIndex() const { return const_cast(this)->node()->leftCollapsingAbsorbingChildIndex(); } + int rightCollapsingAbsorbingChildIndex() const { return const_cast(this)->node()->rightCollapsingAbsorbingChildIndex(); } + bool hasText() { return node()->hasText(); } + char XNTChar() const { return const_cast(this)->node()->XNTChar(); } + + // Layout modification + void deleteBeforeCursor(LayoutCursor * cursor) { return node()->deleteBeforeCursor(cursor); } + bool removeGreySquaresFromAllMatrixAncestors() { return node()->removeGreySquaresFromAllMatrixAncestors(); } + bool addGreySquaresToAllMatrixAncestors() { return node()->addGreySquaresToAllMatrixAncestors(); } + Layout layoutToPointWhenInserting() { return Layout(node()->layoutToPointWhenInserting()); } + + // Cursor + LayoutCursor cursor() const; + LayoutCursor equivalentCursor(LayoutCursor * cursor); // Tree - LayoutNode * parent() const override { return static_cast(TreeNode::parent()); } - LayoutNode * childAtIndex(int i) const override { return static_cast(TreeNode::childAtIndex(i)); } - LayoutNode * root() override { return static_cast(TreeNode::root()); } - - // Tree navigation - virtual void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) = 0; - virtual void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) = 0; - virtual void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) { - moveCursorVertically(VerticalDirection::Up, cursor, shouldRecomputeLayout, equivalentPositionVisited); + Layout childAtIndex(int i); + Layout root() const { + assert(!isUninitialized()); + return Layout(node()->root()); } - virtual void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) { - moveCursorVertically(VerticalDirection::Down, cursor, shouldRecomputeLayout, equivalentPositionVisited); + Layout parent() const { + assert(!isUninitialized()); + return Layout(node()->parent()); } - void moveCursorUpInDescendants(LayoutCursor * cursor, bool * shouldRecomputeLayout) { - return moveCursorInDescendantsVertically(VerticalDirection::Up, cursor, shouldRecomputeLayout); - } - void moveCursorDownInDescendants(LayoutCursor * cursor, bool * shouldRecomputeLayout) { - return moveCursorInDescendantsVertically(VerticalDirection::Down, cursor, shouldRecomputeLayout); - } - virtual LayoutCursor equivalentCursor(LayoutCursor * cursor); // Tree modification + //Add + void addSibling(LayoutCursor * cursor, Layout sibling, bool moveCursor); + // Replace + void replaceChild(Layout oldChild, Layout newChild, LayoutCursor * cursor = nullptr, bool force = false); + void replaceChildWithEmpty(Layout oldChild, LayoutCursor * cursor = nullptr); + void replaceWith(Layout newChild, LayoutCursor * cursor); + void replaceWithJuxtapositionOf(Layout leftChild, Layout rightChild, LayoutCursor * cursor, bool putCursorInTheMiddle = false); // Collapse - virtual bool shouldCollapseSiblingsOnLeft() const { return false; } - virtual bool shouldCollapseSiblingsOnRight() const { return false; } - virtual int leftCollapsingAbsorbingChildIndex() const { return 0; } - virtual int rightCollapsingAbsorbingChildIndex() const { return 0; } - virtual void didCollapseSiblings(LayoutCursor * cursor) {} - - // User input - virtual void deleteBeforeCursor(LayoutCursor * cursor); - - // Other - virtual LayoutNode * layoutToPointWhenInserting() { - return numberOfChildren() > 0 ? childAtIndex(0) : this; - } - bool removeGreySquaresFromAllMatrixAncestors() { return changeGreySquaresOfAllMatrixAncestors(false); } - bool addGreySquaresToAllMatrixAncestors() { return changeGreySquaresOfAllMatrixAncestors(true); } - /* 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; } - virtual bool isCollapsable(int * numberOfOpenParenthesis, bool goingLeft) const { return true; } - /* isCollapsable is used when adding a sibling fraction: should the layout be - * inserted in the numerator (or denominator)? For instance, 1+2|3-4 should - * become 1+ 2/3 - 4 when pressing "Divide": a CharLayout is collapsable if - * its char is not +, -, or *. */ - virtual bool canBeOmittedMultiplicationLeftFactor() const; - virtual bool canBeOmittedMultiplicationRightFactor() const; - /* canBeOmittedMultiplicationLeftFactor and RightFactor return true if the - * layout, next to another layout, might be the factor of a multiplication - * with an omitted multiplication sign. For instance, an absolute value layout - * returns true, because |3|2 means |3|*2. A '+' CharLayout returns false, - * because +'something' nevers means +*'something'. */ - virtual bool mustHaveLeftSibling() const { return false; } - virtual bool isVerticalOffset() const { return false; } - /* For now, mustHaveLeftSibling and isVerticalOffset behave the same, but code - * is clearer with different names. */ - virtual bool isHorizontal() const { return false; } - virtual bool isLeftParenthesis() const { return false; } - virtual bool isRightParenthesis() const { return false; } - virtual bool isLeftBracket() const { return false; } - virtual bool isRightBracket() const { return false; } - virtual bool isEmpty() const { return false; } - virtual bool isMatrix() const { return false; } - virtual bool hasUpperLeftIndex() const { return false; } - virtual char XNTChar() const { - LayoutNode * p = parent(); - return p == nullptr ? Ion::Charset::Empty : p->XNTChar(); - } - - // TODO: put private - virtual bool willAddChildAtIndex(LayoutNode * l, int * index, int * currentNumberOfChildren, LayoutCursor * cursor) { return true; } - virtual bool willAddSibling(LayoutCursor * cursor, LayoutNode * sibling, bool moveCursor) { return true; } - virtual void willAddSiblingToEmptyChildAtIndex(int childIndex) {} - virtual bool willReplaceChild(LayoutNode * oldChild, LayoutNode * newChild, LayoutCursor * cursor, bool force) { return true; } - virtual void didReplaceChildAtIndex(int index, LayoutCursor * cursor, bool force) {} - virtual bool willRemoveChild(LayoutNode * l, LayoutCursor * cursor, bool force); - virtual void didRemoveChildAtIndex(int index, LayoutCursor * cursor, bool force) {} - + void collapseSiblings(LayoutCursor * cursor); protected: - // Tree navigation - virtual void moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited); - - // Tree - Direct children() { return Direct(this); } - - // Sizing and positioning - virtual KDSize computeSize() = 0; - virtual KDCoordinate computeBaseline() = 0; - virtual KDPoint positionOfChild(LayoutNode * child) = 0; - - /* m_baseline is the signed vertical distance from the top of the layout to - * the fraction bar of an hypothetical fraction sibling layout. If the top of - * the layout is under that bar, the baseline is negative. */ - KDCoordinate m_baseline; - KDRect m_frame; - bool m_baselined; // TODO Do not use so much space for 3 bools - bool m_positioned; - bool m_sized; + // Add + void addChildAtIndex(Layout l, int index, int currentNumberOfChildren, LayoutCursor * cursor); + // Remove + void removeChild(Layout l, LayoutCursor * cursor, bool force = false); + void removeChildAtIndex(int index, LayoutCursor * cursor, bool force = false); private: - void moveCursorInDescendantsVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout); - void scoreCursorInDescendantsVertically ( - VerticalDirection direction, - LayoutCursor * cursor, - bool * shouldRecomputeLayout, - LayoutNode ** childResult, - void * resultPosition, - int * resultScore); - virtual void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) = 0; - bool changeGreySquaresOfAllMatrixAncestors(bool add); + // Tree modification + enum class HorizontalDirection { + Left, + Right + }; + void collapseOnDirection(HorizontalDirection direction, int absorbingChildIndex); }; } diff --git a/poincare/include/poincare/layout_cursor.h b/poincare/include/poincare/layout_cursor.h index 2fc9ae4ca..c665bfe13 100644 --- a/poincare/include/poincare/layout_cursor.h +++ b/poincare/include/poincare/layout_cursor.h @@ -1,16 +1,15 @@ #ifndef POINCARE_LAYOUT_CURSOR_H #define POINCARE_LAYOUT_CURSOR_H -#include #include namespace Poincare { class HorizontalLayoutNode; -class VerticalOffsetLayoutReference; +class VerticalOffsetLayout; class LayoutCursor { - friend class LayoutReference; + friend class Layout; friend class HorizontalLayoutNode; public: constexpr static KDCoordinate k_cursorWidth = 1; @@ -28,48 +27,48 @@ public: }; LayoutCursor() : - m_layoutRef(), + m_layout(), m_position(Position::Right) {} - LayoutCursor(LayoutReference layoutR, Position position = Position::Right) : - m_layoutRef(layoutR.node()), + LayoutCursor(Layout layoutR, Position position = Position::Right) : + m_layout(layoutR.node()), m_position(position) {} LayoutCursor(LayoutNode * node, Position position = Position::Right) : - m_layoutRef(node), + m_layout(node), m_position(position) {} //TODO make this private and friend class layout_node LayoutCursor clone() const { - return LayoutCursor(m_layoutRef, m_position); + return LayoutCursor(m_layout, m_position); } // Definition - bool isDefined() const { return !m_layoutRef.isUninitialized(); } + bool isDefined() const { return !m_layout.isUninitialized(); } // Getters and setters - LayoutReference layoutReference() { return m_layoutRef; } - LayoutNode * layoutNode() { return m_layoutRef.node(); } // TODO Make private + friend classes ? + Layout layouterence() { return m_layout; } + LayoutNode * layoutNode() { return m_layout.node(); } // TODO Make private + friend classes ? - int layoutIdentifier() { return m_layoutRef.identifier(); } - void setLayoutReference(LayoutReference r) { - if (r != m_layoutRef) { - m_layoutRef = r; + int layoutIdentifier() { return m_layout.identifier(); } + void setLayout(Layout r) { + if (r != m_layout) { + m_layout = r; } } void setLayoutNode(LayoutNode * n) { - if (n->identifier() != m_layoutRef.identifier()) { - /* Compare the identifiers and not the nodes because m_layoutRef might + if (n->identifier() != m_layout.identifier()) { + /* Compare the identifiers and not the nodes because m_layout might * temporarily be pointing to a GhostNode. In this case, - * m_layoutRef.node() would crash because of the assertion that the node + * m_layout.node() would crash because of the assertion that the node * is not ghost. */ - m_layoutRef = LayoutReference(n); + m_layout = Layout(n); } } void setTo(LayoutCursor * other) { - m_layoutRef = other->layoutReference(); + m_layout = other->layouterence(); m_position = other->position(); } Position position() const { return m_position; } @@ -114,19 +113,19 @@ public: void addFractionLayoutAndCollapseSiblings(); void addXNTCharLayout(); void insertText(const char * text); - void addLayoutAndMoveCursor(LayoutReference l); + void addLayoutAndMoveCursor(Layout l); bool showEmptyLayoutIfNeeded() { return privateShowHideEmptyLayoutIfNeeded(true); } bool hideEmptyLayoutIfNeeded() { return privateShowHideEmptyLayoutIfNeeded(false); } - void performBackspace() { m_layoutRef.deleteBeforeCursor(this); } + void performBackspace() { m_layout.deleteBeforeCursor(this); } void clearLayout(); private: constexpr static KDCoordinate k_cursorHeight = 18; KDCoordinate layoutHeight(); - void privateAddEmptyPowerLayout(VerticalOffsetLayoutReference v); + void privateAddEmptyPowerLayout(VerticalOffsetLayout v); bool baseForNewPowerLayout(); bool privateShowHideEmptyLayoutIfNeeded(bool show); - LayoutReference m_layoutRef; + Layout m_layout; Position m_position; }; diff --git a/poincare/include/poincare/layout_helper.h b/poincare/include/poincare/layout_helper.h index e2d2da52b..e7c9fd2da 100644 --- a/poincare/include/poincare/layout_helper.h +++ b/poincare/include/poincare/layout_helper.h @@ -2,20 +2,20 @@ #define POINCARE_LAYOUT_HELPER_H #include -#include +#include #include namespace Poincare { namespace LayoutHelper { /* Expression to Layout */ - LayoutReference Infix(const Expression & expression, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, const char * operatorName); - LayoutReference Prefix(const Expression & expression, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, const char * operatorName); + Layout Infix(const Expression & expression, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, const char * operatorName); + Layout Prefix(const Expression & expression, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, const char * operatorName); /* Create special layouts */ - LayoutReference Parentheses(LayoutReference layout, bool cloneLayout); - HorizontalLayoutReference String(const char * buffer, int bufferSize, KDText::FontSize fontSize = KDText::FontSize::Large); - LayoutReference Logarithm(LayoutReference argument, LayoutReference index); + Layout Parentheses(Layout layout, bool cloneLayout); + HorizontalLayout String(const char * buffer, int bufferSize, KDText::FontSize fontSize = KDText::FontSize::Large); + Layout Logarithm(Layout argument, Layout index); }; } diff --git a/poincare/include/poincare/layout_node.h b/poincare/include/poincare/layout_node.h new file mode 100644 index 000000000..644c2bda5 --- /dev/null +++ b/poincare/include/poincare/layout_node.h @@ -0,0 +1,160 @@ +#ifndef POINCARE_LAYOUT_NODE_H +#define POINCARE_LAYOUT_NODE_H + +#include +#include +#include +#include + +namespace Poincare { + +class LayoutCursor; +class Layout; + +class LayoutNode : public TreeNode, public SerializationHelperInterface { + friend class Layout; +public: + enum class VerticalDirection { + Up, + Down + }; + + // Constructor + LayoutNode() : + TreeNode(), + m_baseline(0), + m_frame(KDRectZero), + m_baselined(false), + m_positioned(false), + m_sized(false) + { + } + + // Rendering + void draw(KDContext * ctx, KDPoint p, KDColor expressionColor = KDColorBlack, KDColor backgroundColor = KDColorWhite); + KDPoint origin(); + KDPoint absoluteOrigin(); + KDSize layoutSize(); + KDCoordinate baseline(); + virtual void invalidAllSizesPositionsAndBaselines(); + + // SerializationHelperInterface + SerializationHelperInterface * serializableChildAtIndex(int i) const override { return childAtIndex(i); } + int numberOfSerializableChildren() const override { return numberOfChildren(); } + + // Tree + LayoutNode * parent() const override { return static_cast(TreeNode::parent()); } + LayoutNode * childAtIndex(int i) const override { return static_cast(TreeNode::childAtIndex(i)); } + LayoutNode * root() override { return static_cast(TreeNode::root()); } + + // Tree navigation + virtual void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) = 0; + virtual void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) = 0; + virtual void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) { + moveCursorVertically(VerticalDirection::Up, cursor, shouldRecomputeLayout, equivalentPositionVisited); + } + virtual void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) { + moveCursorVertically(VerticalDirection::Down, cursor, shouldRecomputeLayout, equivalentPositionVisited); + } + void moveCursorUpInDescendants(LayoutCursor * cursor, bool * shouldRecomputeLayout) { + return moveCursorInDescendantsVertically(VerticalDirection::Up, cursor, shouldRecomputeLayout); + } + void moveCursorDownInDescendants(LayoutCursor * cursor, bool * shouldRecomputeLayout) { + return moveCursorInDescendantsVertically(VerticalDirection::Down, cursor, shouldRecomputeLayout); + } + virtual LayoutCursor equivalentCursor(LayoutCursor * cursor); + + // Tree modification + // Collapse + virtual bool shouldCollapseSiblingsOnLeft() const { return false; } + virtual bool shouldCollapseSiblingsOnRight() const { return false; } + virtual int leftCollapsingAbsorbingChildIndex() const { return 0; } + virtual int rightCollapsingAbsorbingChildIndex() const { return 0; } + virtual void didCollapseSiblings(LayoutCursor * cursor) {} + + // User input + virtual void deleteBeforeCursor(LayoutCursor * cursor); + + // Other + virtual LayoutNode * layoutToPointWhenInserting() { + return numberOfChildren() > 0 ? childAtIndex(0) : this; + } + bool removeGreySquaresFromAllMatrixAncestors() { return changeGreySquaresOfAllMatrixAncestors(false); } + bool addGreySquaresToAllMatrixAncestors() { return changeGreySquaresOfAllMatrixAncestors(true); } + /* 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; } + virtual bool isCollapsable(int * numberOfOpenParenthesis, bool goingLeft) const { return true; } + /* isCollapsable is used when adding a sibling fraction: should the layout be + * inserted in the numerator (or denominator)? For instance, 1+2|3-4 should + * become 1+ 2/3 - 4 when pressing "Divide": a CharLayout is collapsable if + * its char is not +, -, or *. */ + virtual bool canBeOmittedMultiplicationLeftFactor() const; + virtual bool canBeOmittedMultiplicationRightFactor() const; + /* canBeOmittedMultiplicationLeftFactor and RightFactor return true if the + * layout, next to another layout, might be the factor of a multiplication + * with an omitted multiplication sign. For instance, an absolute value layout + * returns true, because |3|2 means |3|*2. A '+' CharLayout returns false, + * because +'something' nevers means +*'something'. */ + virtual bool mustHaveLeftSibling() const { return false; } + virtual bool isVerticalOffset() const { return false; } + /* For now, mustHaveLeftSibling and isVerticalOffset behave the same, but code + * is clearer with different names. */ + virtual bool isHorizontal() const { return false; } + virtual bool isLeftParenthesis() const { return false; } + virtual bool isRightParenthesis() const { return false; } + virtual bool isLeftBracket() const { return false; } + virtual bool isRightBracket() const { return false; } + virtual bool isEmpty() const { return false; } + virtual bool isMatrix() const { return false; } + virtual bool hasUpperLeftIndex() const { return false; } + virtual char XNTChar() const { + LayoutNode * p = parent(); + return p == nullptr ? Ion::Charset::Empty : p->XNTChar(); + } + + // TODO: put private + virtual bool willAddChildAtIndex(LayoutNode * l, int * index, int * currentNumberOfChildren, LayoutCursor * cursor) { return true; } + virtual bool willAddSibling(LayoutCursor * cursor, LayoutNode * sibling, bool moveCursor) { return true; } + virtual void willAddSiblingToEmptyChildAtIndex(int childIndex) {} + virtual bool willReplaceChild(LayoutNode * oldChild, LayoutNode * newChild, LayoutCursor * cursor, bool force) { return true; } + virtual void didReplaceChildAtIndex(int index, LayoutCursor * cursor, bool force) {} + virtual bool willRemoveChild(LayoutNode * l, LayoutCursor * cursor, bool force); + virtual void didRemoveChildAtIndex(int index, LayoutCursor * cursor, bool force) {} + +protected: + // Tree navigation + virtual void moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited); + + // Tree + Direct children() { return Direct(this); } + + // Sizing and positioning + virtual KDSize computeSize() = 0; + virtual KDCoordinate computeBaseline() = 0; + virtual KDPoint positionOfChild(LayoutNode * child) = 0; + + /* m_baseline is the signed vertical distance from the top of the layout to + * the fraction bar of an hypothetical fraction sibling layout. If the top of + * the layout is under that bar, the baseline is negative. */ + KDCoordinate m_baseline; + KDRect m_frame; + bool m_baselined; // TODO Do not use so much space for 3 bools + bool m_positioned; + bool m_sized; +private: + void moveCursorInDescendantsVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout); + void scoreCursorInDescendantsVertically ( + VerticalDirection direction, + LayoutCursor * cursor, + bool * shouldRecomputeLayout, + LayoutNode ** childResult, + void * resultPosition, + int * resultScore); + virtual void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) = 0; + bool changeGreySquaresOfAllMatrixAncestors(bool add); +}; + +} + +#endif diff --git a/poincare/include/poincare/layout_reference.h b/poincare/include/poincare/layout_reference.h deleted file mode 100644 index 6eb9e0bbd..000000000 --- a/poincare/include/poincare/layout_reference.h +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef POINCARE_LAYOUT_REFERENCE_H -#define POINCARE_LAYOUT_REFERENCE_H - -#include -#include - -namespace Poincare { - -class LayoutCursor; - -class LayoutReference : public TreeHandle { - friend class GridLayoutNode; - friend class HorizontalLayoutNode; - friend class LayoutNode; - friend class LayoutCursor; - friend class VerticalOffsetLayoutNode; -public: - LayoutReference() : TreeHandle() {} - LayoutReference(const LayoutNode * node) : TreeHandle(node) {} - LayoutReference clone() const; - LayoutNode * node() const { - assert(isUninitialized() || !TreeHandle::node()->isGhost()); - return static_cast(TreeHandle::node()); - } - - // Rendering - void draw(KDContext * ctx, KDPoint p, KDColor expressionColor = KDColorBlack, KDColor backgroundColor = KDColorWhite) { - return node()->draw(ctx, p, expressionColor, backgroundColor); - } - void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) { - return node()->render(ctx, p, expressionColor, backgroundColor); - } - //TODO: check these methods are needed here, not just in Node - KDSize layoutSize() { return node()->layoutSize(); } - KDPoint absoluteOrigin() { return node()->absoluteOrigin(); } - KDCoordinate baseline() { return node()->baseline(); } - void invalidAllSizesPositionsAndBaselines() { return node()->invalidAllSizesPositionsAndBaselines(); } - - // Serialization - int serialize(char * buffer, int bufferSize) const { return node()->serialize(buffer, bufferSize); } - - // Layout properties - KDPoint positionOfChild(LayoutReference child) { return node()->positionOfChild(child.node()); } - bool mustHaveLeftSibling() const { return const_cast(this)->node()->mustHaveLeftSibling(); } - bool isEmpty() const { return const_cast(this)->node()->isEmpty(); } - bool isHorizontal() const { return const_cast(this)->node()->isHorizontal(); } - bool isMatrix() const { return const_cast(this)->node()->isMatrix(); } - bool isVerticalOffset() const { return const_cast(this)->node()->isVerticalOffset(); } - bool isLeftParenthesis() const { return const_cast(this)->node()->isLeftParenthesis(); } - bool isCollapsable(int * numberOfOpenParenthesis, bool goingLeft) const { return const_cast(this)->node()->isCollapsable(numberOfOpenParenthesis, goingLeft); } - int leftCollapsingAbsorbingChildIndex() const { return const_cast(this)->node()->leftCollapsingAbsorbingChildIndex(); } - int rightCollapsingAbsorbingChildIndex() const { return const_cast(this)->node()->rightCollapsingAbsorbingChildIndex(); } - bool hasText() { return node()->hasText(); } - char XNTChar() const { return const_cast(this)->node()->XNTChar(); } - - // Layout modification - void deleteBeforeCursor(LayoutCursor * cursor) { return node()->deleteBeforeCursor(cursor); } - bool removeGreySquaresFromAllMatrixAncestors() { return node()->removeGreySquaresFromAllMatrixAncestors(); } - bool addGreySquaresToAllMatrixAncestors() { return node()->addGreySquaresToAllMatrixAncestors(); } - LayoutReference layoutToPointWhenInserting() { return LayoutReference(node()->layoutToPointWhenInserting()); } - - // Cursor - LayoutCursor cursor() const; - LayoutCursor equivalentCursor(LayoutCursor * cursor); - - // Tree - LayoutReference childAtIndex(int i); - LayoutReference root() const { - assert(!isUninitialized()); - return LayoutReference(node()->root()); - } - LayoutReference parent() const { - assert(!isUninitialized()); - return LayoutReference(node()->parent()); - } - - // Tree modification - //Add - void addSibling(LayoutCursor * cursor, LayoutReference sibling, bool moveCursor); - // Replace - void replaceChild(LayoutReference oldChild, LayoutReference newChild, LayoutCursor * cursor = nullptr, bool force = false); - void replaceChildWithEmpty(LayoutReference oldChild, LayoutCursor * cursor = nullptr); - void replaceWith(LayoutReference newChild, LayoutCursor * cursor); - void replaceWithJuxtapositionOf(LayoutReference leftChild, LayoutReference rightChild, LayoutCursor * cursor, bool putCursorInTheMiddle = false); - // Collapse - void collapseSiblings(LayoutCursor * cursor); -protected: - // Add - void addChildAtIndex(LayoutReference l, int index, int currentNumberOfChildren, LayoutCursor * cursor); - // Remove - void removeChild(LayoutReference l, LayoutCursor * cursor, bool force = false); - void removeChildAtIndex(int index, LayoutCursor * cursor, bool force = false); -private: - // Tree modification - enum class HorizontalDirection { - Left, - Right - }; - void collapseOnDirection(HorizontalDirection direction, int absorbingChildIndex); -}; - -} - -#endif diff --git a/poincare/include/poincare/least_common_multiple.h b/poincare/include/poincare/least_common_multiple.h index 8151a1edb..59eeb82f3 100644 --- a/poincare/include/poincare/least_common_multiple.h +++ b/poincare/include/poincare/least_common_multiple.h @@ -21,7 +21,7 @@ public: Type type() const override { return Type::LeastCommonMultiple; } private: /* Layout */ - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/include/poincare/left_parenthesis_layout.h b/poincare/include/poincare/left_parenthesis_layout.h index 98e3a3861..b8db2841a 100644 --- a/poincare/include/poincare/left_parenthesis_layout.h +++ b/poincare/include/poincare/left_parenthesis_layout.h @@ -33,9 +33,9 @@ protected: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; }; -class LeftParenthesisLayoutReference : public LayoutReference { +class LeftParenthesisLayout : public Layout { public: - LeftParenthesisLayoutReference(); + LeftParenthesisLayout(); }; } diff --git a/poincare/include/poincare/left_square_bracket_layout.h b/poincare/include/poincare/left_square_bracket_layout.h index 039cb4d88..a033179cf 100644 --- a/poincare/include/poincare/left_square_bracket_layout.h +++ b/poincare/include/poincare/left_square_bracket_layout.h @@ -27,9 +27,9 @@ protected: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; }; -class LeftSquareBracketLayoutReference : public LayoutReference { +class LeftSquareBracketLayout : public Layout { public: - LeftSquareBracketLayoutReference(); + LeftSquareBracketLayout(); }; } diff --git a/poincare/include/poincare/logarithm.h b/poincare/include/poincare/logarithm.h index 4766bc685..5bd9b6d9b 100644 --- a/poincare/include/poincare/logarithm.h +++ b/poincare/include/poincare/logarithm.h @@ -25,7 +25,7 @@ public: Type type() const override { return Type::Logarithm; } // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "log"); } diff --git a/poincare/include/poincare/matrix.h b/poincare/include/poincare/matrix.h index 49014d5f5..85eb9df2f 100644 --- a/poincare/include/poincare/matrix.h +++ b/poincare/include/poincare/matrix.h @@ -47,7 +47,7 @@ public: } // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode = Preferences::PrintFloatMode::Decimal, int numberOfSignificantDigits = 0) const override; private: template Evaluation templatedApproximate(Context& context, Preferences::AngleUnit angleUnit) const; diff --git a/poincare/include/poincare/matrix_dimension.h b/poincare/include/poincare/matrix_dimension.h index f114b3a8a..6bc8a035b 100644 --- a/poincare/include/poincare/matrix_dimension.h +++ b/poincare/include/poincare/matrix_dimension.h @@ -21,7 +21,7 @@ public: Type type() const override { return Type::MatrixDimension; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; const char * name() const { return "dim"; } // Simplification diff --git a/poincare/include/poincare/matrix_inverse.h b/poincare/include/poincare/matrix_inverse.h index 647101e07..1c4bbb20e 100644 --- a/poincare/include/poincare/matrix_inverse.h +++ b/poincare/include/poincare/matrix_inverse.h @@ -21,7 +21,7 @@ public: Type type() const override { return Type::MatrixInverse; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; const char * name() const { return "inverse"; } // Simplification diff --git a/poincare/include/poincare/matrix_layout.h b/poincare/include/poincare/matrix_layout.h index fb93657a1..e7b5fcb0d 100644 --- a/poincare/include/poincare/matrix_layout.h +++ b/poincare/include/poincare/matrix_layout.h @@ -3,15 +3,15 @@ #include #include -#include +#include namespace Poincare { -class MatrixLayoutReference; +class MatrixLayout; class MatrixLayoutNode : public GridLayoutNode { - friend class LayoutReference; - friend class MatrixLayoutReference; + friend class Layout; + friend class MatrixLayout; public: using GridLayoutNode::GridLayoutNode; @@ -54,17 +54,17 @@ private: void didReplaceChildAtIndex(int index, LayoutCursor * cursor, bool force) override; }; -class MatrixLayoutReference : public GridLayoutReference { +class MatrixLayout : public GridLayout { friend class MatrixLayoutNode; public: - MatrixLayoutReference(const MatrixLayoutNode * n); - MatrixLayoutReference(); - MatrixLayoutReference(LayoutReference l1, LayoutReference l2, LayoutReference l3, LayoutReference l4); + MatrixLayout(const MatrixLayoutNode * n); + MatrixLayout(); + MatrixLayout(Layout l1, Layout l2, Layout l3, Layout l4); bool hasGreySquares() const { return node()->hasGreySquares(); } void addGreySquares() { node()->addGreySquares(); } void removeGreySquares() { node()->removeGreySquares(); } private: - MatrixLayoutNode * node() const { return static_cast(LayoutReference::node()); } + MatrixLayoutNode * node() const { return static_cast(Layout::node()); } }; } diff --git a/poincare/include/poincare/matrix_trace.h b/poincare/include/poincare/matrix_trace.h index 87b6590d1..6157c82f0 100644 --- a/poincare/include/poincare/matrix_trace.h +++ b/poincare/include/poincare/matrix_trace.h @@ -21,7 +21,7 @@ public: Type type() const override { return Type::MatrixTrace; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; const char * name() const { return "trace"; } // Simplification diff --git a/poincare/include/poincare/matrix_transpose.h b/poincare/include/poincare/matrix_transpose.h index ebe7093ae..79c8750d5 100644 --- a/poincare/include/poincare/matrix_transpose.h +++ b/poincare/include/poincare/matrix_transpose.h @@ -21,7 +21,7 @@ public: Type type() const override { return Type::MatrixTranspose; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; const char * name() const { return "transpose"; } // Simplification diff --git a/poincare/include/poincare/multiplication.h b/poincare/include/poincare/multiplication.h index b46d2a7d6..5c3df8a48 100644 --- a/poincare/include/poincare/multiplication.h +++ b/poincare/include/poincare/multiplication.h @@ -38,7 +38,7 @@ private: // Layout bool childNeedsParenthesis(const SerializationHelperInterface * child) const override; - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Serialize int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; diff --git a/poincare/include/poincare/naperian_logarithm.h b/poincare/include/poincare/naperian_logarithm.h index 84aad46b6..8745cc98e 100644 --- a/poincare/include/poincare/naperian_logarithm.h +++ b/poincare/include/poincare/naperian_logarithm.h @@ -24,7 +24,7 @@ public: private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return LayoutHelper::Prefix(this, floatDisplayMode, numberOfSignificantDigits, name()); } int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { diff --git a/poincare/include/poincare/nth_root.h b/poincare/include/poincare/nth_root.h index 1f5b94544..a9d24d6b6 100644 --- a/poincare/include/poincare/nth_root.h +++ b/poincare/include/poincare/nth_root.h @@ -23,7 +23,7 @@ public: private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "root"); } diff --git a/poincare/include/poincare/nth_root_layout.h b/poincare/include/poincare/nth_root_layout.h index 36ef4caaf..c588ed13d 100644 --- a/poincare/include/poincare/nth_root_layout.h +++ b/poincare/include/poincare/nth_root_layout.h @@ -3,14 +3,13 @@ #include #include -#include namespace Poincare { -class NthRootLayoutReference; +class NthRootLayout; class NthRootLayoutNode : public LayoutNode { - friend class NthRootLayoutReference; + friend class NthRootLayout; public: constexpr static KDCoordinate k_leftRadixHeight = 8; constexpr static KDCoordinate k_leftRadixWidth = 5; @@ -66,12 +65,12 @@ private: bool m_hasIndex; }; -class NthRootLayoutReference : public LayoutReference { +class NthRootLayout : public Layout { public: - explicit NthRootLayoutReference(LayoutReference radicand); - NthRootLayoutReference(LayoutReference radicand, LayoutReference index); + explicit NthRootLayout(Layout radicand); + NthRootLayout(Layout radicand, Layout index); private: - NthRootLayoutReference(); + NthRootLayout(); }; } diff --git a/poincare/include/poincare/opposite.h b/poincare/include/poincare/opposite.h index 91042fe9b..505856ebc 100644 --- a/poincare/include/poincare/opposite.h +++ b/poincare/include/poincare/opposite.h @@ -37,7 +37,7 @@ public: // Layout bool childNeedsParenthesis(const SerializationHelperInterface * child) const override; - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode = Preferences::PrintFloatMode::Decimal, int numberOfSignificantDigits = 0) const override; // Simplification diff --git a/poincare/include/poincare/parenthesis.h b/poincare/include/poincare/parenthesis.h index 1af1d6dfd..2a6ec4be2 100644 --- a/poincare/include/poincare/parenthesis.h +++ b/poincare/include/poincare/parenthesis.h @@ -23,7 +23,7 @@ public: int polynomialDegree(char symbolName) const override; // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; diff --git a/poincare/include/poincare/permute_coefficient.h b/poincare/include/poincare/permute_coefficient.h index 01673d4b9..1cf2d413a 100644 --- a/poincare/include/poincare/permute_coefficient.h +++ b/poincare/include/poincare/permute_coefficient.h @@ -26,7 +26,7 @@ public: Type type() const override{ return Type::PermuteCoefficient; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/include/poincare/power.h b/poincare/include/poincare/power.h index 39c86fa1e..c139fde92 100644 --- a/poincare/include/poincare/power.h +++ b/poincare/include/poincare/power.h @@ -36,7 +36,7 @@ private: constexpr static int k_maxApproximatePowerMatrix = 1000; // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Serialize bool childNeedsParenthesis(const SerializationHelperInterface * child) const override; diff --git a/poincare/include/poincare/prediction_interval.h b/poincare/include/poincare/prediction_interval.h index 12b37656b..21a323306 100644 --- a/poincare/include/poincare/prediction_interval.h +++ b/poincare/include/poincare/prediction_interval.h @@ -26,7 +26,7 @@ public: int polynomialDegree(char symbolName) const override { return -1; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/include/poincare/product.h b/poincare/include/poincare/product.h index 35b87b212..f8bbe140d 100644 --- a/poincare/include/poincare/product.h +++ b/poincare/include/poincare/product.h @@ -19,7 +19,7 @@ public: private: const char * name() const override { return "product"; } float emptySequenceValue() const override { return 1.0f; } - LayoutReference createSequenceLayout(LayoutReference argumentLayout, LayoutReference subscriptLayout, LayoutReference superscriptLayout) const override; + Layout createSequenceLayout(Layout argumentLayout, Layout subscriptLayout, Layout superscriptLayout) const override; Evaluation evaluateWithNextTerm(DoublePrecision p, Evaluation a, Evaluation b) const override { return templatedApproximateWithNextTerm(a, b); } diff --git a/poincare/include/poincare/product_layout.h b/poincare/include/poincare/product_layout.h index 395873d47..f37897f34 100644 --- a/poincare/include/poincare/product_layout.h +++ b/poincare/include/poincare/product_layout.h @@ -23,10 +23,10 @@ private: constexpr static KDCoordinate k_lineThickness = 1; }; -class ProductLayoutReference : public LayoutReference { +class ProductLayout : public Layout { public: - ProductLayoutReference(LayoutReference argument, LayoutReference lowerB, LayoutReference upperB) : - LayoutReference(TreePool::sharedPool()->createTreeNode()) + ProductLayout(Layout argument, Layout lowerB, Layout upperB) : + Layout(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, argument); replaceChildAtIndexInPlace(1, lowerB); diff --git a/poincare/include/poincare/randint.h b/poincare/include/poincare/randint.h index e63fa17b6..c5da772d4 100644 --- a/poincare/include/poincare/randint.h +++ b/poincare/include/poincare/randint.h @@ -23,7 +23,7 @@ public: Type type() const override { return Type::Randint; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/include/poincare/random.h b/poincare/include/poincare/random.h index e9aa2117c..3a6c0a62f 100644 --- a/poincare/include/poincare/random.h +++ b/poincare/include/poincare/random.h @@ -26,7 +26,7 @@ public: Expression setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) override; private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/include/poincare/rational.h b/poincare/include/poincare/rational.h index f1eee04f7..9e56793ef 100644 --- a/poincare/include/poincare/rational.h +++ b/poincare/include/poincare/rational.h @@ -38,7 +38,7 @@ public: Sign sign() const override { return m_negative ? Sign::Negative : Sign::Positive; } // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Approximation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return Complex(templatedApproximate()); } diff --git a/poincare/include/poincare/real_part.h b/poincare/include/poincare/real_part.h index 8e7f90b37..a9a75834c 100644 --- a/poincare/include/poincare/real_part.h +++ b/poincare/include/poincare/real_part.h @@ -24,7 +24,7 @@ public: Type type() const override { return Type::RealPart; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/include/poincare/right_parenthesis_layout.h b/poincare/include/poincare/right_parenthesis_layout.h index 0cd9212fd..fd30b6d35 100644 --- a/poincare/include/poincare/right_parenthesis_layout.h +++ b/poincare/include/poincare/right_parenthesis_layout.h @@ -34,9 +34,9 @@ protected: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; }; -class RightParenthesisLayoutReference : public LayoutReference { +class RightParenthesisLayout : public Layout { public: - RightParenthesisLayoutReference(); + RightParenthesisLayout(); }; } diff --git a/poincare/include/poincare/right_square_bracket_layout.h b/poincare/include/poincare/right_square_bracket_layout.h index 32bb77589..438c70299 100644 --- a/poincare/include/poincare/right_square_bracket_layout.h +++ b/poincare/include/poincare/right_square_bracket_layout.h @@ -27,9 +27,9 @@ protected: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; }; -class RightSquareBracketLayoutReference : public LayoutReference { +class RightSquareBracketLayout : public Layout { public: - RightSquareBracketLayoutReference(); + RightSquareBracketLayout(); }; } diff --git a/poincare/include/poincare/round.h b/poincare/include/poincare/round.h index f6ae9e201..c5557e64c 100644 --- a/poincare/include/poincare/round.h +++ b/poincare/include/poincare/round.h @@ -24,7 +24,7 @@ public: Type type() const override { return Type::Round; } private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/include/poincare/sequence.h b/poincare/include/poincare/sequence.h index ec316d60c..c787952a2 100644 --- a/poincare/include/poincare/sequence.h +++ b/poincare/include/poincare/sequence.h @@ -12,11 +12,11 @@ class SequenceNode : public ExpressionNode { public: int numberOfChildren() const override { return 3; } private: - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); } - virtual LayoutReference createSequenceLayout(LayoutReference subscriptLayout, LayoutReference superscriptLayout, LayoutReference argumentLayout) const = 0; + virtual Layout createSequenceLayout(Layout subscriptLayout, Layout superscriptLayout, Layout argumentLayout) const = 0; virtual const char * name() const = 0; /* Approximation */ Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } diff --git a/poincare/include/poincare/sequence_layout.h b/poincare/include/poincare/sequence_layout.h index a5b637e05..61855690b 100644 --- a/poincare/include/poincare/sequence_layout.h +++ b/poincare/include/poincare/sequence_layout.h @@ -3,7 +3,6 @@ #include #include -#include namespace Poincare { diff --git a/poincare/include/poincare/sine.h b/poincare/include/poincare/sine.h index d7a1d18ad..a6d7f6224 100644 --- a/poincare/include/poincare/sine.h +++ b/poincare/include/poincare/sine.h @@ -28,7 +28,7 @@ public: private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/include/poincare/square_root.h b/poincare/include/poincare/square_root.h index 20fd75979..6f574649d 100644 --- a/poincare/include/poincare/square_root.h +++ b/poincare/include/poincare/square_root.h @@ -24,7 +24,7 @@ public: private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; diff --git a/poincare/include/poincare/store.h b/poincare/include/poincare/store.h index 8f4148703..c33a1b755 100644 --- a/poincare/include/poincare/store.h +++ b/poincare/include/poincare/store.h @@ -28,7 +28,7 @@ private: // Simplification Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Evalutation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } diff --git a/poincare/include/poincare/subtraction.h b/poincare/include/poincare/subtraction.h index 931332cf0..a46734214 100644 --- a/poincare/include/poincare/subtraction.h +++ b/poincare/include/poincare/subtraction.h @@ -36,7 +36,7 @@ public: /* Layout */ bool childNeedsParenthesis(const SerializationHelperInterface * child) const override; - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; /* Simplification */ diff --git a/poincare/include/poincare/sum.h b/poincare/include/poincare/sum.h index 8e28b119d..9aefb83b6 100644 --- a/poincare/include/poincare/sum.h +++ b/poincare/include/poincare/sum.h @@ -19,7 +19,7 @@ public: private: const char * name() const override { return "sum"; } float emptySequenceValue() const override { return 0.0f; } - LayoutReference createSequenceLayout(LayoutReference argumentLayout, LayoutReference subscriptLayout, LayoutReference superscriptLayout) const override; + Layout createSequenceLayout(Layout argumentLayout, Layout subscriptLayout, Layout superscriptLayout) const override; Evaluation evaluateWithNextTerm(DoublePrecision p, Evaluation a, Evaluation b) const override { return templatedApproximateWithNextTerm(a, b); } diff --git a/poincare/include/poincare/sum_layout.h b/poincare/include/poincare/sum_layout.h index d307b4c57..5dc9949d8 100644 --- a/poincare/include/poincare/sum_layout.h +++ b/poincare/include/poincare/sum_layout.h @@ -21,10 +21,10 @@ private: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; }; -class SumLayoutReference : public LayoutReference { +class SumLayout : public Layout { public: - SumLayoutReference(LayoutReference argument, LayoutReference lowerB, LayoutReference upperB) : - LayoutReference(TreePool::sharedPool()->createTreeNode()) + SumLayout(Layout argument, Layout lowerB, Layout upperB) : + Layout(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, argument); replaceChildAtIndexInPlace(1, lowerB); diff --git a/poincare/include/poincare/symbol.h b/poincare/include/poincare/symbol.h index 6474dfe7f..afc252cce 100644 --- a/poincare/include/poincare/symbol.h +++ b/poincare/include/poincare/symbol.h @@ -39,7 +39,7 @@ public: int simplificationOrderSameType(const ExpressionNode * e, bool canBeInterrupted) const override; /* Layout */ - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; /* Simplification */ diff --git a/poincare/include/poincare/tangent.h b/poincare/include/poincare/tangent.h index 7622aabe1..e09c70220 100644 --- a/poincare/include/poincare/tangent.h +++ b/poincare/include/poincare/tangent.h @@ -25,7 +25,7 @@ public: private: // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/include/poincare/undefined.h b/poincare/include/poincare/undefined.h index 293e45be5..fa8c49643 100644 --- a/poincare/include/poincare/undefined.h +++ b/poincare/include/poincare/undefined.h @@ -30,7 +30,7 @@ public: } // Layout - LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode = Preferences::PrintFloatMode::Decimal, int numberOfSignificantDigits = 0) const override; private: template Evaluation templatedApproximate() const; diff --git a/poincare/include/poincare/vertical_offset_layout.h b/poincare/include/poincare/vertical_offset_layout.h index 0f5fb84a3..921028ff7 100644 --- a/poincare/include/poincare/vertical_offset_layout.h +++ b/poincare/include/poincare/vertical_offset_layout.h @@ -3,7 +3,6 @@ #include #include -#include namespace Poincare { @@ -57,9 +56,9 @@ private: Type m_type; }; -class VerticalOffsetLayoutReference : public LayoutReference { +class VerticalOffsetLayout : public Layout { public: - VerticalOffsetLayoutReference(LayoutReference l, VerticalOffsetLayoutNode::Type type); + VerticalOffsetLayout(Layout l, VerticalOffsetLayoutNode::Type type); }; } diff --git a/poincare/src/absolute_value.cpp b/poincare/src/absolute_value.cpp index 18dfba73f..0c33a9c95 100644 --- a/poincare/src/absolute_value.cpp +++ b/poincare/src/absolute_value.cpp @@ -15,8 +15,8 @@ Complex AbsoluteValueNode::computeOnComplex(const std::complex c, Preferen return Complex(std::abs(c)); } -LayoutReference AbsoluteValueNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { - return AbsoluteValueLayoutReference(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits)); +Layout AbsoluteValueNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { + return AbsoluteValueLayout(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits)); } Expression AbsoluteValueNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { diff --git a/poincare/src/addition.cpp b/poincare/src/addition.cpp index dc8278f78..63f99c65a 100644 --- a/poincare/src/addition.cpp +++ b/poincare/src/addition.cpp @@ -35,7 +35,7 @@ bool AdditionNode::childNeedsParenthesis(const SerializationHelperInterface * ch return false; } -LayoutReference AdditionNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout AdditionNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Infix(Addition(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/arc_cosine.cpp b/poincare/src/arc_cosine.cpp index 3863e6b0b..7fc675580 100644 --- a/poincare/src/arc_cosine.cpp +++ b/poincare/src/arc_cosine.cpp @@ -6,7 +6,7 @@ namespace Poincare { -LayoutReference ArcCosineNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout ArcCosineNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(ArcCosine(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/arc_sine.cpp b/poincare/src/arc_sine.cpp index 2781c78f5..55b0294af 100644 --- a/poincare/src/arc_sine.cpp +++ b/poincare/src/arc_sine.cpp @@ -6,7 +6,7 @@ namespace Poincare { -LayoutReference ArcSineNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout ArcSineNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(ArcSine(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/arc_tangent.cpp b/poincare/src/arc_tangent.cpp index 3e23d00ca..654363b4d 100644 --- a/poincare/src/arc_tangent.cpp +++ b/poincare/src/arc_tangent.cpp @@ -6,7 +6,7 @@ namespace Poincare { -LayoutReference ArcTangentNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout ArcTangentNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(ArcTangent(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/binomial_coefficient.cpp b/poincare/src/binomial_coefficient.cpp index 1bd9c4497..7921806ef 100644 --- a/poincare/src/binomial_coefficient.cpp +++ b/poincare/src/binomial_coefficient.cpp @@ -13,8 +13,8 @@ Expression BinomialCoefficientNode::shallowReduce(Context & context, Preferences return BinomialCoefficient(this).shallowReduce(context, angleUnit); } -LayoutReference BinomialCoefficientNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { - return BinomialCoefficientLayoutReference( +Layout BinomialCoefficientNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { + return BinomialCoefficientLayout( childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits), childAtIndex(1)->createLayout(floatDisplayMode, numberOfSignificantDigits)); } diff --git a/poincare/src/bracket_pair_layout.cpp b/poincare/src/bracket_pair_layout.cpp index 21dc9dcb0..345a9cf89 100644 --- a/poincare/src/bracket_pair_layout.cpp +++ b/poincare/src/bracket_pair_layout.cpp @@ -69,11 +69,11 @@ void BracketPairLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * should void BracketPairLayoutNode::deleteBeforeCursor(LayoutCursor * cursor) { if (cursor->isEquivalentTo(LayoutCursor(childLayout(), LayoutCursor::Position::Left))) { // Case: Left of the operand. Delete the layout, keep the operand. - LayoutReference thisRef = LayoutReference(this); - LayoutReference child = LayoutReference(childLayout()); + Layout thisRef = Layout(this); + Layout child = Layout(childLayout()); thisRef.replaceChildWithGhostInPlace(child); // WARNING: do not call "this" afterwards - cursor->setLayoutReference(thisRef.childAtIndex(0)); + cursor->setLayout(thisRef.childAtIndex(0)); cursor->setPosition(LayoutCursor::Position::Left); thisRef.replaceWith(child, cursor); return; diff --git a/poincare/src/ceiling.cpp b/poincare/src/ceiling.cpp index 8c8964843..9e299572a 100644 --- a/poincare/src/ceiling.cpp +++ b/poincare/src/ceiling.cpp @@ -10,8 +10,8 @@ namespace Poincare { -LayoutReference CeilingNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { - return CeilingLayoutReference(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits)); +Layout CeilingNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { + return CeilingLayout(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits)); } int CeilingNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { diff --git a/poincare/src/char_layout.cpp b/poincare/src/char_layout.cpp index b52bf306b..1a80467db 100644 --- a/poincare/src/char_layout.cpp +++ b/poincare/src/char_layout.cpp @@ -61,8 +61,8 @@ void CharLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionColor, ctx->drawString(string, p, m_fontSize, expressionColor, backgroundColor); } -CharLayoutReference::CharLayoutReference(char c, KDText::FontSize fontSize) : - LayoutReference(TreePool::sharedPool()->createTreeNode()) +CharLayout::CharLayout(char c, KDText::FontSize fontSize) : + Layout(TreePool::sharedPool()->createTreeNode()) { node()->setChar(c); node()->setFontSize(fontSize); diff --git a/poincare/src/complex_argument.cpp b/poincare/src/complex_argument.cpp index d15822c55..271cb9705 100644 --- a/poincare/src/complex_argument.cpp +++ b/poincare/src/complex_argument.cpp @@ -9,7 +9,7 @@ extern "C" { namespace Poincare { -LayoutReference ComplexArgumentNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout ComplexArgumentNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(ComplexArgument(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/condensed_sum_layout.cpp b/poincare/src/condensed_sum_layout.cpp index 140a9ddbe..395e5669c 100644 --- a/poincare/src/condensed_sum_layout.cpp +++ b/poincare/src/condensed_sum_layout.cpp @@ -40,8 +40,8 @@ KDPoint CondensedSumLayoutNode::positionOfChild(LayoutNode * child) { return KDPoint(x,y); } -CondensedSumLayoutReference::CondensedSumLayoutReference(LayoutReference base, LayoutReference subscript, LayoutReference superscript) : - LayoutReference(TreePool::sharedPool()->createTreeNode()) +CondensedSumLayout::CondensedSumLayout(Layout base, Layout subscript, Layout superscript) : + Layout(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, base); replaceChildAtIndexInPlace(1, subscript); diff --git a/poincare/src/confidence_interval.cpp b/poincare/src/confidence_interval.cpp index 48a9e718e..e2d413afe 100644 --- a/poincare/src/confidence_interval.cpp +++ b/poincare/src/confidence_interval.cpp @@ -11,7 +11,7 @@ namespace Poincare { -LayoutReference ConfidenceIntervalNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout ConfidenceIntervalNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(ConfidenceInterval(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/conjugate.cpp b/poincare/src/conjugate.cpp index 69a6cb7bd..10557b37c 100644 --- a/poincare/src/conjugate.cpp +++ b/poincare/src/conjugate.cpp @@ -7,8 +7,8 @@ namespace Poincare { -LayoutReference ConjugateNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { - return ConjugateLayoutReference(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits)); +Layout ConjugateNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { + return ConjugateLayout(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits)); } int ConjugateNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { diff --git a/poincare/src/conjugate_layout.cpp b/poincare/src/conjugate_layout.cpp index e40213a9a..f556bd39d 100644 --- a/poincare/src/conjugate_layout.cpp +++ b/poincare/src/conjugate_layout.cpp @@ -96,7 +96,7 @@ bool ConjugateLayoutNode::willReplaceChild(LayoutNode * oldChild, LayoutNode * n } assert(oldChild == childLayout()); if (!force && newChild->isEmpty()) { - LayoutReference(this).replaceWith(LayoutReference(newChild), cursor); + Layout(this).replaceWith(Layout(newChild), cursor); // WARNING: do not call "this" afterwards return false; } diff --git a/poincare/src/cosine.cpp b/poincare/src/cosine.cpp index 5e8f79db7..8191389d0 100644 --- a/poincare/src/cosine.cpp +++ b/poincare/src/cosine.cpp @@ -17,7 +17,7 @@ Complex CosineNode::computeOnComplex(const std::complex c, Preferences::An return Complex(Trigonometry::RoundToMeaningfulDigits(res)); } -LayoutReference CosineNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout CosineNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(Cosine(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/decimal.cpp b/poincare/src/decimal.cpp index e8b41c405..753243dca 100644 --- a/poincare/src/decimal.cpp +++ b/poincare/src/decimal.cpp @@ -78,7 +78,7 @@ Expression DecimalNode::shallowBeautify(Context & context, Preferences::AngleUni return Decimal(this).shallowBeautify(context, angleUnit); } -LayoutReference DecimalNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout DecimalNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { char buffer[k_maxBufferSize]; int numberOfChars = convertToText(buffer, k_maxBufferSize, floatDisplayMode, numberOfSignificantDigits); return LayoutHelper::String(buffer, numberOfChars); diff --git a/poincare/src/determinant.cpp b/poincare/src/determinant.cpp index dd54b34c4..a76049057 100644 --- a/poincare/src/determinant.cpp +++ b/poincare/src/determinant.cpp @@ -8,7 +8,7 @@ extern "C" { namespace Poincare { -LayoutReference DeterminantNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout DeterminantNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(Determinant(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/division.cpp b/poincare/src/division.cpp index 2287ca10e..c904e2f1d 100644 --- a/poincare/src/division.cpp +++ b/poincare/src/division.cpp @@ -29,10 +29,10 @@ bool DivisionNode::childNeedsParenthesis(const SerializationHelperInterface * ch return static_cast(child)->isOfType(types, 5); } -LayoutReference DivisionNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout DivisionNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { const ExpressionNode * numerator = childAtIndex(0)->type() == Type::Parenthesis ? childAtIndex(0)->childAtIndex(0) : childAtIndex(0); const ExpressionNode * denominator = childAtIndex(1)->type() == Type::Parenthesis ? childAtIndex(1)->childAtIndex(0) : childAtIndex(1); - return FractionLayoutReference(numerator->createLayout(floatDisplayMode, numberOfSignificantDigits), denominator->createLayout(floatDisplayMode, numberOfSignificantDigits)); + return FractionLayout(numerator->createLayout(floatDisplayMode, numberOfSignificantDigits), denominator->createLayout(floatDisplayMode, numberOfSignificantDigits)); } Expression DivisionNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { diff --git a/poincare/src/division_quotient.cpp b/poincare/src/division_quotient.cpp index a5e5833de..6f07d38da 100644 --- a/poincare/src/division_quotient.cpp +++ b/poincare/src/division_quotient.cpp @@ -12,7 +12,7 @@ Expression DivisionQuotientNode::shallowReduce(Context & context, Preferences::A return DivisionQuotient(this).shallowReduce(context, angleUnit); } -LayoutReference DivisionQuotientNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout DivisionQuotientNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(DivisionQuotient(this), floatDisplayMode, numberOfSignificantDigits, name()); } int DivisionQuotientNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { diff --git a/poincare/src/division_remainder.cpp b/poincare/src/division_remainder.cpp index ae3b34da2..0a0e55fa0 100644 --- a/poincare/src/division_remainder.cpp +++ b/poincare/src/division_remainder.cpp @@ -8,7 +8,7 @@ namespace Poincare { -LayoutReference DivisionRemainderNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout DivisionRemainderNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(DivisionRemainder(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/empty_expression.cpp b/poincare/src/empty_expression.cpp index 7dd0bd1c8..538057093 100644 --- a/poincare/src/empty_expression.cpp +++ b/poincare/src/empty_expression.cpp @@ -10,8 +10,8 @@ int EmptyExpressionNode::serialize(char * buffer, int bufferSize, Preferences::P return SerializationHelper::Char(buffer, bufferSize, Ion::Charset::Empty); } -LayoutReference EmptyExpressionNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { - return EmptyLayoutReference(); +Layout EmptyExpressionNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { + return EmptyLayout(); } template Evaluation EmptyExpressionNode::templatedApproximate(Context& context, Preferences::AngleUnit angleUnit) const { diff --git a/poincare/src/empty_layout.cpp b/poincare/src/empty_layout.cpp index 19da38842..924a26a24 100644 --- a/poincare/src/empty_layout.cpp +++ b/poincare/src/empty_layout.cpp @@ -66,8 +66,8 @@ void EmptyLayoutNode::moveCursorVertically(VerticalDirection direction, LayoutCu } bool EmptyLayoutNode::willAddSibling(LayoutCursor * cursor, LayoutNode * sibling, bool moveCursor) { - EmptyLayoutReference thisRef(this); - LayoutReference siblingRef(sibling); // Create the reference now, as the node might be moved + EmptyLayout thisRef(this); + Layout siblingRef(sibling); // Create the reference now, as the node might be moved if (m_color == Color::Grey) { /* The parent is a MatrixLayout, and the current empty row or column is * being filled in, so add a new empty row or column. */ @@ -94,9 +94,9 @@ void EmptyLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionColor } } -EmptyLayoutReference::EmptyLayoutReference(const EmptyLayoutNode * n) : LayoutReference(n) {} -EmptyLayoutReference::EmptyLayoutReference(EmptyLayoutNode::Color color, bool visible, KDText::FontSize fontSize, bool margins) : - LayoutReference(TreePool::sharedPool()->createTreeNode()) +EmptyLayout::EmptyLayout(const EmptyLayoutNode * n) : Layout(n) {} +EmptyLayout::EmptyLayout(EmptyLayoutNode::Color color, bool visible, KDText::FontSize fontSize, bool margins) : + Layout(TreePool::sharedPool()->createTreeNode()) { node()->setColor(color); node()->setVisible(visible); diff --git a/poincare/src/equal.cpp b/poincare/src/equal.cpp index 03a726f65..f4988754f 100644 --- a/poincare/src/equal.cpp +++ b/poincare/src/equal.cpp @@ -23,10 +23,10 @@ Expression EqualNode::shallowReduce(Context & context, Preferences::AngleUnit an return Equal(this).shallowReduce(context, angleUnit); } -LayoutReference EqualNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { - HorizontalLayoutReference result; +Layout EqualNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { + HorizontalLayout result; result.addOrMergeChildAtIndex(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits), 0, false); - result.addChildAtIndex(CharLayoutReference('='), result.numberOfChildren(), result.numberOfChildren(), nullptr); + result.addChildAtIndex(CharLayout('='), result.numberOfChildren(), result.numberOfChildren(), nullptr); result.addOrMergeChildAtIndex(childAtIndex(1)->createLayout(floatDisplayMode, numberOfSignificantDigits), result.numberOfChildren(), false); return result; } diff --git a/poincare/src/expression.cpp b/poincare/src/expression.cpp index ad6736e55..5ae9d4ed0 100644 --- a/poincare/src/expression.cpp +++ b/poincare/src/expression.cpp @@ -229,8 +229,8 @@ bool Expression::isEqualToItsApproximationLayout(Expression approximation, char /* Layout Helper */ -LayoutReference Expression::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { - return isUninitialized() ? LayoutReference() : node()->createLayout(floatDisplayMode, numberOfSignificantDigits); +Layout Expression::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { + return isUninitialized() ? Layout() : node()->createLayout(floatDisplayMode, numberOfSignificantDigits); } int Expression::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return isUninitialized() ? 0 : node()->serialize(buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits); } diff --git a/poincare/src/factor.cpp b/poincare/src/factor.cpp index 33f8eba13..cc1a71b77 100644 --- a/poincare/src/factor.cpp +++ b/poincare/src/factor.cpp @@ -13,7 +13,7 @@ extern "C" { namespace Poincare { -LayoutReference FactorNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout FactorNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(Factor(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/factorial.cpp b/poincare/src/factorial.cpp index c06278166..61a4d3620 100644 --- a/poincare/src/factorial.cpp +++ b/poincare/src/factorial.cpp @@ -50,11 +50,11 @@ Complex FactorialNode::computeOnComplex(const std::complex c, Preferences: return Complex(std::round(result)); } -LayoutReference FactorialNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { - HorizontalLayoutReference result; +Layout FactorialNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { + HorizontalLayout result; result.addOrMergeChildAtIndex(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits), 0, false); int childrenCount = result.numberOfChildren(); - result.addChildAtIndex(CharLayoutReference('!'), childrenCount, childrenCount, nullptr); + result.addChildAtIndex(CharLayout('!'), childrenCount, childrenCount, nullptr); return result; } diff --git a/poincare/src/floor.cpp b/poincare/src/floor.cpp index 09e6a2ca1..e8506fad8 100644 --- a/poincare/src/floor.cpp +++ b/poincare/src/floor.cpp @@ -10,8 +10,8 @@ namespace Poincare { -LayoutReference FloorNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { - return FloorLayoutReference(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits)); +Layout FloorNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { + return FloorLayout(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits)); } int FloorNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { diff --git a/poincare/src/frac_part.cpp b/poincare/src/frac_part.cpp index f07d83c38..014961ba2 100644 --- a/poincare/src/frac_part.cpp +++ b/poincare/src/frac_part.cpp @@ -7,7 +7,7 @@ namespace Poincare { -LayoutReference FracPartNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout FracPartNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(FracPart(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/fraction_layout.cpp b/poincare/src/fraction_layout.cpp index 0d5d3daff..da2053c95 100644 --- a/poincare/src/fraction_layout.cpp +++ b/poincare/src/fraction_layout.cpp @@ -90,20 +90,20 @@ void FractionLayoutNode::deleteBeforeCursor(LayoutCursor * cursor) { if (cursor->layoutNode() == denominatorLayout()) { /* Case: Left of the denominator. Replace the fraction with a horizontal * juxtaposition of the numerator and the denominator. */ - LayoutReference thisRef = LayoutReference(this); + Layout thisRef = Layout(this); assert(cursor->position() == LayoutCursor::Position::Left); if (numeratorLayout()->isEmpty() && denominatorLayout()->isEmpty()) { /* Case: Numerator and denominator are empty. Move the cursor and replace * the fraction with an empty layout. */ - thisRef.replaceWith(EmptyLayoutReference(), cursor); + thisRef.replaceWith(EmptyLayout(), cursor); // WARNING: Do no use "this" afterwards return; } /* Else, replace the fraction with a juxtaposition of the numerator and * denominator. Place the cursor in the middle of the juxtaposition, which * is right of the numerator. */ - LayoutReference numeratorRef = LayoutReference(numeratorLayout()); - LayoutReference denominatorRef = LayoutReference(denominatorLayout()); + Layout numeratorRef = Layout(numeratorLayout()); + Layout denominatorRef = Layout(denominatorLayout()); thisRef.replaceChildWithGhostInPlace(numeratorRef); // WARNING: Do no use "this" afterwards thisRef.replaceChildWithGhostInPlace(denominatorRef); @@ -216,8 +216,8 @@ void FractionLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionCo ctx->fillRect(KDRect(p.x()+Metric::FractionAndConjugateHorizontalMargin, fractionLineY, layoutSize().width()-2*Metric::FractionAndConjugateHorizontalMargin, k_fractionLineHeight), expressionColor); } -FractionLayoutReference::FractionLayoutReference(LayoutReference numerator, LayoutReference denominator) : - LayoutReference(TreePool::sharedPool()->createTreeNode()) +FractionLayout::FractionLayout(Layout numerator, Layout denominator) : + Layout(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, numerator); replaceChildAtIndexInPlace(1, denominator); diff --git a/poincare/src/global_context.cpp b/poincare/src/global_context.cpp index ab35342a3..175152be7 100644 --- a/poincare/src/global_context.cpp +++ b/poincare/src/global_context.cpp @@ -38,14 +38,14 @@ const Expression GlobalContext::expressionForSymbol(const Symbol & symbol) { return Expression(static_cast(TreePool::sharedPool()->copyTreeFromAddress(record.value().buffer, record.value().size))); } -LayoutReference GlobalContext::layoutForSymbol(const Symbol & symbol, int numberOfSignificantDigits) { +Layout GlobalContext::layoutForSymbol(const Symbol & symbol, int numberOfSignificantDigits) { if (Symbol::isMatrixSymbol(symbol.name())) { Expression e = expressionForSymbol(symbol); if (!e.isUninitialized()) { return e.createLayout(Preferences::PrintFloatMode::Decimal, numberOfSignificantDigits); } } - return LayoutReference(); + return Layout(); } void GlobalContext::setExpressionForSymbolName(const Expression & expression, const Symbol & symbol, Context & context) { diff --git a/poincare/src/great_common_divisor.cpp b/poincare/src/great_common_divisor.cpp index 5003ac49f..c8e12c979 100644 --- a/poincare/src/great_common_divisor.cpp +++ b/poincare/src/great_common_divisor.cpp @@ -8,7 +8,7 @@ namespace Poincare { -LayoutReference GreatCommonDivisorNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout GreatCommonDivisorNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(GreatCommonDivisor(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/grid_layout.cpp b/poincare/src/grid_layout.cpp index 1a5355c60..f10bde101 100644 --- a/poincare/src/grid_layout.cpp +++ b/poincare/src/grid_layout.cpp @@ -97,13 +97,13 @@ void GridLayoutNode::didAddChildAtIndex(int newNumberOfChildren) { // Protected void GridLayoutNode::addEmptyRow(EmptyLayoutNode::Color color) { - GridLayoutReference thisRef = GridLayoutReference(this); + GridLayout thisRef = GridLayout(this); int previousNumberOfChildren = numberOfChildren(); int columnsCount = m_numberOfColumns; int previousRowCount = m_numberOfRows; for (int i = 0; i < columnsCount; i++) { thisRef.addChildAtIndex( - EmptyLayoutReference(color), + EmptyLayout(color), previousNumberOfChildren, previousNumberOfChildren + i, nullptr); @@ -113,13 +113,13 @@ void GridLayoutNode::addEmptyRow(EmptyLayoutNode::Color color) { } void GridLayoutNode::addEmptyColumn(EmptyLayoutNode::Color color) { - GridLayoutReference thisRef = GridLayoutReference(this); + GridLayout thisRef = GridLayout(this); int previousNumberOfChildren = numberOfChildren(); int rowsCount = m_numberOfRows; int futureColumnsCount = m_numberOfColumns + 1; for (int i = 0; i < rowsCount; i++) { thisRef.addChildAtIndex( - EmptyLayoutReference(color), + EmptyLayout(color), i*futureColumnsCount + futureColumnsCount-1, previousNumberOfChildren + i, nullptr); @@ -130,7 +130,7 @@ void GridLayoutNode::addEmptyColumn(EmptyLayoutNode::Color color) { void GridLayoutNode::deleteRowAtIndex(int index) { assert(index >= 0 && index < m_numberOfRows); - LayoutReference thisRef = LayoutReference(this); + Layout thisRef = Layout(this); for (int i = 0; i < m_numberOfColumns; i++) { thisRef.removeChildAtIndexInPlace(index * m_numberOfColumns); } @@ -139,7 +139,7 @@ void GridLayoutNode::deleteRowAtIndex(int index) { void GridLayoutNode::deleteColumnAtIndex(int index) { assert(index >= 0 && index < m_numberOfColumns); - LayoutReference thisRef = LayoutReference(this); + Layout thisRef = Layout(this); for (int i = (m_numberOfRows - 1) * m_numberOfColumns + index; i > -1; i-= m_numberOfColumns) { thisRef.removeChildAtIndexInPlace(i); } @@ -262,7 +262,7 @@ KDCoordinate GridLayoutNode::width() const { } // Grid Layout Reference -void GridLayoutReference::setDimensions(int rows, int columns) { +void GridLayout::setDimensions(int rows, int columns) { assert(rows * columns == numberOfChildren()); setNumberOfRows(rows); setNumberOfColumns(columns); diff --git a/poincare/src/horizontal_layout.cpp b/poincare/src/horizontal_layout.cpp index d78e0cb35..cad3199eb 100644 --- a/poincare/src/horizontal_layout.cpp +++ b/poincare/src/horizontal_layout.cpp @@ -225,7 +225,7 @@ KDPoint HorizontalLayoutNode::positionOfChild(LayoutNode * l) { bool HorizontalLayoutNode::willAddChildAtIndex(LayoutNode * l, int * index, int * currentNumberOfChildren, LayoutCursor * cursor) { if (m_numberOfChildren > 0) { - HorizontalLayoutReference thisRef = HorizontalLayoutReference(this); + HorizontalLayout thisRef = HorizontalLayout(this); thisRef.removeEmptyChildBeforeInsertionAtIndex(index, currentNumberOfChildren, !l->mustHaveLeftSibling(), cursor); *currentNumberOfChildren = thisRef.numberOfChildren(); } @@ -233,7 +233,7 @@ bool HorizontalLayoutNode::willAddChildAtIndex(LayoutNode * l, int * index, int } bool HorizontalLayoutNode::willAddSibling(LayoutCursor * cursor, LayoutNode * sibling, bool moveCursor) { - HorizontalLayoutReference thisRef(this); + HorizontalLayout thisRef(this); int newChildIndex = cursor->position() == LayoutCursor::Position::Left ? 0 : numberOfChildren(); thisRef.addOrMergeChildAtIndex(sibling, newChildIndex, true, cursor); return false; @@ -244,7 +244,7 @@ bool HorizontalLayoutNode::willRemoveChild(LayoutNode * l, LayoutCursor * cursor assert(childAtIndex(0) == l); LayoutNode * p = parent(); if (p != nullptr) { - LayoutReference(p).removeChild(HorizontalLayoutReference(this), cursor); + Layout(p).removeChild(HorizontalLayout(this), cursor); // WARNING: Do not call "this" afterwards return false; } @@ -257,7 +257,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()) { - LayoutReference(this).addChildAtIndex(EmptyLayoutReference(), 0, numberOfChildren(), cursor); + Layout(this).addChildAtIndex(EmptyLayout(), 0, numberOfChildren(), cursor); } } @@ -268,7 +268,7 @@ bool HorizontalLayoutNode::willReplaceChild(LayoutNode * oldChild, LayoutNode * if (force) { return true; } - HorizontalLayoutReference thisRef(this); + HorizontalLayout thisRef(this); int oldChildIndex = indexOfChild(oldChild); if (newChild->isEmpty()) { if (numberOfChildren() > 1) { @@ -277,10 +277,10 @@ bool HorizontalLayoutNode::willReplaceChild(LayoutNode * oldChild, LayoutNode * thisRef.removeChild(oldChild, nullptr); if (cursor != nullptr) { if (oldChildIndex == 0) { - cursor->setLayoutReference(thisRef); + cursor->setLayout(thisRef); cursor->setPosition(LayoutCursor::Position::Left); } else { - cursor->setLayoutReference(thisRef.childAtIndex(oldChildIndex -1)); + cursor->setLayout(thisRef.childAtIndex(oldChildIndex -1)); cursor->setPosition(LayoutCursor::Position::Right); } } @@ -300,7 +300,7 @@ bool HorizontalLayoutNode::willReplaceChild(LayoutNode * oldChild, LayoutNode * thisRef.removeChild(oldChild, nullptr); // WARNING: do not call "this" afterwards if (cursor != nullptr) { - cursor->setLayoutReference(thisRef); + cursor->setLayout(thisRef); cursor->setPosition(LayoutCursor::Position::Left); } return false; @@ -336,7 +336,7 @@ bool HorizontalLayoutNode::willReplaceChild(LayoutNode * oldChild, LayoutNode * } } bool oldChildRemovedAtMerge = oldChild->isEmpty(); - thisRef.mergeChildrenAtIndex(HorizontalLayoutReference(static_cast(newChild)), indexForInsertion + 1, true); + thisRef.mergeChildrenAtIndex(HorizontalLayout(static_cast(newChild)), indexForInsertion + 1, true); // WARNING: do not call "this" afterwards if (!oldChildRemovedAtMerge) { thisRef.removeChildAtIndex(indexForInsertion, cursor); @@ -350,55 +350,55 @@ bool HorizontalLayoutNode::willReplaceChild(LayoutNode * oldChild, LayoutNode * return true; } -// HorizontalLayoutReference +// HorizontalLayout -HorizontalLayoutReference::HorizontalLayoutReference() : LayoutReference(TreePool::sharedPool()->createTreeNode()) {} +HorizontalLayout::HorizontalLayout() : Layout(TreePool::sharedPool()->createTreeNode()) {} -HorizontalLayoutReference::HorizontalLayoutReference(LayoutReference l) : HorizontalLayoutReference() { +HorizontalLayout::HorizontalLayout(Layout l) : HorizontalLayout() { addChildAtIndexInPlace(l, 0, 0); } -HorizontalLayoutReference::HorizontalLayoutReference(LayoutReference l1, LayoutReference l2) : HorizontalLayoutReference() { +HorizontalLayout::HorizontalLayout(Layout l1, Layout l2) : HorizontalLayout() { addChildAtIndexInPlace(l1, 0, 0); addChildAtIndexInPlace(l2, 1, 1); } -HorizontalLayoutReference::HorizontalLayoutReference(LayoutReference l1, LayoutReference l2, LayoutReference l3) : HorizontalLayoutReference() { +HorizontalLayout::HorizontalLayout(Layout l1, Layout l2, Layout l3) : HorizontalLayout() { addChildAtIndexInPlace(l1, 0, 0); addChildAtIndexInPlace(l2, 1, 1); addChildAtIndexInPlace(l3, 2, 2); } -HorizontalLayoutReference::HorizontalLayoutReference(LayoutReference l1, LayoutReference l2, LayoutReference l3, LayoutReference l4) : HorizontalLayoutReference() { +HorizontalLayout::HorizontalLayout(Layout l1, Layout l2, Layout l3, Layout l4) : HorizontalLayout() { addChildAtIndexInPlace(l1, 0, 0); addChildAtIndexInPlace(l2, 1, 1); addChildAtIndexInPlace(l3, 2, 2); addChildAtIndexInPlace(l4, 3, 3); } -HorizontalLayoutReference::HorizontalLayoutReference(const LayoutReference * children, size_t numberOfChildren) : HorizontalLayoutReference() { +HorizontalLayout::HorizontalLayout(const Layout * children, size_t numberOfChildren) : HorizontalLayout() { for (size_t i = 0; i < numberOfChildren; i++) { addChildAtIndexInPlace(children[i], i, i); } } -void HorizontalLayoutReference::addOrMergeChildAtIndex(LayoutReference l, int index, bool removeEmptyChildren, LayoutCursor * cursor) { +void HorizontalLayout::addOrMergeChildAtIndex(Layout l, int index, bool removeEmptyChildren, LayoutCursor * cursor) { if (l.isHorizontal()) { - mergeChildrenAtIndex(HorizontalLayoutReference(static_cast(l.node())), index, removeEmptyChildren, cursor); + mergeChildrenAtIndex(HorizontalLayout(static_cast(l.node())), index, removeEmptyChildren, cursor); } else { addChildAtIndex(l, index, numberOfChildren(), cursor, removeEmptyChildren); } } -void HorizontalLayoutReference::addChildAtIndex(LayoutReference l, int index, int currentNumberOfChildren, LayoutCursor * cursor, bool removeEmptyChildren) { +void HorizontalLayout::addChildAtIndex(Layout l, int index, int currentNumberOfChildren, LayoutCursor * cursor, bool removeEmptyChildren) { if (!removeEmptyChildren || !l.isEmpty() || numberOfChildren() == 0 || (index < numberOfChildren() && childAtIndex(index).mustHaveLeftSibling())) { - LayoutReference::addChildAtIndex(l, index, currentNumberOfChildren, cursor); + Layout::addChildAtIndex(l, index, currentNumberOfChildren, cursor); } } -void HorizontalLayoutReference::mergeChildrenAtIndex(HorizontalLayoutReference h, int index, bool removeEmptyChildren, LayoutCursor * cursor) { +void HorizontalLayout::mergeChildrenAtIndex(HorizontalLayout h, int index, bool removeEmptyChildren, LayoutCursor * cursor) { int newIndex = index; // Remove h if it is a child @@ -423,7 +423,7 @@ void HorizontalLayoutReference::mergeChildrenAtIndex(HorizontalLayoutReference h assert(newIndex >= 0 && newIndex <= numberOfChildren()); // Prepare the next cursor position - LayoutReference nextPointedLayout; + Layout nextPointedLayout; LayoutCursor::Position nextPosition = LayoutCursor::Position::Left; if (newIndex < numberOfChildren()) { nextPointedLayout = childAtIndex(newIndex); @@ -457,18 +457,18 @@ void HorizontalLayoutReference::mergeChildrenAtIndex(HorizontalLayoutReference h // Set the cursor if (cursor != nullptr) { - cursor->setLayoutReference(nextPointedLayout); + cursor->setLayout(nextPointedLayout); cursor->setPosition(nextPosition); } } -void HorizontalLayoutReference::removeEmptyChildBeforeInsertionAtIndex(int * index, int * currentNumberOfChildren, bool shouldRemoveOnLeft, LayoutCursor * cursor) { +void HorizontalLayout::removeEmptyChildBeforeInsertionAtIndex(int * index, int * currentNumberOfChildren, bool shouldRemoveOnLeft, LayoutCursor * cursor) { int childrenCount = currentNumberOfChildren == nullptr ? numberOfChildren() : *currentNumberOfChildren; assert(*index >= 0 && *index <= childrenCount); /* If empty, remove the child that would be on the right of the inserted * layout. */ if (*index < childrenCount) { - LayoutReference c = childAtIndex(*index); + Layout c = childAtIndex(*index); if (c.isEmpty()) { removeChild(c, cursor, true); childrenCount--; @@ -480,7 +480,7 @@ void HorizontalLayoutReference::removeEmptyChildBeforeInsertionAtIndex(int * ind /* If empty, remove the child that would be on the left of the inserted * layout. */ if (shouldRemoveOnLeft && *index - 1 >= 0 && *index - 1 < childrenCount) { - LayoutReference c = childAtIndex(*index - 1); + Layout c = childAtIndex(*index - 1); if (c.isEmpty()) { removeChild(c, cursor, true); *index = *index - 1; diff --git a/poincare/src/hyperbolic_trigonometric_function.cpp b/poincare/src/hyperbolic_trigonometric_function.cpp index 1ae98438c..2bd0d3b5e 100644 --- a/poincare/src/hyperbolic_trigonometric_function.cpp +++ b/poincare/src/hyperbolic_trigonometric_function.cpp @@ -3,7 +3,7 @@ namespace Poincare { -LayoutReference HyperbolicTrigonometricFunctionNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout HyperbolicTrigonometricFunctionNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(HyperbolicTrigonometricFunction(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/imaginary_part.cpp b/poincare/src/imaginary_part.cpp index 8ad23c497..4c2a94711 100644 --- a/poincare/src/imaginary_part.cpp +++ b/poincare/src/imaginary_part.cpp @@ -7,7 +7,7 @@ namespace Poincare { -LayoutReference ImaginaryPartNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout ImaginaryPartNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(ImaginaryPart(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/infinity.cpp b/poincare/src/infinity.cpp index 796f55f7c..691fb0f48 100644 --- a/poincare/src/infinity.cpp +++ b/poincare/src/infinity.cpp @@ -13,7 +13,7 @@ Expression InfinityNode::setSign(Sign s, Context & context, Preferences::AngleUn return Infinity(this).setSign(s, context, angleUnit); } -LayoutReference InfinityNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout InfinityNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { char buffer[5]; int numberOfChars = serialize(buffer, 5, floatDisplayMode, numberOfSignificantDigits); return LayoutHelper::String(buffer, numberOfChars); diff --git a/poincare/src/integer.cpp b/poincare/src/integer.cpp index 5c1e072b5..10c484a11 100644 --- a/poincare/src/integer.cpp +++ b/poincare/src/integer.cpp @@ -277,7 +277,7 @@ int Integer::serialize(char * buffer, int bufferSize) const { // Layout -HorizontalLayoutReference Integer::createLayout() const { +HorizontalLayout Integer::createLayout() const { char buffer[k_maxNumberOfDigitsBase10]; int numberOfChars = serialize(buffer, k_maxNumberOfDigitsBase10); return LayoutHelper::String(buffer, numberOfChars); diff --git a/poincare/src/integral.cpp b/poincare/src/integral.cpp index 9f948d219..855da2452 100644 --- a/poincare/src/integral.cpp +++ b/poincare/src/integral.cpp @@ -21,8 +21,8 @@ int IntegralNode::polynomialDegree(char symbolName) const { return ExpressionNode::polynomialDegree(symbolName); } -LayoutReference IntegralNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { - return IntegralLayoutReference( +Layout IntegralNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { + return IntegralLayout( childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits), childAtIndex(1)->createLayout(floatDisplayMode, numberOfSignificantDigits), childAtIndex(2)->createLayout(floatDisplayMode, numberOfSignificantDigits)); diff --git a/poincare/src/integral_layout.cpp b/poincare/src/integral_layout.cpp index 6bb7cac3b..c9dbebfd7 100644 --- a/poincare/src/integral_layout.cpp +++ b/poincare/src/integral_layout.cpp @@ -119,11 +119,11 @@ void IntegralLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldReco void IntegralLayoutNode::deleteBeforeCursor(LayoutCursor * cursor) { if (cursor->isEquivalentTo(LayoutCursor(integrandLayout(), LayoutCursor::Position::Left))) { // Case: Left of the integrand. Delete the layout, keep the integrand. - LayoutReference thisRef = LayoutReference(this); - LayoutReference integrand = LayoutReference(integrandLayout()); + Layout thisRef = Layout(this); + Layout integrand = Layout(integrandLayout()); thisRef.replaceChildWithGhostInPlace(integrand); // WARNING: Do not use "this" afterwards - cursor->setLayoutReference(thisRef.childAtIndex(0)); + cursor->setLayout(thisRef.childAtIndex(0)); cursor->setPosition(LayoutCursor::Position::Left); thisRef.replaceWith(integrand, cursor); return; diff --git a/poincare/src/layout.cpp b/poincare/src/layout.cpp index 1d28f7ade..35106f58c 100644 --- a/poincare/src/layout.cpp +++ b/poincare/src/layout.cpp @@ -1,231 +1,273 @@ #include +#include +#include +#include #include #include -#include -#include -#include namespace Poincare { - -// Rendering - -void LayoutNode::draw(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) { - for (LayoutNode * l : children()) { - l->draw(ctx, p, expressionColor, backgroundColor); +Layout Layout::clone() const { + if (isUninitialized()) { + return Layout(); } - render(ctx, absoluteOrigin().translatedBy(p), expressionColor, backgroundColor); + TreeHandle c = TreeHandle::clone(); + Layout cast = Layout(static_cast(c.node())); + cast.invalidAllSizesPositionsAndBaselines(); + return cast; } -KDPoint LayoutNode::origin() { - LayoutNode * p = parent(); - if (p == nullptr) { - return absoluteOrigin(); - } else { - return KDPoint(absoluteOrigin().x() - p->absoluteOrigin().x(), - absoluteOrigin().y() - p->absoluteOrigin().y()); - } +// Cursor +LayoutCursor Layout::cursor() const { + assert(!isUninitialized()); + return LayoutCursor(const_cast(this)->node()); } -KDPoint LayoutNode::absoluteOrigin() { - LayoutNode * p = parent(); - if (!m_positioned) { - if (p != nullptr) { - m_frame.setOrigin(p->absoluteOrigin().translatedBy(p->positionOfChild(this))); - } else { - m_frame.setOrigin(KDPointZero); - } - m_positioned = true; - } - return m_frame.origin(); +LayoutCursor Layout::equivalentCursor(LayoutCursor * cursor) { + assert(!isUninitialized()); + return node()->equivalentCursor(cursor); } -KDSize LayoutNode::layoutSize() { - if (!m_sized) { - m_frame.setSize(computeSize()); - m_sized = true; - } - return m_frame.size(); -} - -KDCoordinate LayoutNode::baseline() { - if (!m_baselined) { - m_baseline = computeBaseline(); - m_baselined = true; - } - return m_baseline; -} - -void LayoutNode::invalidAllSizesPositionsAndBaselines() { - m_sized = false; - m_positioned = false; - m_baselined = false; - for (LayoutNode * l : children()) { - l->invalidAllSizesPositionsAndBaselines(); - } -} - -// Tree navigation -LayoutCursor LayoutNode::equivalentCursor(LayoutCursor * cursor) { - // Only HorizontalLayout may have no parent, and it overloads this method - assert(parent() != nullptr); - return (cursor->layoutReference().node() == this) ? parent()->equivalentCursor(cursor) : LayoutCursor(); +Layout Layout::childAtIndex(int i) { + TreeHandle c = TreeHandle::childAtIndex(i); + return static_cast(c); } // Tree modification -void LayoutNode::deleteBeforeCursor(LayoutCursor * cursor) { - int indexOfPointedLayout = indexOfChild(cursor->layoutNode()); - if (indexOfPointedLayout >= 0) { - // Case: The pointed layout is a child. Move Left. - assert(cursor->position() == LayoutCursor::Position::Left); - bool shouldRecomputeLayout = false; - cursor->moveLeft(&shouldRecomputeLayout); +void Layout::replaceChild(Layout oldChild, Layout newChild, LayoutCursor * cursor, bool force) { + int childIndex = indexOfChild(oldChild); + assert(childIndex >= 0); + if (!node()->willReplaceChild(oldChild.node(), newChild.node(), cursor, force)) { return; } - assert(cursor->layoutNode() == this); - LayoutNode * p = parent(); - // Case: this is the pointed layout. - if (p == nullptr) { - // Case: No parent. Return. + replaceChildInPlace(oldChild, newChild); + if (cursor != nullptr) { + cursor->setLayout(newChild); + } + node()->didReplaceChildAtIndex(childIndex, cursor, force); +} + +void Layout::replaceChildWithEmpty(Layout oldChild, LayoutCursor * cursor) { + replaceChild(oldChild, EmptyLayout(), cursor); +} + +void Layout::replaceWith(Layout newChild, LayoutCursor * cursor) { + Layout p = parent(); + assert(!p.isUninitialized()); + p.replaceChild(*this, newChild, cursor); +} + +void Layout::replaceWithJuxtapositionOf(Layout leftChild, Layout rightChild, LayoutCursor * cursor, bool putCursorInTheMiddle) { + Layout p = parent(); + assert(!p.isUninitialized()); + if (!p.isHorizontal()) { + /* One of the children to juxtapose might be "this", so we cannot just call + * replaceWith. */ + HorizontalLayout horizontalLayoutR; + p.replaceChild(*this, horizontalLayoutR, cursor); + horizontalLayoutR.addOrMergeChildAtIndex(leftChild, 0, false); + if (putCursorInTheMiddle) { + if (!horizontalLayoutR.isEmpty()) { + cursor->setLayout(horizontalLayoutR.childAtIndex(horizontalLayoutR.numberOfChildren()-1)); + cursor->setPosition(LayoutCursor::Position::Right); + } else { + cursor->setLayout(horizontalLayoutR); + cursor->setPosition(LayoutCursor::Position::Left); + } + } + horizontalLayoutR.addOrMergeChildAtIndex(rightChild, 1, false); + return; + } + /* The parent is an Horizontal layout, so directly add the two juxtaposition + * children to the parent. */ + int idxInParent = p.indexOfChild(*this); + HorizontalLayout castedParent = HorizontalLayout(static_cast(p.node())); + if (putCursorInTheMiddle) { + if (idxInParent > 0) { + cursor->setLayout(castedParent.childAtIndex(idxInParent-1)); + cursor->setPosition(LayoutCursor::Position::Right); + } else { + cursor->setLayout(castedParent); + cursor->setPosition(LayoutCursor::Position::Left); + } + } + castedParent.addOrMergeChildAtIndex(rightChild, idxInParent, true); + castedParent.addOrMergeChildAtIndex(leftChild, idxInParent, true, putCursorInTheMiddle ? cursor : nullptr); + p.removeChild(*this, cursor->layouterence() == *this ? cursor : nullptr); +} + +void Layout::addChildAtIndex(Layout l, int index, int currentNumberOfChildren, LayoutCursor * cursor) { + int newIndex = index; + int newCurrentNumberOfChildren = currentNumberOfChildren; + if (!node()->willAddChildAtIndex(l.node(), &newIndex, &newCurrentNumberOfChildren, cursor)) { + return; + } + Layout nextPointedLayout; + LayoutCursor::Position nextPosition = LayoutCursor::Position::Left; + if (cursor != nullptr) { + if (newIndex < this->numberOfChildren()) { + nextPointedLayout = childAtIndex(newIndex); + nextPosition = LayoutCursor::Position::Left; + } else { + nextPointedLayout = *this; + nextPosition = LayoutCursor::Position::Right; + } + } + + addChildAtIndexInPlace(l, newIndex, newCurrentNumberOfChildren); + + if (cursor != nullptr) { + cursor->setLayout(nextPointedLayout); + cursor->setPosition(nextPosition); + } +} + +void Layout::addSibling(LayoutCursor * cursor, Layout sibling, bool moveCursor) { + if (!node()->willAddSibling(cursor, sibling.node(), moveCursor)) { + return; + } + /* The layout must have a parent, because HorizontalLayout's + * preprocessAddSibling returns false only an HorizontalLayout can be the + * root layout. */ + Layout rootLayout = root(); + Layout p = parent(); + assert(!p.isUninitialized()); + if (p.isHorizontal()) { + int indexInParent = p.indexOfChild(*this); + int siblingIndex = cursor->position() == LayoutCursor::Position::Left ? indexInParent : indexInParent + 1; + + /* Special case: If the neighbour sibling is a VerticalOffsetLayout, let it + * handle the insertion of the new sibling. Do not enter the special case if + * "this" is a VerticalOffsetLayout, to avoid an infinite loop. */ + if (!isVerticalOffset()) { + Layout neighbour; + if (cursor->position() == LayoutCursor::Position::Left && indexInParent > 0) { + neighbour = p.childAtIndex(indexInParent - 1); + } else if (cursor->position() == LayoutCursor::Position::Right && indexInParent < p.numberOfChildren() - 1) { + neighbour = p.childAtIndex(indexInParent + 1); + } + if (!neighbour.isUninitialized() && neighbour.isVerticalOffset()) { + if (moveCursor) { + cursor->setLayout(neighbour); + cursor->setPosition(cursor->position() == LayoutCursor::Position::Left ? LayoutCursor::Position::Right : LayoutCursor::Position::Left); + } + neighbour.addSibling(cursor, sibling, moveCursor); + return; + } + } + + // Else, let the parent add the sibling. + HorizontalLayout(static_cast(p.node())).addOrMergeChildAtIndex(sibling, siblingIndex, true, moveCursor ? cursor : nullptr); return; } if (cursor->position() == LayoutCursor::Position::Left) { - // Case: Left. Ask the parent. - p->deleteBeforeCursor(cursor); - return; - } - assert(cursor->position() == LayoutCursor::Position::Right); - // Case: Right. Delete the layout (or replace it with an EmptyLayout). - LayoutReference(p).removeChild(LayoutReference(this), cursor); - // WARNING: Do no use "this" afterwards -} - -bool LayoutNode::willRemoveChild(LayoutNode * l, LayoutCursor * cursor, bool force) { - if (!force) { - LayoutReference(this).replaceChildWithEmpty(LayoutReference(l), cursor); - return false; - } - return true; -} - -// Other -bool LayoutNode::canBeOmittedMultiplicationLeftFactor() const { - /* WARNING: canBeOmittedMultiplicationLeftFactor is true when and only when - * isCollapsable is true too. If isCollapsable changes, it might not be the - * case anymore so make sure to modify this function if needed. */ - int numberOfOpenParentheses = 0; - return isCollapsable(&numberOfOpenParentheses, true); -} - -bool LayoutNode::canBeOmittedMultiplicationRightFactor() const { - /* WARNING: canBeOmittedMultiplicationLeftFactor is true when and only when - * isCollapsable is true and isVerticalOffset is false. If one of these - * functions changes, it might not be the case anymore so make sure to modify - * canBeOmittedMultiplicationRightFactor if needed. */ - int numberOfOpenParentheses = 0; - return isCollapsable(&numberOfOpenParentheses, false) && !isVerticalOffset(); -} - -// Private - -void LayoutNode::moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { - if (!equivalentPositionVisited) { - LayoutCursor cursorEquivalent = equivalentCursor(cursor); - if (cursorEquivalent.isDefined()) { - cursor->setLayoutReference(cursorEquivalent.layoutReference()); - cursor->setPosition(cursorEquivalent.position()); - if (direction == VerticalDirection::Up) { - cursor->layoutNode()->moveCursorUp(cursor, shouldRecomputeLayout, true); - } else { - cursor->layoutNode()->moveCursorDown(cursor, shouldRecomputeLayout, true); - } - return; - } - } - LayoutNode * p = parent(); - if (p == nullptr) { - cursor->setLayoutReference(LayoutReference()); - return; - } - if (direction == VerticalDirection::Up) { - p->moveCursorUp(cursor, shouldRecomputeLayout, true); + replaceWithJuxtapositionOf(sibling, *this, cursor); } else { - p->moveCursorDown(cursor, shouldRecomputeLayout, true); + assert(cursor->position() == LayoutCursor::Position::Right); + replaceWithJuxtapositionOf(*this, sibling, cursor); } } -void LayoutNode::moveCursorInDescendantsVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout) { - LayoutNode * childResult = nullptr; - LayoutNode ** childResultPtr = &childResult; - LayoutCursor::Position resultPosition = LayoutCursor::Position::Left; - /* The distance between the cursor and its next position cannot be greater - * than this initial value of score. */ - int resultScore = Ion::Display::Width*Ion::Display::Width + Ion::Display::Height*Ion::Display::Height; - - scoreCursorInDescendantsVertically(direction, cursor, shouldRecomputeLayout, childResultPtr, &resultPosition, &resultScore); - - // If there is a valid result - LayoutReference resultRef(childResult); - if ((*childResultPtr) != nullptr) { - *shouldRecomputeLayout = childResult->addGreySquaresToAllMatrixAncestors(); - // WARNING: Do not use "this" afterwards +void Layout::removeChild(Layout l, LayoutCursor * cursor, bool force) { + if (!node()->willRemoveChild(l.node(), cursor, force)) { + return; } - cursor->setLayoutReference(resultRef); - cursor->setPosition(resultPosition); -} - -void LayoutNode::scoreCursorInDescendantsVertically ( - VerticalDirection direction, - LayoutCursor * cursor, - bool * shouldRecomputeLayout, - LayoutNode ** childResult, - void * resultPosition, - int * resultScore) -{ - LayoutCursor::Position * castedResultPosition = static_cast(resultPosition); - KDPoint cursorMiddleLeft = cursor->middleLeftPoint(); - bool layoutIsUnderOrAbove = direction == VerticalDirection::Up ? m_frame.isAbove(cursorMiddleLeft) : m_frame.isUnder(cursorMiddleLeft); - bool layoutContains = m_frame.contains(cursorMiddleLeft); - - if (layoutIsUnderOrAbove) { - // Check the distance to a Left cursor. - int currentDistance = LayoutCursor(this, LayoutCursor::Position::Left).middleLeftPoint().squareDistanceTo(cursorMiddleLeft); - if (currentDistance <= *resultScore ){ - *childResult = this; - *castedResultPosition = LayoutCursor::Position::Left; - *resultScore = currentDistance; - } - - // Check the distance to a Right cursor. - currentDistance = LayoutCursor(this, LayoutCursor::Position::Right).middleLeftPoint().squareDistanceTo(cursorMiddleLeft); - if (currentDistance < *resultScore) { - *childResult = this; - *castedResultPosition = LayoutCursor::Position::Right; - *resultScore = currentDistance; - } - } - if (layoutIsUnderOrAbove || layoutContains) { - for (LayoutNode * c : children()) { - c->scoreCursorInDescendantsVertically(direction, cursor, shouldRecomputeLayout, childResult, castedResultPosition, resultScore); - } - } -} - -bool LayoutNode::changeGreySquaresOfAllMatrixAncestors(bool add) { - bool changedSquares = false; - LayoutReference currentAncestor = LayoutReference(parent()); - while (!currentAncestor.isUninitialized()) { - if (currentAncestor.isMatrix()) { - if (add) { - MatrixLayoutReference(static_cast(currentAncestor.node())).addGreySquares(); + assert(hasChild(l)); + int index = indexOfChild(l); + removeChildInPlace(l, l.numberOfChildren()); + if (cursor) { + if (index < numberOfChildren()) { + Layout newCursorRef = childAtIndex(index); + cursor->setLayout(newCursorRef); + cursor->setPosition(LayoutCursor::Position::Left); + } else { + int newPointedLayoutIndex = index - 1; + if (newPointedLayoutIndex >= 0 && newPointedLayoutIndex < numberOfChildren()) { + cursor->setLayout(childAtIndex(newPointedLayoutIndex)); + cursor->setPosition(LayoutCursor::Position::Right); } else { - MatrixLayoutReference(static_cast(currentAncestor.node())).removeGreySquares(); + cursor->setLayout(*this); + cursor->setPosition(LayoutCursor::Position::Right); } - changedSquares = true; } - currentAncestor = currentAncestor.parent(); } - return changedSquares; + node()->didRemoveChildAtIndex(index, cursor, force); +} + +void Layout::removeChildAtIndex(int index, LayoutCursor * cursor, bool force) { + removeChild(childAtIndex(index), cursor, force); +} + +void Layout::collapseOnDirection(HorizontalDirection direction, int absorbingChildIndex) { + Layout p = parent(); + if (p.isUninitialized() || !p.isHorizontal()) { + return; + } + int idxInParent = p.indexOfChild(*this); + int numberOfSiblings = p.numberOfChildren(); + int numberOfOpenParenthesis = 0; + bool canCollapse = true; + Layout absorbingChild = childAtIndex(absorbingChildIndex); + if (absorbingChild.isUninitialized() || !absorbingChild.isHorizontal()) { + return; + } + HorizontalLayout horizontalAbsorbingChild = HorizontalLayout(static_cast(absorbingChild.node())); + if (direction == HorizontalDirection::Right && idxInParent < numberOfSiblings - 1) { + canCollapse = !(p.childAtIndex(idxInParent+1).mustHaveLeftSibling()); + } + Layout sibling; + bool forceCollapse = false; + while (canCollapse) { + if (direction == HorizontalDirection::Right && idxInParent == numberOfSiblings - 1) { + break; + } + if (direction == HorizontalDirection::Left && idxInParent == 0) { + break; + } + int siblingIndex = direction == HorizontalDirection::Right ? idxInParent+1 : idxInParent-1; + sibling = p.childAtIndex(siblingIndex); + /* Even if forceCollapse is true, isCollapsable should be called to update + * the number of open parentheses. */ + bool shouldCollapse = sibling.isCollapsable(&numberOfOpenParenthesis, direction == HorizontalDirection::Left); + if (shouldCollapse || forceCollapse) { + /* If the collapse direction is Left and the next sibling to be collapsed + * must have a left sibling, force the collapsing of this needed left + * sibling. */ + forceCollapse = direction == HorizontalDirection::Left && sibling.mustHaveLeftSibling(); + p.removeChildAtIndex(siblingIndex, nullptr); + int newIndex = direction == HorizontalDirection::Right ? absorbingChild.numberOfChildren() : 0; + horizontalAbsorbingChild.addOrMergeChildAtIndex(sibling, newIndex, true); + numberOfSiblings--; + if (direction == HorizontalDirection::Left) { + idxInParent--; + } + } else { + break; + } + } +} + +void Layout::collapseSiblings(LayoutCursor * cursor) { + Layout rootLayout = root(); + if (node()->shouldCollapseSiblingsOnRight()) { + Layout absorbingChild = childAtIndex(rightCollapsingAbsorbingChildIndex()); + if (!absorbingChild.isHorizontal()) { + Layout horRef = HorizontalLayout(); + replaceChild(absorbingChild, horRef, cursor, true); + horRef.addChildAtIndexInPlace(absorbingChild, 0, 0); + } + collapseOnDirection(HorizontalDirection::Right, rightCollapsingAbsorbingChildIndex()); + } + if (node()->shouldCollapseSiblingsOnLeft()) { + Layout absorbingChild = childAtIndex(leftCollapsingAbsorbingChildIndex()); + if (!absorbingChild.isHorizontal()) { + Layout horRef = HorizontalLayout(); + replaceChild(absorbingChild, horRef, cursor, true); + horRef.addChildAtIndexInPlace(absorbingChild, 0, 0); + } + collapseOnDirection(HorizontalDirection::Left, leftCollapsingAbsorbingChildIndex()); + } + node()->didCollapseSiblings(cursor); } } diff --git a/poincare/src/layout_cursor.cpp b/poincare/src/layout_cursor.cpp index a02e0ed89..aa1f19c2a 100644 --- a/poincare/src/layout_cursor.cpp +++ b/poincare/src/layout_cursor.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include @@ -25,15 +25,15 @@ KDCoordinate LayoutCursor::baseline() { if (layoutHeight() == 0) { return k_cursorHeight/2; } - KDCoordinate layoutBaseline = m_layoutRef.baseline(); - LayoutReference equivalentLayoutReference = m_layoutRef.equivalentCursor(this).layoutReference(); - if (equivalentLayoutReference.isUninitialized()) { + KDCoordinate layoutBaseline = m_layout.baseline(); + Layout equivalentLayout = m_layout.equivalentCursor(this).layouterence(); + if (equivalentLayout.isUninitialized()) { return layoutBaseline; } - if (m_layoutRef.hasChild(equivalentLayoutReference)) { - return equivalentLayoutReference.baseline(); - } else if (m_layoutRef.hasSibling(equivalentLayoutReference)) { - return max(layoutBaseline, equivalentLayoutReference.baseline()); + if (m_layout.hasChild(equivalentLayout)) { + return equivalentLayout.baseline(); + } else if (m_layout.hasSibling(equivalentLayout)) { + return max(layoutBaseline, equivalentLayout.baseline()); } return layoutBaseline; } @@ -49,9 +49,9 @@ bool LayoutCursor::isEquivalentTo(LayoutCursor cursor) { /* Position */ KDPoint LayoutCursor::middleLeftPoint() { - KDPoint layoutOrigin = layoutReference().absoluteOrigin(); - KDCoordinate x = layoutOrigin.x() + (m_position == Position::Left ? 0 : m_layoutRef.layoutSize().width()); - KDCoordinate y = layoutOrigin.y() + m_layoutRef.baseline() - k_cursorHeight/2; + KDPoint layoutOrigin = layouterence().absoluteOrigin(); + KDCoordinate x = layoutOrigin.x() + (m_position == Position::Left ? 0 : m_layout.layoutSize().width()); + KDCoordinate y = layoutOrigin.y() + m_layout.baseline() - k_cursorHeight/2; return KDPoint(x,y); } @@ -73,67 +73,67 @@ void LayoutCursor::move(MoveDirection direction, bool * shouldRecomputeLayout) { /* Layout modification */ void LayoutCursor::addEmptyExponentialLayout() { - EmptyLayoutReference emptyLayout; - HorizontalLayoutReference sibling = HorizontalLayoutReference( - CharLayoutReference(Ion::Charset::Exponential), - VerticalOffsetLayoutReference(emptyLayout, VerticalOffsetLayoutNode::Type::Superscript)); - m_layoutRef.addSibling(this, sibling, false); - m_layoutRef = emptyLayout; + EmptyLayout emptyLayout; + HorizontalLayout sibling = HorizontalLayout( + CharLayout(Ion::Charset::Exponential), + VerticalOffsetLayout(emptyLayout, VerticalOffsetLayoutNode::Type::Superscript)); + m_layout.addSibling(this, sibling, false); + m_layout = emptyLayout; } void LayoutCursor::addEmptyMatrixLayout() { - MatrixLayoutReference matrixLayout = MatrixLayoutReference( - EmptyLayoutReference(EmptyLayoutNode::Color::Yellow), - EmptyLayoutReference(EmptyLayoutNode::Color::Grey), - EmptyLayoutReference(EmptyLayoutNode::Color::Grey), - EmptyLayoutReference(EmptyLayoutNode::Color::Grey)); - m_layoutRef.addSibling(this, matrixLayout, false); - m_layoutRef = matrixLayout.childAtIndex(0); + MatrixLayout matrixLayout = MatrixLayout( + EmptyLayout(EmptyLayoutNode::Color::Yellow), + EmptyLayout(EmptyLayoutNode::Color::Grey), + EmptyLayout(EmptyLayoutNode::Color::Grey), + EmptyLayout(EmptyLayoutNode::Color::Grey)); + m_layout.addSibling(this, matrixLayout, false); + m_layout = matrixLayout.childAtIndex(0); m_position = Position::Right; } void LayoutCursor::addEmptySquareRootLayout() { - HorizontalLayoutReference child1 = HorizontalLayoutReference(EmptyLayoutReference()); - NthRootLayoutReference newChild = NthRootLayoutReference(child1); - m_layoutRef.addSibling(this, newChild, false); - m_layoutRef = newChild.childAtIndex(0); - ((LayoutReference *)&newChild)->collapseSiblings(this); + HorizontalLayout child1 = HorizontalLayout(EmptyLayout()); + NthRootLayout newChild = NthRootLayout(child1); + m_layout.addSibling(this, newChild, false); + m_layout = newChild.childAtIndex(0); + ((Layout *)&newChild)->collapseSiblings(this); } void LayoutCursor::addEmptyPowerLayout() { - VerticalOffsetLayoutReference offsetLayout = VerticalOffsetLayoutReference(EmptyLayoutReference(), VerticalOffsetLayoutNode::Type::Superscript); + VerticalOffsetLayout offsetLayout = VerticalOffsetLayout(EmptyLayout(), VerticalOffsetLayoutNode::Type::Superscript); privateAddEmptyPowerLayout(offsetLayout); - m_layoutRef = offsetLayout.childAtIndex(0); + m_layout = offsetLayout.childAtIndex(0); } void LayoutCursor::addEmptySquarePowerLayout() { - VerticalOffsetLayoutReference offsetLayout = VerticalOffsetLayoutReference(CharLayoutReference('2'), VerticalOffsetLayoutNode::Type::Superscript); + VerticalOffsetLayout offsetLayout = VerticalOffsetLayout(CharLayout('2'), VerticalOffsetLayoutNode::Type::Superscript); privateAddEmptyPowerLayout(offsetLayout); } void LayoutCursor::addEmptyTenPowerLayout() { - EmptyLayoutReference emptyLayout; - HorizontalLayoutReference sibling = HorizontalLayoutReference( - CharLayoutReference(Ion::Charset::MiddleDot), - CharLayoutReference('1'), - CharLayoutReference('0'), - VerticalOffsetLayoutReference( + EmptyLayout emptyLayout; + HorizontalLayout sibling = HorizontalLayout( + CharLayout(Ion::Charset::MiddleDot), + CharLayout('1'), + CharLayout('0'), + VerticalOffsetLayout( emptyLayout, VerticalOffsetLayoutNode::Type::Superscript)); - m_layoutRef.addSibling(this, sibling, false); - m_layoutRef = emptyLayout; + m_layout.addSibling(this, sibling, false); + m_layout = emptyLayout; } void LayoutCursor::addFractionLayoutAndCollapseSiblings() { - HorizontalLayoutReference child1 = HorizontalLayoutReference(EmptyLayoutReference()); - HorizontalLayoutReference child2 = HorizontalLayoutReference(EmptyLayoutReference()); - FractionLayoutReference newChild = FractionLayoutReference(child1, child2); - m_layoutRef.addSibling(this, newChild, true); - LayoutReference(newChild.node()).collapseSiblings(this); + HorizontalLayout child1 = HorizontalLayout(EmptyLayout()); + HorizontalLayout child2 = HorizontalLayout(EmptyLayout()); + FractionLayout newChild = FractionLayout(child1, child2); + m_layout.addSibling(this, newChild, true); + Layout(newChild.node()).collapseSiblings(this); } void LayoutCursor::addXNTCharLayout() { - m_layoutRef.addSibling(this, CharLayoutReference(m_layoutRef.XNTChar()), true); + m_layout.addSibling(this, CharLayout(m_layout.XNTChar()), true); } void LayoutCursor::insertText(const char * text) { @@ -141,97 +141,97 @@ void LayoutCursor::insertText(const char * text) { if (textLength <= 0) { return; } - LayoutReference newChild; - LayoutReference pointedChild; + Layout newChild; + Layout pointedChild; bool specialUnderScore = false; for (int i = 0; i < textLength; i++) { if (text[i] == Ion::Charset::Empty) { continue; } if (text[i] == Ion::Charset::MultiplicationSign) { - newChild = CharLayoutReference(Ion::Charset::MiddleDot); + newChild = CharLayout(Ion::Charset::MiddleDot); } else if (text[i] == '(') { - newChild = LeftParenthesisLayoutReference(); + newChild = LeftParenthesisLayout(); if (pointedChild.isUninitialized()) { pointedChild = newChild; } } else if (text[i] == ')') { - newChild = RightParenthesisLayoutReference(); + newChild = RightParenthesisLayout(); } else if (text[i] == '_') { specialUnderScore = (i < textLength) && (text[i+1] == '{'); if (!specialUnderScore) { - newChild = CharLayoutReference('_'); + newChild = CharLayout('_'); } else { continue; } } else if (text[i] == '{' && specialUnderScore) { - newChild = CharLayoutReference('('); //TODO ?? Was a char layout before, not a parenthesis left + newChild = CharLayout('('); //TODO ?? Was a char layout before, not a parenthesis left } else if (text[i] == '}' && specialUnderScore) { - newChild = CharLayoutReference(')'); //TODO + newChild = CharLayout(')'); //TODO specialUnderScore = false; } /* We never insert text with brackets for now. Removing this code saves the * binary file 2K. */ #if 0 else if (text[i] == '[') { - newChild = LeftSquareBracketLayoutReference(); + newChild = LeftSquareBracketLayout(); } else if (text[i] == ']') { - newChild = RightSquareBracketLayoutReference(); + newChild = RightSquareBracketLayout(); } #endif else { - newChild = CharLayoutReference(text[i]); + newChild = CharLayout(text[i]); } - m_layoutRef.addSibling(this, newChild, true); + m_layout.addSibling(this, newChild, true); } if (!pointedChild.isUninitialized() && !pointedChild.parent().isUninitialized()) { - m_layoutRef = pointedChild; + m_layout = pointedChild; } } -void LayoutCursor::addLayoutAndMoveCursor(LayoutReference l) { +void LayoutCursor::addLayoutAndMoveCursor(Layout l) { bool layoutWillBeMerged = l.isHorizontal(); - m_layoutRef.addSibling(this, l, true); + m_layout.addSibling(this, l, true); if (!layoutWillBeMerged) { l.collapseSiblings(this); } } void LayoutCursor::clearLayout() { - LayoutReference rootLayoutR = m_layoutRef.root(); + Layout rootLayoutR = m_layout.root(); assert(rootLayoutR.isHorizontal()); rootLayoutR.removeChildrenInPlace(rootLayoutR.numberOfChildren()); - m_layoutRef = rootLayoutR; + m_layout = rootLayoutR; } /* Private */ KDCoordinate LayoutCursor::layoutHeight() { - LayoutReference equivalentLayoutReference = m_layoutRef.equivalentCursor(this).layoutReference(); - if (!equivalentLayoutReference.isUninitialized() && m_layoutRef.hasChild(equivalentLayoutReference)) { - return equivalentLayoutReference.layoutSize().height(); + Layout equivalentLayout = m_layout.equivalentCursor(this).layouterence(); + if (!equivalentLayout.isUninitialized() && m_layout.hasChild(equivalentLayout)) { + return equivalentLayout.layoutSize().height(); } - KDCoordinate pointedLayoutHeight = m_layoutRef.layoutSize().height(); - if (!equivalentLayoutReference.isUninitialized() && m_layoutRef.hasSibling(equivalentLayoutReference)) { - KDCoordinate equivalentLayoutHeight = equivalentLayoutReference.layoutSize().height(); - KDCoordinate pointedLayoutBaseline = m_layoutRef.baseline(); - KDCoordinate equivalentLayoutBaseline = equivalentLayoutReference.baseline(); + KDCoordinate pointedLayoutHeight = m_layout.layoutSize().height(); + if (!equivalentLayout.isUninitialized() && m_layout.hasSibling(equivalentLayout)) { + KDCoordinate equivalentLayoutHeight = equivalentLayout.layoutSize().height(); + KDCoordinate pointedLayoutBaseline = m_layout.baseline(); + KDCoordinate equivalentLayoutBaseline = equivalentLayout.baseline(); return max(pointedLayoutBaseline, equivalentLayoutBaseline) + max(pointedLayoutHeight - pointedLayoutBaseline, equivalentLayoutHeight - equivalentLayoutBaseline); } return pointedLayoutHeight; } -void LayoutCursor::privateAddEmptyPowerLayout(VerticalOffsetLayoutReference v) { +void LayoutCursor::privateAddEmptyPowerLayout(VerticalOffsetLayout v) { // If there is already a base if (baseForNewPowerLayout()) { - m_layoutRef.addSibling(this, v, true); + m_layout.addSibling(this, v, true); return; } // Else, add an empty base - EmptyLayoutReference e = EmptyLayoutReference(); - HorizontalLayoutReference newChild = HorizontalLayoutReference(e, v); - m_layoutRef.addSibling(this, newChild, true); + EmptyLayout e = EmptyLayout(); + HorizontalLayout newChild = HorizontalLayout(e, v); + m_layout.addSibling(this, newChild, true); } bool LayoutCursor::baseForNewPowerLayout() { @@ -239,22 +239,22 @@ bool LayoutCursor::baseForNewPowerLayout() { * be the base of a new power layout: the base layout should be anything but * an horizontal layout with no child. */ if (m_position == Position::Right) { - return !(m_layoutRef.isHorizontal() && m_layoutRef.numberOfChildren() == 0); + return !(m_layout.isHorizontal() && m_layout.numberOfChildren() == 0); } else { assert(m_position == Position::Left); - if (m_layoutRef.isHorizontal()) { + if (m_layout.isHorizontal()) { return false; } - if (m_layoutRef.isEmpty()) { + if (m_layout.isEmpty()) { /* If the cursor is on the left of an EmptyLayout, move it to its right, * the empty layout will take care of changing its color and adding a new * row/column to its parent matrix if needed. */ m_position = Position::Right; return true; } - LayoutCursor equivalentLayoutCursor = m_layoutRef.equivalentCursor(this); - if (equivalentLayoutCursor.layoutReference().isUninitialized() - || (equivalentLayoutCursor.layoutReference().isHorizontal() + LayoutCursor equivalentLayoutCursor = m_layout.equivalentCursor(this); + if (equivalentLayoutCursor.layouterence().isUninitialized() + || (equivalentLayoutCursor.layouterence().isHorizontal() && equivalentLayoutCursor.position() == Position::Left)) { return false; @@ -266,14 +266,14 @@ bool LayoutCursor::baseForNewPowerLayout() { bool LayoutCursor::privateShowHideEmptyLayoutIfNeeded(bool show) { /* Find Empty layouts adjacent to the cursor: Check the pointed layout and the * equivalent cursor positions */ - LayoutReference adjacentEmptyLayout; + Layout adjacentEmptyLayout; - if (m_layoutRef.isEmpty()) { + if (m_layout.isEmpty()) { // Check the pointed layout - adjacentEmptyLayout = m_layoutRef; + adjacentEmptyLayout = m_layout; } else { // Check the equivalent cursor position - LayoutReference equivalentPointedLayout = m_layoutRef.equivalentCursor(this).layoutReference(); + Layout equivalentPointedLayout = m_layout.equivalentCursor(this).layouterence(); if (!equivalentPointedLayout.isUninitialized() && equivalentPointedLayout.isEmpty()) { adjacentEmptyLayout = equivalentPointedLayout; } diff --git a/poincare/src/layout_helper.cpp b/poincare/src/layout_helper.cpp index 9423b4d88..4ea3d4f07 100644 --- a/poincare/src/layout_helper.cpp +++ b/poincare/src/layout_helper.cpp @@ -8,10 +8,10 @@ namespace Poincare { -LayoutReference LayoutHelper::Infix(const Expression & expression, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, const char * operatorName) { +Layout LayoutHelper::Infix(const Expression & expression, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, const char * operatorName) { int numberOfChildren = expression.numberOfChildren(); assert(numberOfChildren > 1); - HorizontalLayoutReference result; + HorizontalLayout result; result.addOrMergeChildAtIndex(expression.childAtIndex(0).createLayout(floatDisplayMode, numberOfSignificantDigits), 0, true); for (int i = 1; i < numberOfChildren; i++) { result.addOrMergeChildAtIndex(String(operatorName, strlen(operatorName)), result.numberOfChildren(), true); @@ -23,18 +23,18 @@ LayoutReference LayoutHelper::Infix(const Expression & expression, Preferences:: return result; } -LayoutReference LayoutHelper::Prefix(const Expression & expression, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, const char * operatorName) { - HorizontalLayoutReference result; +Layout LayoutHelper::Prefix(const Expression & expression, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, const char * operatorName) { + HorizontalLayout result; // Add the operator name. result.addOrMergeChildAtIndex(String(operatorName, strlen(operatorName)), 0, true); // Create the layout of arguments separated by commas. - HorizontalLayoutReference args; + HorizontalLayout args; int numberOfChildren = expression.numberOfChildren(); if (numberOfChildren > 0) { args.addOrMergeChildAtIndex(expression.childAtIndex(0).createLayout(floatDisplayMode, numberOfSignificantDigits), 0, true); for (int i = 1; i < numberOfChildren; i++) { - args.addChildAtIndex(CharLayoutReference(','), args.numberOfChildren(), args.numberOfChildren(), nullptr); + args.addChildAtIndex(CharLayout(','), args.numberOfChildren(), args.numberOfChildren(), nullptr); args.addOrMergeChildAtIndex(expression.childAtIndex(i).createLayout(floatDisplayMode, numberOfSignificantDigits), args.numberOfChildren(), true); } } @@ -43,28 +43,28 @@ LayoutReference LayoutHelper::Prefix(const Expression & expression, Preferences: return result; } -LayoutReference LayoutHelper::Parentheses(LayoutReference layoutRef, bool cloneLayout) { - HorizontalLayoutReference result; - result.addChildAtIndex(LeftParenthesisLayoutReference(), 0, 0, nullptr); - if (!layoutRef.isUninitialized()) { - result.addOrMergeChildAtIndex(cloneLayout ? layoutRef.clone() : layoutRef, 1, true); +Layout LayoutHelper::Parentheses(Layout layout, bool cloneLayout) { + HorizontalLayout result; + result.addChildAtIndex(LeftParenthesisLayout(), 0, 0, nullptr); + if (!layout.isUninitialized()) { + result.addOrMergeChildAtIndex(cloneLayout ? layout.clone() : layout, 1, true); } - result.addChildAtIndex(RightParenthesisLayoutReference(), result.numberOfChildren(), result.numberOfChildren(), nullptr); + result.addChildAtIndex(RightParenthesisLayout(), result.numberOfChildren(), result.numberOfChildren(), nullptr); return result; } -HorizontalLayoutReference LayoutHelper::String(const char * buffer, int bufferSize, KDText::FontSize fontSize) { +HorizontalLayout LayoutHelper::String(const char * buffer, int bufferSize, KDText::FontSize fontSize) { assert(bufferSize > 0); - HorizontalLayoutReference resultLayout; + HorizontalLayout resultLayout; for (int i = 0; i < bufferSize; i++) { - resultLayout.addChildAtIndex(CharLayoutReference(buffer[i], fontSize), i, i, nullptr); + resultLayout.addChildAtIndex(CharLayout(buffer[i], fontSize), i, i, nullptr); } return resultLayout; } -LayoutReference LayoutHelper::Logarithm(LayoutReference argument, LayoutReference index) { - HorizontalLayoutReference resultLayout = String("log", 3); - VerticalOffsetLayoutReference offsetLayout = VerticalOffsetLayoutReference(index, VerticalOffsetLayoutNode::Type::Subscript); +Layout LayoutHelper::Logarithm(Layout argument, Layout index) { + HorizontalLayout resultLayout = String("log", 3); + VerticalOffsetLayout offsetLayout = VerticalOffsetLayout(index, VerticalOffsetLayoutNode::Type::Subscript); resultLayout.addChildAtIndex(offsetLayout, resultLayout.numberOfChildren(), resultLayout.numberOfChildren(), nullptr); resultLayout.addOrMergeChildAtIndex(Parentheses(argument, false), resultLayout.numberOfChildren(), true); return resultLayout; diff --git a/poincare/src/layout_node.cpp b/poincare/src/layout_node.cpp new file mode 100644 index 000000000..3b883dfe1 --- /dev/null +++ b/poincare/src/layout_node.cpp @@ -0,0 +1,231 @@ +#include +#include +#include +#include +#include +#include + +namespace Poincare { + +// Rendering + +void LayoutNode::draw(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) { + for (LayoutNode * l : children()) { + l->draw(ctx, p, expressionColor, backgroundColor); + } + render(ctx, absoluteOrigin().translatedBy(p), expressionColor, backgroundColor); +} + +KDPoint LayoutNode::origin() { + LayoutNode * p = parent(); + if (p == nullptr) { + return absoluteOrigin(); + } else { + return KDPoint(absoluteOrigin().x() - p->absoluteOrigin().x(), + absoluteOrigin().y() - p->absoluteOrigin().y()); + } +} + +KDPoint LayoutNode::absoluteOrigin() { + LayoutNode * p = parent(); + if (!m_positioned) { + if (p != nullptr) { + m_frame.setOrigin(p->absoluteOrigin().translatedBy(p->positionOfChild(this))); + } else { + m_frame.setOrigin(KDPointZero); + } + m_positioned = true; + } + return m_frame.origin(); +} + +KDSize LayoutNode::layoutSize() { + if (!m_sized) { + m_frame.setSize(computeSize()); + m_sized = true; + } + return m_frame.size(); +} + +KDCoordinate LayoutNode::baseline() { + if (!m_baselined) { + m_baseline = computeBaseline(); + m_baselined = true; + } + return m_baseline; +} + +void LayoutNode::invalidAllSizesPositionsAndBaselines() { + m_sized = false; + m_positioned = false; + m_baselined = false; + for (LayoutNode * l : children()) { + l->invalidAllSizesPositionsAndBaselines(); + } +} + +// Tree navigation +LayoutCursor LayoutNode::equivalentCursor(LayoutCursor * cursor) { + // Only HorizontalLayout may have no parent, and it overloads this method + assert(parent() != nullptr); + return (cursor->layouterence().node() == this) ? parent()->equivalentCursor(cursor) : LayoutCursor(); +} + +// Tree modification + +void LayoutNode::deleteBeforeCursor(LayoutCursor * cursor) { + int indexOfPointedLayout = indexOfChild(cursor->layoutNode()); + if (indexOfPointedLayout >= 0) { + // Case: The pointed layout is a child. Move Left. + assert(cursor->position() == LayoutCursor::Position::Left); + bool shouldRecomputeLayout = false; + cursor->moveLeft(&shouldRecomputeLayout); + return; + } + assert(cursor->layoutNode() == this); + LayoutNode * p = parent(); + // Case: this is the pointed layout. + if (p == nullptr) { + // Case: No parent. Return. + return; + } + if (cursor->position() == LayoutCursor::Position::Left) { + // Case: Left. Ask the parent. + p->deleteBeforeCursor(cursor); + return; + } + assert(cursor->position() == LayoutCursor::Position::Right); + // Case: Right. Delete the layout (or replace it with an EmptyLayout). + Layout(p).removeChild(Layout(this), cursor); + // WARNING: Do no use "this" afterwards +} + +bool LayoutNode::willRemoveChild(LayoutNode * l, LayoutCursor * cursor, bool force) { + if (!force) { + Layout(this).replaceChildWithEmpty(Layout(l), cursor); + return false; + } + return true; +} + +// Other +bool LayoutNode::canBeOmittedMultiplicationLeftFactor() const { + /* WARNING: canBeOmittedMultiplicationLeftFactor is true when and only when + * isCollapsable is true too. If isCollapsable changes, it might not be the + * case anymore so make sure to modify this function if needed. */ + int numberOfOpenParentheses = 0; + return isCollapsable(&numberOfOpenParentheses, true); +} + +bool LayoutNode::canBeOmittedMultiplicationRightFactor() const { + /* WARNING: canBeOmittedMultiplicationLeftFactor is true when and only when + * isCollapsable is true and isVerticalOffset is false. If one of these + * functions changes, it might not be the case anymore so make sure to modify + * canBeOmittedMultiplicationRightFactor if needed. */ + int numberOfOpenParentheses = 0; + return isCollapsable(&numberOfOpenParentheses, false) && !isVerticalOffset(); +} + +// Private + +void LayoutNode::moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { + if (!equivalentPositionVisited) { + LayoutCursor cursorEquivalent = equivalentCursor(cursor); + if (cursorEquivalent.isDefined()) { + cursor->setLayout(cursorEquivalent.layouterence()); + cursor->setPosition(cursorEquivalent.position()); + if (direction == VerticalDirection::Up) { + cursor->layoutNode()->moveCursorUp(cursor, shouldRecomputeLayout, true); + } else { + cursor->layoutNode()->moveCursorDown(cursor, shouldRecomputeLayout, true); + } + return; + } + } + LayoutNode * p = parent(); + if (p == nullptr) { + cursor->setLayout(Layout()); + return; + } + if (direction == VerticalDirection::Up) { + p->moveCursorUp(cursor, shouldRecomputeLayout, true); + } else { + p->moveCursorDown(cursor, shouldRecomputeLayout, true); + } +} + +void LayoutNode::moveCursorInDescendantsVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout) { + LayoutNode * childResult = nullptr; + LayoutNode ** childResultPtr = &childResult; + LayoutCursor::Position resultPosition = LayoutCursor::Position::Left; + /* The distance between the cursor and its next position cannot be greater + * than this initial value of score. */ + int resultScore = Ion::Display::Width*Ion::Display::Width + Ion::Display::Height*Ion::Display::Height; + + scoreCursorInDescendantsVertically(direction, cursor, shouldRecomputeLayout, childResultPtr, &resultPosition, &resultScore); + + // If there is a valid result + Layout resultRef(childResult); + if ((*childResultPtr) != nullptr) { + *shouldRecomputeLayout = childResult->addGreySquaresToAllMatrixAncestors(); + // WARNING: Do not use "this" afterwards + } + cursor->setLayout(resultRef); + cursor->setPosition(resultPosition); +} + +void LayoutNode::scoreCursorInDescendantsVertically ( + VerticalDirection direction, + LayoutCursor * cursor, + bool * shouldRecomputeLayout, + LayoutNode ** childResult, + void * resultPosition, + int * resultScore) +{ + LayoutCursor::Position * castedResultPosition = static_cast(resultPosition); + KDPoint cursorMiddleLeft = cursor->middleLeftPoint(); + bool layoutIsUnderOrAbove = direction == VerticalDirection::Up ? m_frame.isAbove(cursorMiddleLeft) : m_frame.isUnder(cursorMiddleLeft); + bool layoutContains = m_frame.contains(cursorMiddleLeft); + + if (layoutIsUnderOrAbove) { + // Check the distance to a Left cursor. + int currentDistance = LayoutCursor(this, LayoutCursor::Position::Left).middleLeftPoint().squareDistanceTo(cursorMiddleLeft); + if (currentDistance <= *resultScore ){ + *childResult = this; + *castedResultPosition = LayoutCursor::Position::Left; + *resultScore = currentDistance; + } + + // Check the distance to a Right cursor. + currentDistance = LayoutCursor(this, LayoutCursor::Position::Right).middleLeftPoint().squareDistanceTo(cursorMiddleLeft); + if (currentDistance < *resultScore) { + *childResult = this; + *castedResultPosition = LayoutCursor::Position::Right; + *resultScore = currentDistance; + } + } + if (layoutIsUnderOrAbove || layoutContains) { + for (LayoutNode * c : children()) { + c->scoreCursorInDescendantsVertically(direction, cursor, shouldRecomputeLayout, childResult, castedResultPosition, resultScore); + } + } +} + +bool LayoutNode::changeGreySquaresOfAllMatrixAncestors(bool add) { + bool changedSquares = false; + Layout currentAncestor = Layout(parent()); + while (!currentAncestor.isUninitialized()) { + if (currentAncestor.isMatrix()) { + if (add) { + MatrixLayout(static_cast(currentAncestor.node())).addGreySquares(); + } else { + MatrixLayout(static_cast(currentAncestor.node())).removeGreySquares(); + } + changedSquares = true; + } + currentAncestor = currentAncestor.parent(); + } + return changedSquares; +} + +} diff --git a/poincare/src/layout_reference.cpp b/poincare/src/layout_reference.cpp deleted file mode 100644 index 8cb28697b..000000000 --- a/poincare/src/layout_reference.cpp +++ /dev/null @@ -1,274 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -namespace Poincare { -LayoutReference LayoutReference::clone() const { - if (isUninitialized()) { - return LayoutReference(); - } - TreeHandle c = TreeHandle::clone(); - LayoutReference cast = LayoutReference(static_cast(c.node())); - cast.invalidAllSizesPositionsAndBaselines(); - return cast; -} - -// Cursor -LayoutCursor LayoutReference::cursor() const { - assert(!isUninitialized()); - return LayoutCursor(const_cast(this)->node()); -} - -LayoutCursor LayoutReference::equivalentCursor(LayoutCursor * cursor) { - assert(!isUninitialized()); - return node()->equivalentCursor(cursor); -} - -LayoutReference LayoutReference::childAtIndex(int i) { - TreeHandle c = TreeHandle::childAtIndex(i); - return static_cast(c); -} - -// Tree modification - -void LayoutReference::replaceChild(LayoutReference oldChild, LayoutReference newChild, LayoutCursor * cursor, bool force) { - int childIndex = indexOfChild(oldChild); - assert(childIndex >= 0); - if (!node()->willReplaceChild(oldChild.node(), newChild.node(), cursor, force)) { - return; - } - replaceChildInPlace(oldChild, newChild); - if (cursor != nullptr) { - cursor->setLayoutReference(newChild); - } - node()->didReplaceChildAtIndex(childIndex, cursor, force); -} - -void LayoutReference::replaceChildWithEmpty(LayoutReference oldChild, LayoutCursor * cursor) { - replaceChild(oldChild, EmptyLayoutReference(), cursor); -} - -void LayoutReference::replaceWith(LayoutReference newChild, LayoutCursor * cursor) { - LayoutReference p = parent(); - assert(!p.isUninitialized()); - p.replaceChild(*this, newChild, cursor); -} - -void LayoutReference::replaceWithJuxtapositionOf(LayoutReference leftChild, LayoutReference rightChild, LayoutCursor * cursor, bool putCursorInTheMiddle) { - LayoutReference p = parent(); - assert(!p.isUninitialized()); - if (!p.isHorizontal()) { - /* One of the children to juxtapose might be "this", so we cannot just call - * replaceWith. */ - HorizontalLayoutReference horizontalLayoutR; - p.replaceChild(*this, horizontalLayoutR, cursor); - horizontalLayoutR.addOrMergeChildAtIndex(leftChild, 0, false); - if (putCursorInTheMiddle) { - if (!horizontalLayoutR.isEmpty()) { - cursor->setLayoutReference(horizontalLayoutR.childAtIndex(horizontalLayoutR.numberOfChildren()-1)); - cursor->setPosition(LayoutCursor::Position::Right); - } else { - cursor->setLayoutReference(horizontalLayoutR); - cursor->setPosition(LayoutCursor::Position::Left); - } - } - horizontalLayoutR.addOrMergeChildAtIndex(rightChild, 1, false); - return; - } - /* The parent is an Horizontal layout, so directly add the two juxtaposition - * children to the parent. */ - int idxInParent = p.indexOfChild(*this); - HorizontalLayoutReference castedParent = HorizontalLayoutReference(static_cast(p.node())); - if (putCursorInTheMiddle) { - if (idxInParent > 0) { - cursor->setLayoutReference(castedParent.childAtIndex(idxInParent-1)); - cursor->setPosition(LayoutCursor::Position::Right); - } else { - cursor->setLayoutReference(castedParent); - cursor->setPosition(LayoutCursor::Position::Left); - } - } - castedParent.addOrMergeChildAtIndex(rightChild, idxInParent, true); - castedParent.addOrMergeChildAtIndex(leftChild, idxInParent, true, putCursorInTheMiddle ? cursor : nullptr); - p.removeChild(*this, cursor->layoutReference() == *this ? cursor : nullptr); -} - -void LayoutReference::addChildAtIndex(LayoutReference l, int index, int currentNumberOfChildren, LayoutCursor * cursor) { - int newIndex = index; - int newCurrentNumberOfChildren = currentNumberOfChildren; - if (!node()->willAddChildAtIndex(l.node(), &newIndex, &newCurrentNumberOfChildren, cursor)) { - return; - } - LayoutReference nextPointedLayout; - LayoutCursor::Position nextPosition = LayoutCursor::Position::Left; - if (cursor != nullptr) { - if (newIndex < this->numberOfChildren()) { - nextPointedLayout = childAtIndex(newIndex); - nextPosition = LayoutCursor::Position::Left; - } else { - nextPointedLayout = *this; - nextPosition = LayoutCursor::Position::Right; - } - } - - addChildAtIndexInPlace(l, newIndex, newCurrentNumberOfChildren); - - if (cursor != nullptr) { - cursor->setLayoutReference(nextPointedLayout); - cursor->setPosition(nextPosition); - } -} - -void LayoutReference::addSibling(LayoutCursor * cursor, LayoutReference sibling, bool moveCursor) { - if (!node()->willAddSibling(cursor, sibling.node(), moveCursor)) { - return; - } - /* The layout must have a parent, because HorizontalLayoutReference's - * preprocessAddSibling returns false only an HorizontalLayout can be the - * root layout. */ - LayoutReference rootLayout = root(); - LayoutReference p = parent(); - assert(!p.isUninitialized()); - if (p.isHorizontal()) { - int indexInParent = p.indexOfChild(*this); - int siblingIndex = cursor->position() == LayoutCursor::Position::Left ? indexInParent : indexInParent + 1; - - /* Special case: If the neighbour sibling is a VerticalOffsetLayout, let it - * handle the insertion of the new sibling. Do not enter the special case if - * "this" is a VerticalOffsetLayout, to avoid an infinite loop. */ - if (!isVerticalOffset()) { - LayoutReference neighbour; - if (cursor->position() == LayoutCursor::Position::Left && indexInParent > 0) { - neighbour = p.childAtIndex(indexInParent - 1); - } else if (cursor->position() == LayoutCursor::Position::Right && indexInParent < p.numberOfChildren() - 1) { - neighbour = p.childAtIndex(indexInParent + 1); - } - if (!neighbour.isUninitialized() && neighbour.isVerticalOffset()) { - if (moveCursor) { - cursor->setLayoutReference(neighbour); - cursor->setPosition(cursor->position() == LayoutCursor::Position::Left ? LayoutCursor::Position::Right : LayoutCursor::Position::Left); - } - neighbour.addSibling(cursor, sibling, moveCursor); - return; - } - } - - // Else, let the parent add the sibling. - HorizontalLayoutReference(static_cast(p.node())).addOrMergeChildAtIndex(sibling, siblingIndex, true, moveCursor ? cursor : nullptr); - return; - } - if (cursor->position() == LayoutCursor::Position::Left) { - replaceWithJuxtapositionOf(sibling, *this, cursor); - } else { - assert(cursor->position() == LayoutCursor::Position::Right); - replaceWithJuxtapositionOf(*this, sibling, cursor); - } -} - -void LayoutReference::removeChild(LayoutReference l, LayoutCursor * cursor, bool force) { - if (!node()->willRemoveChild(l.node(), cursor, force)) { - return; - } - assert(hasChild(l)); - int index = indexOfChild(l); - removeChildInPlace(l, l.numberOfChildren()); - if (cursor) { - if (index < numberOfChildren()) { - LayoutReference newCursorRef = childAtIndex(index); - cursor->setLayoutReference(newCursorRef); - cursor->setPosition(LayoutCursor::Position::Left); - } else { - int newPointedLayoutIndex = index - 1; - if (newPointedLayoutIndex >= 0 && newPointedLayoutIndex < numberOfChildren()) { - cursor->setLayoutReference(childAtIndex(newPointedLayoutIndex)); - cursor->setPosition(LayoutCursor::Position::Right); - } else { - cursor->setLayoutReference(*this); - cursor->setPosition(LayoutCursor::Position::Right); - } - } - } - node()->didRemoveChildAtIndex(index, cursor, force); -} - -void LayoutReference::removeChildAtIndex(int index, LayoutCursor * cursor, bool force) { - removeChild(childAtIndex(index), cursor, force); -} - -void LayoutReference::collapseOnDirection(HorizontalDirection direction, int absorbingChildIndex) { - LayoutReference p = parent(); - if (p.isUninitialized() || !p.isHorizontal()) { - return; - } - int idxInParent = p.indexOfChild(*this); - int numberOfSiblings = p.numberOfChildren(); - int numberOfOpenParenthesis = 0; - bool canCollapse = true; - LayoutReference absorbingChild = childAtIndex(absorbingChildIndex); - if (absorbingChild.isUninitialized() || !absorbingChild.isHorizontal()) { - return; - } - HorizontalLayoutReference horizontalAbsorbingChild = HorizontalLayoutReference(static_cast(absorbingChild.node())); - if (direction == HorizontalDirection::Right && idxInParent < numberOfSiblings - 1) { - canCollapse = !(p.childAtIndex(idxInParent+1).mustHaveLeftSibling()); - } - LayoutReference sibling; - bool forceCollapse = false; - while (canCollapse) { - if (direction == HorizontalDirection::Right && idxInParent == numberOfSiblings - 1) { - break; - } - if (direction == HorizontalDirection::Left && idxInParent == 0) { - break; - } - int siblingIndex = direction == HorizontalDirection::Right ? idxInParent+1 : idxInParent-1; - sibling = p.childAtIndex(siblingIndex); - /* Even if forceCollapse is true, isCollapsable should be called to update - * the number of open parentheses. */ - bool shouldCollapse = sibling.isCollapsable(&numberOfOpenParenthesis, direction == HorizontalDirection::Left); - if (shouldCollapse || forceCollapse) { - /* If the collapse direction is Left and the next sibling to be collapsed - * must have a left sibling, force the collapsing of this needed left - * sibling. */ - forceCollapse = direction == HorizontalDirection::Left && sibling.mustHaveLeftSibling(); - p.removeChildAtIndex(siblingIndex, nullptr); - int newIndex = direction == HorizontalDirection::Right ? absorbingChild.numberOfChildren() : 0; - horizontalAbsorbingChild.addOrMergeChildAtIndex(sibling, newIndex, true); - numberOfSiblings--; - if (direction == HorizontalDirection::Left) { - idxInParent--; - } - } else { - break; - } - } -} - -void LayoutReference::collapseSiblings(LayoutCursor * cursor) { - LayoutReference rootLayout = root(); - if (node()->shouldCollapseSiblingsOnRight()) { - LayoutReference absorbingChild = childAtIndex(rightCollapsingAbsorbingChildIndex()); - if (!absorbingChild.isHorizontal()) { - LayoutReference horRef = HorizontalLayoutReference(); - replaceChild(absorbingChild, horRef, cursor, true); - horRef.addChildAtIndexInPlace(absorbingChild, 0, 0); - } - collapseOnDirection(HorizontalDirection::Right, rightCollapsingAbsorbingChildIndex()); - } - if (node()->shouldCollapseSiblingsOnLeft()) { - LayoutReference absorbingChild = childAtIndex(leftCollapsingAbsorbingChildIndex()); - if (!absorbingChild.isHorizontal()) { - LayoutReference horRef = HorizontalLayoutReference(); - replaceChild(absorbingChild, horRef, cursor, true); - horRef.addChildAtIndexInPlace(absorbingChild, 0, 0); - } - collapseOnDirection(HorizontalDirection::Left, leftCollapsingAbsorbingChildIndex()); - } - node()->didCollapseSiblings(cursor); -} - -} diff --git a/poincare/src/least_common_multiple.cpp b/poincare/src/least_common_multiple.cpp index 13bfc8a3d..1ee3cce2c 100644 --- a/poincare/src/least_common_multiple.cpp +++ b/poincare/src/least_common_multiple.cpp @@ -8,7 +8,7 @@ namespace Poincare { -LayoutReference LeastCommonMultipleNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout LeastCommonMultipleNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(LeastCommonMultiple(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/left_parenthesis_layout.cpp b/poincare/src/left_parenthesis_layout.cpp index 27d81546b..150af8b98 100644 --- a/poincare/src/left_parenthesis_layout.cpp +++ b/poincare/src/left_parenthesis_layout.cpp @@ -59,6 +59,6 @@ void LeftParenthesisLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expre RenderWithChildHeight(ParenthesisLayoutNode::ChildHeightGivenLayoutHeight(layoutSize().height()), ctx, p, expressionColor, backgroundColor); } -LeftParenthesisLayoutReference::LeftParenthesisLayoutReference() : LayoutReference(TreePool::sharedPool()->createTreeNode()) {} +LeftParenthesisLayout::LeftParenthesisLayout() : Layout(TreePool::sharedPool()->createTreeNode()) {} } diff --git a/poincare/src/left_square_bracket_layout.cpp b/poincare/src/left_square_bracket_layout.cpp index 5379c1ef3..b380e9b8c 100644 --- a/poincare/src/left_square_bracket_layout.cpp +++ b/poincare/src/left_square_bracket_layout.cpp @@ -8,6 +8,6 @@ void LeftSquareBracketLayoutNode::render(KDContext * ctx, KDPoint p, KDColor exp ctx->fillRect(KDRect(p.x()+k_externWidthMargin, p.y() + childHeight(), k_bracketWidth, k_lineThickness), expressionColor); } -LeftSquareBracketLayoutReference::LeftSquareBracketLayoutReference() : LayoutReference(TreePool::sharedPool()->createTreeNode()) {} +LeftSquareBracketLayout::LeftSquareBracketLayout() : Layout(TreePool::sharedPool()->createTreeNode()) {} } diff --git a/poincare/src/logarithm.cpp b/poincare/src/logarithm.cpp index acd9e32cb..cba1cad9d 100644 --- a/poincare/src/logarithm.cpp +++ b/poincare/src/logarithm.cpp @@ -18,12 +18,12 @@ namespace Poincare { template<> -LayoutReference LogarithmNode<1>::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout LogarithmNode<1>::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(this, floatDisplayMode, numberOfSignificantDigits, "log"); } template<> -LayoutReference LogarithmNode<2>::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout LogarithmNode<2>::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Logarithm( childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits), childAtIndex(1)->createLayout(floatDisplayMode, numberOfSignificantDigits)); diff --git a/poincare/src/matrix.cpp b/poincare/src/matrix.cpp index 9920c0632..f1a9cfb27 100644 --- a/poincare/src/matrix.cpp +++ b/poincare/src/matrix.cpp @@ -21,9 +21,9 @@ int MatrixNode::polynomialDegree(char symbolName) const { return -1; } -LayoutReference MatrixNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout MatrixNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { assert(numberOfChildren() > 0); - MatrixLayoutReference layout; + MatrixLayout layout; for (int i = 0; i < numberOfChildren(); i++) { layout.addChildAtIndex(childAtIndex(i)->createLayout(floatDisplayMode, numberOfSignificantDigits), i, i, nullptr); } diff --git a/poincare/src/matrix_dimension.cpp b/poincare/src/matrix_dimension.cpp index fe1188936..c0eb8829e 100644 --- a/poincare/src/matrix_dimension.cpp +++ b/poincare/src/matrix_dimension.cpp @@ -11,7 +11,7 @@ Expression MatrixDimensionNode::shallowReduce(Context & context, Preferences::An return MatrixDimension(this).shallowReduce(context, angleUnit); } -LayoutReference MatrixDimensionNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout MatrixDimensionNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(MatrixDimension(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/matrix_inverse.cpp b/poincare/src/matrix_inverse.cpp index 42d651c07..83a267a95 100644 --- a/poincare/src/matrix_inverse.cpp +++ b/poincare/src/matrix_inverse.cpp @@ -14,7 +14,7 @@ Expression MatrixInverseNode::shallowReduce(Context & context, Preferences::Angl return MatrixInverse(this).shallowReduce(context, angleUnit); } -LayoutReference MatrixInverseNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout MatrixInverseNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(MatrixInverse(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/matrix_layout.cpp b/poincare/src/matrix_layout.cpp index 68b5fd9ea..ca5c7f184 100644 --- a/poincare/src/matrix_layout.cpp +++ b/poincare/src/matrix_layout.cpp @@ -11,7 +11,7 @@ namespace Poincare { void MatrixLayoutNode::addGreySquares() { if (!hasGreySquares()) { - LayoutReference thisRef(this); + Layout thisRef(this); addEmptyRow(EmptyLayoutNode::Color::Grey); addEmptyColumn(EmptyLayoutNode::Color::Grey); } @@ -137,12 +137,12 @@ KDPoint MatrixLayoutNode::positionOfChild(LayoutNode * l) { } void MatrixLayoutNode::moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { - MatrixLayoutReference thisRef = MatrixLayoutReference(this); + MatrixLayout thisRef = MatrixLayout(this); bool shouldRemoveGreySquares = false; 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->layoutReference().hasAncestor(thisRef.childAtIndex(childIndex), true)) { + if (cursor->layouterence().hasAncestor(thisRef.childAtIndex(childIndex), true)) { // The cursor is leaving the matrix, so remove the grey squares. shouldRemoveGreySquares = true; break; @@ -266,10 +266,10 @@ void MatrixLayoutNode::didReplaceChildAtIndex(int index, LayoutCursor * cursor, } } -MatrixLayoutReference::MatrixLayoutReference(const MatrixLayoutNode * n) : GridLayoutReference(n) {} -MatrixLayoutReference::MatrixLayoutReference() : GridLayoutReference(TreePool::sharedPool()->createTreeNode()) {} -MatrixLayoutReference::MatrixLayoutReference(LayoutReference l1, LayoutReference l2, LayoutReference l3, LayoutReference l4) : - MatrixLayoutReference() +MatrixLayout::MatrixLayout(const MatrixLayoutNode * n) : GridLayout(n) {} +MatrixLayout::MatrixLayout() : GridLayout(TreePool::sharedPool()->createTreeNode()) {} +MatrixLayout::MatrixLayout(Layout l1, Layout l2, Layout l3, Layout l4) : + MatrixLayout() { addChildAtIndexInPlace(l1, 0, 0); addChildAtIndexInPlace(l2, 1, 1); diff --git a/poincare/src/matrix_trace.cpp b/poincare/src/matrix_trace.cpp index a26859d43..a176fac0f 100644 --- a/poincare/src/matrix_trace.cpp +++ b/poincare/src/matrix_trace.cpp @@ -13,7 +13,7 @@ Expression MatrixTraceNode::shallowReduce(Context & context, Preferences::AngleU return MatrixTrace(this).shallowReduce(context, angleUnit); } -LayoutReference MatrixTraceNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout MatrixTraceNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(MatrixTrace(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/matrix_transpose.cpp b/poincare/src/matrix_transpose.cpp index 611c3e20e..c6c632024 100644 --- a/poincare/src/matrix_transpose.cpp +++ b/poincare/src/matrix_transpose.cpp @@ -11,7 +11,7 @@ Expression MatrixTransposeNode::shallowReduce(Context & context, Preferences::An return MatrixTranspose(this).shallowReduce(context, angleUnit); } -LayoutReference MatrixTransposeNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout MatrixTransposeNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(MatrixTranspose(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/multiplication.cpp b/poincare/src/multiplication.cpp index 813b90966..b0a33cae7 100644 --- a/poincare/src/multiplication.cpp +++ b/poincare/src/multiplication.cpp @@ -75,7 +75,7 @@ bool MultiplicationNode::childNeedsParenthesis(const SerializationHelperInterfac return static_cast(child)->isOfType(types, 3); } -LayoutReference MultiplicationNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout MultiplicationNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { const char middleDotString[] = {Ion::Charset::MiddleDot, 0}; return LayoutHelper::Infix(Multiplication(this), floatDisplayMode, numberOfSignificantDigits, middleDotString); } diff --git a/poincare/src/nth_root.cpp b/poincare/src/nth_root.cpp index 6a685deba..a5c0d67e1 100644 --- a/poincare/src/nth_root.cpp +++ b/poincare/src/nth_root.cpp @@ -8,8 +8,8 @@ namespace Poincare { -LayoutReference NthRootNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { - return NthRootLayoutReference( +Layout NthRootNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { + return NthRootLayout( childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits), childAtIndex(1)->createLayout(floatDisplayMode, numberOfSignificantDigits)); } diff --git a/poincare/src/nth_root_layout.cpp b/poincare/src/nth_root_layout.cpp index 709d47669..73c0330b9 100644 --- a/poincare/src/nth_root_layout.cpp +++ b/poincare/src/nth_root_layout.cpp @@ -135,11 +135,11 @@ void NthRootLayoutNode::deleteBeforeCursor(LayoutCursor * cursor) { && cursor->position() == LayoutCursor::Position::Left) { // Case: Left of the radicand. Delete the layout, keep the radicand. - LayoutReference radicand = LayoutReference(radicandLayout()); - LayoutReference thisRef = LayoutReference(this); + Layout radicand = Layout(radicandLayout()); + Layout thisRef = Layout(this); thisRef.replaceChildWithGhostInPlace(radicand); // WARNING: Do not call "this" afterwards - cursor->setLayoutReference(thisRef.childAtIndex(0)); + cursor->setLayout(thisRef.childAtIndex(0)); thisRef.replaceWith(radicand, cursor); return; } @@ -269,16 +269,16 @@ void NthRootLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionCol } } -NthRootLayoutReference::NthRootLayoutReference(LayoutReference radicand) : NthRootLayoutReference() { +NthRootLayout::NthRootLayout(Layout radicand) : NthRootLayout() { replaceChildAtIndexInPlace(0, radicand); } -NthRootLayoutReference::NthRootLayoutReference(LayoutReference radicand, LayoutReference index) : NthRootLayoutReference() { +NthRootLayout::NthRootLayout(Layout radicand, Layout index) : NthRootLayout() { replaceChildAtIndexInPlace(0, radicand); addChildAtIndexInPlace(index, 1, 1); static_cast(node())->setNumberOfChildren(2); } -NthRootLayoutReference::NthRootLayoutReference() : LayoutReference(TreePool::sharedPool()->createTreeNode()) {} +NthRootLayout::NthRootLayout() : Layout(TreePool::sharedPool()->createTreeNode()) {} } diff --git a/poincare/src/opposite.cpp b/poincare/src/opposite.cpp index ac4fbf6b8..cefe5abe2 100644 --- a/poincare/src/opposite.cpp +++ b/poincare/src/opposite.cpp @@ -37,8 +37,8 @@ bool OppositeNode::childNeedsParenthesis(const SerializationHelperInterface * ch return static_cast(child)->isOfType(types, 3); } -LayoutReference OppositeNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { - HorizontalLayoutReference result = HorizontalLayoutReference(CharLayoutReference('-')); +Layout OppositeNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { + HorizontalLayout result = HorizontalLayout(CharLayout('-')); if (childAtIndex(0)->type() == Type::Opposite) { result.addOrMergeChildAtIndex(LayoutHelper::Parentheses(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits), false), 1, false); } else { diff --git a/poincare/src/parenthesis.cpp b/poincare/src/parenthesis.cpp index 835235e24..8b603f24b 100644 --- a/poincare/src/parenthesis.cpp +++ b/poincare/src/parenthesis.cpp @@ -7,7 +7,7 @@ int ParenthesisNode::polynomialDegree(char symbolName) const { return childAtIndex(0)->polynomialDegree(symbolName); } -LayoutReference ParenthesisNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout ParenthesisNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Parentheses(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits), false); } diff --git a/poincare/src/permute_coefficient.cpp b/poincare/src/permute_coefficient.cpp index d038c55bb..e67c0c09e 100644 --- a/poincare/src/permute_coefficient.cpp +++ b/poincare/src/permute_coefficient.cpp @@ -9,7 +9,7 @@ extern "C" { namespace Poincare { -LayoutReference PermuteCoefficientNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout PermuteCoefficientNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(PermuteCoefficient(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index 30070abf6..3fe9c8b9b 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -92,15 +92,15 @@ Complex PowerNode::compute(const std::complex c, const std::complex d) // Layout -LayoutReference PowerNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout PowerNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { ExpressionNode * indiceOperand = childAtIndex(1); // Delete eventual parentheses of the indice in the pretty print if (indiceOperand->type() == ExpressionNode::Type::Parenthesis) { indiceOperand = indiceOperand->childAtIndex(0); } - HorizontalLayoutReference result = HorizontalLayoutReference(); + HorizontalLayout result = HorizontalLayout(); result.addOrMergeChildAtIndex(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits), 0, false); - result.addChildAtIndex(VerticalOffsetLayoutReference( + result.addChildAtIndex(VerticalOffsetLayout( indiceOperand->createLayout(floatDisplayMode, numberOfSignificantDigits), VerticalOffsetLayoutNode::Type::Superscript), result.numberOfChildren(), diff --git a/poincare/src/prediction_interval.cpp b/poincare/src/prediction_interval.cpp index fbcd846cd..017e4fb36 100644 --- a/poincare/src/prediction_interval.cpp +++ b/poincare/src/prediction_interval.cpp @@ -12,7 +12,7 @@ extern "C" { namespace Poincare { -LayoutReference PredictionIntervalNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout PredictionIntervalNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(PredictionInterval(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/product.cpp b/poincare/src/product.cpp index 07e57d310..96c7d3f98 100644 --- a/poincare/src/product.cpp +++ b/poincare/src/product.cpp @@ -9,8 +9,8 @@ extern "C" { namespace Poincare { -LayoutReference ProductNode::createSequenceLayout(LayoutReference argumentLayout, LayoutReference subscriptLayout, LayoutReference superscriptLayout) const { - return ProductLayoutReference(argumentLayout, subscriptLayout, superscriptLayout); +Layout ProductNode::createSequenceLayout(Layout argumentLayout, Layout subscriptLayout, Layout superscriptLayout) const { + return ProductLayout(argumentLayout, subscriptLayout, superscriptLayout); } template diff --git a/poincare/src/randint.cpp b/poincare/src/randint.cpp index ae5acc057..e7c2635a3 100644 --- a/poincare/src/randint.cpp +++ b/poincare/src/randint.cpp @@ -10,7 +10,7 @@ extern "C" { namespace Poincare { -LayoutReference RandintNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout RandintNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(Randint(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/random.cpp b/poincare/src/random.cpp index fc64d5b7b..43c155bf0 100644 --- a/poincare/src/random.cpp +++ b/poincare/src/random.cpp @@ -10,7 +10,7 @@ Expression RandomNode::setSign(Sign s, Context & context, Preferences::AngleUnit return Random(this).setSign(s, context, angleUnit); } -LayoutReference RandomNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout RandomNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(Random(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/rational.cpp b/poincare/src/rational.cpp index 34df4f41d..714ceecef 100644 --- a/poincare/src/rational.cpp +++ b/poincare/src/rational.cpp @@ -90,13 +90,13 @@ Expression RationalNode::setSign(Sign s, Context & context, Preferences::AngleUn // Layout -LayoutReference RationalNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { - HorizontalLayoutReference numeratorLayout = signedNumerator().createLayout(); +Layout RationalNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { + HorizontalLayout numeratorLayout = signedNumerator().createLayout(); if (denominator().isOne()) { return numeratorLayout; } - HorizontalLayoutReference denominatorLayout = denominator().createLayout(); - return FractionLayoutReference(numeratorLayout, denominatorLayout); + HorizontalLayout denominatorLayout = denominator().createLayout(); + return FractionLayout(numeratorLayout, denominatorLayout); } // Approximation diff --git a/poincare/src/real_part.cpp b/poincare/src/real_part.cpp index ec9516f4e..875315a27 100644 --- a/poincare/src/real_part.cpp +++ b/poincare/src/real_part.cpp @@ -5,7 +5,7 @@ namespace Poincare { -LayoutReference RealPartNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout RealPartNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(RealPart(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/right_parenthesis_layout.cpp b/poincare/src/right_parenthesis_layout.cpp index f7ffb58c9..e6a305113 100644 --- a/poincare/src/right_parenthesis_layout.cpp +++ b/poincare/src/right_parenthesis_layout.cpp @@ -59,6 +59,6 @@ void RightParenthesisLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expr RenderWithChildHeight(ParenthesisLayoutNode::ChildHeightGivenLayoutHeight(layoutSize().height()), ctx, p, expressionColor, backgroundColor); } -RightParenthesisLayoutReference::RightParenthesisLayoutReference() : LayoutReference(TreePool::sharedPool()->createTreeNode()) {} +RightParenthesisLayout::RightParenthesisLayout() : Layout(TreePool::sharedPool()->createTreeNode()) {} } diff --git a/poincare/src/right_square_bracket_layout.cpp b/poincare/src/right_square_bracket_layout.cpp index f2c405b3c..f5b6aecc4 100644 --- a/poincare/src/right_square_bracket_layout.cpp +++ b/poincare/src/right_square_bracket_layout.cpp @@ -8,6 +8,6 @@ void RightSquareBracketLayoutNode::render(KDContext * ctx, KDPoint p, KDColor ex ctx->fillRect(KDRect(p.x()+k_widthMargin-k_bracketWidth+1, p.y() + childHeight(), k_bracketWidth, k_lineThickness), expressionColor); } -RightSquareBracketLayoutReference::RightSquareBracketLayoutReference() : LayoutReference(TreePool::sharedPool()->createTreeNode()) {} +RightSquareBracketLayout::RightSquareBracketLayout() : Layout(TreePool::sharedPool()->createTreeNode()) {} } diff --git a/poincare/src/round.cpp b/poincare/src/round.cpp index 8709bad9d..570506926 100644 --- a/poincare/src/round.cpp +++ b/poincare/src/round.cpp @@ -7,7 +7,7 @@ namespace Poincare { -LayoutReference RoundNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout RoundNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(Round(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/sequence.cpp b/poincare/src/sequence.cpp index 14035e506..85ca379ca 100644 --- a/poincare/src/sequence.cpp +++ b/poincare/src/sequence.cpp @@ -11,7 +11,7 @@ extern "C" { namespace Poincare { -LayoutReference SequenceNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout SequenceNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return createSequenceLayout(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits), childAtIndex(1)->createLayout(floatDisplayMode, numberOfSignificantDigits), childAtIndex(2)->createLayout(floatDisplayMode, numberOfSignificantDigits)); } diff --git a/poincare/src/sequence_layout.cpp b/poincare/src/sequence_layout.cpp index 8ba49fd3e..314aba4dd 100644 --- a/poincare/src/sequence_layout.cpp +++ b/poincare/src/sequence_layout.cpp @@ -105,11 +105,11 @@ void SequenceLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldReco void SequenceLayoutNode::deleteBeforeCursor(LayoutCursor * cursor) { if (cursor->isEquivalentTo(LayoutCursor(argumentLayout(), LayoutCursor::Position::Left))) { // Case: Left of the argument. Delete the layout, keep the argument. - LayoutReference argument = LayoutReference(argumentLayout()); - LayoutReference thisRef = LayoutReference(this); + Layout argument = Layout(argumentLayout()); + Layout thisRef = Layout(this); thisRef.replaceChildWithGhostInPlace(argument); // WARNING: Do not call "this" afterwards - cursor->setLayoutReference(thisRef.childAtIndex(0)); + cursor->setLayout(thisRef.childAtIndex(0)); thisRef.replaceWith(argument, cursor); return; } diff --git a/poincare/src/sine.cpp b/poincare/src/sine.cpp index 43560e93b..567bcdb55 100644 --- a/poincare/src/sine.cpp +++ b/poincare/src/sine.cpp @@ -17,7 +17,7 @@ Complex SineNode::computeOnComplex(const std::complex c, Preferences::Angl return Complex(Trigonometry::RoundToMeaningfulDigits(res)); } -LayoutReference SineNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout SineNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(Sine(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/square_root.cpp b/poincare/src/square_root.cpp index 3c6b63a55..c362ba0e4 100644 --- a/poincare/src/square_root.cpp +++ b/poincare/src/square_root.cpp @@ -8,8 +8,8 @@ namespace Poincare { -LayoutReference SquareRootNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { - return NthRootLayoutReference(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits)); +Layout SquareRootNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { + return NthRootLayout(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits)); } static_assert('\x91' == Ion::Charset::Root, "Unicode error"); diff --git a/poincare/src/store.cpp b/poincare/src/store.cpp index 881e77918..87725b566 100644 --- a/poincare/src/store.cpp +++ b/poincare/src/store.cpp @@ -22,10 +22,10 @@ int StoreNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatM return SerializationHelper::Infix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "\x90"); } -LayoutReference StoreNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { - HorizontalLayoutReference result = HorizontalLayoutReference(); +Layout StoreNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { + HorizontalLayout result = HorizontalLayout(); result.addOrMergeChildAtIndex(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits), 0, false); - result.addChildAtIndex(CharLayoutReference(Ion::Charset::Sto), result.numberOfChildren(), result.numberOfChildren(), nullptr); + result.addChildAtIndex(CharLayout(Ion::Charset::Sto), result.numberOfChildren(), result.numberOfChildren(), nullptr); result.addOrMergeChildAtIndex(childAtIndex(1)->createLayout(floatDisplayMode, numberOfSignificantDigits), result.numberOfChildren(), false); return result; } diff --git a/poincare/src/subtraction.cpp b/poincare/src/subtraction.cpp index d2de10f8c..3628d6f8c 100644 --- a/poincare/src/subtraction.cpp +++ b/poincare/src/subtraction.cpp @@ -30,7 +30,7 @@ bool SubtractionNode::childNeedsParenthesis(const SerializationHelperInterface * return static_cast(child)->isOfType(types, 3); } -LayoutReference SubtractionNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout SubtractionNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Infix(Subtraction(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/sum.cpp b/poincare/src/sum.cpp index bd2af7b81..e3e03acb0 100644 --- a/poincare/src/sum.cpp +++ b/poincare/src/sum.cpp @@ -11,8 +11,8 @@ extern "C" { namespace Poincare { -LayoutReference SumNode::createSequenceLayout(LayoutReference argumentLayout, LayoutReference subscriptLayout, LayoutReference superscriptLayout) const { - return SumLayoutReference(argumentLayout, subscriptLayout, superscriptLayout); +Layout SumNode::createSequenceLayout(Layout argumentLayout, Layout subscriptLayout, Layout superscriptLayout) const { + return SumLayout(argumentLayout, subscriptLayout, superscriptLayout); } template diff --git a/poincare/src/symbol.cpp b/poincare/src/symbol.cpp index 3c2bc8e8b..49f65ca05 100644 --- a/poincare/src/symbol.cpp +++ b/poincare/src/symbol.cpp @@ -79,35 +79,35 @@ int SymbolNode::simplificationOrderSameType(const ExpressionNode * e, bool canBe return -1; } -LayoutReference SymbolNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout SymbolNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { if (m_name == Symbol::SpecialSymbols::Ans) { return LayoutHelper::String("ans", 3); } if (m_name == Symbol::SpecialSymbols::un) { - return HorizontalLayoutReference( - CharLayoutReference('u'), - VerticalOffsetLayoutReference( - CharLayoutReference('n'), + return HorizontalLayout( + CharLayout('u'), + VerticalOffsetLayout( + CharLayout('n'), VerticalOffsetLayoutNode::Type::Subscript)); } if (m_name == Symbol::SpecialSymbols::un1) { - return HorizontalLayoutReference( - CharLayoutReference('u'), - VerticalOffsetLayoutReference( + return HorizontalLayout( + CharLayout('u'), + VerticalOffsetLayout( LayoutHelper::String("n+1", 3), VerticalOffsetLayoutNode::Type::Subscript)); } if (m_name == Symbol::SpecialSymbols::vn) { - return HorizontalLayoutReference( - CharLayoutReference('v'), - VerticalOffsetLayoutReference( - CharLayoutReference('n'), + return HorizontalLayout( + CharLayout('v'), + VerticalOffsetLayout( + CharLayout('n'), VerticalOffsetLayoutNode::Type::Subscript)); } if (m_name == Symbol::SpecialSymbols::vn1) { - return HorizontalLayoutReference( - CharLayoutReference('v'), - VerticalOffsetLayoutReference( + return HorizontalLayout( + CharLayout('v'), + VerticalOffsetLayout( LayoutHelper::String("n+1", 3), VerticalOffsetLayoutNode::Type::Subscript)); } diff --git a/poincare/src/tangent.cpp b/poincare/src/tangent.cpp index fcdbcaec0..76b81eab1 100644 --- a/poincare/src/tangent.cpp +++ b/poincare/src/tangent.cpp @@ -13,7 +13,7 @@ float TangentNode::characteristicXRange(Context & context, Preferences::AngleUni return Trigonometry::characteristicXRange(Tangent(this), context, angleUnit); } -LayoutReference TangentNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout TangentNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return LayoutHelper::Prefix(Tangent(this), floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/src/undefined.cpp b/poincare/src/undefined.cpp index 65b9b6ea8..2c14278cc 100644 --- a/poincare/src/undefined.cpp +++ b/poincare/src/undefined.cpp @@ -17,7 +17,7 @@ Expression UndefinedNode::setSign(Sign s, Context & context, Preferences::AngleU return Undefined(); } -LayoutReference UndefinedNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { +Layout UndefinedNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { char buffer[6]; int numberOfChars = PrintFloat::convertFloatToText(NAN, buffer, 6, numberOfSignificantDigits, floatDisplayMode); return LayoutHelper::String(buffer, numberOfChars); diff --git a/poincare/src/vertical_offset_layout.cpp b/poincare/src/vertical_offset_layout.cpp index cdf466fea..8966dcbfe 100644 --- a/poincare/src/vertical_offset_layout.cpp +++ b/poincare/src/vertical_offset_layout.cpp @@ -112,7 +112,7 @@ void VerticalOffsetLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shou void VerticalOffsetLayoutNode::deleteBeforeCursor(LayoutCursor * cursor) { if (cursor->layoutNode() == indiceLayout()) { assert(cursor->position() == LayoutCursor::Position::Left); - LayoutReference parentRef(parent()); + Layout parentRef(parent()); LayoutNode * base = baseLayout(); if (indiceLayout()->isEmpty()) { int indexInParent = parentRef.node()->indexOfChild(this); @@ -122,7 +122,7 @@ void VerticalOffsetLayoutNode::deleteBeforeCursor(LayoutCursor * cursor) { cursor->setPosition(LayoutCursor::Position::Right); parentRef.removeChildAtIndex(indexInParent, cursor); // WARNING: do not call "this" afterwards - cursor->setLayoutReference(parentRef.childAtIndex(indexInParent-1)); + cursor->setLayout(parentRef.childAtIndex(indexInParent-1)); cursor->setPosition(LayoutCursor::Position::Right); parentRef.removeChildAtIndex(indexInParent-1, cursor); return; @@ -229,14 +229,14 @@ bool VerticalOffsetLayoutNode::willAddSibling(LayoutCursor * cursor, LayoutNode if (sibling->isVerticalOffset()) { VerticalOffsetLayoutNode * verticalOffsetSibling = static_cast(sibling); if (verticalOffsetSibling->type() == Type::Superscript) { - LayoutReference rootLayout = root(); - LayoutReference thisRef = LayoutReference(this); - LayoutReference parentRef = LayoutReference(parent()); + Layout rootLayout = root(); + Layout thisRef = Layout(this); + Layout parentRef = Layout(parent()); assert(parentRef.isHorizontal()); // Add the Left parenthesis int idxInParent = parentRef.indexOfChild(thisRef); int leftParenthesisIndex = idxInParent; - LeftParenthesisLayoutReference leftParenthesis = LeftParenthesisLayoutReference(); + LeftParenthesisLayout leftParenthesis = LeftParenthesisLayout(); int numberOfOpenParenthesis = 0; while (leftParenthesisIndex > 0 && parentRef.childAtIndex(leftParenthesisIndex-1).isCollapsable(&numberOfOpenParenthesis, true)) @@ -247,7 +247,7 @@ bool VerticalOffsetLayoutNode::willAddSibling(LayoutCursor * cursor, LayoutNode idxInParent = parentRef.indexOfChild(thisRef); // Add the Right parenthesis - RightParenthesisLayoutReference rightParenthesis = RightParenthesisLayoutReference(); + RightParenthesisLayout rightParenthesis = RightParenthesisLayout(); if (cursor->position() == LayoutCursor::Position::Right) { parentRef.addChildAtIndex(rightParenthesis, idxInParent + 1, parentRef.numberOfChildren(), nullptr); } else { @@ -255,7 +255,7 @@ bool VerticalOffsetLayoutNode::willAddSibling(LayoutCursor * cursor, LayoutNode parentRef.addChildAtIndex(rightParenthesis, idxInParent, parentRef.numberOfChildren(), nullptr); } if (!rightParenthesis.parent().isUninitialized()) { - cursor->setLayoutReference(rightParenthesis); + cursor->setLayout(rightParenthesis); } } } @@ -271,8 +271,8 @@ LayoutNode * VerticalOffsetLayoutNode::baseLayout() { return parentNode->childAtIndex(idxInParent - 1); } -VerticalOffsetLayoutReference::VerticalOffsetLayoutReference(LayoutReference l, VerticalOffsetLayoutNode::Type type) : - LayoutReference(TreePool::sharedPool()->createTreeNode()) +VerticalOffsetLayout::VerticalOffsetLayout(Layout l, VerticalOffsetLayoutNode::Type type) : + Layout(TreePool::sharedPool()->createTreeNode()) { static_cast(node())->setType(type); replaceChildAtIndexInPlace(0,l); diff --git a/poincare/test/fraction_layout.cpp b/poincare/test/fraction_layout.cpp index e38e663c8..149ac26c6 100644 --- a/poincare/test/fraction_layout.cpp +++ b/poincare/test/fraction_layout.cpp @@ -12,7 +12,7 @@ QUIZ_CASE(poincare_fraction_layout_create) { * 12|34+5 -> "Divide" -> --- + 5 * |34 * */ - HorizontalLayoutReference layout = static_cast(LayoutHelper::String("1234+5", 6)); + HorizontalLayout layout = static_cast(LayoutHelper::String("1234+5", 6)); LayoutCursor cursor(layout.childAtIndex(2), LayoutCursor::Position::Left); cursor.addFractionLayoutAndCollapseSiblings(); assert_expression_layout_serialize_to(layout, "(12)/(34)+5"); @@ -25,8 +25,8 @@ QUIZ_CASE(poincare_fraction_layout_delete) { * --- -> "BackSpace" -> 12|34 * |34 * */ - HorizontalLayoutReference layout1 = HorizontalLayoutReference( - FractionLayoutReference( + HorizontalLayout layout1 = HorizontalLayout( + FractionLayout( LayoutHelper::String("12", 2), LayoutHelper::String("34", 2) ) @@ -40,12 +40,12 @@ QUIZ_CASE(poincare_fraction_layout_delete) { * 1 + --- -> "BackSpace" -> 1+|3 * |3 * */ - HorizontalLayoutReference layout2 = HorizontalLayoutReference( - CharLayoutReference('1'), - CharLayoutReference('+'), - FractionLayoutReference( - EmptyLayoutReference(), - CharLayoutReference('3') + HorizontalLayout layout2 = HorizontalLayout( + CharLayout('1'), + CharLayout('+'), + FractionLayout( + EmptyLayout(), + CharLayout('3') ) ); LayoutCursor cursor2(layout2.childAtIndex(2).childAtIndex(1), LayoutCursor::Position::Left); @@ -55,8 +55,8 @@ QUIZ_CASE(poincare_fraction_layout_delete) { } QUIZ_CASE(poincare_fraction_layout_serialize) { - FractionLayoutReference layout = FractionLayoutReference( - CharLayoutReference('1'), + FractionLayout layout = FractionLayout( + CharLayout('1'), LayoutHelper::String("2+3", 3) ); assert_expression_layout_serialize_to(layout, "(1)/(2+3)"); diff --git a/poincare/test/helper.cpp b/poincare/test/helper.cpp index 64330db04..0ba387dc3 100644 --- a/poincare/test/helper.cpp +++ b/poincare/test/helper.cpp @@ -123,7 +123,7 @@ void assert_parsed_expression_layout_serialize_to_self(const char * expressionLa #if POINCARE_TESTS_PRINT_EXPRESSIONS cout << "---- Serialize: " << expressionLayout << "----" << endl; #endif - LayoutReference el = e.createLayout(DecimalMode, PrintFloat::k_numberOfStoredSignificantDigits); + Layout el = e.createLayout(DecimalMode, PrintFloat::k_numberOfStoredSignificantDigits); constexpr int bufferSize = 255; char buffer[bufferSize]; el.serialize(buffer, bufferSize); @@ -133,7 +133,7 @@ void assert_parsed_expression_layout_serialize_to_self(const char * expressionLa quiz_assert(strcmp(expressionLayout, buffer) == 0); } -void assert_expression_layout_serialize_to(Poincare::LayoutReference layout, const char * serialization) { +void assert_expression_layout_serialize_to(Poincare::Layout layout, const char * serialization) { constexpr int bufferSize = 255; char buffer[bufferSize]; layout.serialize(buffer, bufferSize); diff --git a/poincare/test/helper.h b/poincare/test/helper.h index 32a267650..6ad4d4ada 100644 --- a/poincare/test/helper.h +++ b/poincare/test/helper.h @@ -29,4 +29,4 @@ void assert_parsed_expression_serialize_to(Poincare::Expression expression, cons // Layouts void assert_parsed_expression_layout_serialize_to_self(const char * expressionLayout); -void assert_expression_layout_serialize_to(Poincare::LayoutReference layout, const char * serialization); +void assert_expression_layout_serialize_to(Poincare::Layout layout, const char * serialization); diff --git a/poincare/test/layouts.cpp b/poincare/test/layouts.cpp index 61c5b77e3..d8c9ab44d 100644 --- a/poincare/test/layouts.cpp +++ b/poincare/test/layouts.cpp @@ -8,30 +8,30 @@ using namespace Poincare; QUIZ_CASE(poincare_create_all_layouts) { - EmptyLayoutReference e0; - AbsoluteValueLayoutReference e1(e0); - CharLayoutReference e2('a'); - BinomialCoefficientLayoutReference e3(e1, e2); - CeilingLayoutReference e4(e3); - RightParenthesisLayoutReference e5; - RightSquareBracketLayoutReference e6; - CondensedSumLayoutReference e7(e4, e5, e6); - ConjugateLayoutReference e8(e7); - LeftParenthesisLayoutReference e10; - FloorLayoutReference e11(e10); - FractionLayoutReference e12(e8, e11); - HorizontalLayoutReference e13; - LeftSquareBracketLayoutReference e14; - IntegralLayoutReference e15(e12, e13, e14); - NthRootLayoutReference e16(e15); - MatrixLayoutReference e17; - EmptyLayoutReference e18; - EmptyLayoutReference e19; - EmptyLayoutReference e20; - ProductLayoutReference e21(e18, e19, e20); - EmptyLayoutReference e22; - EmptyLayoutReference e23; - EmptyLayoutReference e24; - SumLayoutReference e25(e22, e23, e24); - VerticalOffsetLayoutReference e26(e25, VerticalOffsetLayoutNode::Type::Superscript); + EmptyLayout e0; + AbsoluteValueLayout e1(e0); + CharLayout e2('a'); + BinomialCoefficientLayout e3(e1, e2); + CeilingLayout e4(e3); + RightParenthesisLayout e5; + RightSquareBracketLayout e6; + CondensedSumLayout e7(e4, e5, e6); + ConjugateLayout e8(e7); + LeftParenthesisLayout e10; + FloorLayout e11(e10); + FractionLayout e12(e8, e11); + HorizontalLayout e13; + LeftSquareBracketLayout e14; + IntegralLayout e15(e12, e13, e14); + NthRootLayout e16(e15); + MatrixLayout e17; + EmptyLayout e18; + EmptyLayout e19; + EmptyLayout e20; + ProductLayout e21(e18, e19, e20); + EmptyLayout e22; + EmptyLayout e23; + EmptyLayout e24; + SumLayout e25(e22, e23, e24); + VerticalOffsetLayout e26(e25, VerticalOffsetLayoutNode::Type::Superscript); } diff --git a/poincare/test/parentheses_layout.cpp b/poincare/test/parentheses_layout.cpp index 2580dcd75..412409f06 100644 --- a/poincare/test/parentheses_layout.cpp +++ b/poincare/test/parentheses_layout.cpp @@ -11,20 +11,20 @@ QUIZ_CASE(poincare_parenthesis_layout_size) { * 4 * Assert that the first and last parentheses have the same size. */ - HorizontalLayoutReference layout = HorizontalLayoutReference(); - LeftParenthesisLayoutReference leftPar = LeftParenthesisLayoutReference(); - RightParenthesisLayoutReference rightPar = RightParenthesisLayoutReference(); + HorizontalLayout layout = HorizontalLayout(); + LeftParenthesisLayout leftPar = LeftParenthesisLayout(); + RightParenthesisLayout rightPar = RightParenthesisLayout(); layout.addChildAtIndex(leftPar, 0, 0, nullptr); - layout.addChildAtIndex(CharLayoutReference('2'), 1, 1, nullptr); - layout.addChildAtIndex(CharLayoutReference('+'), 2, 2, nullptr); - layout.addChildAtIndex(LeftParenthesisLayoutReference(), 3, 3, nullptr); - layout.addChildAtIndex(FractionLayoutReference( - CharLayoutReference('3'), - CharLayoutReference('4')), + layout.addChildAtIndex(CharLayout('2'), 1, 1, nullptr); + layout.addChildAtIndex(CharLayout('+'), 2, 2, nullptr); + layout.addChildAtIndex(LeftParenthesisLayout(), 3, 3, nullptr); + layout.addChildAtIndex(FractionLayout( + CharLayout('3'), + CharLayout('4')), 4, 4, nullptr); - layout.addChildAtIndex(RightParenthesisLayoutReference(), 4, 4, nullptr); - layout.addChildAtIndex(CharLayoutReference('6'), 5, 5, nullptr); + layout.addChildAtIndex(RightParenthesisLayout(), 4, 4, nullptr); + layout.addChildAtIndex(CharLayout('6'), 5, 5, nullptr); layout.addChildAtIndex(rightPar, 7, 7, nullptr); - layout.addChildAtIndex(CharLayoutReference('1'), 8, 8, nullptr); + layout.addChildAtIndex(CharLayout('1'), 8, 8, nullptr); quiz_assert(leftPar.layoutSize().height() == rightPar.layoutSize().height()); } diff --git a/poincare/test/vertical_offset_layout.cpp b/poincare/test/vertical_offset_layout.cpp index 41bff2a88..421ee2f2b 100644 --- a/poincare/test/vertical_offset_layout.cpp +++ b/poincare/test/vertical_offset_layout.cpp @@ -9,9 +9,9 @@ using namespace Poincare; QUIZ_CASE(poincare_vertical_offset_layout_serialize) { assert_parsed_expression_layout_serialize_to_self("(2)^(3)"); - HorizontalLayoutReference layout = HorizontalLayoutReference( - CharLayoutReference('2'), - VerticalOffsetLayoutReference( + HorizontalLayout layout = HorizontalLayout( + CharLayout('2'), + VerticalOffsetLayout( LayoutHelper::String("4+5", 3), VerticalOffsetLayoutNode::Type::Superscript )