From 460e692309f5f60cd3893b188f2234c63ac3adc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 7 Feb 2017 12:01:17 +0100 Subject: [PATCH 1/4] [apps/sequence] Improve sequence model Change-Id: I1369646291c4da852777f07c4730c640c3df76ac --- apps/sequence/sequence.cpp | 85 ++++++++++++++++++++++++++ apps/sequence/sequence.h | 23 ++++++- apps/shared/function.h | 2 +- apps/shared/function_expression_cell.h | 2 +- 4 files changed, 109 insertions(+), 3 deletions(-) diff --git a/apps/sequence/sequence.cpp b/apps/sequence/sequence.cpp index aaf1d2810..b3626cf39 100644 --- a/apps/sequence/sequence.cpp +++ b/apps/sequence/sequence.cpp @@ -1,7 +1,92 @@ #include "sequence.h" +#include + +using namespace Shared; namespace Sequence { +Sequence::Sequence(const char * text, KDColor color) : + Function(text, color), + m_type(Type::Explicite), + m_firstInitialConditionText(""), + m_secondInitialConditionText(""), + m_firstInitialConditionExpression(nullptr), + m_secondInitialConditionExpression(nullptr), + m_firstInitialConditionLayout(nullptr), + m_secondInitialConditionLayout(nullptr) +{ +} + +Sequence::~Sequence() { + ((Function *)this)->Shared::Function::~Function(); + if (m_firstInitialConditionLayout != nullptr) { + delete m_firstInitialConditionLayout; + } + if (m_secondInitialConditionLayout != nullptr) { + delete m_secondInitialConditionLayout; + } + if (m_firstInitialConditionExpression != nullptr) { + delete m_firstInitialConditionExpression; + } + if (m_secondInitialConditionExpression != nullptr) { + delete m_secondInitialConditionExpression; + } +} + +Sequence::Type Sequence::type() { + return m_type; +} + +void Sequence::setType(Type type) { + m_type = type; +} + +Poincare::Expression * Sequence::firstInitialConditionExpression() { + return m_firstInitialConditionExpression; +} + +Poincare::Expression * Sequence::secondInitialConditionExpression() { + return m_secondInitialConditionExpression; +} + +Poincare::ExpressionLayout * Sequence::firstInitialConditionLayout() { + return m_firstInitialConditionLayout; +} + +Poincare::ExpressionLayout * Sequence::secondInitialConditionLayout() { + return m_secondInitialConditionLayout; +} + +void Sequence::setFirstInitialConditionContent(const char * c) { + strlcpy(m_firstInitialConditionText, c, sizeof(m_firstInitialConditionText)); + if (m_firstInitialConditionExpression != nullptr) { + delete m_firstInitialConditionExpression; + } + m_firstInitialConditionExpression = Poincare::Expression::parse(m_firstInitialConditionText); + if (m_firstInitialConditionLayout != nullptr) { + delete m_firstInitialConditionLayout; + } + m_firstInitialConditionLayout = nullptr; + if (m_firstInitialConditionExpression) { + m_firstInitialConditionLayout = expression()->createLayout(); + } +} + +void Sequence::setSecondInitialConditionContent(const char * c) { + strlcpy(m_secondInitialConditionText, c, sizeof(m_secondInitialConditionText)); + if (m_secondInitialConditionExpression != nullptr) { + delete m_secondInitialConditionExpression; + } + m_secondInitialConditionExpression = Poincare::Expression::parse(m_secondInitialConditionText); + if (m_secondInitialConditionLayout != nullptr) { + delete m_secondInitialConditionLayout; + } + m_secondInitialConditionLayout = nullptr; + if (m_secondInitialConditionExpression) { + m_secondInitialConditionLayout = expression()->createLayout(); + } +} + char Sequence::symbol() const { return 'n'; } diff --git a/apps/sequence/sequence.h b/apps/sequence/sequence.h index a455f26ef..1a5e6df54 100644 --- a/apps/sequence/sequence.h +++ b/apps/sequence/sequence.h @@ -7,9 +7,30 @@ namespace Sequence { class Sequence : public Shared::Function { public: - using Shared::Function::Function; + enum class Type { + Explicite = 0, + SingleRecurrence = 1, + DoubleRecurrence = 2 + }; + Sequence(const char * text = nullptr, KDColor color = KDColorBlack); + ~Sequence(); + Type type(); + void setType(Type type); + Poincare::Expression * firstInitialConditionExpression(); + Poincare::Expression * secondInitialConditionExpression(); + Poincare::ExpressionLayout * firstInitialConditionLayout(); + Poincare::ExpressionLayout * secondInitialConditionLayout(); + void setFirstInitialConditionContent(const char * c); + void setSecondInitialConditionContent(const char * c); private: char symbol() const override; + Type m_type; + char m_firstInitialConditionText[Shared::Function::k_bodyLength]; + char m_secondInitialConditionText[Shared::Function::k_bodyLength]; + Poincare::Expression * m_firstInitialConditionExpression; + Poincare::Expression * m_secondInitialConditionExpression; + Poincare::ExpressionLayout * m_firstInitialConditionLayout; + Poincare::ExpressionLayout * m_secondInitialConditionLayout; }; } diff --git a/apps/shared/function.h b/apps/shared/function.h index 47afdb182..d55a0a72b 100644 --- a/apps/shared/function.h +++ b/apps/shared/function.h @@ -21,10 +21,10 @@ public: void setColor(KDColor m_color); float evaluateAtAbscissa(float x, Poincare::Context * context, Poincare::Expression::AngleUnit angleUnit) const; protected: + constexpr static int k_bodyLength = 255; Poincare::Expression * m_expression; private: virtual char symbol() const = 0; - constexpr static int k_bodyLength = 255; char m_text[k_bodyLength]; const char * m_name; KDColor m_color; diff --git a/apps/shared/function_expression_cell.h b/apps/shared/function_expression_cell.h index 691d521dd..7252e07fc 100644 --- a/apps/shared/function_expression_cell.h +++ b/apps/shared/function_expression_cell.h @@ -9,7 +9,7 @@ namespace Shared { class FunctionExpressionCell : public EvenOddCell { public: FunctionExpressionCell(); - void setFunction(Function * f); + virtual void setFunction(Function * f); Function * function(); void reloadCell() override; int numberOfSubviews() const override; From 7b9dbb88a5a7a24485a93afd2110ff906bfba02b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 7 Feb 2017 14:30:04 +0100 Subject: [PATCH 2/4] [apps/sequence/list] Create a class sequence expression cell inheriting from function expression cell Change-Id: Icaec669c684ebbaa353f6801ca2f976e5fb76a9a --- apps/sequence/Makefile | 1 + .../list/sequence_expression_cell.cpp | 116 ++++++++++++++++++ apps/sequence/list/sequence_expression_cell.h | 32 +++++ apps/shared/function_expression_cell.cpp | 13 +- apps/shared/function_expression_cell.h | 9 +- 5 files changed, 166 insertions(+), 5 deletions(-) create mode 100644 apps/sequence/list/sequence_expression_cell.cpp create mode 100644 apps/sequence/list/sequence_expression_cell.h diff --git a/apps/sequence/Makefile b/apps/sequence/Makefile index 32f219641..879b005eb 100644 --- a/apps/sequence/Makefile +++ b/apps/sequence/Makefile @@ -1,5 +1,6 @@ app_objs += $(addprefix apps/sequence/,\ app.o\ + list/sequence_expression_cell.o\ values/values_controller.o\ sequence.o\ sequence_store.o\ diff --git a/apps/sequence/list/sequence_expression_cell.cpp b/apps/sequence/list/sequence_expression_cell.cpp new file mode 100644 index 000000000..2c3a36e0e --- /dev/null +++ b/apps/sequence/list/sequence_expression_cell.cpp @@ -0,0 +1,116 @@ +#include "sequence_expression_cell.h" + +using namespace Shared; + +namespace Sequence { + +SequenceExpressionCell::SequenceExpressionCell(Responder * parentResponder) : + FunctionExpressionCell(), + Responder(parentResponder), + m_sequence(nullptr), + m_numberOfSubCells(1), + m_selectedSubCell(0), + m_firstInitialConditionView(EvenOddExpressionCell()), + m_secondInitialConditionView(EvenOddExpressionCell()) +{ +} + +int SequenceExpressionCell::selectedSubCell() { + return m_selectedSubCell; +} + +void SequenceExpressionCell::selectSubCell(int selectedSubCell) { + m_selectedSubCell = selectedSubCell; + m_expressionView.setHighlighted(selectedSubCell == 0); + m_firstInitialConditionView.setHighlighted(selectedSubCell == 1); + m_secondInitialConditionView.setHighlighted(selectedSubCell == 2); + reloadCell(); +} + +void SequenceExpressionCell::setFunction(Function * f) { + FunctionExpressionCell::setFunction(f); + m_sequence = (Sequence *)f; + m_numberOfSubCells = (int)m_sequence->type()+1; + if (m_numberOfSubCells > 1) { + m_firstInitialConditionView.setExpression(m_sequence->firstInitialConditionLayout()); + } + 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); + } +} + +void SequenceExpressionCell::setHighlighted(bool highlight) { + m_expressionView.setHighlighted(false); + m_firstInitialConditionView.setHighlighted(false); + m_secondInitialConditionView.setHighlighted(false); + TableViewCell::setHighlighted(highlight); + if (isHighlighted()) { + if (m_selectedSubCell == 0) { + m_expressionView.setHighlighted(true); + } + if (m_selectedSubCell == 1) { + m_firstInitialConditionView.setHighlighted(true); + } + if (m_selectedSubCell == 2) { + m_secondInitialConditionView.setHighlighted(true); + } + } + reloadCell(); +} + +void SequenceExpressionCell::setEven(bool even) { + m_expressionView.setEven(even); + m_firstInitialConditionView.setEven(even); + m_secondInitialConditionView.setEven(even); + reloadCell(); +} + +int SequenceExpressionCell::numberOfSubviews() const { + return m_numberOfSubCells; +} + +View * SequenceExpressionCell::subviewAtIndex(int index) { + if (index == 0) { + return &m_expressionView; + } + if (index == 1) { + return &m_firstInitialConditionView; + } + return &m_secondInitialConditionView; +} + +void SequenceExpressionCell::layoutSubviews() { + KDCoordinate cellHeight = bounds().height()/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); + m_firstInitialConditionView.setFrame(expressionFrame); + expressionFrame = KDRect(k_separatorThickness, 2*cellHeight, bounds().width() - k_separatorThickness, cellHeight); + m_secondInitialConditionView.setFrame(expressionFrame); +} + +bool SequenceExpressionCell::handleEvent(Ion::Events::Event event) { + if (m_selectedSubCell < 2 && event == Ion::Events::Down) { + selectSubCell(m_selectedSubCell+1); + return true; + } + if (m_selectedSubCell > 0 && event == Ion::Events::Up) { + selectSubCell(m_selectedSubCell-1); + return true; + } + return false; +} + +} diff --git a/apps/sequence/list/sequence_expression_cell.h b/apps/sequence/list/sequence_expression_cell.h new file mode 100644 index 000000000..c7cd4ea68 --- /dev/null +++ b/apps/sequence/list/sequence_expression_cell.h @@ -0,0 +1,32 @@ +#ifndef SEQUENCE_SEQUENCE_EXPRESSION_CELL_H +#define SEQUENCE_SEQUENCE_EXPRESSION_CELL_H + +#include "../sequence.h" +#include "../../shared/function_expression_cell.h" + +namespace Sequence { + +class SequenceExpressionCell : public Shared::FunctionExpressionCell, public Responder { +public: + SequenceExpressionCell(Responder * parentResponder = nullptr); + void setFunction(Shared::Function * f) override; + 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; + bool handleEvent(Ion::Events::Event event) override; +private: + Sequence * m_sequence; + int m_numberOfSubCells; + int m_selectedSubCell; + EvenOddExpressionCell m_firstInitialConditionView; + EvenOddExpressionCell m_secondInitialConditionView; +}; + +} + +#endif diff --git a/apps/shared/function_expression_cell.cpp b/apps/shared/function_expression_cell.cpp index abbe9795a..3751ea805 100644 --- a/apps/shared/function_expression_cell.cpp +++ b/apps/shared/function_expression_cell.cpp @@ -6,7 +6,7 @@ namespace Shared { FunctionExpressionCell::FunctionExpressionCell() : EvenOddCell(), m_function(nullptr), - m_expressionView(ExpressionView()) + m_expressionView(EvenOddExpressionCell()) { } @@ -17,7 +17,6 @@ void FunctionExpressionCell::setFunction(Function * f) { void FunctionExpressionCell::reloadCell() { EvenOddCell::reloadCell(); - m_expressionView.setBackgroundColor(backgroundColor()); if (m_function) { bool active = m_function->isActive(); KDColor textColor = active ? KDColorBlack : Palette::GreyDark; @@ -25,6 +24,16 @@ void FunctionExpressionCell::reloadCell() { } } +void FunctionExpressionCell::setEven(bool even) { + EvenOddCell::setEven(even); + m_expressionView.setEven(even); +} + +void FunctionExpressionCell::setHighlighted(bool highlight) { + EvenOddCell::setHighlighted(highlight); + m_expressionView.setHighlighted(highlight); +} + Function * FunctionExpressionCell::function() { return m_function; } diff --git a/apps/shared/function_expression_cell.h b/apps/shared/function_expression_cell.h index 7252e07fc..b563a2bae 100644 --- a/apps/shared/function_expression_cell.h +++ b/apps/shared/function_expression_cell.h @@ -12,15 +12,18 @@ public: 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; -private: - static constexpr KDCoordinate k_emptyRowHeight = 50; +protected: constexpr static KDCoordinate k_separatorThickness = 1; Function * m_function; - ExpressionView m_expressionView; + EvenOddExpressionCell m_expressionView; +private: + static constexpr KDCoordinate k_emptyRowHeight = 50; }; } From f76b603c672fcdeeed3e776d7e4419734eeea682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 7 Feb 2017 14:31:33 +0100 Subject: [PATCH 3/4] [apps/sequence] Create a class sequence title cell Change-Id: I2a891e6a47ec742cedfa6780ee1a50eb3df24085 --- apps/sequence/Makefile | 1 + apps/sequence/sequence_title_cell.cpp | 91 +++++++++++++++++++ apps/sequence/sequence_title_cell.h | 32 +++++++ apps/shared/function_title_cell.cpp | 11 ++- apps/shared/function_title_cell.h | 8 +- .../escher/even_odd_buffer_text_cell.h | 2 +- escher/src/even_odd_buffer_text_cell.cpp | 4 +- 7 files changed, 140 insertions(+), 9 deletions(-) create mode 100644 apps/sequence/sequence_title_cell.cpp create mode 100644 apps/sequence/sequence_title_cell.h diff --git a/apps/sequence/Makefile b/apps/sequence/Makefile index 879b005eb..ebaeb7c53 100644 --- a/apps/sequence/Makefile +++ b/apps/sequence/Makefile @@ -4,6 +4,7 @@ app_objs += $(addprefix apps/sequence/,\ values/values_controller.o\ sequence.o\ sequence_store.o\ + sequence_title_cell.o\ ) app_images += apps/sequence/sequence_icon.png diff --git a/apps/sequence/sequence_title_cell.cpp b/apps/sequence/sequence_title_cell.cpp new file mode 100644 index 000000000..57bc4849f --- /dev/null +++ b/apps/sequence/sequence_title_cell.cpp @@ -0,0 +1,91 @@ +#include "sequence_title_cell.h" + +using namespace Shared; + +namespace Sequence { + +SequenceTitleCell::SequenceTitleCell(Responder * parentResponder) : + FunctionTitleCell(FunctionTitleCell::Orientation::VerticalIndicator), + Responder(parentResponder), + m_numberOfSubCells(1), + m_selectedSubCell(0), + m_firstInitialConditionView(KDText::FontSize::Large, 0.5f, 0.5f), + m_secondInitialConditionView(KDText::FontSize::Large, 0.5f, 0.5f) +{ +} + +int SequenceTitleCell::selectedSubCell() { + return m_selectedSubCell; +} + +void SequenceTitleCell::selectSubCell(int selectedSubCell) { + m_selectedSubCell = selectedSubCell; + m_bufferTextView.setHighlighted(selectedSubCell == 0); + m_firstInitialConditionView.setHighlighted(selectedSubCell == 1); + m_secondInitialConditionView.setHighlighted(selectedSubCell == 2); + reloadCell(); +} + +void SequenceTitleCell::setHighlighted(bool highlight) { + m_bufferTextView.setHighlighted(false); + m_firstInitialConditionView.setHighlighted(false); + m_secondInitialConditionView.setHighlighted(false); + TableViewCell::setHighlighted(highlight); + if (isHighlighted()) { + if (m_selectedSubCell == 0) { + m_bufferTextView.setHighlighted(true); + } + if (m_selectedSubCell == 1) { + m_firstInitialConditionView.setHighlighted(true); + } + if (m_selectedSubCell == 2) { + m_secondInitialConditionView.setHighlighted(true); + } + } + reloadCell(); +} + +void SequenceTitleCell::setEven(bool even) { + m_bufferTextView.setEven(even); + m_firstInitialConditionView.setEven(even); + m_secondInitialConditionView.setEven(even); + reloadCell(); +} + +int SequenceTitleCell::numberOfSubviews() const { + return m_numberOfSubCells; +} + +View * SequenceTitleCell::subviewAtIndex(int index) { + if (index == 0) { + return &m_bufferTextView; + } + if (index == 1) { + return &m_firstInitialConditionView; + } + return &m_secondInitialConditionView; +} + +void SequenceTitleCell::layoutSubviews() { + KDCoordinate cellHeight = bounds().height()/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_firstInitialConditionView.setFrame(expressionFrame); + expressionFrame = KDRect(k_colorIndicatorThickness, 2*cellHeight, bounds().width() - k_separatorThickness, cellHeight); + m_secondInitialConditionView.setFrame(expressionFrame); +} + +bool SequenceTitleCell::handleEvent(Ion::Events::Event event) { + if (m_selectedSubCell < 2 && event == Ion::Events::Down) { + selectSubCell(m_selectedSubCell+1); + return true; + } + if (m_selectedSubCell > 0 && event == Ion::Events::Up) { + selectSubCell(m_selectedSubCell-1); + return true; + } + return false; +} + +} diff --git a/apps/sequence/sequence_title_cell.h b/apps/sequence/sequence_title_cell.h new file mode 100644 index 000000000..6524ed884 --- /dev/null +++ b/apps/sequence/sequence_title_cell.h @@ -0,0 +1,32 @@ +#ifndef SEQUENCE_SEQUENCE_TITLE_CELL_H +#define SEQUENCE_SEQUENCE_TITLE_CELL_H + +#include "../shared/function_title_cell.h" + +namespace Sequence { + +class SequenceTitleCell : public Shared::FunctionTitleCell, public Responder { +public: + SequenceTitleCell(Responder * parentResponder = nullptr); + void setFirstInitialConditionText(const char * textContent); + void setSecondInitialConditionText(const char * textContent); + int selectedSubCell(); + void selectSubCell(int index); + void setHighlighted(bool highlight) override; + void setEven(bool even) override; + int numberOfSubviews() const override; + View * subviewAtIndex(int index) override; + void layoutSubviews() 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_firstInitialConditionView; + EvenOddBufferTextCell m_secondInitialConditionView; +}; + +} + +#endif diff --git a/apps/shared/function_title_cell.cpp b/apps/shared/function_title_cell.cpp index 8abdd59e1..769751fde 100644 --- a/apps/shared/function_title_cell.cpp +++ b/apps/shared/function_title_cell.cpp @@ -10,9 +10,14 @@ FunctionTitleCell::FunctionTitleCell(Orientation orientation, KDText::FontSize s { } -void FunctionTitleCell::reloadCell() { - EvenOddCell::reloadCell(); - m_bufferTextView.setBackgroundColor(backgroundColor()); +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) { diff --git a/apps/shared/function_title_cell.h b/apps/shared/function_title_cell.h index 4a124144e..a27b20f2d 100644 --- a/apps/shared/function_title_cell.h +++ b/apps/shared/function_title_cell.h @@ -15,14 +15,16 @@ public: void setColor(KDColor color); void setText(const char * textContent); void drawRect(KDContext * ctx, KDRect rect) const override; - 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; - private: +protected: constexpr static KDCoordinate k_colorIndicatorThickness = 2; + EvenOddBufferTextCell m_bufferTextView; +private: KDColor m_functionColor; - BufferTextView m_bufferTextView; Orientation m_orientation; }; diff --git a/escher/include/escher/even_odd_buffer_text_cell.h b/escher/include/escher/even_odd_buffer_text_cell.h index 446359404..e6fa67f87 100644 --- a/escher/include/escher/even_odd_buffer_text_cell.h +++ b/escher/include/escher/even_odd_buffer_text_cell.h @@ -6,7 +6,7 @@ class EvenOddBufferTextCell : public EvenOddCell { public: - EvenOddBufferTextCell(KDText::FontSize size = KDText::FontSize::Small); + EvenOddBufferTextCell(KDText::FontSize size = KDText::FontSize::Small, float horizontalAlignment = 1.0f, float verticalAlignment = 0.5f); void reloadCell() override; void setText(const char * textContent); void setTextColor(KDColor textColor); diff --git a/escher/src/even_odd_buffer_text_cell.cpp b/escher/src/even_odd_buffer_text_cell.cpp index a6970c0dc..fd858c0e2 100644 --- a/escher/src/even_odd_buffer_text_cell.cpp +++ b/escher/src/even_odd_buffer_text_cell.cpp @@ -1,9 +1,9 @@ #include #include -EvenOddBufferTextCell::EvenOddBufferTextCell(KDText::FontSize size) : +EvenOddBufferTextCell::EvenOddBufferTextCell(KDText::FontSize size, float horizontalAlignment, float verticalAlignment) : EvenOddCell(), - m_bufferTextView(BufferTextView(size, 1.0f, 0.5f)) + m_bufferTextView(BufferTextView(size, horizontalAlignment, verticalAlignment)) { } From 4f16289bd772ef5791391e8dbbfb29aff8bf9bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 7 Feb 2017 14:32:20 +0100 Subject: [PATCH 4/4] [apps/sequence/list] Create a class list controller Change-Id: I95c569cccf3bd80025c9195faeda08fc69a62ea3 --- apps/sequence/Makefile | 1 + apps/sequence/list/list_controller.cpp | 56 ++++++++++++++++++++++++++ apps/sequence/list/list_controller.h | 33 +++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 apps/sequence/list/list_controller.cpp create mode 100644 apps/sequence/list/list_controller.h diff --git a/apps/sequence/Makefile b/apps/sequence/Makefile index ebaeb7c53..3e26683b2 100644 --- a/apps/sequence/Makefile +++ b/apps/sequence/Makefile @@ -1,5 +1,6 @@ app_objs += $(addprefix apps/sequence/,\ app.o\ + list/list_controller.o\ list/sequence_expression_cell.o\ values/values_controller.o\ sequence.o\ diff --git a/apps/sequence/list/list_controller.cpp b/apps/sequence/list/list_controller.cpp new file mode 100644 index 000000000..ec9ce92fc --- /dev/null +++ b/apps/sequence/list/list_controller.cpp @@ -0,0 +1,56 @@ +#include "list_controller.h" +#include + +using namespace Shared; + +namespace Sequence { + +ListController::ListController(Responder * parentResponder, SequenceStore * sequenceStore, HeaderViewController * header) : + Shared::ListController(parentResponder, sequenceStore, header), + m_parameterController(ListParameterController(this, sequenceStore)) +{ +} + +const char * ListController::title() const { + return "Suites"; +} + +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(); + } + 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); + } else { + app()->setFirstResponder(t); + } +} + +ListParameterController * ListController::parameterController() { + return &m_parameterController; +} + +int ListController::maxNumberOfRows() { + return k_maxNumberOfRows; +} + +TableViewCell * ListController::titleCells(int index) { + assert(index >= 0 && index < k_maxNumberOfRows); + return &m_functionTitleCells[index]; +} + +TableViewCell * ListController::expressionCells(int index) { + assert(index >= 0 && index < k_maxNumberOfRows); + return &m_expressionCells[index]; +} + +} diff --git a/apps/sequence/list/list_controller.h b/apps/sequence/list/list_controller.h new file mode 100644 index 000000000..690a4e4f2 --- /dev/null +++ b/apps/sequence/list/list_controller.h @@ -0,0 +1,33 @@ +#ifndef SEQUENCE_LIST_CONTROLLER_H +#define SEQUENCE_LIST_CONTROLLER_H + +#include +#include "../sequence_title_cell.h" +#include "../sequence_store.h" +#include "sequence_expression_cell.h" +#include "../../shared/new_function_cell.h" +#include "../../shared/list_controller.h" +#include "../../shared/list_parameter_controller.h" + +namespace Sequence { + +class ListController : public Shared::ListController, public SelectableTableViewDelegate { +public: + ListController(Responder * parentResponder, SequenceStore * sequenceStore, HeaderViewController * header); + const char * title() const override; + bool handleEvent(Ion::Events::Event event) override; + void tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY) override; +private: + Shared::ListParameterController * parameterController() override; + int maxNumberOfRows() override; + TableViewCell * titleCells(int index) override; + TableViewCell * expressionCells(int index) override; + constexpr static int k_maxNumberOfRows = 3; + SequenceTitleCell m_functionTitleCells[k_maxNumberOfRows]; + SequenceExpressionCell m_expressionCells[k_maxNumberOfRows]; + Shared::ListParameterController m_parameterController; +}; + +} + +#endif