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)) { }