mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[apps] In sequence: enable to change initial sequence index
This commit is contained in:
committed by
EmilieNumworks
parent
967e963657
commit
509ee874b4
@@ -1,6 +1,7 @@
|
||||
#include "list_parameter_controller.h"
|
||||
#include "list_controller.h"
|
||||
#include "../app.h"
|
||||
#include "../../apps_container.h"
|
||||
|
||||
using namespace Poincare;
|
||||
using namespace Shared;
|
||||
@@ -8,8 +9,9 @@ using namespace Shared;
|
||||
namespace Sequence {
|
||||
|
||||
ListParameterController::ListParameterController(ListController * listController, SequenceStore * sequenceStore) :
|
||||
Shared::ListParameterController(listController, sequenceStore, I18n::Message::SequenceColor, I18n::Message::DeleteSequence),
|
||||
Shared::ListParameterController(listController, sequenceStore, I18n::Message::SequenceColor, I18n::Message::DeleteSequence, this),
|
||||
m_typeCell(I18n::Message::SequenceType),
|
||||
m_initialRankCell(&m_selectableTableView, this, m_draftTextBuffer, I18n::Message::FirstTermIndex),
|
||||
m_typeParameterController(this, sequenceStore, listController, TableCell::Layout::Horizontal, Metric::CommonTopMargin, Metric::CommonRightMargin,
|
||||
Metric::CommonBottomMargin, Metric::CommonLeftMargin),
|
||||
m_sequence(nullptr)
|
||||
@@ -26,30 +28,38 @@ void ListParameterController::setFunction(Shared::Function * function) {
|
||||
}
|
||||
|
||||
bool ListParameterController::handleEvent(Ion::Events::Event event) {
|
||||
bool hasAdditionalRow = hasInitialRankRow();
|
||||
#if FUNCTION_COLOR_CHOICE
|
||||
if (event == Ion::Events::OK || event == Ion::Events::EXE || (event == Ion::Events::Right && selectedRow() == 1)) {
|
||||
#else
|
||||
if (event == Ion::Events::OK || event == Ion::Events::EXE || (event == Ion::Events::Right && selectedRow() == 0)) {
|
||||
#endif
|
||||
int selectedRowIndex = selectedRow();
|
||||
switch (selectedRowIndex) {
|
||||
#if FUNCTION_COLOR_CHOICE
|
||||
case 0:
|
||||
return handleEnterOnRow(selectedRowIndex);
|
||||
case 1:
|
||||
if (selectedRowIndex == 0) {
|
||||
return handleEnterOnRow(selectedRowIndex);
|
||||
}
|
||||
if (selectedRowIndex == 1) {
|
||||
#else
|
||||
case 0:
|
||||
if (selectedRowIndex == 0) {
|
||||
#endif
|
||||
{
|
||||
StackViewController * stack = (StackViewController *)(parentResponder());
|
||||
m_typeParameterController.setSequence(m_sequence);
|
||||
stack->push(&m_typeParameterController);
|
||||
return true;
|
||||
}
|
||||
StackViewController * stack = (StackViewController *)(parentResponder());
|
||||
m_typeParameterController.setSequence(m_sequence);
|
||||
stack->push(&m_typeParameterController);
|
||||
return true;
|
||||
}
|
||||
#if FUNCTION_COLOR_CHOICE
|
||||
case 3:
|
||||
if (selectedRowIndex == 2+hasAdditionalRow) {
|
||||
|
||||
#else
|
||||
case 2:
|
||||
if (selectedRowIndex == 1+hasAdditionalRow) {
|
||||
#endif
|
||||
return handleEnterOnRow(selectedRowIndex-hasAdditionalRow-1);
|
||||
}
|
||||
#if FUNCTION_COLOR_CHOICE
|
||||
if (selectedRowIndex == 3+hasAdditionalRow) {
|
||||
#else
|
||||
if (selectedRowIndex == 2+hasAdditionalRow) {
|
||||
#endif
|
||||
if (m_functionStore->numberOfFunctions() > 0) {
|
||||
m_functionStore->removeFunction(m_function);
|
||||
@@ -58,15 +68,16 @@ bool ListParameterController::handleEvent(Ion::Events::Event event) {
|
||||
stack->pop();
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return handleEnterOnRow(selectedRowIndex-1);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int ListParameterController::numberOfRows() {
|
||||
return k_totalNumberOfCell;
|
||||
if (hasInitialRankRow()) {
|
||||
return k_totalNumberOfCell;
|
||||
}
|
||||
return k_totalNumberOfCell-1;
|
||||
};
|
||||
|
||||
HighlightCell * ListParameterController::reusableCell(int index) {
|
||||
@@ -75,8 +86,12 @@ HighlightCell * ListParameterController::reusableCell(int index) {
|
||||
return Shared::ListParameterController::reusableCell(index);*/
|
||||
case 0://1:
|
||||
return &m_typeCell;
|
||||
case 1:
|
||||
if (hasInitialRankRow()) {
|
||||
return &m_initialRankCell;
|
||||
}
|
||||
default:
|
||||
return Shared::ListParameterController::reusableCell(index-1);
|
||||
return Shared::ListParameterController::reusableCell(index-1-hasInitialRankRow());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,10 +100,78 @@ int ListParameterController::reusableCellCount() {
|
||||
}
|
||||
|
||||
void ListParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) {
|
||||
cell->setHighlighted(index == selectedRow()); // See FIXME in SelectableTableView::reloadData()
|
||||
Shared::ListParameterController::willDisplayCellForIndex(cell, index);
|
||||
if (cell == &m_typeCell && m_sequence != nullptr) {
|
||||
m_typeCell.setExpression(m_sequence->definitionName());
|
||||
}
|
||||
if (cell == &m_initialRankCell && m_sequence != nullptr) {
|
||||
MessageTableCellWithEditableText * myCell = (MessageTableCellWithEditableText *) cell;
|
||||
if (myCell->isEditing()) {
|
||||
return;
|
||||
}
|
||||
char buffer[Sequence::k_initialRankNumberOfDigits+1];
|
||||
Integer(m_sequence->initialRank()).writeTextInBuffer(buffer, Sequence::k_initialRankNumberOfDigits+1);
|
||||
myCell->setAccessoryText(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
bool ListParameterController::textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) {
|
||||
return event == Ion::Events::Down || event == Ion::Events::Up || TextFieldDelegate::textFieldShouldFinishEditing(textField, event);
|
||||
}
|
||||
|
||||
bool ListParameterController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {
|
||||
AppsContainer * appsContainer = ((TextFieldDelegateApp *)app())->container();
|
||||
Context * globalContext = appsContainer->globalContext();
|
||||
double floatBody = Expression::approximateToScalar<double>(text, *globalContext);
|
||||
int index = std::round(floatBody);
|
||||
if (std::isnan(floatBody) || std::isinf(floatBody)) {
|
||||
app()->displayWarning(I18n::Message::UndefinedValue);
|
||||
return false;
|
||||
}
|
||||
if (index < 0) {
|
||||
app()->displayWarning(I18n::Message::ForbiddenValue);
|
||||
}
|
||||
m_sequence->setInitialRank(index);
|
||||
// Invalidate sequence context cache when changing sequence type
|
||||
static_cast<App *>(app())->localContext()->resetCache();
|
||||
m_selectableTableView.reloadCellAtLocation(0, selectedRow());
|
||||
m_selectableTableView.handleEvent(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ListParameterController::tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY) {
|
||||
if (previousSelectedCellX == t->selectedColumn() && previousSelectedCellY == t->selectedRow()) {
|
||||
return;
|
||||
}
|
||||
if (!hasInitialRankRow()) {
|
||||
return;
|
||||
}
|
||||
#if FUNCTION_COLOR_CHOICE
|
||||
if (previousSelectedCellY == 2) {
|
||||
#else
|
||||
if (previousSelectedCellY == 1) {
|
||||
#endif
|
||||
MessageTableCellWithEditableText * myCell = (MessageTableCellWithEditableText *)t->cellAtLocation(previousSelectedCellX, previousSelectedCellY);
|
||||
myCell->setEditing(false);
|
||||
app()->setFirstResponder(&m_selectableTableView);
|
||||
}
|
||||
#if FUNCTION_COLOR_CHOICE
|
||||
if (t->selectedRow() == 2) {
|
||||
#else
|
||||
if (t->selectedRow() == 1) {
|
||||
#endif
|
||||
MessageTableCellWithEditableText * myNewCell = (MessageTableCellWithEditableText *)t->selectedCell();
|
||||
app()->setFirstResponder(myNewCell);
|
||||
}
|
||||
}
|
||||
|
||||
TextFieldDelegateApp * ListParameterController::textFieldDelegateApp() {
|
||||
return (TextFieldDelegateApp *)app();
|
||||
}
|
||||
|
||||
bool ListParameterController::hasInitialRankRow() {
|
||||
return m_sequence && m_sequence->type() != Sequence::Type::Explicite;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define SEQUENCE_LIST_PARAM_CONTROLLER_H
|
||||
|
||||
#include "../../shared/list_parameter_controller.h"
|
||||
#include "../../shared/parameter_text_field_delegate.h"
|
||||
#include "../sequence.h"
|
||||
#include "../sequence_store.h"
|
||||
#include "type_parameter_controller.h"
|
||||
@@ -10,7 +11,7 @@ namespace Sequence {
|
||||
|
||||
class ListController;
|
||||
|
||||
class ListParameterController : public Shared::ListParameterController {
|
||||
class ListParameterController : public Shared::ListParameterController, public SelectableTableViewDelegate, public Shared::ParameterTextFieldDelegate {
|
||||
public:
|
||||
ListParameterController(ListController * list, SequenceStore * sequenceStore);
|
||||
const char * title() override;
|
||||
@@ -20,13 +21,21 @@ public:
|
||||
HighlightCell * reusableCell(int index) override;
|
||||
int reusableCellCount() override;
|
||||
void willDisplayCellForIndex(HighlightCell * cell, int index) override;
|
||||
|
||||
bool textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) override;
|
||||
bool textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) override;
|
||||
void tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY) override;
|
||||
Shared::TextFieldDelegateApp * textFieldDelegateApp() override;
|
||||
private:
|
||||
#if FUNCTION_COLOR_CHOICE
|
||||
constexpr static int k_totalNumberOfCell = 4;
|
||||
constexpr static int k_totalNumberOfCell = 5;
|
||||
#else
|
||||
constexpr static int k_totalNumberOfCell = 3;
|
||||
constexpr static int k_totalNumberOfCell = 4;
|
||||
#endif
|
||||
bool hasInitialRankRow();
|
||||
MessageTableCellWithChevronAndExpression m_typeCell;
|
||||
MessageTableCellWithEditableText m_initialRankCell;
|
||||
char m_draftTextBuffer[MessageTableCellWithEditableText::k_bufferLength];
|
||||
TypeParameterController m_typeParameterController;
|
||||
Sequence * m_sequence;
|
||||
};
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
namespace Shared {
|
||||
|
||||
ListParameterController::ListParameterController(Responder * parentResponder, FunctionStore * functionStore, I18n::Message functionColorMessage, I18n::Message deleteFunctionMessage) :
|
||||
ListParameterController::ListParameterController(Responder * parentResponder, FunctionStore * functionStore, I18n::Message functionColorMessage, I18n::Message deleteFunctionMessage, SelectableTableViewDelegate * tableDelegate) :
|
||||
ViewController(parentResponder),
|
||||
m_selectableTableView(this, this, 0, 1, Metric::CommonTopMargin, Metric::CommonRightMargin,
|
||||
Metric::CommonBottomMargin, Metric::CommonLeftMargin, this),
|
||||
Metric::CommonBottomMargin, Metric::CommonLeftMargin, this, tableDelegate),
|
||||
m_functionStore(functionStore),
|
||||
m_function(nullptr),
|
||||
#if FUNCTION_COLOR_CHOICE
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Shared {
|
||||
|
||||
class ListParameterController : public ViewController, public SimpleListViewDataSource, public SelectableTableViewDataSource {
|
||||
public:
|
||||
ListParameterController(Responder * parentResponder, FunctionStore * functionStore, I18n::Message functionColorMessage, I18n::Message deleteFunctionMessage);
|
||||
ListParameterController(Responder * parentResponder, FunctionStore * functionStore, I18n::Message functionColorMessage, I18n::Message deleteFunctionMessage, SelectableTableViewDelegate * tableDelegate = nullptr);
|
||||
|
||||
View * view() override;
|
||||
const char * title() override;
|
||||
|
||||
Reference in New Issue
Block a user