diff --git a/apps/graph/function.cpp b/apps/graph/function.cpp index 95ac5065f..ee39131a3 100644 --- a/apps/graph/function.cpp +++ b/apps/graph/function.cpp @@ -4,6 +4,7 @@ namespace Graph { Function::Function(const char * text, KDColor color) : + m_text(""), m_name(text), m_color(color), m_expression(nullptr), @@ -22,7 +23,10 @@ void Function::setContent(const char * c) { if (m_layout != nullptr) { delete m_layout; } - m_layout = expression()->createLayout(); + m_layout = nullptr; + if (m_expression) { + m_layout = expression()->createLayout(); + } } void Function::setColor(KDColor color) { diff --git a/apps/graph/function_store.cpp b/apps/graph/function_store.cpp index 754eb1db8..c51203d28 100644 --- a/apps/graph/function_store.cpp +++ b/apps/graph/function_store.cpp @@ -23,7 +23,22 @@ Function * FunctionStore::activeFunctionAtIndex(int i) { assert(i>=0 && i=0 && inumberOfFunctions(); i++) { - Function * f = m_functionStore->functionAtIndex(i); + for (int i=0; inumberOfDefinedFunctions(); i++) { + Function * f = m_functionStore->definedFunctionAtIndex(i); if (f->isActive()) { float y = f->evaluateAtAbscissa(x, m_evaluateContext); KDCoordinate py = floatToPixel(Axis::Vertical, y); diff --git a/apps/graph/list/function_expression_view.cpp b/apps/graph/list/function_expression_view.cpp index cc96889a7..4f780af21 100644 --- a/apps/graph/list/function_expression_view.cpp +++ b/apps/graph/list/function_expression_view.cpp @@ -9,6 +9,9 @@ FunctionExpressionView::FunctionExpressionView() : void FunctionExpressionView::drawRect(KDContext * ctx, KDRect rect) const { EvenOddCell::drawRect(ctx, rect); + if (m_function->layout() == nullptr) { + return; + } // Select the background color according to the even line and the cursor selection KDColor background = backgroundColor(); // Select text color according to the state of the function diff --git a/apps/graph/list/function_name_view.cpp b/apps/graph/list/function_name_view.cpp index 65509fb92..b59d4768e 100644 --- a/apps/graph/list/function_name_view.cpp +++ b/apps/graph/list/function_name_view.cpp @@ -28,9 +28,13 @@ void FunctionNameView::drawRect(KDContext * ctx, KDRect rect) const { KDColor background = backgroundColor(); // Position the name of the function const char * functionName = m_function->name(); - KDCoordinate baseline = m_function->layout()->baseline(); KDSize textSize = KDText::stringSize(functionName); - KDSize expressionSize = m_function->layout()->size(); + KDCoordinate baseline = textSize.height(); + KDSize expressionSize = textSize; + if (m_function->layout()) { + baseline = m_function->layout()->baseline(); + expressionSize = m_function->layout()->size(); + } KDPoint origin(0.5f*(k_colorIndicatorThickness + m_frame.width() - 4*textSize.width()), baseline-textSize.height()+0.5f*(m_frame.height() - expressionSize.height())); ctx->drawString(functionName, origin, functionNameColor, background); diff --git a/apps/graph/list/list_controller.cpp b/apps/graph/list/list_controller.cpp index 99288b494..1bb9acf6e 100644 --- a/apps/graph/list/list_controller.cpp +++ b/apps/graph/list/list_controller.cpp @@ -25,7 +25,7 @@ Responder * ListController::tabController() const{ } int ListController::numberOfRows() { - return m_functionStore->numberOfFunctions(); + return 1 + m_functionStore->numberOfFunctions(); }; int ListController::numberOfColumns() { @@ -33,7 +33,13 @@ int ListController::numberOfColumns() { }; KDCoordinate ListController::rowHeight(int j) { + if (j == numberOfRows() - 1) { + return k_emptyRowHeight; + } Function * function = m_functionStore->functionAtIndex(j); + if (function->layout() == nullptr) { + return k_emptyRowHeight; + } KDCoordinate functionSize = function->layout()->size().height(); return functionSize + k_verticalFunctionMargin; } diff --git a/apps/graph/list/list_controller.h b/apps/graph/list/list_controller.h index 068a6695d..12bca26c8 100644 --- a/apps/graph/list/list_controller.h +++ b/apps/graph/list/list_controller.h @@ -38,6 +38,7 @@ public: private: static constexpr KDCoordinate k_verticalFunctionMargin = 50-12; static constexpr KDCoordinate k_functionNameWidth = 65; + static constexpr KDCoordinate k_emptyRowHeight = 50; Responder * tabController() const; constexpr static int k_maxNumberOfRows = 6; // !!! CAUTION: The order here is important diff --git a/apps/graph/values/values_controller.cpp b/apps/graph/values/values_controller.cpp index ce4215d44..a9b48a753 100644 --- a/apps/graph/values/values_controller.cpp +++ b/apps/graph/values/values_controller.cpp @@ -99,9 +99,9 @@ int ValuesController::numberOfRows() { int ValuesController::numberOfColumns() { int result = 1; - for (int i = 0; i < m_functionStore->numberOfFunctions(); i++) { - if (m_functionStore->functionAtIndex(i)->isActive()) { - result += 1 + m_functionStore->functionAtIndex(i)->displayDerivative(); + for (int i = 0; i < m_functionStore->numberOfDefinedFunctions(); i++) { + if (m_functionStore->definedFunctionAtIndex(i)->isActive()) { + result += 1 + m_functionStore->definedFunctionAtIndex(i)->displayDerivative(); } } return result; @@ -426,15 +426,15 @@ void ValuesController::willDisplayCellAtLocation(View * cell, int i, int j) { Function * ValuesController::functionAtColumn(int i) { assert(i > 0); int index = 1; - for (int k = 0; k < m_functionStore->numberOfFunctions(); k++) { - if (m_functionStore->functionAtIndex(k)->isActive()) { + for (int k = 0; k < m_functionStore->numberOfDefinedFunctions(); k++) { + if (m_functionStore->definedFunctionAtIndex(k)->isActive()) { if (i == index) { - return m_functionStore->functionAtIndex(k); + return m_functionStore->definedFunctionAtIndex(k); } index++; - if (m_functionStore->functionAtIndex(k)->displayDerivative()) { + if (m_functionStore->definedFunctionAtIndex(k)->displayDerivative()) { if (i == index) { - return m_functionStore->functionAtIndex(k); + return m_functionStore->definedFunctionAtIndex(k); } index++; } @@ -447,13 +447,13 @@ Function * ValuesController::functionAtColumn(int i) { bool ValuesController::isDerivativeColumn(int i) { assert(i >= 1); int index = 1; - for (int k = 0; k < m_functionStore->numberOfFunctions(); k++) { - if (m_functionStore->functionAtIndex(k)->isActive()) { + for (int k = 0; k < m_functionStore->numberOfDefinedFunctions(); k++) { + if (m_functionStore->definedFunctionAtIndex(k)->isActive()) { if (i == index) { return false; } index++; - if (m_functionStore->functionAtIndex(k)->displayDerivative()) { + if (m_functionStore->definedFunctionAtIndex(k)->displayDerivative()) { if (i == index) { return true; } diff --git a/poincare/src/expression.cpp b/poincare/src/expression.cpp index a7e70f4de..861c387d5 100644 --- a/poincare/src/expression.cpp +++ b/poincare/src/expression.cpp @@ -14,6 +14,9 @@ Expression::~Expression() { } Expression * Expression::parse(char const * string) { + if (string[0] == 0) { + return nullptr; + } YY_BUFFER_STATE buf = poincare_expression_yy_scan_string(string); Expression * expression = 0; poincare_expression_yyparse(&expression);