mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/graph/values] create a class function parameter controller
Change-Id: I93180ce61600faf43229e70408b61a306a2ce577
This commit is contained in:
@@ -13,6 +13,7 @@ app_objs += $(addprefix apps/graph/,\
|
||||
list/list_controller.o\
|
||||
list/parameter_controller.o\
|
||||
values/abscissa_parameter_controller.o\
|
||||
values/function_parameter_controller.o\
|
||||
values/function_title_cell.o\
|
||||
values/interval.o\
|
||||
values/title_cell.o\
|
||||
|
||||
94
apps/graph/values/function_parameter_controller.cpp
Normal file
94
apps/graph/values/function_parameter_controller.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
#include "function_parameter_controller.h"
|
||||
#include <assert.h>
|
||||
|
||||
namespace Graph {
|
||||
|
||||
FunctionParameterController::FunctionParameterController(Responder * parentResponder) :
|
||||
ViewController(parentResponder),
|
||||
m_pageTitle("Colonne f(x)"),
|
||||
m_displayDerivativeColumn(SwitchListViewCell((char*)"Colonne de la fonction derivee")),
|
||||
m_copyColumn(ListViewCell((char*)"Copier la colonne dans une liste")),
|
||||
m_listView(ListView(this,Metric::TopMargin, Metric::RightMargin,
|
||||
Metric::BottomMargin, Metric::LeftMargin)),
|
||||
m_activeCell(0),
|
||||
m_function(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
const char * FunctionParameterController::title() const {
|
||||
return m_pageTitle;
|
||||
}
|
||||
|
||||
View * FunctionParameterController::view() {
|
||||
return &m_listView;
|
||||
}
|
||||
|
||||
void FunctionParameterController::setFunction(Function * function) {
|
||||
m_function = function;
|
||||
for (int currentChar = 0; currentChar < k_maxNumberOfCharsInTitle; currentChar++) {
|
||||
if (m_pageTitle[currentChar] == '(') {
|
||||
m_pageTitle[currentChar-1] = *m_function->name();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FunctionParameterController::didBecomeFirstResponder() {
|
||||
setActiveCell(m_activeCell);
|
||||
}
|
||||
|
||||
void FunctionParameterController::setActiveCell(int index) {
|
||||
if (index < 0 || index >= k_totalNumberOfCell) {
|
||||
return;
|
||||
}
|
||||
ListViewCell * previousCell = (ListViewCell *)(m_listView.cellAtIndex(m_activeCell));
|
||||
previousCell->setHighlighted(false);
|
||||
|
||||
m_activeCell = index;
|
||||
m_listView.scrollToRow(index);
|
||||
ListViewCell * cell = (ListViewCell *)(m_listView.cellAtIndex(index));
|
||||
cell->setHighlighted(true);
|
||||
}
|
||||
|
||||
bool FunctionParameterController::handleEvent(Ion::Events::Event event) {
|
||||
switch (event) {
|
||||
case Ion::Events::Event::DOWN_ARROW:
|
||||
setActiveCell(m_activeCell+1);
|
||||
return true;
|
||||
case Ion::Events::Event::UP_ARROW:
|
||||
setActiveCell(m_activeCell-1);
|
||||
return true;
|
||||
case Ion::Events::Event::ENTER:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int FunctionParameterController::numberOfRows() {
|
||||
return k_totalNumberOfCell;
|
||||
};
|
||||
|
||||
View * FunctionParameterController::reusableCell(int index) {
|
||||
assert(index >= 0);
|
||||
assert(index < k_totalNumberOfCell);
|
||||
View * cells[] = {&m_displayDerivativeColumn, &m_copyColumn};
|
||||
return cells[index];
|
||||
}
|
||||
|
||||
int FunctionParameterController::reusableCellCount() {
|
||||
return k_totalNumberOfCell;
|
||||
}
|
||||
|
||||
KDCoordinate FunctionParameterController::cellHeight() {
|
||||
return 35;
|
||||
}
|
||||
|
||||
void FunctionParameterController::willDisplayCellForIndex(View * cell, int index) {
|
||||
if (cell == &m_displayDerivativeColumn) {
|
||||
SwitchView * switchView = (SwitchView *)m_displayDerivativeColumn.contentView();
|
||||
switchView->setState(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
38
apps/graph/values/function_parameter_controller.h
Normal file
38
apps/graph/values/function_parameter_controller.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef GRAPH_FUNCTION_PARAM_CONTROLLER_H
|
||||
#define GRAPH_FUNCTION_PARAM_CONTROLLER_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "../function.h"
|
||||
|
||||
namespace Graph {
|
||||
class FunctionParameterController : public ViewController, public ListViewDataSource {
|
||||
public:
|
||||
FunctionParameterController(Responder * parentResponder);
|
||||
|
||||
View * view() override;
|
||||
const char * title() const override;
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
void didBecomeFirstResponder() override;
|
||||
|
||||
void setActiveCell(int index);
|
||||
int numberOfRows() override;
|
||||
KDCoordinate cellHeight() override;
|
||||
View * reusableCell(int index) override;
|
||||
int reusableCellCount() override;
|
||||
void willDisplayCellForIndex(View * cell, int index) override;
|
||||
|
||||
void setFunction(Function * function);
|
||||
private:
|
||||
constexpr static int k_totalNumberOfCell = 2;
|
||||
constexpr static int k_maxNumberOfCharsInTitle = 16;
|
||||
char m_pageTitle[k_maxNumberOfCharsInTitle];
|
||||
SwitchListViewCell m_displayDerivativeColumn;
|
||||
ListViewCell m_copyColumn;
|
||||
ListView m_listView;
|
||||
int m_activeCell;
|
||||
Function * m_function;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user