Numworks Epsilon  1.4.1
Graphing Calculator Operating System
list_controller.cpp
Go to the documentation of this file.
1 #include "list_controller.h"
2 #include "../app.h"
3 #include "../../i18n.h"
4 #include <assert.h>
5 #include <escher/metric.h>
6 
7 using namespace Shared;
8 
9 namespace Graph {
10 
12  Shared::ListController(parentResponder, functionStore, header, footer, I18n::Message::AddFunction),
13  m_functionTitleCells{},
14  m_expressionCells{},
15  m_parameterController(this, functionStore, I18n::Message::FunctionColor, I18n::Message::DeleteFunction)
16 {
17 }
18 
19 const char * ListController::title() {
20  return I18n::translate(I18n::Message::FunctionTab);
21 }
22 
26  }
27  return 1 + m_functionStore->numberOfFunctions();
28 };
29 
33  }
34  Function * function = m_functionStore->functionAtIndex(j);
35  if (function->layout() == nullptr) {
37  }
38  KDCoordinate functionSize = function->layout()->size().height();
39  return functionSize + Metric::StoreRowHeight - KDText::charSize().height();
40 }
41 
42 void ListController::editExpression(Function * function, Ion::Events::Event event) {
43  char * initialText = nullptr;
44  char initialTextContent[TextField::maxBufferSize()];
45  if (event == Ion::Events::OK || event == Ion::Events::EXE) {
46  strlcpy(initialTextContent, function->text(), sizeof(initialTextContent));
47  initialText = initialTextContent;
48  }
49  App * myApp = (App *)app();
50  InputViewController * inputController = myApp->inputViewController();
51  inputController->edit(this, event, function, initialText,
52  [](void * context, void * sender){
53  Shared::Function * myFunction = (Shared::Function *)context;
54  InputViewController * myInputViewController = (InputViewController *)sender;
55  const char * textBody = myInputViewController->textBody();
56  myFunction->setContent(textBody);
57  },
58  [](void * context, void * sender){
59  });
60 }
61 
62 ListParameterController * ListController::parameterController() {
63  return &m_parameterController;
64 }
65 
66 int ListController::maxNumberOfRows() {
67  return k_maxNumberOfRows;
68 }
69 
70 HighlightCell * ListController::titleCells(int index) {
71  assert(index >= 0 && index < k_maxNumberOfRows);
72  return m_functionTitleCells[index];
73 }
74 
75 HighlightCell * ListController::expressionCells(int index) {
76  assert(index >= 0 && index < k_maxNumberOfRows);
77  return m_expressionCells[index];
78 }
79 
80 
81 void ListController::willDisplayTitleCellAtIndex(HighlightCell * cell, int j) {
82  FunctionTitleCell * myFunctionCell = (FunctionTitleCell *)cell;
83  CartesianFunction * function = ((CartesianFunctionStore *)m_functionStore)->functionAtIndex(j);
84  char bufferName[5] = {*function->name(),'(', m_functionStore->symbol(),')', 0};
85  myFunctionCell->setText(bufferName);
86  KDColor functionNameColor = function->isActive() ? function->color() : Palette::GreyDark;
87  myFunctionCell->setColor(functionNameColor);
88 }
89 
90 void ListController::willDisplayExpressionCellAtIndex(HighlightCell * cell, int j) {
93  myCell->setExpression(f->layout());
94  bool active = f->isActive();
95  KDColor textColor = active ? KDColorBlack : Palette::GreyDark;
96  myCell->setTextColor(textColor);
97 }
98 
99 bool ListController::removeFunctionRow(Function * function) {
100  if (m_functionStore->numberOfFunctions() > 1) {
101  m_functionStore->removeFunction(function);
102  return true;
103  }
104  return false;
105 }
106 
107 View * ListController::loadView() {
108  for (int i = 0; i < k_maxNumberOfRows; i++) {
110  m_expressionCells[i] = new FunctionExpressionCell();
111  }
113 }
114 
115 void ListController::unloadView(View * view) {
116  for (int i = 0; i < k_maxNumberOfRows; i++) {
117  delete m_functionTitleCells[i];
118  m_functionTitleCells[i] = nullptr;
119  delete m_expressionCells[i];
120  m_expressionCells[i] = nullptr;
121  }
123 }
124 
125 }
static constexpr KDCoordinate StoreRowHeight
Definition: metric.h:26
virtual void setContent(const char *c)
Definition: function.cpp:37
Definition: i18n.h:6
void edit(Responder *caller, Ion::Events::Event event, void *context, const char *initialText, Invocation::Action successAction, Invocation::Action failureAction)
#define assert(e)
Definition: assert.h:9
static constexpr int maxBufferSize()
Definition: text_field.h:23
constexpr Event EXE
Definition: events.h:114
int16_t KDCoordinate
Definition: coordinate.h:6
static constexpr KDColor GreyDark
Definition: palette.h:15
size_t strlcpy(char *dst, const char *src, size_t len)
Definition: strlcpy.c:3
virtual void setColor(KDColor color)
Definition: app.cpp:9
FunctionStore * m_functionStore
virtual Function * functionAtIndex(int i)=0
KDCoordinate rowHeight(int j) override
enum Message uint16_t enum Language uint16_t const char * translate(Message m, Language l=(Language) 0)
Definition: i18n.cpp:5
virtual int maxNumberOfFunctions()=0
View * loadView() override
constexpr KDColor KDColorBlack
Definition: color.h:41
int numberOfRows() override
Poincare::ExpressionLayout * layout()
Definition: function.cpp:79
ListController(Responder *parentResponder, FunctionStore *functionStore, ButtonRowController *header, ButtonRowController *footer, I18n::Message text)
Definition: app.h:23
void unloadView(View *view) override
Definition: color.h:6
Definition: view.h:23
const char * title() override
static constexpr KDSize charSize(FontSize size=FontSize::Large)
Definition: text.h:16
App * app()
Definition: responder.cpp:77
void setExpression(Poincare::ExpressionLayout *expressionLayout)
constexpr Event OK
Definition: events.h:65
virtual char symbol() const =0
virtual void removeFunction(Function *f)=0
constexpr KDCoordinate height() const
Definition: size.h:11