diff --git a/apps/geometry/Makefile b/apps/geometry/Makefile index b44a60242..0047120de 100644 --- a/apps/geometry/Makefile +++ b/apps/geometry/Makefile @@ -9,6 +9,7 @@ app_geometry_src = $(addprefix apps/geometry/,\ list/figure_parameters_controller.cpp \ list/objects_controller.cpp \ list/message_table_cell_with_selector.cpp \ + figure_store.cpp \ ) apps_src += $(app_geometry_src) diff --git a/apps/geometry/figure_store.cpp b/apps/geometry/figure_store.cpp new file mode 100644 index 000000000..b67aa4115 --- /dev/null +++ b/apps/geometry/figure_store.cpp @@ -0,0 +1 @@ +#include "figure_store.h" \ No newline at end of file diff --git a/apps/geometry/figure_store.h b/apps/geometry/figure_store.h new file mode 100644 index 000000000..fe170417a --- /dev/null +++ b/apps/geometry/figure_store.h @@ -0,0 +1,14 @@ +#ifndef FIGURE__STORE__H +#define FIGURE__STORE__H + +#include "../shared/expression_model_store.h" + +namespace Geometry { + +class FigureStore: Shared::ExpressionModelStore { + +}; + +} + +#endif diff --git a/apps/geometry/figures/figure_type.h b/apps/geometry/figures/figure_type.h index bd4fddefc..201092aa3 100644 --- a/apps/geometry/figures/figure_type.h +++ b/apps/geometry/figures/figure_type.h @@ -6,7 +6,7 @@ namespace Geometry { enum class FigureType { None = 0, // Used to trigger assert in debug mode Expression, // It's not a real figure type but we use it to build figures like points - + Point, Line, diff --git a/apps/geometry/figures/point_by_coordinates.h b/apps/geometry/figures/point_by_coordinates.h index e06ffed68..a76773345 100644 --- a/apps/geometry/figures/point_by_coordinates.h +++ b/apps/geometry/figures/point_by_coordinates.h @@ -5,7 +5,7 @@ #include "point.h" namespace Geometry { - + class PointByCoordinatesNode : public PointNode { public: virtual size_t size() const override { return sizeof(PointByCoordinatesNode); } diff --git a/apps/geometry/list/figure_parameters_controller.cpp b/apps/geometry/list/figure_parameters_controller.cpp index 1a9bee70a..15d3b3f76 100644 --- a/apps/geometry/list/figure_parameters_controller.cpp +++ b/apps/geometry/list/figure_parameters_controller.cpp @@ -3,12 +3,17 @@ namespace Geometry { -FigureParametersController::FigureParametersController(Responder * parentResponder): +FigureParametersController::FigureParametersController(Responder * parentResponder): ViewController(parentResponder), m_lastSelectedRow(0), - m_selectableTableView(this) + m_selectableTableView(this), + m_okButton(&m_selectableTableView, I18n::Message::Ok, Invocation([](void * context, void * sender) { + FigureParametersController * parameterController = (FigureParametersController *) context; + parameterController->returnToMenu(); + return true; + }, this)) { - for (int i = 0; i < k_choiceCells; i++) { + for (int i = 0; i < k_choiceCells; i++) { m_choicesCells[i].setParentResponder(&m_selectableTableView); } for (int i = 0; i < k_textCells; i++) { @@ -31,27 +36,32 @@ void FigureParametersController::viewWillAppear() { selectRow(m_lastSelectedRow); } -bool FigureParametersController::handleEvent(Ion::Events::Event event) { - if (event == Ion::Events::OK || event == Ion::Events::EXE) { - StackViewController * stack = static_cast(parentResponder()); - stack->pop(); - stack->pop(); - stack->pop(); - return true; - } - return false; +void FigureParametersController::returnToMenu() { + StackViewController * stack = static_cast(parentResponder()); + stack->pop(); + stack->pop(); + stack->pop(); } /* ListViewDataSource */ int FigureParametersController::typeAtLocation(int i, int j) { - return (int) m_typeOfParametersAtIndexFunction(i); + if (j == m_numberOfParametersFunction()) { + return 0; // It's equivalent to "None", so we can use it for button cell + } + return (int) m_typeOfParametersAtIndexFunction(j); } int FigureParametersController::reusableCellCount(int type) { + if (type == 0) { + return 1; + } return type == (int) FigureType::Expression ? k_textCells: k_choiceCells; } HighlightCell * FigureParametersController::reusableCell(int index, int type) { + if (type == 0) { + return &m_okButton; + } if (type == (int) FigureType::Expression) { return &m_textCells[index]; } @@ -59,13 +69,19 @@ HighlightCell * FigureParametersController::reusableCell(int index, int type) { } int FigureParametersController::numberOfRows() const { - return m_numberOfParametersFunction(); + return m_numberOfParametersFunction() + 1; } KDCoordinate FigureParametersController::rowHeight(int j) { + if (j == numberOfRows()-1) { + return Metric::ParameterCellHeight+k_buttonMargin; + } return Metric::ParameterCellHeight; } KDCoordinate FigureParametersController::cumulatedHeightFromIndex(int j) { + if (j == numberOfRows()) { + return j*Metric::ParameterCellHeight+k_buttonMargin; + } return Metric::ParameterCellHeight*j; } @@ -84,6 +100,14 @@ bool FigureParametersController::textFieldShouldFinishEditing(TextField * textFi } bool FigureParametersController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) { + m_selectableTableView.reloadCellAtLocation(0, selectedRow()); + m_selectableTableView.reloadData(); + textField->setText(text); + if (event == Ion::Events::EXE || event == Ion::Events::OK) { + m_selectableTableView.selectCellAtLocation(selectedColumn(), selectedRow() + 1); + } else { + m_selectableTableView.handleEvent(event); + } return true; } diff --git a/apps/geometry/list/figure_parameters_controller.h b/apps/geometry/list/figure_parameters_controller.h index 203ff81de..362111b97 100644 --- a/apps/geometry/list/figure_parameters_controller.h +++ b/apps/geometry/list/figure_parameters_controller.h @@ -7,40 +7,40 @@ #include "../figures/figure.h" #include "../../shared/parameter_text_field_delegate.h" #include "../../shared/input_event_handler_delegate.h" +#include "../../shared/button_with_separator.h" namespace Geometry { -typedef int (*NumberOfParametersFunction)(); -typedef FigureType (*TypeOfParametersAtIndexFunction)(int); +typedef int (*NumberOfParametersFunction)(); +typedef FigureType (*TypeOfParametersAtIndexFunction)(int); /** - * \brief Controller returnig the parameter choosen by the user to define the figure + * \brief Controller returning the parameter choosen by the user to define the figure */ class FigureParametersController : public ViewController, public ListViewDataSource, public SelectableTableViewDataSource, public Shared::ParameterTextFieldDelegate, public Shared::InputEventHandlerDelegate { public: FigureParametersController(Responder * parentResponder); void setParametersInfoFunctions(NumberOfParametersFunction numberOfParametersFunction, TypeOfParametersAtIndexFunction typeOfParametersAtIndexFunction); - + void returnToMenu(); /* ViewController */ const char * title() override { return I18n::translate(I18n::Message::ParametersChoice); } // We want to avoid using half of the screen just for titles - virtual DisplayParameter displayParameter() override { return DisplayParameter::DoNotShowOwnTitle; } + virtual DisplayParameter displayParameter() override { return DisplayParameter::DoNotShowOwnTitle; } View * view() override { return &m_selectableTableView; }; /* Responder */ void didBecomeFirstResponder() override; void viewWillAppear() override; - bool handleEvent(Ion::Events::Event event) override; /* ListViewDataSource */ - int typeAtLocation(int i, int j) override; // TO IMPLEMENT + int typeAtLocation(int i, int j) override; int reusableCellCount(int type) override; // TO IMPLEMENT - HighlightCell * reusableCell(int index, int type) override; // TO IMPLEMENT + HighlightCell * reusableCell(int index, int type) override; int numberOfRows() const override; KDCoordinate rowHeight(int j) override; KDCoordinate cumulatedHeightFromIndex(int j) override; int indexFromCumulatedHeight(KDCoordinate offsetY) override; - void willDisplayCellForIndex(HighlightCell * cell, int index) override; + void willDisplayCellForIndex(HighlightCell * cell, int index) override; /* InputEventHandlerDelegate */ bool textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) override; @@ -50,9 +50,11 @@ private: SelectableTableView m_selectableTableView; constexpr static int k_textCells = 2; constexpr static int k_choiceCells = 3; + constexpr static int k_buttonMargin = 6; int m_lastSelectedRow; MessageTableCellWithEditableText m_textCells[k_textCells]; MessageTableCellWithSelector m_choicesCells[k_choiceCells]; + ButtonWithSeparator m_okButton; NumberOfParametersFunction m_numberOfParametersFunction; TypeOfParametersAtIndexFunction m_typeOfParametersAtIndexFunction; }; diff --git a/apps/geometry/list/figures_controller.h b/apps/geometry/list/figures_controller.h index bead7aedf..1c9e44cbb 100644 --- a/apps/geometry/list/figures_controller.h +++ b/apps/geometry/list/figures_controller.h @@ -13,7 +13,7 @@ class FiguresController : public ViewController, public SelectableTableViewDataS public: FiguresController(Responder * parentResponder); - /* ViewController */ + /* ViewController */ View * view() override { return &m_selectableTableView; } /* Responder */ @@ -43,4 +43,4 @@ private: }; } -#endif \ No newline at end of file +#endif \ No newline at end of file