mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
App: Move the app in the apps/ folder
Change-Id: I9c6a3eb58c718f1c796652e94534b53a2a302f8b
This commit is contained in:
2
Makefile
2
Makefile
@@ -60,7 +60,7 @@ include ion/Makefile
|
||||
include kandinsky/Makefile
|
||||
include poincare/Makefile
|
||||
include escher/Makefile
|
||||
include app/Makefile
|
||||
include apps/Makefile
|
||||
include quiz/Makefile # Quiz should be included at the end
|
||||
|
||||
%.elf: $(objs)
|
||||
|
||||
@@ -1,376 +0,0 @@
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <ion.h>
|
||||
}
|
||||
#include <escher.h>
|
||||
|
||||
class MyFunCell : public ChildlessView, public Responder {
|
||||
public:
|
||||
MyFunCell();
|
||||
void setMessage(const char * message);
|
||||
void setEven(bool even);
|
||||
|
||||
void drawRect(KDRect rect) const override;
|
||||
void setFocused(bool focused) override;
|
||||
private:
|
||||
const char * m_message;
|
||||
bool m_focused;
|
||||
bool m_even;
|
||||
};
|
||||
|
||||
MyFunCell::MyFunCell() :
|
||||
ChildlessView(),
|
||||
m_focused(false),
|
||||
m_even(false)
|
||||
{
|
||||
m_message = "NULL";
|
||||
}
|
||||
|
||||
void MyFunCell::drawRect(KDRect rect) const {
|
||||
KDColor background = m_even ? KDColorRGB(0xEE, 0xEE, 0xEE) : KDColorRGB(0x77,0x77,0x77);
|
||||
KDFillRect(rect, background);
|
||||
KDDrawString(m_message, KDPointZero, m_focused);
|
||||
}
|
||||
|
||||
void MyFunCell::setMessage(const char * message) {
|
||||
m_message = message;
|
||||
}
|
||||
|
||||
void MyFunCell::setFocused(bool focused) {
|
||||
m_focused = focused;
|
||||
markRectAsDirty(bounds());
|
||||
}
|
||||
|
||||
void MyFunCell::setEven(bool even) {
|
||||
m_even = even;
|
||||
}
|
||||
|
||||
class ListController : public ViewController, public TableViewDataSource {
|
||||
public:
|
||||
ListController();
|
||||
|
||||
void setActiveCell(int index);
|
||||
|
||||
View * view() override;
|
||||
const char * title() const override;
|
||||
bool handleEvent(ion_event_t event) override;
|
||||
|
||||
int numberOfCells() override;
|
||||
void willDisplayCellForIndex(View * cell, int index) override;
|
||||
KDCoordinate cellHeight() override;
|
||||
View * reusableCell(int index) override;
|
||||
int reusableCellCount() override;
|
||||
private:
|
||||
constexpr static int k_totalNumberOfModels = 20;
|
||||
constexpr static int k_maxNumberOfCells = 10;
|
||||
// !!! CAUTION: The order here is important
|
||||
// The cells should be initialized *before* the tableview!
|
||||
MyFunCell m_cells[k_maxNumberOfCells];
|
||||
TableView m_tableView;
|
||||
const char ** m_messages;
|
||||
int m_activeCell;
|
||||
KDCoordinate m_manualScrolling;
|
||||
};
|
||||
|
||||
static const char * sMessages[] = {
|
||||
"AAA 0", "BBB 1", "CCC 2", "DDD 3", "EEE 4",
|
||||
"FFF 5", "GGG 6", "HHH 7", "III 8", "JJJ 9",
|
||||
"KKK10", "LLL11", "MMM12", "NNN13", "OOO14",
|
||||
"PPP15", "QQQ16", "RRR17", "SSS18", "TTT19"
|
||||
};
|
||||
|
||||
ListController::ListController() :
|
||||
ViewController(),
|
||||
m_tableView(TableView(this)),
|
||||
m_activeCell(0),
|
||||
m_manualScrolling(0)
|
||||
{
|
||||
m_messages = sMessages;
|
||||
}
|
||||
|
||||
View * ListController::view() {
|
||||
return &m_tableView;
|
||||
}
|
||||
|
||||
const char * ListController::title() const {
|
||||
return "List";
|
||||
}
|
||||
|
||||
void ListController::setActiveCell(int index) {
|
||||
if (index < 0 || index >= k_totalNumberOfModels) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_activeCell = index;
|
||||
m_tableView.scrollToRow(index);
|
||||
MyFunCell * cell = (MyFunCell *)(m_tableView.cellAtIndex(index));
|
||||
cell->setParentResponder(this);
|
||||
App::runningApp()->focus(cell);
|
||||
}
|
||||
|
||||
bool ListController::handleEvent(ion_event_t event) {
|
||||
switch (event) {
|
||||
case DOWN_ARROW:
|
||||
setActiveCell(m_activeCell+1);
|
||||
return true;
|
||||
case UP_ARROW:
|
||||
setActiveCell(m_activeCell-1);
|
||||
return true;
|
||||
case ENTER:
|
||||
m_manualScrolling += 10;
|
||||
m_tableView.setContentOffset({0, m_manualScrolling});
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int ListController::numberOfCells() {
|
||||
return k_totalNumberOfModels;
|
||||
};
|
||||
|
||||
View * ListController::reusableCell(int index) {
|
||||
assert(index >= 0);
|
||||
assert(index < k_maxNumberOfCells);
|
||||
return &m_cells[index];
|
||||
}
|
||||
|
||||
int ListController::reusableCellCount() {
|
||||
return k_maxNumberOfCells;
|
||||
}
|
||||
|
||||
void ListController::willDisplayCellForIndex(View * cell, int index) {
|
||||
MyFunCell * myCell = (MyFunCell *)cell;
|
||||
myCell->setMessage(m_messages[index]);
|
||||
myCell->setEven(index%2 == 0);
|
||||
}
|
||||
|
||||
KDCoordinate ListController::cellHeight() {
|
||||
return 40;
|
||||
}
|
||||
|
||||
class CursorView : public ChildlessView {
|
||||
public:
|
||||
using ChildlessView::ChildlessView;
|
||||
void drawRect(KDRect rect) const override;
|
||||
};
|
||||
|
||||
void CursorView::drawRect(KDRect rect) const {
|
||||
KDFillRect(rect, KDColorRed);
|
||||
}
|
||||
|
||||
class GraphView : public View {
|
||||
public:
|
||||
GraphView();
|
||||
void drawRect(KDRect rect) const override;
|
||||
void moveCursorRight();
|
||||
private:
|
||||
int numberOfSubviews() const override;
|
||||
View * subviewAtIndex(int index) override;
|
||||
void layoutSubviews() override;
|
||||
|
||||
CursorView m_cursorView;
|
||||
KDPoint m_cursorPosition;
|
||||
};
|
||||
|
||||
GraphView::GraphView() :
|
||||
View(),
|
||||
m_cursorView(CursorView()),
|
||||
m_cursorPosition(KDPointZero)
|
||||
{
|
||||
}
|
||||
|
||||
int GraphView::numberOfSubviews() const {
|
||||
return 1;
|
||||
};
|
||||
|
||||
View * GraphView::subviewAtIndex(int index) {
|
||||
return &m_cursorView;
|
||||
}
|
||||
|
||||
void GraphView::moveCursorRight() {
|
||||
m_cursorPosition.x = m_cursorPosition.x + 2;
|
||||
layoutSubviews();
|
||||
}
|
||||
|
||||
void GraphView::layoutSubviews() {
|
||||
KDRect cursorFrame;
|
||||
cursorFrame.origin = m_cursorPosition;
|
||||
cursorFrame.width = 10;
|
||||
cursorFrame.height = 10;
|
||||
m_cursorView.setFrame(cursorFrame);
|
||||
}
|
||||
|
||||
void GraphView::drawRect(KDRect rect) const {
|
||||
KDFillRect(rect, KDColorWhite);
|
||||
KDCoordinate x_grid_step = m_frame.width/10;
|
||||
KDCoordinate y_grid_step = m_frame.height/10;
|
||||
KDColor gridColor = KDColorGray(0xEE);
|
||||
for (KDCoordinate x=m_frame.x; x<m_frame.width; x += x_grid_step) {
|
||||
KDRect verticalGridRect;
|
||||
verticalGridRect.x = x;
|
||||
verticalGridRect.y = m_frame.y;
|
||||
verticalGridRect.width = 1;
|
||||
verticalGridRect.height = m_frame.height;
|
||||
KDFillRect(verticalGridRect, gridColor);
|
||||
}
|
||||
for (KDCoordinate y=m_frame.y; y<m_frame.height; y += y_grid_step) {
|
||||
KDRect horizontalGridRect;
|
||||
horizontalGridRect.x = m_frame.x;
|
||||
horizontalGridRect.y = y;
|
||||
horizontalGridRect.width = m_frame.width;
|
||||
horizontalGridRect.height = 1;
|
||||
KDFillRect(horizontalGridRect, gridColor);
|
||||
}
|
||||
|
||||
for (int i=m_frame.x; i<m_frame.width; i++) {
|
||||
KDPoint p;
|
||||
p.x = i;
|
||||
p.y = (i*i)/m_frame.height;
|
||||
KDSetPixel(p, KDColorRGB(0x7F, 0, 0));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class GraphController : public ViewController {
|
||||
public:
|
||||
GraphController(KDColor c);
|
||||
View * view() override;
|
||||
const char * title() const override;
|
||||
void setFocused(bool focused) override;
|
||||
bool handleEvent(ion_event_t event) override;
|
||||
private:
|
||||
#if 0
|
||||
//SolidColorView m_view;
|
||||
static constexpr int k_bufferSize = 100;
|
||||
char buffer[k_bufferSize];
|
||||
TextField m_view;
|
||||
#else
|
||||
GraphView m_view;
|
||||
#endif
|
||||
};
|
||||
|
||||
GraphController::GraphController(KDColor c) :
|
||||
ViewController(),
|
||||
//m_view(TextField(buffer, k_bufferSize))
|
||||
//m_view(SolidColorView(c))
|
||||
m_view(GraphView())
|
||||
{
|
||||
//m_view.setParentResponder(this);
|
||||
}
|
||||
|
||||
View * GraphController::view() {
|
||||
return &m_view;
|
||||
}
|
||||
|
||||
const char * GraphController::title() const {
|
||||
return "Graph";
|
||||
}
|
||||
|
||||
void GraphController::setFocused(bool focused) {
|
||||
/*
|
||||
if (focused) {
|
||||
App::runningApp()->focus(&m_view);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
bool GraphController::handleEvent(ion_event_t event) {
|
||||
switch (event) {
|
||||
case ENTER:
|
||||
m_view.moveCursorRight();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class MyTestApp : public App {
|
||||
public:
|
||||
MyTestApp();
|
||||
protected:
|
||||
ViewController * rootViewController() override;
|
||||
private:
|
||||
GraphController m_graphViewController;
|
||||
ListController m_listViewController;
|
||||
TabViewController m_tabViewController;
|
||||
};
|
||||
|
||||
MyTestApp::MyTestApp() :
|
||||
App(),
|
||||
m_graphViewController(GraphController(KDColorWhite)),
|
||||
m_listViewController(ListController()),
|
||||
m_tabViewController(&m_graphViewController, &m_listViewController)
|
||||
{
|
||||
}
|
||||
|
||||
ViewController * MyTestApp::rootViewController() {
|
||||
return &m_tabViewController;
|
||||
}
|
||||
|
||||
void ion_app() {
|
||||
|
||||
//KDDrawString("Hello", {0,0}, 0);
|
||||
|
||||
//KDFillRect({0,0,100,100}, 0x55);
|
||||
//KDFillRect({100,100,100,100}, 0x99);
|
||||
|
||||
/*
|
||||
KDCoordinate i = 0;
|
||||
char message[4] = {'F', 'O', 'O', 0};
|
||||
while (1) {
|
||||
KDPoint p = {i, i};
|
||||
KDDrawString(message, p, false);
|
||||
ion_event_t event = ion_get_event();
|
||||
if (event < 0x100) {
|
||||
message[1] = event;
|
||||
}
|
||||
i+= 1;
|
||||
}
|
||||
*/
|
||||
|
||||
MyTestApp myApp = MyTestApp();
|
||||
|
||||
myApp.run();
|
||||
|
||||
/*
|
||||
int i = 0;
|
||||
|
||||
while(true) {
|
||||
#if ESCHER_VIEW_LOGGING
|
||||
std::cout << window << std::endl;
|
||||
#endif
|
||||
tabVC.setActiveTab(i);
|
||||
ion_event_t event = ion_get_event();
|
||||
tabVC.handleKeyEvent(event);
|
||||
i = (i+1)%2;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
static GraphApp app = GraphApp();
|
||||
app.run();
|
||||
*/
|
||||
/*
|
||||
KDRect wholeScreen = {0, 0, 100, 100};
|
||||
KDColor a = 0x55;
|
||||
View * window = new SolidColorView(wholeScreen, a);
|
||||
KDRect textRect = {0, 0, 50, 50};
|
||||
MyTextView * textView = new MyTextView(textRect);
|
||||
window->addSubview(textView);
|
||||
|
||||
//window->draw();
|
||||
|
||||
while (1) {
|
||||
ion_sleep();
|
||||
textRect.y = textRect.y+1;
|
||||
textView->setFrame(textRect);
|
||||
}
|
||||
|
||||
delete textView;
|
||||
delete window;
|
||||
*/
|
||||
}
|
||||
9
apps/Makefile
Normal file
9
apps/Makefile
Normal file
@@ -0,0 +1,9 @@
|
||||
include apps/graph/Makefile
|
||||
|
||||
app_objs += $(addprefix apps/,\
|
||||
main.o\
|
||||
)
|
||||
|
||||
products += $(app_objs) app.elf app.hex app.bin
|
||||
|
||||
app.elf: $(app_objs)
|
||||
8
apps/graph/Makefile
Normal file
8
apps/graph/Makefile
Normal file
@@ -0,0 +1,8 @@
|
||||
app_objs += $(addprefix apps/graph/,\
|
||||
graph_app.o\
|
||||
graph/cursor_view.o\
|
||||
graph/graph_controller.o\
|
||||
graph/graph_view.o\
|
||||
list/function_cell.o\
|
||||
list/list_controller.o\
|
||||
)
|
||||
5
apps/graph/graph/cursor_view.cpp
Normal file
5
apps/graph/graph/cursor_view.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "cursor_view.h"
|
||||
|
||||
void CursorView::drawRect(KDRect rect) const {
|
||||
KDFillRect(rect, KDColorRed);
|
||||
}
|
||||
12
apps/graph/graph/cursor_view.h
Normal file
12
apps/graph/graph/cursor_view.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef GRAPH_CURSOR_VIEW_H
|
||||
#define GRAPH_CURSOR_VIEW_H
|
||||
|
||||
#include <escher.h>
|
||||
|
||||
class CursorView : public ChildlessView {
|
||||
public:
|
||||
using ChildlessView::ChildlessView;
|
||||
void drawRect(KDRect rect) const override;
|
||||
};
|
||||
|
||||
#endif
|
||||
36
apps/graph/graph/graph_controller.cpp
Normal file
36
apps/graph/graph/graph_controller.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "graph_controller.h"
|
||||
|
||||
GraphController::GraphController(KDColor c) :
|
||||
ViewController(),
|
||||
//m_view(TextField(buffer, k_bufferSize))
|
||||
//m_view(SolidColorView(c))
|
||||
m_view(GraphView())
|
||||
{
|
||||
//m_view.setParentResponder(this);
|
||||
}
|
||||
|
||||
View * GraphController::view() {
|
||||
return &m_view;
|
||||
}
|
||||
|
||||
const char * GraphController::title() const {
|
||||
return "Graph";
|
||||
}
|
||||
|
||||
void GraphController::setFocused(bool focused) {
|
||||
/*
|
||||
if (focused) {
|
||||
App::runningApp()->focus(&m_view);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
bool GraphController::handleEvent(ion_event_t event) {
|
||||
switch (event) {
|
||||
case ENTER:
|
||||
m_view.moveCursorRight();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
18
apps/graph/graph/graph_controller.h
Normal file
18
apps/graph/graph/graph_controller.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef GRAPH_GRAPH_CONTROLLER_H
|
||||
#define GRAPH_GRAPH_CONTROLLER_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "graph_view.h"
|
||||
|
||||
class GraphController : public ViewController {
|
||||
public:
|
||||
GraphController(KDColor c);
|
||||
View * view() override;
|
||||
const char * title() const override;
|
||||
void setFocused(bool focused) override;
|
||||
bool handleEvent(ion_event_t event) override;
|
||||
private:
|
||||
GraphView m_view;
|
||||
};
|
||||
|
||||
#endif
|
||||
58
apps/graph/graph/graph_view.cpp
Normal file
58
apps/graph/graph/graph_view.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "graph_view.h"
|
||||
|
||||
GraphView::GraphView() :
|
||||
View(),
|
||||
m_cursorView(CursorView()),
|
||||
m_cursorPosition(KDPointZero)
|
||||
{
|
||||
}
|
||||
|
||||
int GraphView::numberOfSubviews() const {
|
||||
return 1;
|
||||
};
|
||||
|
||||
View * GraphView::subviewAtIndex(int index) {
|
||||
return &m_cursorView;
|
||||
}
|
||||
|
||||
void GraphView::moveCursorRight() {
|
||||
m_cursorPosition.x = m_cursorPosition.x + 2;
|
||||
layoutSubviews();
|
||||
}
|
||||
|
||||
void GraphView::layoutSubviews() {
|
||||
KDRect cursorFrame;
|
||||
cursorFrame.origin = m_cursorPosition;
|
||||
cursorFrame.width = 10;
|
||||
cursorFrame.height = 10;
|
||||
m_cursorView.setFrame(cursorFrame);
|
||||
}
|
||||
|
||||
void GraphView::drawRect(KDRect rect) const {
|
||||
KDFillRect(rect, KDColorWhite);
|
||||
KDCoordinate x_grid_step = m_frame.width/10;
|
||||
KDCoordinate y_grid_step = m_frame.height/10;
|
||||
KDColor gridColor = KDColorGray(0xEE);
|
||||
for (KDCoordinate x=0; x<m_frame.width; x += x_grid_step) {
|
||||
KDRect verticalGridRect;
|
||||
verticalGridRect.x = x;
|
||||
verticalGridRect.y = 0;
|
||||
verticalGridRect.width = 1;
|
||||
verticalGridRect.height = m_frame.height;
|
||||
KDFillRect(verticalGridRect, gridColor);
|
||||
}
|
||||
for (KDCoordinate y=0; y<m_frame.height; y += y_grid_step) {
|
||||
KDRect horizontalGridRect;
|
||||
horizontalGridRect.x = 0;
|
||||
horizontalGridRect.y = y;
|
||||
horizontalGridRect.width = m_frame.width;
|
||||
horizontalGridRect.height = 1;
|
||||
KDFillRect(horizontalGridRect, gridColor);
|
||||
}
|
||||
for (int i=0; i<m_frame.width; i++) {
|
||||
KDPoint p;
|
||||
p.x = i;
|
||||
p.y = (i*i)/m_frame.height;
|
||||
KDSetPixel(p, KDColorRGB(0x7F, 0, 0));
|
||||
}
|
||||
};
|
||||
21
apps/graph/graph/graph_view.h
Normal file
21
apps/graph/graph/graph_view.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef GRAPH_GRAPH_VIEW_H
|
||||
#define GRAPH_GRAPH_VIEW_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "cursor_view.h"
|
||||
|
||||
class GraphView : public View {
|
||||
public:
|
||||
GraphView();
|
||||
void drawRect(KDRect rect) const override;
|
||||
void moveCursorRight();
|
||||
private:
|
||||
int numberOfSubviews() const override;
|
||||
View * subviewAtIndex(int index) override;
|
||||
void layoutSubviews() override;
|
||||
|
||||
CursorView m_cursorView;
|
||||
KDPoint m_cursorPosition;
|
||||
};
|
||||
|
||||
#endif
|
||||
13
apps/graph/graph_app.cpp
Normal file
13
apps/graph/graph_app.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "graph_app.h"
|
||||
|
||||
GraphApp::GraphApp() :
|
||||
App(),
|
||||
m_graphViewController(GraphController(KDColorWhite)),
|
||||
m_listViewController(ListController()),
|
||||
m_tabViewController(&m_graphViewController, &m_listViewController)
|
||||
{
|
||||
}
|
||||
|
||||
ViewController * GraphApp::rootViewController() {
|
||||
return &m_tabViewController;
|
||||
}
|
||||
19
apps/graph/graph_app.h
Normal file
19
apps/graph/graph_app.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef GRAPH_GRAPH_APP_H
|
||||
#define GRAPH_GRAPH_APP_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "graph/graph_controller.h"
|
||||
#include "list/list_controller.h"
|
||||
|
||||
class GraphApp : public App {
|
||||
public:
|
||||
GraphApp();
|
||||
protected:
|
||||
ViewController * rootViewController() override;
|
||||
private:
|
||||
GraphController m_graphViewController;
|
||||
ListController m_listViewController;
|
||||
TabViewController m_tabViewController;
|
||||
};
|
||||
|
||||
#endif
|
||||
28
apps/graph/list/function_cell.cpp
Normal file
28
apps/graph/list/function_cell.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "function_cell.h"
|
||||
|
||||
FunctionCell::FunctionCell() :
|
||||
ChildlessView(),
|
||||
m_focused(false),
|
||||
m_even(false)
|
||||
{
|
||||
m_message = "NULL";
|
||||
}
|
||||
|
||||
void FunctionCell::drawRect(KDRect rect) const {
|
||||
KDColor background = m_even ? KDColorRGB(0xEE, 0xEE, 0xEE) : KDColorRGB(0x77,0x77,0x77);
|
||||
KDFillRect(rect, background);
|
||||
KDDrawString(m_message, KDPointZero, m_focused);
|
||||
}
|
||||
|
||||
void FunctionCell::setMessage(const char * message) {
|
||||
m_message = message;
|
||||
}
|
||||
|
||||
void FunctionCell::setFocused(bool focused) {
|
||||
m_focused = focused;
|
||||
markRectAsDirty(bounds());
|
||||
}
|
||||
|
||||
void FunctionCell::setEven(bool even) {
|
||||
m_even = even;
|
||||
}
|
||||
20
apps/graph/list/function_cell.h
Normal file
20
apps/graph/list/function_cell.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef GRAPH_FUNCTION_CELL_H
|
||||
#define GRAPH_FUNCTION_CELL_H
|
||||
|
||||
#include <escher.h>
|
||||
|
||||
class FunctionCell : public ChildlessView, public Responder {
|
||||
public:
|
||||
FunctionCell();
|
||||
void setMessage(const char * message);
|
||||
void setEven(bool even);
|
||||
|
||||
void drawRect(KDRect rect) const override;
|
||||
void setFocused(bool focused) override;
|
||||
private:
|
||||
const char * m_message;
|
||||
bool m_focused;
|
||||
bool m_even;
|
||||
};
|
||||
|
||||
#endif
|
||||
79
apps/graph/list/list_controller.cpp
Normal file
79
apps/graph/list/list_controller.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
#include "list_controller.h"
|
||||
#include <assert.h>
|
||||
|
||||
static const char * sMessages[] = {
|
||||
"AAA 0", "BBB 1", "CCC 2", "DDD 3", "EEE 4",
|
||||
"FFF 5", "GGG 6", "HHH 7", "III 8", "JJJ 9",
|
||||
"KKK10", "LLL11", "MMM12", "NNN13", "OOO14",
|
||||
"PPP15", "QQQ16", "RRR17", "SSS18", "TTT19"
|
||||
};
|
||||
|
||||
ListController::ListController() :
|
||||
ViewController(),
|
||||
m_tableView(TableView(this)),
|
||||
m_activeCell(0),
|
||||
m_manualScrolling(0)
|
||||
{
|
||||
m_messages = sMessages;
|
||||
}
|
||||
|
||||
View * ListController::view() {
|
||||
return &m_tableView;
|
||||
}
|
||||
|
||||
const char * ListController::title() const {
|
||||
return "List";
|
||||
}
|
||||
|
||||
void ListController::setActiveCell(int index) {
|
||||
if (index < 0 || index >= k_totalNumberOfModels) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_activeCell = index;
|
||||
m_tableView.scrollToRow(index);
|
||||
FunctionCell * cell = (FunctionCell *)(m_tableView.cellAtIndex(index));
|
||||
cell->setParentResponder(this);
|
||||
App::runningApp()->focus(cell);
|
||||
}
|
||||
|
||||
bool ListController::handleEvent(ion_event_t event) {
|
||||
switch (event) {
|
||||
case DOWN_ARROW:
|
||||
setActiveCell(m_activeCell+1);
|
||||
return true;
|
||||
case UP_ARROW:
|
||||
setActiveCell(m_activeCell-1);
|
||||
return true;
|
||||
case ENTER:
|
||||
m_manualScrolling += 10;
|
||||
m_tableView.setContentOffset({0, m_manualScrolling});
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int ListController::numberOfCells() {
|
||||
return k_totalNumberOfModels;
|
||||
};
|
||||
|
||||
View * ListController::reusableCell(int index) {
|
||||
assert(index >= 0);
|
||||
assert(index < k_maxNumberOfCells);
|
||||
return &m_cells[index];
|
||||
}
|
||||
|
||||
int ListController::reusableCellCount() {
|
||||
return k_maxNumberOfCells;
|
||||
}
|
||||
|
||||
void ListController::willDisplayCellForIndex(View * cell, int index) {
|
||||
FunctionCell * myCell = (FunctionCell *)cell;
|
||||
myCell->setMessage(m_messages[index]);
|
||||
myCell->setEven(index%2 == 0);
|
||||
}
|
||||
|
||||
KDCoordinate ListController::cellHeight() {
|
||||
return 40;
|
||||
}
|
||||
34
apps/graph/list/list_controller.h
Normal file
34
apps/graph/list/list_controller.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef GRAPH_LIST_CONTROLLER_H
|
||||
#define GRAPH_LIST_CONTROLLER_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "function_cell.h"
|
||||
|
||||
class ListController : public ViewController, public TableViewDataSource {
|
||||
public:
|
||||
ListController();
|
||||
|
||||
void setActiveCell(int index);
|
||||
|
||||
View * view() override;
|
||||
const char * title() const override;
|
||||
bool handleEvent(ion_event_t event) override;
|
||||
|
||||
int numberOfCells() override;
|
||||
void willDisplayCellForIndex(View * cell, int index) override;
|
||||
KDCoordinate cellHeight() override;
|
||||
View * reusableCell(int index) override;
|
||||
int reusableCellCount() override;
|
||||
private:
|
||||
constexpr static int k_totalNumberOfModels = 20;
|
||||
constexpr static int k_maxNumberOfCells = 10;
|
||||
// !!! CAUTION: The order here is important
|
||||
// The cells should be initialized *before* the tableview!
|
||||
FunctionCell m_cells[k_maxNumberOfCells];
|
||||
TableView m_tableView;
|
||||
const char ** m_messages;
|
||||
int m_activeCell;
|
||||
KDCoordinate m_manualScrolling;
|
||||
};
|
||||
|
||||
#endif
|
||||
6
apps/main.cpp
Normal file
6
apps/main.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "graph/graph_app.h"
|
||||
|
||||
void ion_app() {
|
||||
GraphApp graphApp = GraphApp();
|
||||
graphApp.run();
|
||||
}
|
||||
Reference in New Issue
Block a user