diff --git a/apps/regression/Makefile b/apps/regression/Makefile index bac4096f2..298f561f1 100644 --- a/apps/regression/Makefile +++ b/apps/regression/Makefile @@ -3,6 +3,7 @@ app_objs += $(addprefix apps/regression/,\ banner_view.o\ calculation_controller.o\ data.o\ + even_odd_double_buffer_text_cell.o\ graph_controller.o\ graph_view.o\ ) diff --git a/apps/regression/even_odd_double_buffer_text_cell.cpp b/apps/regression/even_odd_double_buffer_text_cell.cpp new file mode 100644 index 000000000..8564c1129 --- /dev/null +++ b/apps/regression/even_odd_double_buffer_text_cell.cpp @@ -0,0 +1,92 @@ +#include "even_odd_double_buffer_text_cell.h" +#include + +EvenOddDoubleBufferTextCell::EvenOddDoubleBufferTextCell(Responder * parentResponder) : + EvenOddCell(), + Responder(parentResponder), + m_firstTextSelected(true), + m_firstBufferTextView(EvenOddBufferTextCell()), + m_secondBufferTextView(EvenOddBufferTextCell()) +{ +} + +bool EvenOddDoubleBufferTextCell::firstTextSelected() { + return m_firstTextSelected; +} + +void EvenOddDoubleBufferTextCell::selectFirstText(bool selectFirstText) { + m_firstTextSelected = selectFirstText; + m_firstBufferTextView.setHighlighted(selectFirstText); + m_secondBufferTextView.setHighlighted(!selectFirstText); + reloadCell(); +} + +void EvenOddDoubleBufferTextCell::reloadCell() { + m_firstBufferTextView.reloadCell(); + m_secondBufferTextView.reloadCell(); +} + +void EvenOddDoubleBufferTextCell::setHighlighted(bool highlight) { + m_firstBufferTextView.setHighlighted(false); + m_secondBufferTextView.setHighlighted(false); + TableViewCell::setHighlighted(highlight); + if (isHighlighted()) { + if (m_firstTextSelected) { + m_firstBufferTextView.setHighlighted(true); + } else { + m_secondBufferTextView.setHighlighted(false); + } + } + reloadCell(); +} + +void EvenOddDoubleBufferTextCell::setEven(bool even) { + m_firstBufferTextView.setEven(even); + m_secondBufferTextView.setEven(even); + reloadCell(); +} + +void EvenOddDoubleBufferTextCell::setFirstText(const char * textContent) { + m_firstBufferTextView.setText(textContent); +} + +void EvenOddDoubleBufferTextCell::setSecondText(const char * textContent) { + m_secondBufferTextView.setText(textContent); +} + +void EvenOddDoubleBufferTextCell::setTextColor(KDColor textColor) { + m_firstBufferTextView.setTextColor(textColor); + m_secondBufferTextView.setTextColor(textColor); +} + +int EvenOddDoubleBufferTextCell::numberOfSubviews() const { + return 2; +} + +View * EvenOddDoubleBufferTextCell::subviewAtIndex(int index) { + assert(index == 0 || index == 1); + if (index == 0) { + return &m_firstBufferTextView; + } + return &m_secondBufferTextView; +} + +void EvenOddDoubleBufferTextCell::layoutSubviews() { + KDCoordinate width = bounds().width(); + KDCoordinate height = bounds().height(); + m_firstBufferTextView.setFrame(KDRect(0, 0, width/2, height)); + m_secondBufferTextView.setFrame(KDRect(width/2, 0, width/2, height)); +} + +bool EvenOddDoubleBufferTextCell::handleEvent(Ion::Events::Event event) { + if (m_firstTextSelected && event == Ion::Events::Right) { + selectFirstText(false); + return true; + } + if (!m_firstTextSelected && event == Ion::Events::Left) { + selectFirstText(true); + return true; + } + return false; +} + diff --git a/apps/regression/even_odd_double_buffer_text_cell.h b/apps/regression/even_odd_double_buffer_text_cell.h new file mode 100644 index 000000000..8f4b6a093 --- /dev/null +++ b/apps/regression/even_odd_double_buffer_text_cell.h @@ -0,0 +1,27 @@ +#ifndef REGRESSION_EVEN_ODD_DOUBLE_BUFFER_TEXT_CELL_H +#define REGRESSION_EVEN_ODD_DOUBLE_BUFFER_TEXT_CELL_H + +#include + +class EvenOddDoubleBufferTextCell : public EvenOddCell, public Responder{ +public: + EvenOddDoubleBufferTextCell(Responder * parentResponder = nullptr); + void reloadCell() override; + void setHighlighted(bool highlight) override; + void setEven(bool even) override; + bool firstTextSelected(); + void selectFirstText(bool selectFirstText); + void setFirstText(const char * textContent); + void setSecondText(const char * textContent); + void setTextColor(KDColor textColor); + int numberOfSubviews() const override; + View * subviewAtIndex(int index) override; + void layoutSubviews() override; + bool handleEvent(Ion::Events::Event event) override; +protected: + bool m_firstTextSelected; + EvenOddBufferTextCell m_firstBufferTextView; + EvenOddBufferTextCell m_secondBufferTextView; +}; + +#endif diff --git a/escher/include/escher/even_odd_cell.h b/escher/include/escher/even_odd_cell.h index 1b495dfa5..5de9a8bbb 100644 --- a/escher/include/escher/even_odd_cell.h +++ b/escher/include/escher/even_odd_cell.h @@ -6,7 +6,7 @@ class EvenOddCell : public TableViewCell { public: EvenOddCell(); - void setEven(bool even); + virtual void setEven(bool even); virtual KDColor backgroundColor() const; void drawRect(KDContext * ctx, KDRect rect) const override; diff --git a/escher/include/escher/table_view_cell.h b/escher/include/escher/table_view_cell.h index a78f3f948..5d11d54d4 100644 --- a/escher/include/escher/table_view_cell.h +++ b/escher/include/escher/table_view_cell.h @@ -6,7 +6,7 @@ class TableViewCell : public View { public: TableViewCell(); - void setHighlighted(bool highlight); + virtual void setHighlighted(bool highlight); bool isHighlighted() const; virtual void reloadCell(); private: diff --git a/escher/include/escher/text_menu_list_cell.h b/escher/include/escher/text_menu_list_cell.h index e68890f8b..be6a69188 100644 --- a/escher/include/escher/text_menu_list_cell.h +++ b/escher/include/escher/text_menu_list_cell.h @@ -9,7 +9,7 @@ public: TextMenuListCell(char * label = nullptr); void reloadCell() override; View * accessoryView() const override; - void setHighlighted(bool highlight); + void setHighlighted(bool highlight) override; void setAccessoryText(const char * textBody); const char * accessoryText(); void setTextColor(KDColor color) override;