[apps/graph/list] Simplify funciton expression cell to be used by

sequence

Change-Id: I12f5e15c10544294292866b395066bc675b26067
This commit is contained in:
Émilie Feral
2017-02-16 10:49:50 +01:00
parent f2512b2968
commit f605963588
4 changed files with 24 additions and 26 deletions

View File

@@ -1,20 +1,21 @@
#include "function_expression_cell.h"
#include <assert.h>
using namespace Poincare;
namespace Graph {
FunctionExpressionCell::FunctionExpressionCell() :
EvenOddCell(),
m_function(nullptr),
m_expressionView(ExpressionView())
{
}
void FunctionExpressionCell::setFunction(CartesianFunction * f) {
m_function = f;
m_expressionView.setExpression(m_function->layout());
bool active = m_function->isActive();
KDColor textColor = active ? KDColorBlack : Palette::GreyDark;
void FunctionExpressionCell::setExpression(ExpressionLayout * expressionLayout) {
m_expressionView.setExpression(expressionLayout);
}
void FunctionExpressionCell::setTextColor(KDColor textColor) {
m_expressionView.setTextColor(textColor);
}
@@ -28,10 +29,6 @@ void FunctionExpressionCell::setHighlighted(bool highlight) {
m_expressionView.setBackgroundColor(backgroundColor());
}
CartesianFunction * FunctionExpressionCell::function() {
return m_function;
}
int FunctionExpressionCell::numberOfSubviews() const {
return 1;
}

View File

@@ -2,15 +2,14 @@
#define GRAPH_FUNCTION_EXPRESSION_CELL_H
#include <escher.h>
#include "../cartesian_function.h"
namespace Graph {
class FunctionExpressionCell : public EvenOddCell {
public:
FunctionExpressionCell();
virtual void setFunction(CartesianFunction * f);
CartesianFunction * function();
void setExpression(Poincare::ExpressionLayout * expressionLayout);
void setTextColor(KDColor color);
void setEven(bool even) override;
void setHighlighted(bool highlight) override;
int numberOfSubviews() const override;
@@ -19,7 +18,6 @@ public:
void drawRect(KDContext * ctx, KDRect rect) const override;
private:
constexpr static KDCoordinate k_separatorThickness = 1;
CartesianFunction * m_function;
ExpressionView m_expressionView;
};

View File

@@ -30,8 +30,8 @@ bool ListController::handleEvent(Ion::Events::Event event) {
|| m_selectableTableView.selectedRow() == numberOfRows() - 1) {
return false;
}
FunctionExpressionCell * functionCell = (FunctionExpressionCell *)(m_selectableTableView.cellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow()));
editExpression(functionCell, event);
Shared::Function * function = m_functionStore->functionAtIndex(m_selectableTableView.selectedRow());
editExpression(function, event);
return true;
}
@@ -54,8 +54,8 @@ bool ListController::handleEnter() {
m_selectableTableView.reloadData();
return true;
}
FunctionExpressionCell * functionCell = (FunctionExpressionCell *)(m_selectableTableView.cellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow()));
editExpression(functionCell, Ion::Events::OK);
Shared::Function * function = m_functionStore->functionAtIndex(m_selectableTableView.selectedRow());
editExpression(function, Ion::Events::OK);
return true;
}
default:
@@ -65,23 +65,21 @@ bool ListController::handleEnter() {
}
}
void ListController::editExpression(FunctionExpressionCell * functionCell, Ion::Events::Event event) {
void ListController::editExpression(Function * function, Ion::Events::Event event) {
char * initialText = nullptr;
char initialTextContent[255];
if (event == Ion::Events::OK) {
strlcpy(initialTextContent, functionCell->function()->text(), sizeof(initialTextContent));
strlcpy(initialTextContent, function->text(), sizeof(initialTextContent));
initialText = initialTextContent;
}
App * myApp = (App *)app();
InputViewController * inputController = myApp->inputViewController();
inputController->edit(this, event, functionCell, initialText,
inputController->edit(this, event, function, initialText,
[](void * context, void * sender){
FunctionExpressionCell * myCell = (FunctionExpressionCell *) context;
Shared::Function * myFunction = myCell->function();
Shared::Function * myFunction = (Shared::Function *)context;
InputViewController * myInputViewController = (InputViewController *)sender;
const char * textBody = myInputViewController->textBody();
myFunction->setContent(textBody);
myCell->reloadCell();
},
[](void * context, void * sender){
});
@@ -122,7 +120,12 @@ void ListController::willDisplayTitleCellAtIndex(TableViewCell * cell, int j) {
void ListController::willDisplayExpressionCellAtIndex(TableViewCell * cell, int j) {
FunctionExpressionCell * myCell = (FunctionExpressionCell *)cell;
myCell->setFunction(((CartesianFunctionStore *)m_functionStore)->functionAtIndex(j));
Function * f = m_functionStore->functionAtIndex(j);
myCell->setExpression(f->layout());
bool active = f->isActive();
KDColor textColor = active ? KDColorBlack : Palette::GreyDark;
myCell->setTextColor(textColor);
}
}

View File

@@ -18,7 +18,7 @@ public:
bool handleEvent(Ion::Events::Event event) override;
private:
bool handleEnter();
void editExpression(FunctionExpressionCell * functionCell, Ion::Events::Event event);
void editExpression(Shared::Function * function, Ion::Events::Event event);
Shared::ListParameterController * parameterController() override;
int maxNumberOfRows() override;
TableViewCell * titleCells(int index) override;