[apps/shared][apps/graph][apps/sequence] Reorganise list controllers,

function title cells and function expression cells

Change-Id: Idbdae4975c8ed83a023c781dc14929b8c2053bb0
This commit is contained in:
Émilie Feral
2017-02-08 12:03:11 +01:00
parent e414f81d67
commit 0f4d7f0914
21 changed files with 306 additions and 136 deletions

View File

@@ -2,12 +2,14 @@ app_objs += $(addprefix apps/graph/,\
app.o\
function.o\
function_store.o\
function_title_cell.o\
graph/banner_view.o\
graph/curve_parameter_controller.o\
graph/goto_parameter_controller.o\
graph/graph_controller.o\
graph/graph_view.o\
graph/initialisation_parameter_controller.o\
list/function_expression_cell.o\
list/list_controller.o\
values/abscissa_parameter_controller.o\
values/derivative_parameter_controller.o\

View File

@@ -13,8 +13,8 @@ public:
bool displayDerivative();
void setDisplayDerivative(bool display);
float approximateDerivative(float x, Poincare::Context * context, Poincare::Expression::AngleUnit angleUnit) const;
private:
char symbol() const override;
private:
bool m_displayDerivative;
};

View File

@@ -0,0 +1,50 @@
#include "function_title_cell.h"
#include <assert.h>
using namespace Shared;
namespace Graph {
FunctionTitleCell::FunctionTitleCell(Orientation orientation, KDText::FontSize size) :
Shared::FunctionTitleCell(orientation, size),
m_bufferTextView(size, 0.5f, 0.5f)
{
}
void FunctionTitleCell::setHighlighted(bool highlight) {
EvenOddCell::setHighlighted(highlight);
m_bufferTextView.setHighlighted(highlight);
}
void FunctionTitleCell::setEven(bool even) {
EvenOddCell::setEven(even);
m_bufferTextView.setEven(even);
}
void FunctionTitleCell::setColor(KDColor color) {
Shared::FunctionTitleCell::setColor(color);
m_bufferTextView.setTextColor(color);
}
void FunctionTitleCell::setText(const char * title) {
m_bufferTextView.setText(title);
}
int FunctionTitleCell::numberOfSubviews() const {
return 1;
}
View * FunctionTitleCell::subviewAtIndex(int index) {
assert(index == 0);
return &m_bufferTextView;
}
void FunctionTitleCell::layoutSubviews() {
KDRect textFrame(0, k_colorIndicatorThickness, bounds().width(), bounds().height() - k_colorIndicatorThickness);
if (m_orientation == Orientation::VerticalIndicator){
textFrame = KDRect(k_colorIndicatorThickness, 0, bounds().width() - k_colorIndicatorThickness, bounds().height());
}
m_bufferTextView.setFrame(textFrame);
}
}

View File

@@ -0,0 +1,24 @@
#ifndef GRAPH_FUNCTION_TITLE_CELL_H
#define GRAPH_FUNCTION_TITLE_CELL_H
#include "../shared/function_title_cell.h"
namespace Graph {
class FunctionTitleCell : public Shared::FunctionTitleCell {
public:
FunctionTitleCell(Orientation orientation, KDText::FontSize size = KDText::FontSize::Large);
void setEven(bool even) override;
void setHighlighted(bool highlight) override;
void setColor(KDColor color) override;
void setText(const char * textContent);
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
void layoutSubviews() override;
private:
EvenOddBufferTextCell m_bufferTextView;
};
}
#endif

View File

@@ -1,37 +1,32 @@
#include "function_expression_cell.h"
#include <assert.h>
namespace Shared {
namespace Graph {
FunctionExpressionCell::FunctionExpressionCell() :
EvenOddCell(),
m_function(nullptr),
m_expressionView(EvenOddExpressionCell())
m_expressionView(ExpressionView())
{
}
void FunctionExpressionCell::setFunction(Function * f) {
m_function = f;
m_expressionView.setExpression(m_function->layout());
}
void FunctionExpressionCell::reloadCell() {
EvenOddCell::reloadCell();
if (m_function) {
bool active = m_function->isActive();
KDColor textColor = active ? KDColorBlack : Palette::GreyDark;
m_expressionView.setTextColor(textColor);
}
bool active = m_function->isActive();
KDColor textColor = active ? KDColorBlack : Palette::GreyDark;
m_expressionView.setTextColor(textColor);
//layoutSubviews();
}
void FunctionExpressionCell::setEven(bool even) {
EvenOddCell::setEven(even);
m_expressionView.setEven(even);
m_expressionView.setBackgroundColor(backgroundColor());
}
void FunctionExpressionCell::setHighlighted(bool highlight) {
EvenOddCell::setHighlighted(highlight);
m_expressionView.setHighlighted(highlight);
m_expressionView.setBackgroundColor(backgroundColor());
}
Function * FunctionExpressionCell::function() {
@@ -53,7 +48,6 @@ void FunctionExpressionCell::layoutSubviews() {
}
void FunctionExpressionCell::drawRect(KDContext * ctx, KDRect rect) const {
EvenOddCell::drawRect(ctx, rect);
// Color the separator
ctx->fillRect(KDRect(0, 0, k_separatorThickness, bounds().height()), Palette::GreyBright);
}

View File

@@ -1,29 +1,26 @@
#ifndef SHARED_FUNCTION_EXPRESSION_CELL_H
#define SHARED_FUNCTION_EXPRESSION_CELL_H
#ifndef GRAPH_FUNCTION_EXPRESSION_CELL_H
#define GRAPH_FUNCTION_EXPRESSION_CELL_H
#include <escher.h>
#include "function.h"
#include "../function.h"
namespace Shared {
namespace Graph {
class FunctionExpressionCell : public EvenOddCell {
public:
FunctionExpressionCell();
virtual void setFunction(Function * f);
Function * function();
void reloadCell() override;
void setEven(bool even) override;
void setHighlighted(bool highlight) override;
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
void layoutSubviews() override;
void drawRect(KDContext * ctx, KDRect rect) const override;
protected:
private:
constexpr static KDCoordinate k_separatorThickness = 1;
Function * m_function;
EvenOddExpressionCell m_expressionView;
private:
static constexpr KDCoordinate k_emptyRowHeight = 50;
ExpressionView m_expressionView;
};
}

View File

@@ -6,7 +6,7 @@ using namespace Shared;
namespace Graph {
ListController::ListController(Responder * parentResponder, Shared::FunctionStore * functionStore, HeaderViewController * header) :
ListController::ListController(Responder * parentResponder, FunctionStore * functionStore, HeaderViewController * header) :
Shared::ListController(parentResponder, functionStore, header),
m_functionTitleCells{FunctionTitleCell(FunctionTitleCell::Orientation::VerticalIndicator), FunctionTitleCell(FunctionTitleCell::Orientation::VerticalIndicator), FunctionTitleCell(FunctionTitleCell::Orientation::VerticalIndicator),
FunctionTitleCell(FunctionTitleCell::Orientation::VerticalIndicator), FunctionTitleCell(FunctionTitleCell::Orientation::VerticalIndicator)},
@@ -104,4 +104,18 @@ TableViewCell * ListController::expressionCells(int index) {
return &m_expressionCells[index];
}
void ListController::willDisplayTitleCellAtIndex(TableViewCell * cell, int j) {
FunctionTitleCell * myFunctionCell = (FunctionTitleCell *)cell;
Function * function = ((FunctionStore *)m_functionStore)->functionAtIndex(j);
char bufferName[5] = {*function->name(),'(',function->symbol(),')', 0};
myFunctionCell->setText(bufferName);
KDColor functionNameColor = function->isActive() ? function->color() : Palette::GreyDark;
myFunctionCell->setColor(functionNameColor);
}
void ListController::willDisplayExpressionCellAtIndex(TableViewCell * cell, int j) {
FunctionExpressionCell * myCell = (FunctionExpressionCell *)cell;
myCell->setFunction(((FunctionStore *)m_functionStore)->functionAtIndex(j));
}
}

View File

@@ -2,8 +2,9 @@
#define GRAPH_LIST_CONTROLLER_H
#include <escher.h>
#include "../../shared/function_title_cell.h"
#include "../../shared/function_expression_cell.h"
#include "../function_title_cell.h"
#include "function_expression_cell.h"
#include "../function_store.h"
#include "../../shared/new_function_cell.h"
#include "../../shared/list_controller.h"
#include "../../shared/list_parameter_controller.h"
@@ -12,19 +13,21 @@ namespace Graph {
class ListController : public Shared::ListController {
public:
ListController(Responder * parentResponder, Shared::FunctionStore * functionStore, HeaderViewController * header);
ListController(Responder * parentResponder, FunctionStore * functionStore, HeaderViewController * header);
const char * title() const override;
bool handleEvent(Ion::Events::Event event) override;
private:
bool handleEnter();
void editExpression(Shared::FunctionExpressionCell * functionCell, Ion::Events::Event event);
void editExpression(FunctionExpressionCell * functionCell, Ion::Events::Event event);
Shared::ListParameterController * parameterController() override;
int maxNumberOfRows() override;
TableViewCell * titleCells(int index) override;
TableViewCell * expressionCells(int index) override;
void willDisplayTitleCellAtIndex(TableViewCell * cell, int j) override;
void willDisplayExpressionCellAtIndex(TableViewCell * cell, int j) override;
constexpr static int k_maxNumberOfRows = 5;
Shared::FunctionTitleCell m_functionTitleCells[k_maxNumberOfRows];
Shared::FunctionExpressionCell m_expressionCells[k_maxNumberOfRows];
FunctionTitleCell m_functionTitleCells[k_maxNumberOfRows];
FunctionExpressionCell m_expressionCells[k_maxNumberOfRows];
Shared::ListParameterController m_parameterController;
};

View File

@@ -3,7 +3,7 @@
#include <escher.h>
#include "../function_store.h"
#include "../../shared/function_title_cell.h"
#include "../function_title_cell.h"
#include "../../shared/editable_cell_table_view_controller.h"
#include "interval.h"
#include "abscissa_parameter_controller.h"
@@ -62,7 +62,7 @@ private:
constexpr static int k_maxNumberOfCells = 50;
constexpr static int k_maxNumberOfFunctions = 5;
EvenOddPointerTextCell m_abscissaTitleCell;
Shared::FunctionTitleCell m_functionTitleCells[k_maxNumberOfFunctions];
FunctionTitleCell m_functionTitleCells[k_maxNumberOfFunctions];
EvenOddBufferTextCell m_floatCells[k_maxNumberOfCells];
char m_draftTextBuffer[EditableTextCell::k_bufferLength];
EvenOddEditableTextCell m_abscissaCells[k_maxNumberOfAbscissaCells];

View File

@@ -7,31 +7,81 @@ namespace Sequence {
ListController::ListController(Responder * parentResponder, SequenceStore * sequenceStore, HeaderViewController * header) :
Shared::ListController(parentResponder, sequenceStore, header),
m_parameterController(ListParameterController(this, sequenceStore))
m_functionTitleCells{SequenceTitleCell(&m_selectableTableView),SequenceTitleCell(&m_selectableTableView),SequenceTitleCell(&m_selectableTableView)},
m_expressionCells{SequenceExpressionCell(&m_selectableTableView),SequenceExpressionCell(&m_selectableTableView),SequenceExpressionCell(&m_selectableTableView)},
m_parameterController(ListParameterController(this, sequenceStore)),
m_typeParameterController(this)
{
m_selectableTableView.setDelegate(this);
}
const char * ListController::title() const {
return "Suites";
}
KDCoordinate ListController::rowHeight(int j) {
if (m_functionStore->numberOfFunctions() < m_functionStore->maxNumberOfFunctions() && j == numberOfRows() - 1) {
return k_emptyRowHeight;
}
Sequence * sequence = ((SequenceStore *)m_functionStore)->functionAtIndex(j);
KDCoordinate height = 0;
KDCoordinate defaultHeight = sequence->type() == Sequence::Type::Explicite ? k_emptyRowHeight : k_emptySubRowHeight;
if (sequence->layout() == nullptr) {
height += defaultHeight;
} else {
KDCoordinate size = sequence->layout()->size().height();
height += size + defaultHeight - KDText::stringSize(" ").height();
}
if ((int)sequence->type() > 0) {
if (sequence->firstInitialConditionLayout() == nullptr) {
height += defaultHeight;
} else {
KDCoordinate size = sequence->firstInitialConditionLayout()->size().height();
height += size + defaultHeight - KDText::stringSize(" ").height();
}
}
if ((int)sequence->type() > 1) {
if (sequence->secondInitialConditionLayout() == nullptr) {
height += defaultHeight;
} else {
KDCoordinate size = sequence->secondInitialConditionLayout()->size().height();
height += size + defaultHeight - KDText::stringSize(" ").height();
}
}
return height;
}
bool ListController::handleEvent(Ion::Events::Event event) {
if (Shared::ListController::handleEvent(event)) {
return true;
}
if (event == Ion::Events::OK && m_selectableTableView.selectedColumn() == 1
&& m_selectableTableView.selectedRow() == numberOfRows() - 1) {
return addFunction();
if (addFunction()){
m_selectableTableView.dataHasChanged(true);
m_typeParameterController.setSequence((Sequence *)m_functionStore->functionAtIndex(m_selectableTableView.selectedRow()));
StackViewController * stack = stackController();
stack->push(&m_typeParameterController);
return true;
}
return false;
}
return false;
}
void ListController::tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY) {
if (t->selectedRow() < numberOfRows() - 1) {
Responder * myCell = (Responder *)t->cellAtLocation(t->selectedColumn(), t->selectedRow());
app()->setFirstResponder(myCell);
if (m_functionStore->numberOfFunctions() == m_functionStore->maxNumberOfFunctions() || t->selectedRow() < numberOfRows() - 1) {
if (t->selectedColumn() == 0) {
SequenceTitleCell * myCell = (SequenceTitleCell *)t->cellAtLocation(t->selectedColumn(), t->selectedRow());
app()->setFirstResponder(myCell);
} else {
SequenceExpressionCell * myCell = (SequenceExpressionCell *)t->cellAtLocation(t->selectedColumn(), t->selectedRow());
app()->setFirstResponder(myCell);
}
} else {
app()->setFirstResponder(t);
if (app()->firstResponder() != t) {
app()->setFirstResponder(t);
}
}
}
@@ -53,4 +103,27 @@ TableViewCell * ListController::expressionCells(int index) {
return &m_expressionCells[index];
}
void ListController::willDisplayTitleCellAtIndex(TableViewCell * cell, int j) {
SequenceTitleCell * myCell = (SequenceTitleCell *)cell;
Sequence * sequence = ((SequenceStore *)m_functionStore)->functionAtIndex(j);
myCell->setNumberOfSubCells((int)sequence->type()+1);
char bufferName[5] = {*sequence->name(),'(',sequence->symbol(),')', 0};
myCell->setDefinitionText(bufferName);
if ((int)sequence->type() > 0) {
char bufferName[7] = {*sequence->name(),'(',sequence->symbol(),'+','1',')', 0};
myCell->setFirstInitialConditionText(bufferName);
}
if ((int)sequence->type() > 1) {
char bufferName[7] = {*sequence->name(),'(',sequence->symbol(),'+','2',')', 0};
myCell->setSecondInitialConditionText(bufferName);
}
KDColor functionNameColor = sequence->isActive() ? sequence->color() : Palette::GreyDark;
myCell->setColor(functionNameColor);
}
void ListController::willDisplayExpressionCellAtIndex(TableViewCell * cell, int j) {
SequenceExpressionCell * myCell = (SequenceExpressionCell *)cell;
myCell->setSequence(((SequenceStore *)m_functionStore)->functionAtIndex(j));
}
}

View File

@@ -5,6 +5,7 @@
#include "../sequence_title_cell.h"
#include "../sequence_store.h"
#include "sequence_expression_cell.h"
#include "type_parameter_controller.h"
#include "../../shared/new_function_cell.h"
#include "../../shared/list_controller.h"
#include "../../shared/list_parameter_controller.h"
@@ -15,17 +16,22 @@ class ListController : public Shared::ListController, public SelectableTableView
public:
ListController(Responder * parentResponder, SequenceStore * sequenceStore, HeaderViewController * header);
const char * title() const override;
KDCoordinate rowHeight(int j) override;
bool handleEvent(Ion::Events::Event event) override;
void tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY) override;
private:
static constexpr KDCoordinate k_emptySubRowHeight = 30;
Shared::ListParameterController * parameterController() override;
int maxNumberOfRows() override;
TableViewCell * titleCells(int index) override;
TableViewCell * expressionCells(int index) override;
void willDisplayTitleCellAtIndex(TableViewCell * cell, int j) override;
void willDisplayExpressionCellAtIndex(TableViewCell * cell, int j) override;
constexpr static int k_maxNumberOfRows = 3;
SequenceTitleCell m_functionTitleCells[k_maxNumberOfRows];
SequenceExpressionCell m_expressionCells[k_maxNumberOfRows];
Shared::ListParameterController m_parameterController;
TypeParameterController m_typeParameterController;
};
}

View File

@@ -5,11 +5,12 @@ using namespace Shared;
namespace Sequence {
SequenceExpressionCell::SequenceExpressionCell(Responder * parentResponder) :
FunctionExpressionCell(),
Responder(parentResponder),
EvenOddCell(),
m_sequence(nullptr),
m_numberOfSubCells(1),
m_selectedSubCell(0),
m_expressionView(EvenOddExpressionCell()),
m_firstInitialConditionView(EvenOddExpressionCell()),
m_secondInitialConditionView(EvenOddExpressionCell())
{
@@ -27,31 +28,26 @@ void SequenceExpressionCell::selectSubCell(int selectedSubCell) {
reloadCell();
}
void SequenceExpressionCell::setFunction(Function * f) {
FunctionExpressionCell::setFunction(f);
m_sequence = (Sequence *)f;
void SequenceExpressionCell::setSequence(Sequence * sequence) {
m_sequence = sequence;
m_numberOfSubCells = (int)m_sequence->type()+1;
bool active = m_sequence->isActive();
KDColor textColor = active ? KDColorBlack : Palette::GreyDark;
m_expressionView.setExpression(m_sequence->layout());
m_expressionView.setTextColor(textColor);
if (m_numberOfSubCells > 1) {
m_firstInitialConditionView.setExpression(m_sequence->firstInitialConditionLayout());
m_firstInitialConditionView.setTextColor(textColor);
}
if (m_numberOfSubCells > 2) {
m_secondInitialConditionView.setExpression(m_sequence->secondInitialConditionLayout());
}
}
void SequenceExpressionCell::reloadCell() {
FunctionExpressionCell::reloadCell();
m_firstInitialConditionView.setBackgroundColor(backgroundColor());
m_secondInitialConditionView.setBackgroundColor(backgroundColor());
if (m_numberOfSubCells > 1 && m_sequence) {
bool active = m_sequence->isActive();
KDColor textColor = active ? KDColorBlack : Palette::GreyDark;
m_firstInitialConditionView.setTextColor(textColor);
m_secondInitialConditionView.setTextColor(textColor);
}
layoutSubviews();
}
void SequenceExpressionCell::setHighlighted(bool highlight) {
TableViewCell::setHighlighted(highlight);
m_expressionView.setHighlighted(false);
m_firstInitialConditionView.setHighlighted(false);
m_secondInitialConditionView.setHighlighted(false);
@@ -71,6 +67,7 @@ void SequenceExpressionCell::setHighlighted(bool highlight) {
}
void SequenceExpressionCell::setEven(bool even) {
EvenOddCell::setEven(even);
m_expressionView.setEven(even);
m_firstInitialConditionView.setEven(even);
m_secondInitialConditionView.setEven(even);
@@ -92,17 +89,30 @@ View * SequenceExpressionCell::subviewAtIndex(int index) {
}
void SequenceExpressionCell::layoutSubviews() {
KDCoordinate cellHeight = bounds().height()/m_numberOfSubCells;
KDCoordinate cellHeight = (bounds().height()-(m_numberOfSubCells-1)*k_separatorThickness)/m_numberOfSubCells;
KDRect expressionFrame(k_separatorThickness, 0, bounds().width() - k_separatorThickness, cellHeight);
m_expressionView.setFrame(expressionFrame);
expressionFrame = KDRect(k_separatorThickness, cellHeight, bounds().width() - k_separatorThickness, cellHeight);
expressionFrame = KDRect(k_separatorThickness, cellHeight+k_separatorThickness, bounds().width() - k_separatorThickness, cellHeight);
m_firstInitialConditionView.setFrame(expressionFrame);
expressionFrame = KDRect(k_separatorThickness, 2*cellHeight, bounds().width() - k_separatorThickness, cellHeight);
expressionFrame = KDRect(k_separatorThickness, 2*cellHeight+2*k_separatorThickness, bounds().width() - k_separatorThickness, cellHeight);
m_secondInitialConditionView.setFrame(expressionFrame);
}
void SequenceExpressionCell::drawRect(KDContext * ctx, KDRect rect) const {
KDColor separatorColor = m_even ? Palette::WallScreen : KDColorWhite;
// Color the separators
ctx->fillRect(KDRect(0, 0, k_separatorThickness, bounds().height()), Palette::GreyBright);
KDCoordinate cellHeight = (bounds().height()-(m_numberOfSubCells-1)*k_separatorThickness)/m_numberOfSubCells;
if (m_numberOfSubCells > 1) {
ctx->fillRect(KDRect(k_separatorThickness, cellHeight, bounds().width() - k_separatorThickness, k_separatorThickness), separatorColor);
}
if (m_numberOfSubCells > 2) {
ctx->fillRect(KDRect(k_separatorThickness, 2*cellHeight+k_separatorThickness, bounds().width() - k_separatorThickness, k_separatorThickness), separatorColor);
}
}
bool SequenceExpressionCell::handleEvent(Ion::Events::Event event) {
if (m_selectedSubCell < 2 && event == Ion::Events::Down) {
if (m_selectedSubCell < m_numberOfSubCells - 1 && event == Ion::Events::Down) {
selectSubCell(m_selectedSubCell+1);
return true;
}

View File

@@ -2,27 +2,29 @@
#define SEQUENCE_SEQUENCE_EXPRESSION_CELL_H
#include "../sequence.h"
#include "../../shared/function_expression_cell.h"
#include <escher.h>
namespace Sequence {
class SequenceExpressionCell : public Shared::FunctionExpressionCell, public Responder {
class SequenceExpressionCell : public Responder, public EvenOddCell {
public:
SequenceExpressionCell(Responder * parentResponder = nullptr);
void setFunction(Shared::Function * f) override;
SequenceExpressionCell(Responder * parentResponder);
void setSequence(Sequence * sequence);
int selectedSubCell();
void selectSubCell(int index);
void reloadCell() override;
void setHighlighted(bool highlight) override;
void setEven(bool even) override;
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
void layoutSubviews() override;
void drawRect(KDContext * ctx, KDRect rect) const override;
bool handleEvent(Ion::Events::Event event) override;
private:
constexpr static KDCoordinate k_separatorThickness = 1;
Sequence * m_sequence;
int m_numberOfSubCells;
int m_selectedSubCell;
EvenOddExpressionCell m_expressionView;
EvenOddExpressionCell m_firstInitialConditionView;
EvenOddExpressionCell m_secondInitialConditionView;
};

View File

@@ -22,8 +22,8 @@ public:
Poincare::ExpressionLayout * secondInitialConditionLayout();
void setFirstInitialConditionContent(const char * c);
void setSecondInitialConditionContent(const char * c);
private:
char symbol() const override;
private:
Type m_type;
char m_firstInitialConditionText[Shared::Function::k_bodyLength];
char m_secondInitialConditionText[Shared::Function::k_bodyLength];

View File

@@ -9,31 +9,57 @@ SequenceTitleCell::SequenceTitleCell(Responder * parentResponder) :
Responder(parentResponder),
m_numberOfSubCells(1),
m_selectedSubCell(0),
m_definitionView(KDText::FontSize::Large, 0.5f, 0.5f),
m_firstInitialConditionView(KDText::FontSize::Large, 0.5f, 0.5f),
m_secondInitialConditionView(KDText::FontSize::Large, 0.5f, 0.5f)
{
}
void SequenceTitleCell::setDefinitionText(const char * title) {
m_definitionView.setText(title);
}
void SequenceTitleCell::setFirstInitialConditionText(const char * textContent) {
m_firstInitialConditionView.setText(textContent);
}
void SequenceTitleCell::setSecondInitialConditionText(const char * textContent) {
m_secondInitialConditionView.setText(textContent);
}
void SequenceTitleCell::setColor(KDColor color) {
FunctionTitleCell::setColor(color);
m_definitionView.setTextColor(color);
m_firstInitialConditionView.setTextColor(color);
m_secondInitialConditionView.setTextColor(color);
}
void SequenceTitleCell::setNumberOfSubCells(int numberOfSubcells) {
m_numberOfSubCells = numberOfSubcells;
layoutSubviews();
}
int SequenceTitleCell::selectedSubCell() {
return m_selectedSubCell;
}
void SequenceTitleCell::selectSubCell(int selectedSubCell) {
m_selectedSubCell = selectedSubCell;
m_bufferTextView.setHighlighted(selectedSubCell == 0);
m_definitionView.setHighlighted(selectedSubCell == 0);
m_firstInitialConditionView.setHighlighted(selectedSubCell == 1);
m_secondInitialConditionView.setHighlighted(selectedSubCell == 2);
reloadCell();
}
void SequenceTitleCell::setHighlighted(bool highlight) {
m_bufferTextView.setHighlighted(false);
TableViewCell::setHighlighted(highlight);
m_definitionView.setHighlighted(false);
m_firstInitialConditionView.setHighlighted(false);
m_secondInitialConditionView.setHighlighted(false);
TableViewCell::setHighlighted(highlight);
if (isHighlighted()) {
if (m_selectedSubCell == 0) {
m_bufferTextView.setHighlighted(true);
m_definitionView.setHighlighted(true);
}
if (m_selectedSubCell == 1) {
m_firstInitialConditionView.setHighlighted(true);
@@ -46,7 +72,8 @@ void SequenceTitleCell::setHighlighted(bool highlight) {
}
void SequenceTitleCell::setEven(bool even) {
m_bufferTextView.setEven(even);
EvenOddCell::setEven(even);
m_definitionView.setEven(even);
m_firstInitialConditionView.setEven(even);
m_secondInitialConditionView.setEven(even);
reloadCell();
@@ -58,7 +85,7 @@ int SequenceTitleCell::numberOfSubviews() const {
View * SequenceTitleCell::subviewAtIndex(int index) {
if (index == 0) {
return &m_bufferTextView;
return &m_definitionView;
}
if (index == 1) {
return &m_firstInitialConditionView;
@@ -67,17 +94,28 @@ View * SequenceTitleCell::subviewAtIndex(int index) {
}
void SequenceTitleCell::layoutSubviews() {
KDCoordinate cellHeight = bounds().height()/m_numberOfSubCells;
KDCoordinate cellHeight = (bounds().height()-(m_numberOfSubCells-1)*k_separatorThickness)/m_numberOfSubCells;
KDRect expressionFrame(k_colorIndicatorThickness, 0, bounds().width() - k_separatorThickness, cellHeight);
m_bufferTextView.setFrame(expressionFrame);
expressionFrame = KDRect(k_colorIndicatorThickness, cellHeight, bounds().width() - k_separatorThickness, cellHeight);
m_definitionView.setFrame(expressionFrame);
expressionFrame = KDRect(k_colorIndicatorThickness, cellHeight+k_separatorThickness, bounds().width() - k_separatorThickness, cellHeight);
m_firstInitialConditionView.setFrame(expressionFrame);
expressionFrame = KDRect(k_colorIndicatorThickness, 2*cellHeight, bounds().width() - k_separatorThickness, cellHeight);
expressionFrame = KDRect(k_colorIndicatorThickness, 2*cellHeight+2*k_separatorThickness, bounds().width() - k_separatorThickness, cellHeight);
m_secondInitialConditionView.setFrame(expressionFrame);
}
void SequenceTitleCell::drawRect(KDContext * ctx, KDRect rect) const {
KDColor separatorColor = m_even ? Palette::WallScreen : KDColorWhite;
KDCoordinate cellHeight = (bounds().height()-(m_numberOfSubCells-1)*k_separatorThickness)/m_numberOfSubCells;
if (m_numberOfSubCells > 1) {
ctx->fillRect(KDRect(k_separatorThickness, cellHeight, bounds().width() - k_separatorThickness, k_separatorThickness), separatorColor);
}
if (m_numberOfSubCells > 2) {
ctx->fillRect(KDRect(k_separatorThickness, 2*cellHeight+k_separatorThickness, bounds().width() - k_separatorThickness, k_separatorThickness), separatorColor);
}
}
bool SequenceTitleCell::handleEvent(Ion::Events::Event event) {
if (m_selectedSubCell < 2 && event == Ion::Events::Down) {
if (m_selectedSubCell < m_numberOfSubCells-1 && event == Ion::Events::Down) {
selectSubCell(m_selectedSubCell+1);
return true;
}

View File

@@ -8,8 +8,11 @@ namespace Sequence {
class SequenceTitleCell : public Shared::FunctionTitleCell, public Responder {
public:
SequenceTitleCell(Responder * parentResponder = nullptr);
void setDefinitionText(const char * textContent);
void setFirstInitialConditionText(const char * textContent);
void setSecondInitialConditionText(const char * textContent);
void setColor(KDColor color) override;
void setNumberOfSubCells(int numberOfSubcells);
int selectedSubCell();
void selectSubCell(int index);
void setHighlighted(bool highlight) override;
@@ -17,12 +20,13 @@ public:
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
void layoutSubviews() override;
void drawRect(KDContext * ctx, KDRect rect) const override;
bool handleEvent(Ion::Events::Event event) override;
private:
static constexpr KDCoordinate k_emptyRowHeight = 50;
constexpr static KDCoordinate k_separatorThickness = 1;
int m_numberOfSubCells;
int m_selectedSubCell;
EvenOddBufferTextCell m_definitionView;
EvenOddBufferTextCell m_firstInitialConditionView;
EvenOddBufferTextCell m_secondInitialConditionView;
};

View File

@@ -9,7 +9,6 @@ app_objs += $(addprefix apps/shared/,\
float_pair_store.o\
float_parameter_controller.o\
function.o\
function_expression_cell.o\
function_store.o\
function_title_cell.o\
interactive_curve_view_controller.o\

View File

@@ -5,49 +5,16 @@ namespace Shared {
FunctionTitleCell::FunctionTitleCell(Orientation orientation, KDText::FontSize size) :
EvenOddCell(),
m_bufferTextView(size, 0.5f, 0.5f),
m_orientation(orientation)
{
}
void FunctionTitleCell::setHighlighted(bool highlight) {
EvenOddCell::setHighlighted(highlight);
m_bufferTextView.setHighlighted(highlight);
}
void FunctionTitleCell::setEven(bool even) {
EvenOddCell::setEven(even);
m_bufferTextView.setEven(even);
}
void FunctionTitleCell::setText(const char * title) {
m_bufferTextView.setText(title);
}
void FunctionTitleCell::setColor(KDColor color) {
m_functionColor = color;
m_bufferTextView.setTextColor(color);
}
int FunctionTitleCell::numberOfSubviews() const {
return 1;
}
View * FunctionTitleCell::subviewAtIndex(int index) {
assert(index == 0);
return &m_bufferTextView;
}
void FunctionTitleCell::layoutSubviews() {
KDRect textFrame(0, k_colorIndicatorThickness, bounds().width(), bounds().height() - k_colorIndicatorThickness);
if (m_orientation == Orientation::VerticalIndicator){
textFrame = KDRect(k_colorIndicatorThickness, 0, bounds().width() - k_colorIndicatorThickness, bounds().height());
}
m_bufferTextView.setFrame(textFrame);
reloadCell();
}
void FunctionTitleCell::drawRect(KDContext * ctx, KDRect rect) const {
EvenOddCell::drawRect(ctx, rect);
if (m_orientation == Orientation::VerticalIndicator){
ctx->fillRect(KDRect(0, 0, k_colorIndicatorThickness, bounds().height()), m_functionColor);
} else {

View File

@@ -12,20 +12,13 @@ public:
VerticalIndicator
};
FunctionTitleCell(Orientation orientation, KDText::FontSize size = KDText::FontSize::Large);
void setColor(KDColor color);
void setText(const char * textContent);
virtual void setColor(KDColor color);
void drawRect(KDContext * ctx, KDRect rect) const override;
void setEven(bool even) override;
void setHighlighted(bool highlight) override;
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
void layoutSubviews() override;
protected:
constexpr static KDCoordinate k_colorIndicatorThickness = 2;
EvenOddBufferTextCell m_bufferTextView;
Orientation m_orientation;
private:
KDColor m_functionColor;
Orientation m_orientation;
};
}

View File

@@ -1,6 +1,4 @@
#include "list_controller.h"
#include "function_title_cell.h"
#include "function_expression_cell.h"
#include <assert.h>
namespace Shared {
@@ -131,15 +129,9 @@ int ListController::reusableCellCount(int type) {
void ListController::willDisplayCellAtLocation(TableViewCell * cell, int i, int j) {
if (j < numberOfRows() - 1 || m_functionStore->numberOfFunctions() == m_functionStore->maxNumberOfFunctions()) {
if (i == 0) {
FunctionTitleCell * myFunctionCell = (FunctionTitleCell *)cell;
Function * function = m_functionStore->functionAtIndex(j);
char bufferName[5] = {*function->name(),'(','x',')', 0};
myFunctionCell->setText(bufferName);
KDColor functionNameColor = function->isActive() ? function->color() : Palette::GreyDark;
myFunctionCell->setColor(functionNameColor);
willDisplayTitleCellAtIndex(cell, j);
} else {
FunctionExpressionCell * myCell = (FunctionExpressionCell *)cell;
myCell->setFunction(m_functionStore->functionAtIndex(j));
willDisplayExpressionCellAtIndex(cell, j);
}
}
EvenOddCell * myCell = (EvenOddCell *)cell;
@@ -185,12 +177,12 @@ bool ListController::handleEvent(Ion::Events::Event event) {
return false;
}
Responder * ListController::tabController() const{
return (parentResponder()->parentResponder()->parentResponder());
}
StackViewController * ListController::stackController() const{
return (StackViewController *)(parentResponder()->parentResponder());
}
Responder * ListController::tabController() const{
return (parentResponder()->parentResponder()->parentResponder());
}
}

View File

@@ -14,7 +14,7 @@ public:
View * view() override;
int numberOfRows() override;
int numberOfColumns() override;
KDCoordinate rowHeight(int j) override;
virtual KDCoordinate rowHeight(int j) override;
KDCoordinate columnWidth(int i) override;
KDCoordinate cumulatedWidthFromIndex(int i) override;
KDCoordinate cumulatedHeightFromIndex(int j) override;
@@ -27,19 +27,21 @@ public:
void didBecomeFirstResponder() override;
bool handleEvent(Ion::Events::Event event) override;
protected:
static constexpr KDCoordinate k_emptyRowHeight = 50;
bool addFunction();
void configureFunction(Function * function);
StackViewController * stackController() const;
SelectableTableView m_selectableTableView;
FunctionStore * m_functionStore;
private:
static constexpr KDCoordinate k_functionNameWidth = 65;
static constexpr KDCoordinate k_emptyRowHeight = 50;
Responder * tabController() const;
StackViewController * stackController() const;
virtual ListParameterController * parameterController() = 0;
virtual int maxNumberOfRows() = 0;
virtual TableViewCell * titleCells(int index) = 0;
virtual TableViewCell * expressionCells(int index) = 0;
virtual void willDisplayTitleCellAtIndex(TableViewCell * cell, int j) = 0;
virtual void willDisplayExpressionCellAtIndex(TableViewCell * cell, int j) = 0;
EvenOddCell m_emptyCell;
NewFunctionCell m_addNewFunction;
};