mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-29 19:49:58 +02:00
[apps/graph/values] create a class for derivative function parameter
controller Change-Id: Ifdf1a2291739f50e06ba26bd76469c5b5e87e731
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/derivative_parameter_controller.o\
|
||||
values/function_parameter_controller.o\
|
||||
values/function_title_cell.o\
|
||||
values/interval.o\
|
||||
|
||||
105
apps/graph/values/derivative_parameter_controller.cpp
Normal file
105
apps/graph/values/derivative_parameter_controller.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
#include "derivative_parameter_controller.h"
|
||||
#include <assert.h>
|
||||
|
||||
namespace Graph {
|
||||
|
||||
DerivativeParameterController::DerivativeParameterController(Responder * parentResponder) :
|
||||
ViewController(parentResponder),
|
||||
m_pageTitle("Colonne f'(x)"),
|
||||
m_hideColumn(ListViewCell((char*)"Masquer la colonne de la 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 * DerivativeParameterController::title() const {
|
||||
return m_pageTitle;
|
||||
}
|
||||
|
||||
View * DerivativeParameterController::view() {
|
||||
return &m_listView;
|
||||
}
|
||||
|
||||
void DerivativeParameterController::setFunction(Function * function) {
|
||||
m_function = function;
|
||||
for (int currentChar = 0; currentChar < k_maxNumberOfCharsInTitle; currentChar++) {
|
||||
if (m_pageTitle[currentChar] == '(') {
|
||||
m_pageTitle[currentChar-2] = *m_function->name();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DerivativeParameterController::didBecomeFirstResponder() {
|
||||
m_listView.reloadData();
|
||||
setActiveCell(m_activeCell);
|
||||
}
|
||||
|
||||
void DerivativeParameterController::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 DerivativeParameterController::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 handleEnter();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool DerivativeParameterController::handleEnter() {
|
||||
switch (m_activeCell) {
|
||||
case 0:
|
||||
{
|
||||
m_function->setDisplayDerivative(false);
|
||||
StackViewController * stack = (StackViewController *)(parentResponder());
|
||||
stack->pop();
|
||||
return true;
|
||||
}
|
||||
case 1:
|
||||
return false;
|
||||
default:
|
||||
assert(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int DerivativeParameterController::numberOfRows() {
|
||||
return k_totalNumberOfCell;
|
||||
};
|
||||
|
||||
View * DerivativeParameterController::reusableCell(int index) {
|
||||
assert(index >= 0);
|
||||
assert(index < k_totalNumberOfCell);
|
||||
View * cells[] = {&m_hideColumn, &m_copyColumn};
|
||||
return cells[index];
|
||||
}
|
||||
|
||||
int DerivativeParameterController::reusableCellCount() {
|
||||
return k_totalNumberOfCell;
|
||||
}
|
||||
|
||||
KDCoordinate DerivativeParameterController::cellHeight() {
|
||||
return 35;
|
||||
}
|
||||
|
||||
}
|
||||
38
apps/graph/values/derivative_parameter_controller.h
Normal file
38
apps/graph/values/derivative_parameter_controller.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef GRAPH_DERIVATIVE_PARAM_CONTROLLER_H
|
||||
#define GRAPH_DERIVATIVE_PARAM_CONTROLLER_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "../function.h"
|
||||
|
||||
namespace Graph {
|
||||
class DerivativeParameterController : public ViewController, public ListViewDataSource {
|
||||
public:
|
||||
DerivativeParameterController(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 setFunction(Function * function);
|
||||
private:
|
||||
bool handleEnter();
|
||||
constexpr static int k_totalNumberOfCell = 2;
|
||||
constexpr static int k_maxNumberOfCharsInTitle = 16;
|
||||
char m_pageTitle[k_maxNumberOfCharsInTitle];
|
||||
ListViewCell m_hideColumn;
|
||||
ListViewCell m_copyColumn;
|
||||
ListView m_listView;
|
||||
int m_activeCell;
|
||||
Function * m_function;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user