mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/probability] Modify law controller to use table view cells instead of law cells
Change-Id: I95857842332d8d7e8e3b49a4f64c8c4d6840f029
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
app_objs += $(addprefix apps/probability/,\
|
||||
app.o\
|
||||
law/law_cell.o\
|
||||
law/law_controller.o\
|
||||
parameters/parameters_controller.o\
|
||||
)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#ifndef PROBABILITY_LAW_CELL_H
|
||||
#define PROBABILITY_LAW_CELL_H
|
||||
|
||||
#include <escher.h>
|
||||
|
||||
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
|
||||
@@ -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() {
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define PROBABILITY_LAW_CONTROLLER_H
|
||||
|
||||
#include <escher.h>
|
||||
#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;
|
||||
|
||||
Reference in New Issue
Block a user