[apps/graph/list] Define TypeParameterController class

This commit is contained in:
Ruben Dashyan
2019-06-26 09:56:24 +02:00
committed by Léa Saviot
parent 5a79139fb7
commit 9b52d0d1f9
3 changed files with 117 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ app_graph_src = $(addprefix apps/graph/,\
list/list_parameter_controller.cpp \
list/text_field_function_title_cell.cpp \
list/type_helper.cpp \
list/type_parameter_controller.cpp \
values/derivative_parameter_controller.cpp \
values/function_parameter_controller.cpp \
values/values_controller.cpp \

View File

@@ -0,0 +1,72 @@
#include "type_parameter_controller.h"
#include "type_helper.h"
#include <apps/i18n.h>
#include "../app.h"
#include <assert.h>
namespace Graph {
TypeParameterController::TypeParameterController(Responder * parentResponder) :
ViewController(parentResponder),
m_selectableTableView(this, this, this, nullptr),
m_record()
{
}
void TypeParameterController::didBecomeFirstResponder() {
Container::activeApp()->setFirstResponder(&m_selectableTableView);
}
bool TypeParameterController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::OK || event == Ion::Events::EXE) {
assert(!m_record.isNull());
Shared::CartesianFunction::PlotType plotType = static_cast<Shared::CartesianFunction::PlotType>(selectedRow());
App * myApp = App::app();
assert(!m_record.isNull());
Shared::ExpiringPointer<Shared::CartesianFunction> function = myApp->functionStore()->modelForRecord(m_record);
function->setPlotType(plotType);
StackViewController * stack = stackController();
stack->pop();
return true;
}
if (event == Ion::Events::Left && !m_record.isNull()) {
stackController()->pop();
return true;
}
return false;
}
const char * TypeParameterController::title() {
return I18n::translate(I18n::Message::CurveType);
}
void TypeParameterController::viewWillAppear() {
App * myApp = App::app();
assert(!m_record.isNull());
Shared::ExpiringPointer<Shared::CartesianFunction> function = myApp->functionStore()->modelForRecord(m_record);
int row = static_cast<int>(function->plotType());
selectCellAtLocation(0, row);
m_selectableTableView.reloadData();
}
KDCoordinate TypeParameterController::rowHeight(int j) {
return PlotTypeHelper::Layout(j).layoutSize().height() + 15;
}
void TypeParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) {
assert(0 <= index && index < k_numberOfTypes);
MessageTableCellWithExpression * myCell = static_cast<MessageTableCellWithExpression *>(cell);
myCell->setMessage(PlotTypeHelper::Message(index));
myCell->setLayout(PlotTypeHelper::Layout(index));
}
MessageTableCellWithExpression * TypeParameterController::reusableCell(int index, int type) {
assert(0 <= index && index < reusableCellCount(type));
return &m_cells[index];
}
StackViewController * TypeParameterController::stackController() const {
return static_cast<StackViewController *>(parentResponder());
}
}

View File

@@ -0,0 +1,44 @@
#ifndef GRAPH_LIST_TYPE_PARAMATER_CONTROLLER_H
#define GRAPH_LIST_TYPE_PARAMATER_CONTROLLER_H
#include <escher/view_controller.h>
#include <escher/list_view_data_source.h>
#include <escher/selectable_table_view.h>
#include <escher/message_table_cell_with_expression.h>
#include <escher/stack_view_controller.h>
#include <ion/storage.h>
namespace Graph {
class TypeParameterController : public ViewController, public ListViewDataSource, public SelectableTableViewDataSource {
public:
TypeParameterController(Responder * parentResponder);
void didBecomeFirstResponder() override;
bool handleEvent(Ion::Events::Event event) override;
// ViewController
const char * title() override;
View * view() override { return &m_selectableTableView; }
void viewWillAppear() override;
// ListViewDataSource
int numberOfRows() override { return k_numberOfTypes; }
KDCoordinate rowHeight(int j) override;
void willDisplayCellForIndex(HighlightCell * cell, int index) override;
MessageTableCellWithExpression * reusableCell(int index, int type) override;
int reusableCellCount(int type) override { return k_numberOfTypes; }
int typeAtLocation(int i, int j) override { return 0; }
void setRecord(Ion::Storage::Record record) { m_record = record; }
private:
constexpr static int k_numberOfTypes = 3;
StackViewController * stackController() const;
SelectableTableView m_selectableTableView;
MessageTableCellWithExpression m_cells[k_numberOfTypes];
Ion::Storage::Record m_record;
};
}
#endif