From 2c19b09c9d0db68fd89687f3c50f46c87e421866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 26 Sep 2016 14:42:13 +0200 Subject: [PATCH] [apps/probability] Modify law controller to use table view cells instead of law cells Change-Id: I95857842332d8d7e8e3b49a4f64c8c4d6840f029 --- apps/probability/Makefile | 1 - apps/probability/law/law_cell.cpp | 52 ------------------------- apps/probability/law/law_cell.h | 25 ------------ apps/probability/law/law_controller.cpp | 23 ++++++++--- apps/probability/law/law_controller.h | 4 +- 5 files changed, 19 insertions(+), 86 deletions(-) delete mode 100644 apps/probability/law/law_cell.cpp delete mode 100644 apps/probability/law/law_cell.h diff --git a/apps/probability/Makefile b/apps/probability/Makefile index 2c5be0113..b76e2cc01 100644 --- a/apps/probability/Makefile +++ b/apps/probability/Makefile @@ -1,6 +1,5 @@ app_objs += $(addprefix apps/probability/,\ app.o\ - law/law_cell.o\ law/law_controller.o\ parameters/parameters_controller.o\ ) diff --git a/apps/probability/law/law_cell.cpp b/apps/probability/law/law_cell.cpp deleted file mode 100644 index dcc65f971..000000000 --- a/apps/probability/law/law_cell.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "law_cell.h" - -constexpr KDColor separatorColor = KDColor(0xB4B7B9); -constexpr KDColor tableBackgroundColor = KDColor(0xF0F3F5); -constexpr KDCoordinate margin = 20; -constexpr KDColor focusedCellBackgroundColor = KDColor(0xBFD3EB); -constexpr KDColor cellBackgroundColor = KDColor(0xFCFCFC); - -Probability::LawCell::LawCell() : - ChildlessView(), - Responder(nullptr), - m_focused(false), - m_even(false) -{ - m_message = "NULL"; -} - -void Probability::LawCell::drawRect(KDContext * ctx, KDRect rect) const { - KDCoordinate width = bounds().width(); - KDCoordinate height = bounds().height(); - KDColor backgroundColor = (m_focused ? focusedCellBackgroundColor : cellBackgroundColor); - KDColor textColor = (m_focused ? KDColorWhite : KDColorBlack); - - ctx->fillRect(KDRect(margin+1, 1, width-2*margin-1, height-1), backgroundColor); - ctx->fillRect(KDRect(0,0,margin,height), tableBackgroundColor); - ctx->fillRect(KDRect(margin,0,width-2*margin,1), separatorColor); - ctx->fillRect(KDRect(margin,0,1,height), separatorColor); - ctx->fillRect(KDRect(width-margin,0,1,height), separatorColor); - ctx->fillRect(KDRect(width-margin+1,0,margin, height), tableBackgroundColor); - - //KDColor background = m_even ? KDColor(0xEEEEEE) : KDColor(0x777777); - //ctx->fillRect(rect, background); - ctx->drawString(m_message, KDPoint(margin+10, 5), textColor, backgroundColor); -} - -void Probability::LawCell::setMessage(const char * message) { - m_message = message; -} - -void Probability::LawCell::didBecomeFirstResponder() { - m_focused = true; - markRectAsDirty(bounds()); -} - -void Probability::LawCell::didResignFirstResponder() { - m_focused = false; - markRectAsDirty(bounds()); -} - -void Probability::LawCell::setEven(bool even) { - m_even = even; -} diff --git a/apps/probability/law/law_cell.h b/apps/probability/law/law_cell.h deleted file mode 100644 index 79d054889..000000000 --- a/apps/probability/law/law_cell.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef PROBABILITY_LAW_CELL_H -#define PROBABILITY_LAW_CELL_H - -#include - -namespace Probability { - -class LawCell : public ChildlessView, public Responder { -public: - LawCell(); - void setMessage(const char * message); - void setEven(bool even); - - void drawRect(KDContext * ctx, KDRect rect) const override; - void didBecomeFirstResponder() override; - void didResignFirstResponder() override; -private: - const char * m_message; - bool m_focused; - bool m_even; -}; - -} - -#endif diff --git a/apps/probability/law/law_controller.cpp b/apps/probability/law/law_controller.cpp index b435b1756..a110e6072 100644 --- a/apps/probability/law/law_controller.cpp +++ b/apps/probability/law/law_controller.cpp @@ -29,16 +29,21 @@ const char * Probability::LawController::title() const { return "Type de Loi"; } +void Probability::LawController::didBecomeFirstResponder() { + setActiveCell(0); +} + void Probability::LawController::setActiveCell(int index) { if (index < 0 || index >= k_totalNumberOfModels) { return; } + TableViewCell * previousCell = (TableViewCell *)(m_tableView.cellAtIndex(m_activeCell)); + previousCell->setHighlighted(false); m_activeCell = index; m_tableView.scrollToRow(index); - LawCell * cell = (LawCell *)(m_tableView.cellAtIndex(index)); - cell->setParentResponder(this); - app()->setFirstResponder(cell); + TableViewCell * cell = (TableViewCell *)(m_tableView.cellAtIndex(index)); + cell->setHighlighted(true); } bool Probability::LawController::handleEvent(Ion::Events::Event event) { @@ -72,9 +77,15 @@ int Probability::LawController::reusableCellCount() { } void Probability::LawController::willDisplayCellForIndex(View * cell, int index) { - LawCell * myCell = (LawCell *)cell; - myCell->setMessage(m_messages[index]); - myCell->setEven(index%2 == 0); + TableViewCell * myCell = (TableViewCell *)cell; + myCell->textView()->setText(m_messages[index]); + if (m_activeCell == index) { + myCell->textView()->setBackgroundColor(Palette::FocusCellBackgroundColor); + } else { + myCell->textView()->setBackgroundColor(Palette::CellBackgroundColor); + } + myCell->textView()->setTextColor(KDColorBlack); + myCell->textView()->setAlignment(0., 0.5); } KDCoordinate Probability::LawController::cellHeight() { diff --git a/apps/probability/law/law_controller.h b/apps/probability/law/law_controller.h index 810aa77db..645fffeef 100644 --- a/apps/probability/law/law_controller.h +++ b/apps/probability/law/law_controller.h @@ -2,7 +2,6 @@ #define PROBABILITY_LAW_CONTROLLER_H #include -#include "law_cell.h" namespace Probability { @@ -15,6 +14,7 @@ public: View * view() override; const char * title() const override; bool handleEvent(Ion::Events::Event event) override; + void didBecomeFirstResponder() override; int numberOfCells() override; void willDisplayCellForIndex(View * cell, int index) override; @@ -26,7 +26,7 @@ private: constexpr static int k_maxNumberOfCells = 10; // !!! CAUTION: The order here is important // The cells should be initialized *before* the tableview! - LawCell m_cells[k_maxNumberOfCells]; + TableViewCell m_cells[k_maxNumberOfCells]; TableView m_tableView; const char ** m_messages; int m_activeCell;