diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index cfb3d9669..5e189b92d 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -8,9 +8,9 @@ AppsContainer::AppsContainer() : Container(), m_window(AppsWindow()), m_homeApp(this), - m_graphApp(this, &m_globalContext), + m_graphApp(this, &m_globalContext, &m_preferences), m_probabilityApp(this), - m_calculationApp(this, &m_globalContext), + m_calculationApp(this, &m_globalContext, &m_preferences), m_regressionApp(this), m_settingsApp(this, &m_preferences), m_statisticsApp(this), @@ -18,6 +18,7 @@ AppsContainer::AppsContainer() : m_preferences(Preferences()), m_variableBoxController(&m_globalContext) { + refreshPreferences(); } int AppsContainer::numberOfApps() { @@ -71,6 +72,10 @@ void AppsContainer::switchTo(App * app) { Container::switchTo(app); } +void AppsContainer::refreshPreferences() { + m_window.refreshPreferences(&m_preferences); +} + Window * AppsContainer::window() { return &m_window; } diff --git a/apps/apps_container.h b/apps/apps_container.h index cfa5a7219..fa1c8185c 100644 --- a/apps/apps_container.h +++ b/apps/apps_container.h @@ -29,6 +29,7 @@ public: VariableBoxController * variableBoxController(); bool handleEvent(Ion::Events::Event event) override; void switchTo(App * app) override; + void refreshPreferences(); private: Window * window() override; static constexpr int k_numberOfApps = 9; diff --git a/apps/apps_window.cpp b/apps/apps_window.cpp index daa22be70..6ef170aa4 100644 --- a/apps/apps_window.cpp +++ b/apps/apps_window.cpp @@ -18,6 +18,10 @@ void AppsWindow::updateBatteryLevel() { m_titleBarView.setChargeState(Ion::Battery::Charge::EMPTY); } +void AppsWindow::refreshPreferences(Preferences * preferences) { + m_titleBarView.setPreferences(preferences); +} + int AppsWindow::numberOfSubviews() const { return (m_contentView == nullptr ? 1 : 2); } diff --git a/apps/apps_window.h b/apps/apps_window.h index 4f05157c6..5af6c7849 100644 --- a/apps/apps_window.h +++ b/apps/apps_window.h @@ -9,6 +9,7 @@ public: AppsWindow(); void setTitle(const char * title); void updateBatteryLevel(); + void refreshPreferences(Preferences * preferences); private: constexpr static KDCoordinate k_titleBarHeight = 18; int numberOfSubviews() const override; diff --git a/apps/calculation/app.cpp b/apps/calculation/app.cpp index aa703240b..737c56172 100644 --- a/apps/calculation/app.cpp +++ b/apps/calculation/app.cpp @@ -3,9 +3,10 @@ namespace Calculation { -App::App(Container * container, Context * context) : +App::App(Container * container, Context * context, Preferences * preferences) : TextFieldDelegateApp(container, &m_editExpressionController, "Calculs", "CALCULS", ImageStore::CalculationIcon), m_localContext(LocalContext((GlobalContext *)context, &m_calculationStore)), + m_preferences(preferences), m_calculationStore(CalculationStore()), m_historyController(HistoryController(&m_editExpressionController, &m_calculationStore)), m_editExpressionController(EditExpressionController(&m_modalViewController, &m_historyController, &m_calculationStore)) @@ -16,4 +17,8 @@ Context * App::localContext() { return &m_localContext; } +Preferences * App::preferences() { + return m_preferences; +} + } diff --git a/apps/calculation/app.h b/apps/calculation/app.h index d16b11d57..5ed227e23 100644 --- a/apps/calculation/app.h +++ b/apps/calculation/app.h @@ -5,16 +5,19 @@ #include "local_context.h" #include "history_controller.h" #include "../text_field_delegate_app.h" +#include "../preferences.h" #include namespace Calculation { class App : public TextFieldDelegateApp { public: - App(Container * container, Context * context); + App(Container * container, Context * context, Preferences * preferences); Context * localContext() override; + Preferences * preferences(); private: LocalContext m_localContext; + Preferences * m_preferences; CalculationStore m_calculationStore; HistoryController m_historyController; EditExpressionController m_editExpressionController; diff --git a/apps/calculation/calculation.cpp b/apps/calculation/calculation.cpp index 8e967b41d..349f2b966 100644 --- a/apps/calculation/calculation.cpp +++ b/apps/calculation/calculation.cpp @@ -11,59 +11,6 @@ Calculation::Calculation() : { } -Calculation & Calculation::operator= (const Calculation & other) { - strlcpy(m_text, other.m_text, sizeof(m_text)); - if (m_input != nullptr) { - delete m_input; - } - m_input = nullptr; - if (other.m_input) { - m_input = Expression::parse(m_text); - } - if (m_inputLayout != nullptr) { - delete m_inputLayout; - } - m_inputLayout = nullptr; - if (m_input && other.m_inputLayout) { - m_inputLayout = m_input->createLayout(); - } - if (m_output != nullptr) { - delete m_output; - } - m_output = nullptr; - if (other.m_output) { - m_output = other.m_output->clone(); - } - if (m_outputLayout != nullptr) { - delete m_outputLayout; - } - m_outputLayout = nullptr; - if (m_output && other.m_outputLayout) { - m_outputLayout = m_output->createLayout(); - } - return *this; -} - -void Calculation::setContent(const char * c, Context * context) { - strlcpy(m_text, c, sizeof(m_text)); - if (m_input != nullptr) { - delete m_input; - } - m_input = Expression::parse(m_text); - if (m_inputLayout != nullptr) { - delete m_inputLayout; - } - m_inputLayout = m_input->createLayout(); - if (m_output != nullptr) { - delete m_outputLayout; - } - m_output = m_input->evaluate(*context); - if (m_outputLayout != nullptr) { - delete m_outputLayout; - } - m_outputLayout = m_output->createLayout(); -} - Calculation::~Calculation() { if (m_inputLayout != nullptr) { delete m_inputLayout; @@ -79,6 +26,46 @@ Calculation::~Calculation() { } } +void Calculation::reset() { + m_text[0] = 0; + if (m_input != nullptr) { + delete m_input; + } + m_input = nullptr; + if (m_inputLayout != nullptr) { + delete m_inputLayout; + } + m_inputLayout = nullptr; + if (m_output != nullptr) { + delete m_output; + } + m_output = nullptr; + if (m_outputLayout != nullptr) { + delete m_outputLayout; + } + m_outputLayout = nullptr; +} + +void Calculation::setContent(const char * c, Context * context, Preferences * preferences) { + strlcpy(m_text, c, sizeof(m_text)); + if (m_input != nullptr) { + delete m_input; + } + m_input = Expression::parse(m_text); + if (m_inputLayout != nullptr) { + delete m_inputLayout; + } + m_inputLayout = m_input->createLayout(preferences->displayMode()); + if (m_output != nullptr) { + delete m_output; + } + m_output = m_input->evaluate(*context); + if (m_outputLayout != nullptr) { + delete m_outputLayout; + } + m_outputLayout = m_output->createLayout(preferences->displayMode()); +} + const char * Calculation::text() { return m_text; } @@ -100,7 +87,7 @@ ExpressionLayout * Calculation::outputLayout() { } bool Calculation::isEmpty() { - if (m_input == nullptr) { + if (m_output == nullptr) { return true; } return false; diff --git a/apps/calculation/calculation.h b/apps/calculation/calculation.h index 907a3dd27..477e16fad 100644 --- a/apps/calculation/calculation.h +++ b/apps/calculation/calculation.h @@ -2,20 +2,27 @@ #define CALCULATION_CALCULATION_H #include +#include "../preferences.h" namespace Calculation { class Calculation { public: Calculation(); - ~Calculation(); // Delete expression and layout, if needed - Calculation & operator= (const Calculation & other); + ~Calculation(); // Delete expression and layout, if needed + /* The copy assignment operator is deleted as its default implementation does + * not create new expressions. The new object thus become obsolete as soon + * as the copy is deleted (because of our implementation of deletion). To + * avoid any use of obsolete object, we prevent to copy and assign. */ + Calculation & operator= (const Calculation & other) = delete; + /* c.reset() is the equivalent of c = Calculation() without copy assingment. */ + void reset(); const char * text(); Expression * input(); ExpressionLayout * inputLayout(); Expression * output(); ExpressionLayout * outputLayout(); - void setContent(const char * c, Context * context); + void setContent(const char * c, Context * context, Preferences * preferences); bool isEmpty(); constexpr static int k_maximalExpressionTextLength = 255; private: diff --git a/apps/calculation/calculation_store.cpp b/apps/calculation/calculation_store.cpp index e2c574966..af8995875 100644 --- a/apps/calculation/calculation_store.cpp +++ b/apps/calculation/calculation_store.cpp @@ -8,9 +8,9 @@ CalculationStore::CalculationStore() : { } -Calculation * CalculationStore::push(Calculation * c) { +Calculation * CalculationStore::push(const char * text, Context * context, Preferences * preferences) { Calculation * result = m_start; - *m_start++ = *c; + m_start++->setContent(text, context, preferences); if (m_start >= m_calculations + k_maxNumberOfCalculations) { m_start = m_calculations; } @@ -45,7 +45,7 @@ int CalculationStore::numberOfCalculations() { } void CalculationStore::deleteCalculationAtIndex(int i) { - *calculationAtIndex(i) = Calculation(); + calculationAtIndex(i)->reset(); } void CalculationStore::deleteAll() { @@ -53,7 +53,7 @@ void CalculationStore::deleteAll() { Calculation * currentCalc= m_start; while (currentCalc < m_calculations + k_maxNumberOfCalculations) { if (!currentCalc->isEmpty()) { - *currentCalc = Calculation(); + currentCalc->reset(); } currentCalc++; } diff --git a/apps/calculation/calculation_store.h b/apps/calculation/calculation_store.h index 8fc8e9a10..0008b6761 100644 --- a/apps/calculation/calculation_store.h +++ b/apps/calculation/calculation_store.h @@ -2,6 +2,7 @@ #define CALCULATION_CALCULATION_STORE_H #include "calculation.h" +#include "../preferences.h" namespace Calculation { @@ -11,7 +12,7 @@ class CalculationStore { public: CalculationStore(); Calculation * calculationAtIndex(int i); - Calculation * push(Calculation * c); + Calculation * push(const char * text, Context * context, Preferences * preferences); void deleteCalculationAtIndex(int i); void deleteAll(); int numberOfCalculations(); diff --git a/apps/calculation/edit_expression_controller.cpp b/apps/calculation/edit_expression_controller.cpp index d4edfe778..bc5653310 100644 --- a/apps/calculation/edit_expression_controller.cpp +++ b/apps/calculation/edit_expression_controller.cpp @@ -80,10 +80,8 @@ bool EditExpressionController::textFieldDidReceiveEvent(::TextField * textField, } bool EditExpressionController::textFieldDidFinishEditing(::TextField * textField, const char * text) { - Calculation calculation = Calculation(); App * calculationApp = (App *)app(); - calculation.setContent(textBody(), calculationApp->localContext()); - m_calculationStore->push(&calculation); + m_calculationStore->push(textBody(), calculationApp->localContext(), calculationApp->preferences()); m_historyController->reload(); m_contentView.mainView()->scrollToCell(0, m_historyController->numberOfRows()-1); m_contentView.textField()->setText(""); diff --git a/apps/calculation/history_controller.cpp b/apps/calculation/history_controller.cpp index e17c93c87..9561c2be1 100644 --- a/apps/calculation/history_controller.cpp +++ b/apps/calculation/history_controller.cpp @@ -60,18 +60,17 @@ bool HistoryController::handleEvent(Ion::Events::Event event) { HistoryViewCell::SubviewType subviewType = selectedCell->selectedSubviewType(); EditExpressionController * editController = (EditExpressionController *)parentResponder(); Calculation * calculation = m_calculationStore->calculationAtIndex(focusRow); - Calculation newCalculation; + const char * text; if (subviewType == HistoryViewCell::SubviewType::Input) { - newCalculation = *calculation; + text = calculation->text(); } else { char outputText[Calculation::k_maximalExpressionTextLength]; calculation->output()->writeTextInBuffer(outputText, Calculation::k_maximalExpressionTextLength); - /* TODO: this will work when we will parse float */ - //App * calculationApp = (App *)app(); - //newCalculation.setContent(outputText, calculationApp->localContext()); + text = outputText; } m_selectableTableView.deselectTable(); - m_calculationStore->push(&newCalculation); + App * calculationApp = (App *)app(); + m_calculationStore->push(text, calculationApp->localContext(), calculationApp->preferences()); reload(); m_selectableTableView.scrollToCell(0, numberOfRows()-1); app()->setFirstResponder(editController); diff --git a/apps/curve_view.cpp b/apps/curve_view.cpp index f7a236290..5acfbe2e0 100644 --- a/apps/curve_view.cpp +++ b/apps/curve_view.cpp @@ -83,7 +83,7 @@ void CurveView::computeLabels(Axis axis) { for (int index = 0; index < numberOfLabels(axis); index++) { Float(2.0f*step*(ceilf(min(axis)/(2.0f*step)))+index*2.0f*step).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), - Constant::ShortNumberOfSignificantDigits, Float::DisplayMode::Decimal); + Constant::ShortNumberOfSignificantDigits, Expression::DisplayMode::Auto); //TODO: check for size of label? strlcpy(label(axis, index), buffer, strlen(buffer)+1); } diff --git a/apps/editable_cell_table_view_controller.cpp b/apps/editable_cell_table_view_controller.cpp index 0697752a7..23f7fc6ed 100644 --- a/apps/editable_cell_table_view_controller.cpp +++ b/apps/editable_cell_table_view_controller.cpp @@ -63,7 +63,7 @@ int EditableCellTableViewController::indexFromCumulatedHeight(KDCoordinate offse return (offsetY-1) / k_cellHeight; } -void EditableCellTableViewController::willDisplayCellAtLocation(TableViewCell * cell, int i, int j) { +void EditableCellTableViewController::willDisplayCellAtLocationWithDisplayMode(TableViewCell * cell, int i, int j, Expression::DisplayMode displayMode) { EvenOddCell * myCell = (EvenOddCell *)cell; myCell->setEven(j%2 == 0); // The cell is editable @@ -80,7 +80,7 @@ void EditableCellTableViewController::willDisplayCellAtLocation(TableViewCell * return; } } - Float(dataAtLocation(i, j)).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); + Float(dataAtLocation(i, j)).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, displayMode); myEditableValueCell->setText(buffer); return; } @@ -88,7 +88,7 @@ void EditableCellTableViewController::willDisplayCellAtLocation(TableViewCell * void EditableCellTableViewController::didBecomeFirstResponder() { if (m_selectableTableView.selectedRow() == -1) { - m_selectableTableView.selectCellAtLocation(0, 0); + m_selectableTableView.selectCellAtLocation(0, 1); } else { int selectedRow = m_selectableTableView.selectedRow(); selectedRow = selectedRow >= numberOfRows() ? numberOfRows()-1 : selectedRow; diff --git a/apps/editable_cell_table_view_controller.h b/apps/editable_cell_table_view_controller.h index e687396e3..ebd6e7e49 100644 --- a/apps/editable_cell_table_view_controller.h +++ b/apps/editable_cell_table_view_controller.h @@ -2,6 +2,7 @@ #define APPS_EDITABLE_CELL_TABLE_VIEW_CONTROLLER_H #include +#include class EditableCellTableViewController : public ViewController, public TableViewDataSource, public SelectableTableViewDelegate, public TextFieldDelegate { public: @@ -14,7 +15,7 @@ public: void tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY) override; int numberOfRows() override; - void willDisplayCellAtLocation(TableViewCell * cell, int i, int j) override; + void willDisplayCellAtLocationWithDisplayMode(TableViewCell * cell, int i, int j, Expression::DisplayMode displayMode); KDCoordinate rowHeight(int j) override; KDCoordinate cumulatedHeightFromIndex(int j) override; int indexFromCumulatedHeight(KDCoordinate offsetY) override; diff --git a/apps/float_parameter_controller.cpp b/apps/float_parameter_controller.cpp index 80ea1e631..f0fb42765 100644 --- a/apps/float_parameter_controller.cpp +++ b/apps/float_parameter_controller.cpp @@ -27,7 +27,7 @@ int FloatParameterController::activeCell() { void FloatParameterController::willDisplayCellForIndex(TableViewCell * cell, int index) { EditableTextMenuListCell * myCell = (EditableTextMenuListCell *) cell; char buffer[Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)]; - Float(parameterAtIndex(index)).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); + Float(parameterAtIndex(index)).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Expression::DisplayMode::Auto); myCell->setAccessoryText(buffer); } diff --git a/apps/graph/app.cpp b/apps/graph/app.cpp index be898f627..a4cc1f27f 100644 --- a/apps/graph/app.cpp +++ b/apps/graph/app.cpp @@ -3,10 +3,11 @@ namespace Graph { -App::App(Container * container, Context * context) : +App::App(Container * container, Context * context, Preferences * preferences) : TextFieldDelegateApp(container, &m_inputViewController, "Fonctions", "FONCTIONS", ImageStore::GraphIcon), m_functionStore(FunctionStore()), m_xContext(VariableContext('x', context)), + m_preferences(preferences), m_listController(ListController(&m_listHeader, &m_functionStore, &m_listHeader)), m_listHeader(HeaderViewController(nullptr, &m_listController, &m_listController)), m_listStackViewController(StackViewController(&m_tabViewController, &m_listHeader)), @@ -31,4 +32,8 @@ Context * App::localContext() { return &m_xContext; } +Preferences * App::preferences() { + return m_preferences; +} + } diff --git a/apps/graph/app.h b/apps/graph/app.h index 6b17e2068..80bfa74ad 100644 --- a/apps/graph/app.h +++ b/apps/graph/app.h @@ -8,17 +8,20 @@ #include "list/list_controller.h" #include "values/values_controller.h" #include "../text_field_delegate_app.h" +#include "../preferences.h" namespace Graph { class App : public TextFieldDelegateApp { public: - App(Container * container, Context * context); + App(Container * container, Context * context, Preferences * preferences); InputViewController * inputViewController(); Context * localContext() override; + Preferences * preferences(); private: FunctionStore m_functionStore; VariableContext m_xContext; + Preferences * m_preferences; ListController m_listController; HeaderViewController m_listHeader; StackViewController m_listStackViewController; diff --git a/apps/graph/graph/goto_parameter_controller.cpp b/apps/graph/graph/goto_parameter_controller.cpp index 92f6a2f6d..5aa927420 100644 --- a/apps/graph/graph/goto_parameter_controller.cpp +++ b/apps/graph/graph/goto_parameter_controller.cpp @@ -48,4 +48,12 @@ void GoToParameterController::setFunction(Function * function) { m_function = function; } +bool GoToParameterController::textFieldDidFinishEditing(TextField * textField, const char * text) { + FloatParameterController::textFieldDidFinishEditing(textField, text); + StackViewController * stack = (StackViewController *)parentResponder(); + stack->pop(); + stack->pop(); + return true; +} + } diff --git a/apps/graph/graph/goto_parameter_controller.h b/apps/graph/graph/goto_parameter_controller.h index 8a2b75a72..546155282 100644 --- a/apps/graph/graph/goto_parameter_controller.h +++ b/apps/graph/graph/goto_parameter_controller.h @@ -16,6 +16,7 @@ public: TableViewCell * reusableCell(int index) override; int reusableCellCount() override; void setFunction(Function * function); + bool textFieldDidFinishEditing(TextField * textField, const char * text) override; private: float parameterAtIndex(int index) override; void setParameterAtIndex(int parameterIndex, float f) override; diff --git a/apps/graph/graph/graph_controller.cpp b/apps/graph/graph/graph_controller.cpp index 79f67f0dc..27339ab4f 100644 --- a/apps/graph/graph/graph_controller.cpp +++ b/apps/graph/graph/graph_controller.cpp @@ -109,11 +109,12 @@ bool GraphController::handleEnter() { } void GraphController::reloadBannerView() { + App * myApp = (App *)app(); char buffer[k_maxNumberOfCharacters+Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)]; const char * legend = "x = "; int legendLength = strlen(legend); strlcpy(buffer, legend, legendLength+1); - Float(m_cursor.x()).convertFloatToText(buffer+ legendLength, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Float::DisplayMode::Decimal); + Float(m_cursor.x()).convertFloatToText(buffer+ legendLength, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, myApp->preferences()->displayMode()); m_bannerView.setLegendAtIndex(buffer, 0); legend = "00(x) = "; @@ -121,7 +122,7 @@ void GraphController::reloadBannerView() { strlcpy(buffer, legend, legendLength+1); Function * f = m_functionStore->activeFunctionAtIndex(m_indexFunctionSelectedByCursor); buffer[1] = f->name()[0]; - Float(m_cursor.y()).convertFloatToText(buffer+legendLength, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Float::DisplayMode::Decimal); + Float(m_cursor.y()).convertFloatToText(buffer+legendLength, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, myApp->preferences()->displayMode()); m_bannerView.setLegendAtIndex(buffer+1, 1); if (m_bannerView.displayDerivative()) { @@ -129,7 +130,7 @@ void GraphController::reloadBannerView() { buffer[1] = '\''; App * graphApp = (Graph::App *)app(); float y = f->approximateDerivative(m_cursor.x(), graphApp->localContext()); - Float(y).convertFloatToText(buffer + legendLength, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Float::DisplayMode::Decimal); + Float(y).convertFloatToText(buffer + legendLength, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, myApp->preferences()->displayMode()); m_bannerView.setLegendAtIndex(buffer, 2); } } diff --git a/apps/graph/values/values_controller.cpp b/apps/graph/values/values_controller.cpp index 7f0a8c817..bf2465200 100644 --- a/apps/graph/values/values_controller.cpp +++ b/apps/graph/values/values_controller.cpp @@ -122,7 +122,8 @@ int ValuesController::numberOfColumns() { } void ValuesController::willDisplayCellAtLocation(TableViewCell * cell, int i, int j) { - EditableCellTableViewController::willDisplayCellAtLocation(cell, i, j); + App * graphApp = (Graph::App *)app(); + willDisplayCellAtLocationWithDisplayMode(cell, i, j, graphApp->preferences()->displayMode()); if (cellAtLocationIsEditable(i, j)) { return; } @@ -165,11 +166,10 @@ void ValuesController::willDisplayCellAtLocation(TableViewCell * cell, int i, in EvenOddBufferTextCell * myValueCell = (EvenOddBufferTextCell *)cell; Function * function = functionAtColumn(i); float x = m_interval.element(j-1); - App * graphApp = (Graph::App *)app(); if (isDerivativeColumn(i)) { - Float(function->approximateDerivative(x, graphApp->localContext())).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); + Float(function->approximateDerivative(x, graphApp->localContext())).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, graphApp->preferences()->displayMode()); } else { - Float(function->evaluateAtAbscissa(x, graphApp->localContext())).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); + Float(function->evaluateAtAbscissa(x, graphApp->localContext())).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, graphApp->preferences()->displayMode()); } myValueCell->setText(buffer); } diff --git a/apps/node_navigation_controller.cpp b/apps/node_navigation_controller.cpp index 086f09729..71a766165 100644 --- a/apps/node_navigation_controller.cpp +++ b/apps/node_navigation_controller.cpp @@ -122,8 +122,9 @@ bool NodeNavigationController::selectSubMenu(Node * selectedNode) { } void NodeNavigationController::didBecomeFirstResponder() { - m_stack.resetStack(); m_listViewController.setNodeModel(nodeModel()); + StackViewController::didBecomeFirstResponder(); + m_stack.resetStack(); m_listViewController.setFirstSelectedRow(0); app()->setFirstResponder(&m_listViewController); } diff --git a/apps/preferences.cpp b/apps/preferences.cpp index c32c32aec..9bfb4ae4f 100644 --- a/apps/preferences.cpp +++ b/apps/preferences.cpp @@ -2,9 +2,9 @@ Preferences::Preferences() : m_angleUnit(AngleUnit::Degree), - m_displayMode(DisplayMode::Auto), + m_displayMode(Expression::DisplayMode::Auto), m_numberType(NumberType::Reel), - m_complexFormat(ComplexFormat::Cartesian), + m_complexFormat(ComplexFormat::Algebric), m_language(Language::French) { } @@ -19,11 +19,11 @@ void Preferences::setAngleUnit(AngleUnit angleUnit) { } } -Preferences::DisplayMode Preferences::displayMode() const { +Expression::DisplayMode Preferences::displayMode() const { return m_displayMode; } -void Preferences::setDisplayMode(DisplayMode displayMode) { +void Preferences::setDisplayMode(Expression::DisplayMode displayMode) { if (displayMode != m_displayMode) { m_displayMode = displayMode; } diff --git a/apps/preferences.h b/apps/preferences.h index 40c494754..013e14b57 100644 --- a/apps/preferences.h +++ b/apps/preferences.h @@ -1,22 +1,20 @@ #ifndef APPS_PREFERENCES_H #define APPS_PREFERENCES_H +#include + class Preferences { public: enum class AngleUnit { Degree = 0, Radian = 1 }; - enum class DisplayMode { - Auto = 0, - Scientific = 1 - }; enum class NumberType { Reel = 0, Complex = 1 }; enum class ComplexFormat { - Cartesian = 0, + Algebric = 0, Polar = 1 }; enum class Language { @@ -26,8 +24,8 @@ public: Preferences(); AngleUnit angleUnit() const; void setAngleUnit(AngleUnit angleUnit); - DisplayMode displayMode() const; - void setDisplayMode(DisplayMode displayMode); + Expression::DisplayMode displayMode() const; + void setDisplayMode(Expression::DisplayMode displayMode); NumberType numberType() const; void setNumberType(NumberType numberType); ComplexFormat complexFormat() const; @@ -36,7 +34,7 @@ public: void setLanguage(Language language); private: AngleUnit m_angleUnit; - DisplayMode m_displayMode; + Expression::DisplayMode m_displayMode; NumberType m_numberType; ComplexFormat m_complexFormat; Language m_language; diff --git a/apps/probability/app.cpp b/apps/probability/app.cpp index 816510d30..b7ea97389 100644 --- a/apps/probability/app.cpp +++ b/apps/probability/app.cpp @@ -6,7 +6,7 @@ namespace Probability { App::App(Container * container) : TextFieldDelegateApp(container, &m_stackViewController, "Probabilites", "PROBABILITES", ImageStore::ProbabilityIcon), m_lawController(LawController(nullptr)), - m_stackViewController(&m_modalViewController, &m_lawController, true) + m_stackViewController(&m_modalViewController, &m_lawController) { } diff --git a/apps/probability/calculation_controller.cpp b/apps/probability/calculation_controller.cpp index 9d3f514c2..4efbf78fe 100644 --- a/apps/probability/calculation_controller.cpp +++ b/apps/probability/calculation_controller.cpp @@ -9,6 +9,7 @@ namespace Probability { CalculationController::ContentView::ContentView(Responder * parentResponder, CalculationController * calculationController, Calculation * calculation) : + m_titleView(PointerTextView(KDText::FontSize::Small, "Calculer les probabilites", 0.5f, 0.5f, Palette::GreyDark, Palette::WallScreen)), m_lawCurveView(LawCurveView()), m_imageTableView(ImageTableView(parentResponder, calculation, calculationController)), m_calculationCell{EditableTextCell(parentResponder, calculationController, m_draftTextBuffer), @@ -29,66 +30,71 @@ void CalculationController::ContentView::setCalculation(Calculation * calculatio } int CalculationController::ContentView::numberOfSubviews() const { - return 2*m_calculation->numberOfParameters() + 2; + return 2*m_calculation->numberOfParameters() + 3; } View * CalculationController::ContentView::subviewAtIndex(int index) { - assert(index >= 0 && index < 8); + assert(index >= 0 && index < 9); if (index == 0) { - return &m_lawCurveView; + return &m_titleView; } if (index == 1) { - return &m_imageTableView; + return &m_lawCurveView; } if (index == 2) { + return &m_imageTableView; + } + if (index == 3) { m_text[0].setText(m_calculation->legendForParameterAtIndex(0)); m_text[0].setAlignment(0.5f, 0.5f); return &m_text[0]; } - if (index == 4) { + if (index == 5) { m_text[1].setText(m_calculation->legendForParameterAtIndex(1)); m_text[1].setAlignment(0.5f, 0.5f); return &m_text[1]; } - if (index == 6) { + if (index == 7) { m_text[2].setText(m_calculation->legendForParameterAtIndex(2)); m_text[2].setAlignment(0.5f, 0.5f); return &m_text[2]; } - if (index == 3 || index == 5 || index == 7) { - return &m_calculationCell[(index - 3)/2]; + if (index == 4 || index == 6 || index == 8) { + return &m_calculationCell[(index - 4)/2]; } return nullptr; } void CalculationController::ContentView::willDisplayEditableCellAtIndex(int index) { char buffer[Float::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits)]; - Float(m_calculation->parameterAtIndex(index)).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits, Float::DisplayMode::Decimal); + Float(m_calculation->parameterAtIndex(index)).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits, Expression::DisplayMode::Auto); m_calculationCell[index].setText(buffer); } void CalculationController::ContentView::layoutSubviews() { markRectAsDirty(bounds()); + KDCoordinate titleHeight = KDText::stringSize("", KDText::FontSize::Small).height()+k_titleHeightMargin; + m_titleView.setFrame(KDRect(0, 0, bounds().width(), titleHeight)); KDSize charSize = KDText::stringSize(" "); KDCoordinate xCoordinate = 0; - m_lawCurveView.setFrame(KDRect(0, ImageTableView::k_imageHeight, bounds().width(), bounds().height() - ImageTableView::k_imageHeight)); - m_imageTableView.setFrame(KDRect(xCoordinate, 0, ImageTableView::k_imageWidth, 3*ImageTableView::k_imageHeight)); - xCoordinate += ImageTableView::k_imageWidth + k_textMargin; + m_lawCurveView.setFrame(KDRect(0, titleHeight+ImageTableView::k_imageHeight, bounds().width(), bounds().height() - ImageTableView::k_imageHeight-titleHeight)); + m_imageTableView.setFrame(KDRect(xCoordinate, titleHeight, ImageTableView::k_imageWidth, 3*ImageTableView::k_imageHeight)); + xCoordinate += ImageTableView::k_imageWidth + k_textWidthMargin; KDCoordinate numberOfCharacters = strlen(m_calculation->legendForParameterAtIndex(0)); - m_text[0].setFrame(KDRect(xCoordinate, 0, numberOfCharacters*charSize.width(), ImageTableView::k_imageHeight)); - xCoordinate += numberOfCharacters*charSize.width() + k_textMargin; - m_calculationCell[0].setFrame(KDRect(xCoordinate, 0, k_textFieldWidth, ImageTableView::k_imageHeight)); - xCoordinate += k_textFieldWidth + k_textMargin; + m_text[0].setFrame(KDRect(xCoordinate, titleHeight, numberOfCharacters*charSize.width(), ImageTableView::k_imageHeight)); + xCoordinate += numberOfCharacters*charSize.width() + k_textWidthMargin; + m_calculationCell[0].setFrame(KDRect(xCoordinate, titleHeight, k_textFieldWidth, ImageTableView::k_imageHeight)); + xCoordinate += k_textFieldWidth + k_textWidthMargin; numberOfCharacters = strlen(m_calculation->legendForParameterAtIndex(1)); - m_text[1].setFrame(KDRect(xCoordinate, 0, numberOfCharacters*charSize.width(), ImageTableView::k_imageHeight)); - xCoordinate += numberOfCharacters*charSize.width() + k_textMargin; - m_calculationCell[1].setFrame(KDRect(xCoordinate, 0, k_textFieldWidth, ImageTableView::k_imageHeight)); - xCoordinate += k_textFieldWidth + k_textMargin; + m_text[1].setFrame(KDRect(xCoordinate, titleHeight, numberOfCharacters*charSize.width(), ImageTableView::k_imageHeight)); + xCoordinate += numberOfCharacters*charSize.width() + k_textWidthMargin; + m_calculationCell[1].setFrame(KDRect(xCoordinate, titleHeight, k_textFieldWidth, ImageTableView::k_imageHeight)); + xCoordinate += k_textFieldWidth + k_textWidthMargin; if (m_calculation->numberOfParameters() > 2) { numberOfCharacters = strlen(m_calculation->legendForParameterAtIndex(2));; - m_text[2].setFrame(KDRect(xCoordinate, 0, numberOfCharacters*charSize.width(), ImageTableView::k_imageHeight)); - xCoordinate += numberOfCharacters*charSize.width() + k_textMargin; - m_calculationCell[2].setFrame(KDRect(xCoordinate, 0, k_textFieldWidth, ImageTableView::k_imageHeight)); + m_text[2].setFrame(KDRect(xCoordinate, titleHeight, numberOfCharacters*charSize.width(), ImageTableView::k_imageHeight)); + xCoordinate += numberOfCharacters*charSize.width() + k_textWidthMargin; + m_calculationCell[2].setFrame(KDRect(xCoordinate, titleHeight, k_textFieldWidth, ImageTableView::k_imageHeight)); } for (int k = 0; k < m_calculation->numberOfParameters(); k++) { willDisplayEditableCellAtIndex(k); @@ -125,7 +131,7 @@ View * CalculationController::view() { } const char * CalculationController::title() const { - return "Calculer les probabilites"; + return m_titleBuffer; } void CalculationController::reload() { @@ -208,6 +214,7 @@ bool CalculationController::textFieldDidFinishEditing(TextField * textField, con } void CalculationController::didBecomeFirstResponder() { + updateTitle(); for (int subviewIndex = 0; subviewIndex < 2; subviewIndex++) { EditableTextCell * calculCell = m_contentView.calculationCellAtIndex(subviewIndex); calculCell->setHighlighted(false); @@ -227,4 +234,19 @@ void CalculationController::selectSubview(int subviewIndex) { m_highlightedSubviewIndex = subviewIndex; } +void CalculationController::updateTitle() { + int currentChar = 0; + for (int index = 0; index < m_law->numberOfParameter(); index++) { + m_titleBuffer[currentChar++] = m_law->parameterNameAtIndex(index)[0]; + strlcpy(m_titleBuffer+currentChar, " = ", 4); + currentChar += 3; + char buffer[Float::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits)]; + Float(m_law->parameterValueAtIndex(index)).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits, Expression::DisplayMode::Auto); + strlcpy(m_titleBuffer+currentChar, buffer, strlen(buffer)+1); + currentChar += strlen(buffer); + m_titleBuffer[currentChar++] = ' '; + } + m_titleBuffer[currentChar-1] = 0; +} + } diff --git a/apps/probability/calculation_controller.h b/apps/probability/calculation_controller.h index 377dcea1a..512f4fab6 100644 --- a/apps/probability/calculation_controller.h +++ b/apps/probability/calculation_controller.h @@ -23,6 +23,7 @@ public: bool textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) override; bool textFieldDidFinishEditing(TextField * textField, const char * text) override; private: + void updateTitle(); Calculation * m_calculation; class ContentView : public View { public: @@ -38,9 +39,11 @@ private: constexpr static int k_maxNumberOfEditableFields = 3; private: constexpr static KDCoordinate k_textFieldWidth = 50; - constexpr static KDCoordinate k_textMargin = 5; + constexpr static KDCoordinate k_textWidthMargin = 5; + constexpr static KDCoordinate k_titleHeightMargin = 5; int numberOfSubviews() const override; View * subviewAtIndex(int index) override; + PointerTextView m_titleView; LawCurveView m_lawCurveView; ImageTableView m_imageTableView; PointerTextView m_text[k_maxNumberOfEditableFields]; @@ -51,6 +54,8 @@ private: ContentView m_contentView; Law * m_law; int m_highlightedSubviewIndex; + constexpr static int k_maxNumberOfTitleCharacters = 30; + char m_titleBuffer[k_maxNumberOfTitleCharacters]; }; } diff --git a/apps/probability/images/probability_icon.png b/apps/probability/images/probability_icon.png deleted file mode 100644 index e8dbe4dc8..000000000 Binary files a/apps/probability/images/probability_icon.png and /dev/null differ diff --git a/apps/probability/law/exponential_law.cpp b/apps/probability/law/exponential_law.cpp index 75d278bbd..97645a626 100644 --- a/apps/probability/law/exponential_law.cpp +++ b/apps/probability/law/exponential_law.cpp @@ -25,7 +25,8 @@ bool ExponentialLaw::isContinuous() const { const char * ExponentialLaw::parameterNameAtIndex(int index) { assert(index == 0); - return "l"; + constexpr static char name[] = {Ion::Charset::SmallLambda, 0}; + return name; } const char * ExponentialLaw::parameterDefinitionAtIndex(int index) { diff --git a/apps/probability/law/normal_law.cpp b/apps/probability/law/normal_law.cpp index 3f8b4af3d..0e6400751 100644 --- a/apps/probability/law/normal_law.cpp +++ b/apps/probability/law/normal_law.cpp @@ -26,9 +26,11 @@ bool NormalLaw::isContinuous() const { const char * NormalLaw::parameterNameAtIndex(int index) { assert(index >= 0 && index < 2); if (index == 0) { - return "u"; + constexpr static char meanName[] = {Ion::Charset::SmallMu, 0}; + return meanName; } else { - return "o"; + constexpr static char devName[] = {Ion::Charset::SmallSigma, 0}; + return devName; } } diff --git a/apps/probability/law/poisson_law.cpp b/apps/probability/law/poisson_law.cpp index 6bd772702..2da5e5073 100644 --- a/apps/probability/law/poisson_law.cpp +++ b/apps/probability/law/poisson_law.cpp @@ -1,6 +1,7 @@ #include "poisson_law.h" #include #include +#include namespace Probability { @@ -23,12 +24,14 @@ bool PoissonLaw::isContinuous() const { const char * PoissonLaw::parameterNameAtIndex(int index) { assert(index == 0); - return "l"; + constexpr static char name[] = {Ion::Charset::SmallLambda, 0}; + return name; } const char * PoissonLaw::parameterDefinitionAtIndex(int index) { assert(index == 0); - return "l : parametre"; + constexpr static char meanDef[] = {Ion::Charset::SmallLambda, ' ', ':', ' ', 'p', 'a', 'r', 'a', 'm', 'e', 't', 'r', 'e', 0}; + return meanDef; } float PoissonLaw::xMin() { diff --git a/apps/probability/law_controller.cpp b/apps/probability/law_controller.cpp index d73727002..915fd0cf2 100644 --- a/apps/probability/law_controller.cpp +++ b/apps/probability/law_controller.cpp @@ -19,6 +19,30 @@ namespace Probability { +LawController::ContentView::ContentView(SelectableTableView * selectableTableView) : + m_titleView(PointerTextView(KDText::FontSize::Small, "Choisir le type de loi", 0.5f, 0.5f, Palette::GreyDark, Palette::WallScreen)), + m_selectableTableView(selectableTableView) +{ +} + +int LawController::ContentView::numberOfSubviews() const { + return 2; +} + +View * LawController::ContentView::subviewAtIndex(int index) { + assert(index >= 0 && index < 2); + if (index == 0) { + return &m_titleView; + } + return m_selectableTableView; +} + +void LawController::ContentView::layoutSubviews() { + KDCoordinate titleHeight = KDText::stringSize("", KDText::FontSize::Small).height()+k_titleMargin; + m_titleView.setFrame(KDRect(0, 0, bounds().width(), titleHeight)); + m_selectableTableView->setFrame(KDRect(0, titleHeight, bounds().width(), bounds().height()-titleHeight)); +} + static const char * sMessages[] = { "Binomiale", "Uniforme", @@ -29,8 +53,9 @@ static const char * sMessages[] = { LawController::LawController(Responder * parentResponder) : ViewController(parentResponder), - m_selectableTableView(SelectableTableView(this, this, Metric::TopMargin, Metric::RightMargin, + m_selectableTableView(SelectableTableView(this, this, Metric::TopMargin-ContentView::k_titleMargin, Metric::RightMargin, Metric::BottomMargin, Metric::LeftMargin)), + m_contentView(&m_selectableTableView), m_law(nullptr), m_parametersController(ParametersController(nullptr)) { @@ -38,14 +63,7 @@ LawController::LawController(Responder * parentResponder) : } View * LawController::view() { - return &m_selectableTableView; -} - -const char * LawController::title() const { - if (m_law == nullptr) { - return "Choisir le type de Loi"; - } - return m_law->title(); + return &m_contentView; } void Probability::LawController::didBecomeFirstResponder() { @@ -54,8 +72,6 @@ void Probability::LawController::didBecomeFirstResponder() { m_law = nullptr; m_parametersController.setLaw(m_law); } - StackViewController * stack = (StackViewController *)parentResponder(); - stack->updateTitle(); if (m_selectableTableView.selectedRow() == -1) { m_selectableTableView.selectCellAtLocation(0, 0); } else { @@ -68,8 +84,7 @@ bool Probability::LawController::handleEvent(Ion::Events::Event event) { if (event == Ion::Events::OK) { StackViewController * stack = (StackViewController *)parentResponder(); setLawAccordingToIndex(m_selectableTableView.selectedRow()); - stack->updateTitle(); - stack->push(&m_parametersController); + stack->push(&m_parametersController, KDColorWhite, Palette::PurpleBright, Palette::PurpleBright); return true; } return false; diff --git a/apps/probability/law_controller.h b/apps/probability/law_controller.h index 1128129d5..6ab933f52 100644 --- a/apps/probability/law_controller.h +++ b/apps/probability/law_controller.h @@ -12,7 +12,6 @@ class LawController : public ViewController, public SimpleListViewDataSource { public: LawController(Responder * parentResponder); View * view() override; - const char * title() const override; bool handleEvent(Ion::Events::Event event) override; void didBecomeFirstResponder() override; @@ -22,12 +21,22 @@ public: TableViewCell * reusableCell(int index) override; int reusableCellCount() override; private: + class ContentView : public View { + public: + ContentView(SelectableTableView * selectableTableView); + constexpr static KDCoordinate k_titleMargin = 8; + private: + int numberOfSubviews() const override; + View * subviewAtIndex(int index) override; + void layoutSubviews() override; + PointerTextView m_titleView;; + SelectableTableView * m_selectableTableView; + }; void setLawAccordingToIndex(int index); constexpr static int k_totalNumberOfModels = 5; - // !!! CAUTION: The order here is important - // The cells should be initialized *before* the listview! Cell m_cells[k_totalNumberOfModels]; SelectableTableView m_selectableTableView; + ContentView m_contentView; const char ** m_messages; Law * m_law; ParametersController m_parametersController; diff --git a/apps/probability/law_curve_view.cpp b/apps/probability/law_curve_view.cpp index bf199e452..90d3ad4f2 100644 --- a/apps/probability/law_curve_view.cpp +++ b/apps/probability/law_curve_view.cpp @@ -23,13 +23,13 @@ void LawCurveView::setCalculation(Calculation * calculation) { void LawCurveView::drawRect(KDContext * ctx, KDRect rect) const { float lowerBound = m_calculation->lowerBound(); float upperBound = m_calculation->upperBound(); - ctx->fillRect(bounds(), KDColorWhite); + ctx->fillRect(bounds(), Palette::WallScreen); drawAxes(ctx, rect, Axis::Horizontal); drawLabels(ctx, rect, Axis::Horizontal, false); if (m_law->isContinuous()) { - drawCurve(ctx, rect, m_law, KDColorRed, true, lowerBound, upperBound, true); + drawCurve(ctx, rect, m_law, Palette::YellowDark, true, lowerBound, upperBound, true); } else { - drawHistogram(ctx, rect, m_law, 0, 1, false, KDColorBlue, KDColorRed, lowerBound, upperBound); + drawHistogram(ctx, rect, m_law, 0, 1, false, Palette::GreyMiddle, Palette::YellowDark, lowerBound, upperBound); } } diff --git a/apps/probability/parameters_controller.cpp b/apps/probability/parameters_controller.cpp index e10edb319..a90d05f86 100644 --- a/apps/probability/parameters_controller.cpp +++ b/apps/probability/parameters_controller.cpp @@ -7,6 +7,7 @@ namespace Probability { ParametersController::ContentView::ContentView(Responder * parentResponder, SelectableTableView * selectableTableView) : + m_numberOfParameters(1), m_nextButton(Button(parentResponder, "Suivant", Invocation([](void * context, void * sender) { ParametersController * parameterController = (ParametersController *) context; CalculationController * calculationController = parameterController->calculationController(); @@ -14,9 +15,9 @@ ParametersController::ContentView::ContentView(Responder * parentResponder, Sele calculationController->selectSubview(1); calculationController->reload(); StackViewController * stack = parameterController->stackController(); - stack->updateTitle(); - stack->push(calculationController); + stack->push(calculationController, KDColorWhite, Palette::SubTab, Palette::SubTab); }, parentResponder), KDText::FontSize::Large)), + m_titleView(PointerTextView(KDText::FontSize::Small, "Choisir les parametres", 0.5f, 0.5f, Palette::GreyDark, Palette::WallScreen)), m_firstParameterDefinition(PointerTextView(KDText::FontSize::Small, nullptr, 0.5f, 0.5f, KDColorBlack, Palette::WallScreen)), m_secondParameterDefinition(PointerTextView(KDText::FontSize::Small, nullptr, 0.5f, 0.5f, KDColorBlack, Palette::WallScreen)), m_selectableTableView(selectableTableView) @@ -40,30 +41,45 @@ void ParametersController::ContentView::drawRect(KDContext * ctx, KDRect rect) c ctx->fillRect(KDRect(0, tableHeight, bounds().width(), bounds().height() - tableHeight), Palette::WallScreen); } +void ParametersController::ContentView::setNumberOfParameters(int numberOfParameters) { + m_numberOfParameters = numberOfParameters; +} + int ParametersController::ContentView::numberOfSubviews() const { - return 4; + return m_numberOfParameters+3; } View * ParametersController::ContentView::subviewAtIndex(int index) { - assert(index >= 0 && index < 4); + assert(index >= 0 && index < 5); if (index == 0) { - return m_selectableTableView; + return &m_titleView; } if (index == 1) { - return &m_nextButton; + return m_selectableTableView; } if (index == 2) { + return &m_nextButton; + } + if (index == 3) { return &m_firstParameterDefinition; } return &m_secondParameterDefinition; } void ParametersController::ContentView::layoutSubviews() { - int tableHeight = m_selectableTableView->size().height() + Metric::TopMargin + Metric::BottomMargin; - m_selectableTableView->setFrame(KDRect(0, 0, bounds().width(), tableHeight)); - m_nextButton.setFrame(KDRect(Metric::LeftMargin, tableHeight, bounds().width() - Metric::RightMargin - Metric::LeftMargin, k_buttonHeight)); - m_firstParameterDefinition.setFrame(KDRect(0, tableHeight + k_buttonHeight, bounds().width(), k_textHeight)); - m_secondParameterDefinition.setFrame(KDRect(0, tableHeight + k_buttonHeight + k_textHeight, bounds().width(), k_textHeight)); + KDCoordinate titleHeight = KDText::stringSize("", KDText::FontSize::Small).height()+k_titleMargin; + m_titleView.setFrame(KDRect(0, 0, bounds().width(), titleHeight)); + KDCoordinate tableHeight = m_selectableTableView->size().height() + Metric::TopMargin + Metric::BottomMargin; + m_selectableTableView->setFrame(KDRect(0, titleHeight, bounds().width(), tableHeight)); + m_nextButton.setFrame(KDRect(Metric::LeftMargin, titleHeight+tableHeight, bounds().width() - Metric::RightMargin - Metric::LeftMargin, k_buttonHeight)); + KDCoordinate textHeight = KDText::stringSize("", KDText::FontSize::Small).height(); + KDCoordinate defOrigin = (titleHeight+tableHeight+k_buttonHeight)/2+(bounds().height()-textHeight)/2; + m_secondParameterDefinition.setFrame(KDRectZero); + if (m_numberOfParameters == 2) { + defOrigin = (titleHeight+tableHeight+k_buttonHeight)/2+(bounds().height()-2*textHeight-k_textMargin)/2; + m_secondParameterDefinition.setFrame(KDRect(0, defOrigin+textHeight+k_textMargin, bounds().width(), textHeight)); + } + m_firstParameterDefinition.setFrame(KDRect(0, defOrigin, bounds().width(), textHeight)); } /* Parameters Controller */ @@ -84,30 +100,18 @@ View * ParametersController::view() { } const char * ParametersController::title() const { - if (!m_buttonSelected) { - return "Choisir les parametres"; + if (m_law != nullptr) { + return m_law->title(); } - return m_titleBuffer; + return ""; } void ParametersController::setLaw(Law * law) { m_law = law; - m_calculationController.setLaw(law); -} - -void ParametersController::updateTitle() { - int currentChar = 0; - for (int index = 0; index < m_law->numberOfParameter(); index++) { - m_titleBuffer[currentChar++] = m_law->parameterNameAtIndex(index)[0]; - strlcpy(m_titleBuffer+currentChar, " = ", 4); - currentChar += 3; - char buffer[Float::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits)]; - Float(m_law->parameterValueAtIndex(index)).convertFloatToText(buffer, Float::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits, Float::DisplayMode::Decimal); - strlcpy(m_titleBuffer+currentChar, buffer, strlen(buffer)+1); - currentChar += strlen(buffer); - m_titleBuffer[currentChar++] = ' '; + if (m_law != nullptr) { + m_contentView.setNumberOfParameters(m_law->numberOfParameter()); } - m_titleBuffer[currentChar-1] = 0; + m_calculationController.setLaw(law); } bool ParametersController::handleEvent(Ion::Events::Event event) { @@ -116,7 +120,6 @@ bool ParametersController::handleEvent(Ion::Events::Event event) { m_contentView.button()->setBackgroundColor(Palette::Select); m_selectableTableView.deselectTable(); app()->setFirstResponder(m_contentView.button()); - updateTitle(); return true; } if (event == Ion::Events::Up && m_buttonSelected) { @@ -135,7 +138,6 @@ void ParametersController::didBecomeFirstResponder() { } m_contentView.layoutSubviews(); m_buttonSelected = false; - stackController()->updateTitle(); m_contentView.button()->setBackgroundColor(KDColorWhite); FloatParameterController::didBecomeFirstResponder(); } diff --git a/apps/probability/parameters_controller.h b/apps/probability/parameters_controller.h index 3bed94bbb..8bbde1136 100644 --- a/apps/probability/parameters_controller.h +++ b/apps/probability/parameters_controller.h @@ -25,7 +25,6 @@ public: private: float parameterAtIndex(int index) override; void setParameterAtIndex(int parameterIndex, float f) override; - void updateTitle(); class ContentView : public View { public: ContentView(Responder * parentResponder, SelectableTableView * selectableTableView); @@ -33,12 +32,16 @@ private: PointerTextView * parameterDefinitionAtIndex(int index); void drawRect(KDContext * ctx, KDRect rect) const override; void layoutSubviews() override; + void setNumberOfParameters(int numberOfParameters); private: constexpr static KDCoordinate k_buttonHeight = 40; - constexpr static KDCoordinate k_textHeight = 30; + constexpr static KDCoordinate k_textMargin = 5; + constexpr static KDCoordinate k_titleMargin = 5; int numberOfSubviews() const override; View * subviewAtIndex(int index) override; + int m_numberOfParameters; Button m_nextButton; + PointerTextView m_titleView; PointerTextView m_firstParameterDefinition; PointerTextView m_secondParameterDefinition; SelectableTableView * m_selectableTableView; @@ -50,8 +53,6 @@ private: Law * m_law; bool m_buttonSelected; CalculationController m_calculationController; - constexpr static int k_maxNumberOfTitleCharacters = 30; - char m_titleBuffer[k_maxNumberOfTitleCharacters]; }; } diff --git a/apps/regression/calculation_controller.cpp b/apps/regression/calculation_controller.cpp index fb2243b3a..19c48b5d3 100644 --- a/apps/regression/calculation_controller.cpp +++ b/apps/regression/calculation_controller.cpp @@ -23,7 +23,7 @@ CalculationController::CalculationController(Responder * parentResponder, Header } const char * CalculationController::title() const { - return "Statistics"; + return "Statistiques"; } View * CalculationController::view() { diff --git a/apps/regression/go_to_parameter_controller.cpp b/apps/regression/go_to_parameter_controller.cpp index a4b367d75..87c2e8afd 100644 --- a/apps/regression/go_to_parameter_controller.cpp +++ b/apps/regression/go_to_parameter_controller.cpp @@ -69,5 +69,12 @@ void GoToParameterController::willDisplayCellForIndex(TableViewCell * cell, int FloatParameterController::willDisplayCellForIndex(cell, index); } +bool GoToParameterController::textFieldDidFinishEditing(TextField * textField, const char * text) { + FloatParameterController::textFieldDidFinishEditing(textField, text); + StackViewController * stack = (StackViewController *)parentResponder(); + stack->pop(); + stack->pop(); + return true; +} } diff --git a/apps/regression/go_to_parameter_controller.h b/apps/regression/go_to_parameter_controller.h index 8a34f9622..fbb3f7cb5 100644 --- a/apps/regression/go_to_parameter_controller.h +++ b/apps/regression/go_to_parameter_controller.h @@ -17,6 +17,7 @@ public: TableViewCell * reusableCell(int index) override; int reusableCellCount() override; void willDisplayCellForIndex(TableViewCell * cell, int index) override; + bool textFieldDidFinishEditing(TextField * textField, const char * text) override; private: float parameterAtIndex(int index) override; void setParameterAtIndex(int parameterIndex, float f) override; diff --git a/apps/regression/store_controller.cpp b/apps/regression/store_controller.cpp index 600bca8de..ef1fc419d 100644 --- a/apps/regression/store_controller.cpp +++ b/apps/regression/store_controller.cpp @@ -17,7 +17,7 @@ StoreController::StoreController(Responder * parentResponder, Store * store, Hea } void StoreController::willDisplayCellAtLocation(TableViewCell * cell, int i, int j) { - EditableCellTableViewController::willDisplayCellAtLocation(cell, i, j); + ::StoreController::willDisplayCellAtLocation(cell, i, j); if (cellAtLocationIsEditable(i, j)) { return; } diff --git a/apps/settings/main_controller.cpp b/apps/settings/main_controller.cpp index 80fe29294..ebe6fe13c 100644 --- a/apps/settings/main_controller.cpp +++ b/apps/settings/main_controller.cpp @@ -6,12 +6,12 @@ namespace Settings { const SettingsNode angleChildren[2] = {SettingsNode("Degre"), SettingsNode("Radian")}; const SettingsNode displayModeChildren[2] = {SettingsNode("Auto"), SettingsNode("Scientifique")}; const SettingsNode numberTypeChildren[2] = {SettingsNode("Reel"), SettingsNode("Complexe")}; -const SettingsNode complexFormatChildren[2] = {SettingsNode("Cartesien"), SettingsNode("Polaire")}; -const SettingsNode languageChildren[2] = {SettingsNode("Anglais"), SettingsNode("Francais")}; +const SettingsNode complexFormatChildren[2] = {SettingsNode("Algebrique"), SettingsNode("Polaire")}; +const SettingsNode languageChildren[3] = {SettingsNode("Anglais"), SettingsNode("Francais"), SettingsNode("Espagnol")}; const SettingsNode menu[5] = {SettingsNode("Unite d'angles", angleChildren, 2), SettingsNode("Format resultat", displayModeChildren, 2), SettingsNode("Reel ou complexe", numberTypeChildren, 2), SettingsNode("Format complexe", complexFormatChildren, 2), - SettingsNode("Langue", languageChildren, 2)}; + SettingsNode("Langue", languageChildren, 3)}; const SettingsNode model = SettingsNode("Parametres", menu, 5); MainController::MainController(Responder * parentResponder, Preferences * preferences) : diff --git a/apps/settings/sub_controller.cpp b/apps/settings/sub_controller.cpp index 9db5ee706..7af1b5643 100644 --- a/apps/settings/sub_controller.cpp +++ b/apps/settings/sub_controller.cpp @@ -1,11 +1,13 @@ #include "sub_controller.h" +#include "../apps_container.h" #include namespace Settings { SubController::SubController(Responder * parentResponder, Preferences * preferences) : ViewController(parentResponder), - m_cells{MenuListCell(nullptr, KDText::FontSize::Large), MenuListCell(nullptr, KDText::FontSize::Large)}, + m_cells{MenuListCell(nullptr, KDText::FontSize::Large), MenuListCell(nullptr, KDText::FontSize::Large), + MenuListCell(nullptr, KDText::FontSize::Large)}, m_selectableTableView(SelectableTableView(this, this, Metric::TopMargin, Metric::RightMargin, Metric::BottomMargin, Metric::LeftMargin)), m_nodeModel(nullptr), @@ -33,6 +35,8 @@ void SubController::didBecomeFirstResponder() { bool SubController::handleEvent(Ion::Events::Event event) { if (event == Ion::Events::OK) { setPreferenceAtIndexWithValueIndex(m_preferenceIndex, m_selectableTableView.selectedRow()); + AppsContainer * myContainer = (AppsContainer * )app()->container(); + myContainer->refreshPreferences(); StackViewController * stack = stackController(); stack->pop(); } @@ -80,7 +84,7 @@ void SubController::setPreferenceAtIndexWithValueIndex(int preferenceIndex, int m_preferences->setAngleUnit((Preferences::AngleUnit)valueIndex); break; case 1: - m_preferences->setDisplayMode((Preferences::DisplayMode)valueIndex); + m_preferences->setDisplayMode((Expression::DisplayMode)valueIndex); break; case 2: m_preferences->setNumberType((Preferences::NumberType)valueIndex); diff --git a/apps/settings/sub_controller.h b/apps/settings/sub_controller.h index e3c6d152c..a79c7b31d 100644 --- a/apps/settings/sub_controller.h +++ b/apps/settings/sub_controller.h @@ -24,7 +24,7 @@ private: StackViewController * stackController() const; void setPreferenceAtIndexWithValueIndex(int preferenceIndex, int valueIndex); int valueIndexAtPreferenceIndex(int preferenceIndex); - constexpr static int k_totalNumberOfCell = 2; + constexpr static int k_totalNumberOfCell = 3; MenuListCell m_cells[k_totalNumberOfCell]; SelectableTableView m_selectableTableView; Node * m_nodeModel; diff --git a/apps/statistics/store_controller.cpp b/apps/statistics/store_controller.cpp index 05887a8d3..f073a3725 100644 --- a/apps/statistics/store_controller.cpp +++ b/apps/statistics/store_controller.cpp @@ -13,7 +13,7 @@ StoreController::StoreController(Responder * parentResponder, Store * store, Hea } void StoreController::willDisplayCellAtLocation(TableViewCell * cell, int i, int j) { - EditableCellTableViewController::willDisplayCellAtLocation(cell, i, j); + ::StoreController::willDisplayCellAtLocation(cell, i, j); if (cellAtLocationIsEditable(i, j)) { return; } diff --git a/apps/store_controller.cpp b/apps/store_controller.cpp index aca559175..5a75baf14 100644 --- a/apps/store_controller.cpp +++ b/apps/store_controller.cpp @@ -62,6 +62,10 @@ int StoreController::typeAtLocation(int i, int j) { return j!=0; } +void StoreController::willDisplayCellAtLocation(TableViewCell * cell, int i, int j) { + willDisplayCellAtLocationWithDisplayMode(cell, i, j, Expression::DisplayMode::Auto); +} + bool StoreController::handleEvent(Ion::Events::Event event) { if (event == Ion::Events::Up) { m_selectableTableView.deselectTable(); diff --git a/apps/store_controller.h b/apps/store_controller.h index f0ac9d781..80c99f6d5 100644 --- a/apps/store_controller.h +++ b/apps/store_controller.h @@ -17,6 +17,7 @@ public: TableViewCell * reusableCell(int index, int type) override; int reusableCellCount(int type) override; int typeAtLocation(int i, int j) override; + void willDisplayCellAtLocation(TableViewCell * cell, int i, int j) override; bool handleEvent(Ion::Events::Event event) override; protected: static constexpr KDCoordinate k_cellWidth = Ion::Display::Width/2 - Metric::RightMargin/2 - Metric::LeftMargin/2; diff --git a/apps/title_bar_view.cpp b/apps/title_bar_view.cpp index fbaf8cd48..c4a2c1380 100644 --- a/apps/title_bar_view.cpp +++ b/apps/title_bar_view.cpp @@ -5,7 +5,8 @@ extern "C" { TitleBarView::TitleBarView() : View(), - m_titleView(KDText::FontSize::Small, nullptr, 0.5f, 0.5f, KDColorWhite, Palette::YellowDark) + m_titleView(KDText::FontSize::Small, nullptr, 0.5f, 0.5f, KDColorWhite, Palette::YellowDark), + m_preferenceView(KDText::FontSize::Small, 1.0f, 0.5, KDColorWhite, Palette::YellowDark) { } @@ -23,18 +24,44 @@ void TitleBarView::setChargeState(Ion::Battery::Charge chargeState) { } int TitleBarView::numberOfSubviews() const { - return 2; + return 3; } View * TitleBarView::subviewAtIndex(int index) { if (index == 0) { return &m_titleView; } + if (index == 1) { + return &m_preferenceView; + } return &m_batteryView; } void TitleBarView::layoutSubviews() { m_titleView.setFrame(bounds()); + m_preferenceView.setFrame(KDRect(0, 0, m_preferenceView.minimalSizeForOptimalDisplay())); KDSize batterySize = m_batteryView.minimalSizeForOptimalDisplay(); m_batteryView.setFrame(KDRect(bounds().width() - batterySize.width() - k_batteryLeftMargin, (bounds().height()- batterySize.height())/2, batterySize)); } + +void TitleBarView::setPreferences(Preferences * preferences) { + char buffer[13]; + int numberOfChar = 0; + if (preferences->displayMode() == Expression::DisplayMode::Scientific) { + strlcpy(buffer, "sci/", 5); + numberOfChar += 4; + } + if (preferences->numberType() == Preferences::NumberType::Complex) { + strlcpy(buffer+numberOfChar, "cplx/", 6); + numberOfChar += 5; + } + if (preferences->angleUnit() == Preferences::AngleUnit::Radian) { + strlcpy(buffer+numberOfChar, "rad", 4); + } else { + strlcpy(buffer+numberOfChar, "deg", 4); + } + numberOfChar += 3; + buffer[numberOfChar] = 0; + m_preferenceView.setText(buffer); + layoutSubviews(); +} diff --git a/apps/title_bar_view.h b/apps/title_bar_view.h index a0dd33e86..d93c54581 100644 --- a/apps/title_bar_view.h +++ b/apps/title_bar_view.h @@ -3,6 +3,7 @@ #include #include "battery_view.h" +#include "preferences.h" class TitleBarView : public View { public: @@ -10,6 +11,7 @@ public: void drawRect(KDContext * ctx, KDRect rect) const override; void setTitle(const char * title); void setChargeState(Ion::Battery::Charge chargeState); + void setPreferences(Preferences * preferences); private: constexpr static KDCoordinate k_batteryLeftMargin = 5; int numberOfSubviews() const override; @@ -17,6 +19,7 @@ private: View * subviewAtIndex(int index) override; PointerTextView m_titleView; BatteryView m_batteryView; + BufferTextView m_preferenceView; }; #endif diff --git a/apps/variable_box_controller.cpp b/apps/variable_box_controller.cpp index b2cdb84e4..5deab988a 100644 --- a/apps/variable_box_controller.cpp +++ b/apps/variable_box_controller.cpp @@ -224,6 +224,7 @@ VariableBoxController::VariableBoxController(Context * context) : } void VariableBoxController::didBecomeFirstResponder() { + StackViewController::didBecomeFirstResponder(); app()->setFirstResponder(&m_contentViewController); } diff --git a/escher/include/escher/stack_view_controller.h b/escher/include/escher/stack_view_controller.h index 3fbcc25a4..1093879b9 100644 --- a/escher/include/escher/stack_view_controller.h +++ b/escher/include/escher/stack_view_controller.h @@ -13,8 +13,7 @@ public: KDColor textColor = Palette::SubTab, KDColor backgroundColor = KDColorWhite, KDColor separatorColor = Palette::GreyBright); /* Push creates a new StackView and adds it */ - void push(ViewController * vc); - void updateTitle(); + void push(ViewController * vc, KDColor textColor = Palette::SubTab, KDColor backgroundColor = KDColorWhite, KDColor separatorColor = Palette::GreyBright); void pop(); @@ -25,9 +24,9 @@ public: private: class ControllerView : public View { public: - ControllerView(bool displayFirstStackHeader, KDColor textColor, KDColor backgroundColor, KDColor separatorColor); + ControllerView(bool displayFirstStackHeader); void setContentView(View * view); - void pushStack(const char * name); + void pushStack(const char * name, KDColor textColor, KDColor backgroundColor, KDColor separatorColor); void popStack(); protected: #if ESCHER_VIEW_LOGGING @@ -43,9 +42,6 @@ private: View * m_contentView; int8_t m_numberOfStacks; bool m_displayFirstStackHeader; - KDColor m_textColor; - KDColor m_backgroundColor; - KDColor m_separatorColor; }; ControllerView m_view; @@ -55,6 +51,9 @@ private: ViewController * m_children[k_maxNumberOfChildren]; uint8_t m_numberOfChildren; ViewController * m_rootViewController; + KDColor m_textColor; + KDColor m_backgroundColor; + KDColor m_separatorColor; }; #endif diff --git a/escher/src/app.cpp b/escher/src/app.cpp index b88789ed4..efb08d14f 100644 --- a/escher/src/app.cpp +++ b/escher/src/app.cpp @@ -19,13 +19,11 @@ App::App(Container * container, ViewController * rootViewController, const char void App::setWindow(Window * window) { View * view = m_modalViewController.view(); + assert(m_modalViewController.app() == this); + window->setContentView(view); if (m_firstResponder == nullptr) { setFirstResponder(&m_modalViewController); } - assert(m_modalViewController.app() == this); - - window->setContentView(view); - window->redraw(); } diff --git a/escher/src/modal_view_controller.cpp b/escher/src/modal_view_controller.cpp index 2948cd1be..17f216c1f 100644 --- a/escher/src/modal_view_controller.cpp +++ b/escher/src/modal_view_controller.cpp @@ -115,8 +115,8 @@ void ModalViewController::displayModalViewController(ViewController * vc, float m_currentModalViewController = vc; vc->setParentResponder(this); m_previousResponder = app()->firstResponder(); - app()->setFirstResponder(vc); m_contentView.presentModalView(vc->view(), verticalAlignment, horizontalAlignment, topMargin, leftMargin, bottomMargin, rightMargin); + app()->setFirstResponder(vc); } void ModalViewController::dismissModalViewController() { diff --git a/escher/src/stack_view_controller.cpp b/escher/src/stack_view_controller.cpp index 5add39220..9de6b76c0 100644 --- a/escher/src/stack_view_controller.cpp +++ b/escher/src/stack_view_controller.cpp @@ -4,14 +4,11 @@ extern "C" { #include #include -StackViewController::ControllerView::ControllerView(bool displayFirstStackHeader, KDColor textColor, KDColor backgroundColor, KDColor separatorColor) : +StackViewController::ControllerView::ControllerView(bool displayFirstStackHeader) : View(), m_contentView(nullptr), m_numberOfStacks(0), - m_displayFirstStackHeader(displayFirstStackHeader), - m_textColor(textColor), - m_backgroundColor(backgroundColor), - m_separatorColor(separatorColor) + m_displayFirstStackHeader(displayFirstStackHeader) { } @@ -21,11 +18,11 @@ void StackViewController::ControllerView::setContentView(View * view) { markRectAsDirty(bounds()); } -void StackViewController::ControllerView::pushStack(const char * name) { +void StackViewController::ControllerView::pushStack(const char * name, KDColor textColor, KDColor backgroundColor, KDColor separatorColor) { m_stackViews[m_numberOfStacks].setName(name); - m_stackViews[m_numberOfStacks].setTextColor(m_textColor); - m_stackViews[m_numberOfStacks].setBackgroundColor(m_backgroundColor); - m_stackViews[m_numberOfStacks].setSeparatorColor(m_separatorColor); + m_stackViews[m_numberOfStacks].setTextColor(textColor); + m_stackViews[m_numberOfStacks].setBackgroundColor(backgroundColor); + m_stackViews[m_numberOfStacks].setSeparatorColor(separatorColor); m_numberOfStacks++; } @@ -68,11 +65,15 @@ const char * StackViewController::ControllerView::className() const { } #endif -StackViewController::StackViewController(Responder * parentResponder, ViewController * rootViewController, bool displayFirstStackHeader, KDColor textColor, KDColor backgroundColor, KDColor separatorColor) : +StackViewController::StackViewController(Responder * parentResponder, ViewController * rootViewController, + bool displayFirstStackHeader, KDColor textColor, KDColor backgroundColor, KDColor separatorColor) : ViewController(parentResponder), - m_view(ControllerView(displayFirstStackHeader, textColor, backgroundColor, separatorColor)), + m_view(ControllerView(displayFirstStackHeader)), m_numberOfChildren(0), - m_rootViewController(rootViewController) + m_rootViewController(rootViewController), + m_textColor(textColor), + m_backgroundColor(backgroundColor), + m_separatorColor(separatorColor) { // push(rootViewController); } @@ -86,13 +87,8 @@ const char * StackViewController::title() const { } } -void StackViewController::updateTitle() { - m_view.popStack(); - m_view.pushStack(m_children[m_numberOfChildren-1]->title()); -} - -void StackViewController::push(ViewController * vc) { - m_view.pushStack(vc->title()); +void StackViewController::push(ViewController * vc, KDColor textColor, KDColor backgroundColor, KDColor separatorColor) { + m_view.pushStack(vc->title(), textColor, backgroundColor, separatorColor); m_children[m_numberOfChildren++] = vc; setupActiveViewController(); } @@ -114,6 +110,10 @@ void StackViewController::setupActiveViewController() { } void StackViewController::didBecomeFirstResponder() { + if (m_rootViewController != nullptr) { + push(m_rootViewController, m_textColor, m_backgroundColor, m_separatorColor); + m_rootViewController = nullptr; + } ViewController * vc = m_children[m_numberOfChildren-1]; app()->setFirstResponder(vc); } @@ -127,9 +127,5 @@ bool StackViewController::handleEvent(Ion::Events::Event event) { } View * StackViewController::view() { - if (m_rootViewController != nullptr) { - push(m_rootViewController); - m_rootViewController = nullptr; - } return &m_view; } diff --git a/escher/src/tab_view_controller.cpp b/escher/src/tab_view_controller.cpp index cac2c7e9f..076fa6125 100644 --- a/escher/src/tab_view_controller.cpp +++ b/escher/src/tab_view_controller.cpp @@ -113,6 +113,9 @@ void TabViewController::setSelectedTab(int8_t i) { void TabViewController::didBecomeFirstResponder() { setSelectedTab(m_activeChildIndex); + if (m_activeChildIndex < 0) { + setActiveTab(0); + } } void TabViewController::didResignFirstResponder() { @@ -128,9 +131,6 @@ View * TabViewController::view() { m_view.m_tabView.addTabNamed(m_children[i]->title()); } } - if (m_activeChildIndex < 0) { - setActiveTab(0); - } return &m_view; } diff --git a/kandinsky/fonts/ProggyClean.ttf b/kandinsky/fonts/ProggyClean.ttf deleted file mode 100644 index 0270cdfe3..000000000 Binary files a/kandinsky/fonts/ProggyClean.ttf and /dev/null differ diff --git a/kandinsky/fonts/largePixelFont.ttf b/kandinsky/fonts/largePixelFont.ttf deleted file mode 100644 index 778a46dc7..000000000 Binary files a/kandinsky/fonts/largePixelFont.ttf and /dev/null differ diff --git a/kandinsky/fonts/smallPixelFont.ttf b/kandinsky/fonts/smallPixelFont.ttf deleted file mode 100644 index 9f5671cc3..000000000 Binary files a/kandinsky/fonts/smallPixelFont.ttf and /dev/null differ diff --git a/poincare/include/poincare/absolute_value.h b/poincare/include/poincare/absolute_value.h index 8fb91d56f..c1fd0591d 100644 --- a/poincare/include/poincare/absolute_value.h +++ b/poincare/include/poincare/absolute_value.h @@ -10,7 +10,7 @@ public: Type type() const override; Expression * cloneWithDifferentOperands(Expression ** newOperands, int numberOfOperands, bool cloneOperands = true) const override; - ExpressionLayout * createLayout() const override; + ExpressionLayout * createLayout(DisplayMode displayMode = DisplayMode::Auto) const override; }; #endif diff --git a/poincare/include/poincare/addition.h b/poincare/include/poincare/addition.h index f31bdadbf..7767e9f69 100644 --- a/poincare/include/poincare/addition.h +++ b/poincare/include/poincare/addition.h @@ -17,7 +17,7 @@ class Addition : public Expression { Expression * clone() const override; Expression * cloneWithDifferentOperands(Expression** newOperands, int numberOfOperands, bool cloneOperands = true) const override; - ExpressionLayout * createLayout() const override; + ExpressionLayout * createLayout(DisplayMode displayMode = DisplayMode::Auto) const override; bool isCommutative() const override; private: float operateApproximatevelyOn(float a, float b) const; diff --git a/poincare/include/poincare/expression.h b/poincare/include/poincare/expression.h index 33b1cd746..6b6eacdab 100644 --- a/poincare/include/poincare/expression.h +++ b/poincare/include/poincare/expression.h @@ -33,10 +33,14 @@ class Expression { Symbol, Tangent, }; + enum class DisplayMode { + Auto = 0, + Scientific = 1 + }; static Expression * parse(char const * string); virtual ~Expression(); - virtual ExpressionLayout * createLayout() const = 0; // Returned object must be deleted + virtual ExpressionLayout * createLayout(DisplayMode displayMode = DisplayMode::Auto) const = 0; // Returned object must be deleted virtual const Expression * operand(int i) const = 0; virtual int numberOfOperands() const = 0; virtual Expression * clone() const = 0; diff --git a/poincare/include/poincare/float.h b/poincare/include/poincare/float.h index 6c0fbaf54..15e5df79a 100644 --- a/poincare/include/poincare/float.h +++ b/poincare/include/poincare/float.h @@ -10,21 +10,17 @@ public: const char * fractionalPart, int fractionalPartLength, const char * exponent, int exponentLength, bool exponentNegative); - ExpressionLayout * createLayout() const override; + ExpressionLayout * createLayout(DisplayMode displayMode = DisplayMode::Auto) const override; float approximate(Context& context) const override; Expression * evaluate(Context& context) const override; Type type() const override; Expression * clone() const override; bool valueEquals(const Expression * e) const override; - enum class DisplayMode { - Scientific, - Decimal - }; void setNumberOfSignificantDigits(int numberOfDigits); /* The parameter 'DisplayMode' refers to the way to display float 'scientific' - * or 'decimal'. The scientific mode returns float with style -1.2E2 whereas - * the decimal mode tries to return 'natural' float like (0.021) and switches + * or 'auto'. The scientific mode returns float with style -1.2E2 whereas + * the auto mode tries to return 'natural' float like (0.021) and switches * to scientific mode if the float is too small or too big regarding the * number of significant difits. If the buffer size is too small to display * the right number of significant digits, the function forces the scientific @@ -42,7 +38,7 @@ public: private: /* We here define the buffer size to write the lengthest float possible. * At maximum, the number has 7 significant digits so, in the worst case it - * has the form -1.999999e-38 (7+6+1 char) (the decimal mode is always + * has the form -1.999999e-38 (7+6+1 char) (the auto mode is always * shorter. */ constexpr static int k_maxBufferLength = 7+6+1; /* convertFloatToTextPrivate return the string length of the buffer (does not count the 0 last char)*/ diff --git a/poincare/include/poincare/fraction.h b/poincare/include/poincare/fraction.h index 96a0c5987..1d7eac4db 100644 --- a/poincare/include/poincare/fraction.h +++ b/poincare/include/poincare/fraction.h @@ -8,7 +8,7 @@ class Fraction : public BinaryOperation { using BinaryOperation::BinaryOperation; public: - ExpressionLayout * createLayout() const override; + ExpressionLayout * createLayout(DisplayMode displayMode = DisplayMode::Auto) const override; float approximate(Context& context) const override; Type type() const override; Expression * cloneWithDifferentOperands(Expression** newOperands, diff --git a/poincare/include/poincare/function.h b/poincare/include/poincare/function.h index 173b54881..36319c209 100644 --- a/poincare/include/poincare/function.h +++ b/poincare/include/poincare/function.h @@ -13,7 +13,7 @@ public: ~Function(); void setArgument(Expression ** args, int numberOfArguments, bool clone = true); void setArgument(ListData * listData, bool clone = true); - ExpressionLayout * createLayout() const override; + ExpressionLayout * createLayout(DisplayMode displayMode = DisplayMode::Auto) const override; const Expression * operand(int i) const override; int numberOfOperands() const override; Expression * clone() const override; diff --git a/poincare/include/poincare/integer.h b/poincare/include/poincare/integer.h index df8491fa9..c6ab9a488 100644 --- a/poincare/include/poincare/integer.h +++ b/poincare/include/poincare/integer.h @@ -31,7 +31,7 @@ class Integer : public LeafExpression { bool valueEquals(const Expression * e) const override; Expression * clone() const override; - virtual ExpressionLayout * createLayout() const override; + virtual ExpressionLayout * createLayout(DisplayMode displayMode = DisplayMode::Auto) const override; float approximate(Context& context) const override; Expression * evaluate(Context& context) const override; private: diff --git a/poincare/include/poincare/integral.h b/poincare/include/poincare/integral.h index fe4aab97f..beaf25765 100644 --- a/poincare/include/poincare/integral.h +++ b/poincare/include/poincare/integral.h @@ -11,7 +11,7 @@ public: Type type() const override; Expression * cloneWithDifferentOperands(Expression ** newOperands, int numberOfOperands, bool cloneOperands = true) const override; - ExpressionLayout * createLayout() const override; + ExpressionLayout * createLayout(DisplayMode displayMode = DisplayMode::Auto) const override; private: struct DetailedResult { diff --git a/poincare/include/poincare/logarithm.h b/poincare/include/poincare/logarithm.h index 38bfba520..77f1d943d 100644 --- a/poincare/include/poincare/logarithm.h +++ b/poincare/include/poincare/logarithm.h @@ -10,7 +10,7 @@ public: Type type() const override; Expression * cloneWithDifferentOperands(Expression ** newOperands, int numberOfOperands, bool cloneOperands = true) const override; - ExpressionLayout * createLayout() const override; + ExpressionLayout * createLayout(DisplayMode displayMode = DisplayMode::Auto) const override; }; #endif diff --git a/poincare/include/poincare/matrix.h b/poincare/include/poincare/matrix.h index 84da1a2eb..028352c30 100644 --- a/poincare/include/poincare/matrix.h +++ b/poincare/include/poincare/matrix.h @@ -13,7 +13,7 @@ class Matrix : public Expression { const Expression * operand(int i) const override; int numberOfOperands() const override; Expression * clone() const override; - ExpressionLayout * createLayout() const override; + ExpressionLayout * createLayout(DisplayMode displayMode = DisplayMode::Auto) const override; float approximate(Context& context) const override; Expression * evaluate(Context& context) const override; Type type() const override; diff --git a/poincare/include/poincare/multiplication.h b/poincare/include/poincare/multiplication.h index e03d20905..907273ecb 100644 --- a/poincare/include/poincare/multiplication.h +++ b/poincare/include/poincare/multiplication.h @@ -9,7 +9,7 @@ class Multiplication : public BinaryOperation { using BinaryOperation::BinaryOperation; public: Type type() const override; - ExpressionLayout * createLayout() const override; + ExpressionLayout * createLayout(DisplayMode displayMode = DisplayMode::Auto) const override; float approximate(Context& context) const override; Expression * cloneWithDifferentOperands(Expression** newOperands, int numnerOfOperands, bool cloneOperands = true) const override; diff --git a/poincare/include/poincare/nth_root.h b/poincare/include/poincare/nth_root.h index 9880ba20f..b9bb45693 100644 --- a/poincare/include/poincare/nth_root.h +++ b/poincare/include/poincare/nth_root.h @@ -10,7 +10,7 @@ public: Type type() const override; Expression * cloneWithDifferentOperands(Expression ** newOperands, int numberOfOperands, bool cloneOperands = true) const override; - ExpressionLayout * createLayout() const override; + ExpressionLayout * createLayout(DisplayMode displayMode = DisplayMode::Auto) const override; }; #endif diff --git a/poincare/include/poincare/opposite.h b/poincare/include/poincare/opposite.h index e17796cec..828110254 100644 --- a/poincare/include/poincare/opposite.h +++ b/poincare/include/poincare/opposite.h @@ -13,7 +13,7 @@ class Opposite : public Expression { int numberOfOperands() const override; Expression * clone() const override; Expression * evaluate(Context& context) const override; - ExpressionLayout * createLayout() const override; + ExpressionLayout * createLayout(DisplayMode displayMode = DisplayMode::Auto) const override; float approximate(Context& context) const override; Type type() const override; Expression * cloneWithDifferentOperands(Expression** newOperands, diff --git a/poincare/include/poincare/parenthesis.h b/poincare/include/poincare/parenthesis.h index 5b183ad87..3c5bf103f 100644 --- a/poincare/include/poincare/parenthesis.h +++ b/poincare/include/poincare/parenthesis.h @@ -10,7 +10,7 @@ class Parenthesis : public Expression { const Expression * operand(int i) const override; int numberOfOperands() const override; Expression * clone() const override; - ExpressionLayout * createLayout() const override; + ExpressionLayout * createLayout(DisplayMode displayMode = DisplayMode::Auto) const override; float approximate(Context& context) const override; Expression * evaluate(Context& context) const override; Type type() const override; diff --git a/poincare/include/poincare/power.h b/poincare/include/poincare/power.h index 746f53659..54f22e4f5 100644 --- a/poincare/include/poincare/power.h +++ b/poincare/include/poincare/power.h @@ -9,7 +9,7 @@ class Power : public BinaryOperation { using BinaryOperation::BinaryOperation; public: - ExpressionLayout * createLayout() const override; + ExpressionLayout * createLayout(DisplayMode displayMode = DisplayMode::Auto) const override; float approximate(Context& context) const override; Type type() const override; Expression * cloneWithDifferentOperands(Expression** newOperands, diff --git a/poincare/include/poincare/product.h b/poincare/include/poincare/product.h index 7096461a1..248092658 100644 --- a/poincare/include/poincare/product.h +++ b/poincare/include/poincare/product.h @@ -10,7 +10,7 @@ public: Type type() const override; Expression * cloneWithDifferentOperands(Expression ** newOperands, int numberOfOperands, bool cloneOperands = true) const override; - ExpressionLayout * createLayout() const override; + ExpressionLayout * createLayout(DisplayMode displayMode = DisplayMode::Auto) const override; }; #endif diff --git a/poincare/include/poincare/square_root.h b/poincare/include/poincare/square_root.h index 766d7d753..abe81f2ec 100644 --- a/poincare/include/poincare/square_root.h +++ b/poincare/include/poincare/square_root.h @@ -10,7 +10,7 @@ public: Type type() const override; Expression * cloneWithDifferentOperands(Expression ** newOperands, int numberOfOperands, bool cloneOperands = true) const override; - ExpressionLayout * createLayout() const override; + ExpressionLayout * createLayout(DisplayMode displayMode = DisplayMode::Auto) const override; }; #endif diff --git a/poincare/include/poincare/subtraction.h b/poincare/include/poincare/subtraction.h index 6194fa151..e6516dded 100644 --- a/poincare/include/poincare/subtraction.h +++ b/poincare/include/poincare/subtraction.h @@ -9,7 +9,7 @@ class Subtraction : public BinaryOperation { using BinaryOperation::BinaryOperation; public: - ExpressionLayout * createLayout() const override; + ExpressionLayout * createLayout(DisplayMode displayMode = DisplayMode::Auto) const override; float approximate(Context& context) const override; Type type() const override; Expression * cloneWithDifferentOperands(Expression** newOperands, diff --git a/poincare/include/poincare/sum.h b/poincare/include/poincare/sum.h index b7311eabd..4903ae09f 100644 --- a/poincare/include/poincare/sum.h +++ b/poincare/include/poincare/sum.h @@ -10,7 +10,7 @@ public: Type type() const override; Expression * cloneWithDifferentOperands(Expression ** newOperands, int numberOfOperands, bool cloneOperands = true) const override; - ExpressionLayout * createLayout() const override; + ExpressionLayout * createLayout(DisplayMode displayMode = DisplayMode::Auto) const override; }; #endif diff --git a/poincare/include/poincare/symbol.h b/poincare/include/poincare/symbol.h index 6b80bfdd3..cf33aa767 100644 --- a/poincare/include/poincare/symbol.h +++ b/poincare/include/poincare/symbol.h @@ -9,7 +9,7 @@ public: Ans = '^' }; Symbol(char name); - ExpressionLayout * createLayout() const override; + ExpressionLayout * createLayout(DisplayMode displayMode = DisplayMode::Auto) const override; float approximate(Context& context) const override; Expression * evaluate(Context& context) const override; Type type() const override; diff --git a/poincare/src/absolute_value.cpp b/poincare/src/absolute_value.cpp index b3d657652..3306463e4 100644 --- a/poincare/src/absolute_value.cpp +++ b/poincare/src/absolute_value.cpp @@ -28,6 +28,6 @@ float AbsoluteValue::approximate(Context& context) const { return fabsf(m_args[0]->approximate(context)); } -ExpressionLayout * AbsoluteValue::createLayout() const { - return new AbsoluteValueLayout(m_args[0]->createLayout()); +ExpressionLayout * AbsoluteValue::createLayout(DisplayMode displayMode) const { + return new AbsoluteValueLayout(m_args[0]->createLayout(displayMode)); } \ No newline at end of file diff --git a/poincare/src/addition.cpp b/poincare/src/addition.cpp index c63fb06e9..8422f241b 100644 --- a/poincare/src/addition.cpp +++ b/poincare/src/addition.cpp @@ -76,13 +76,13 @@ Expression * Addition::cloneWithDifferentOperands(Expression** newOperands, return new Addition(newOperands, numberOfOperands, cloneOperands); } -ExpressionLayout * Addition::createLayout() const { +ExpressionLayout * Addition::createLayout(DisplayMode displayMode) const { int number_of_children = 2*m_numberOfOperands-1; ExpressionLayout** children_layouts = (ExpressionLayout **)malloc(number_of_children*sizeof(ExpressionLayout *)); - children_layouts[0] = m_operands[0]->createLayout(); + children_layouts[0] = m_operands[0]->createLayout(displayMode); for (int i=1; itype() == Type::Opposite ? new ParenthesisLayout(m_operands[i]->createLayout()) : m_operands[i]->createLayout(); + children_layouts[2*i] = m_operands[i]->type() == Type::Opposite ? new ParenthesisLayout(m_operands[i]->createLayout(displayMode)) : m_operands[i]->createLayout(displayMode); } return new HorizontalLayout(children_layouts, number_of_children); } diff --git a/poincare/src/float.cpp b/poincare/src/float.cpp index c652a4942..39a978104 100644 --- a/poincare/src/float.cpp +++ b/poincare/src/float.cpp @@ -65,9 +65,9 @@ Expression::Type Float::type() const { return Type::Float; } -ExpressionLayout * Float::createLayout() const { +ExpressionLayout * Float::createLayout(DisplayMode displayMode) const { char buffer[k_maxBufferLength]; - convertFloatToText(buffer, k_maxBufferLength, m_numberOfSignificantDigits); + convertFloatToText(buffer, k_maxBufferLength, m_numberOfSignificantDigits, displayMode); int size = 0; while (buffer[size] != 0) { size++; @@ -93,7 +93,7 @@ int Float::convertFloatToText(char * buffer, int bufferSize, * fit the buffer size. If the buffer size is still to small, we only write * the beginning of the float and truncate it (which can result in a non sense * text) */ - if (mode == DisplayMode::Decimal && requiredLength >= bufferSize) { + if (mode == DisplayMode::Auto && requiredLength >= bufferSize) { requiredLength = convertFloatToTextPrivate(tempBuffer, numberOfSignificantDigits, DisplayMode::Scientific); } if (requiredLength >= bufferSize) { @@ -132,7 +132,7 @@ int Float::convertFloatToTextPrivate(char * buffer, int numberOfSignificantDigit } DisplayMode displayMode = mode; - if ((exponentInBase10 >= numberOfSignificantDigits || exponentInBase10 <= -numberOfSignificantDigits) && mode == DisplayMode::Decimal) { + if ((exponentInBase10 >= numberOfSignificantDigits || exponentInBase10 <= -numberOfSignificantDigits) && mode == DisplayMode::Auto) { displayMode = DisplayMode::Scientific; } @@ -181,13 +181,13 @@ int Float::convertFloatToTextPrivate(char * buffer, int numberOfSignificantDigit } // Suppress the decimal marker if no fractional part - if (displayMode == DisplayMode::Decimal && availableCharsForMantissaWithoutSign == exponentInBase10+2) { + if (displayMode == DisplayMode::Auto && availableCharsForMantissaWithoutSign == exponentInBase10+2) { availableCharsForMantissaWithSign--; } // Print mantissa printBase10IntegerWithDecimalMarker(buffer, availableCharsForMantissaWithSign, mantissa, decimalMarkerPosition); - if (displayMode == DisplayMode::Decimal) { + if (displayMode == DisplayMode::Auto) { buffer[availableCharsForMantissaWithSign] = 0; return availableCharsForMantissaWithSign; } diff --git a/poincare/src/fraction.cpp b/poincare/src/fraction.cpp index 692b3ec76..00a0373d8 100644 --- a/poincare/src/fraction.cpp +++ b/poincare/src/fraction.cpp @@ -13,8 +13,8 @@ Expression * Fraction::cloneWithDifferentOperands(Expression** newOperands, return new Fraction(newOperands, cloneOperands); } -ExpressionLayout * Fraction::createLayout() const { - return new FractionLayout(m_operands[0]->createLayout(), m_operands[1]->createLayout()); +ExpressionLayout * Fraction::createLayout(DisplayMode displayMode) const { + return new FractionLayout(m_operands[0]->createLayout(displayMode), m_operands[1]->createLayout(displayMode)); } float Fraction::approximate(Context& context) const { diff --git a/poincare/src/function.cpp b/poincare/src/function.cpp index f2de243ea..64666ee7f 100644 --- a/poincare/src/function.cpp +++ b/poincare/src/function.cpp @@ -65,13 +65,13 @@ Expression * Function::clone() const { return this->cloneWithDifferentOperands(m_args, m_numberOfArguments, true); } -ExpressionLayout * Function::createLayout() const { +ExpressionLayout * Function::createLayout(DisplayMode displayMode) const { ExpressionLayout ** grandChildrenLayouts = (ExpressionLayout **)malloc((2*m_numberOfArguments-1)*sizeof(ExpressionLayout *)); int layoutIndex = 0; - grandChildrenLayouts[layoutIndex++] = m_args[0]->createLayout(); + grandChildrenLayouts[layoutIndex++] = m_args[0]->createLayout(displayMode); for (int i = 1; i < m_numberOfArguments; i++) { grandChildrenLayouts[layoutIndex++] = new StringLayout(",", 1); - grandChildrenLayouts[layoutIndex++] = m_args[i]->createLayout(); + grandChildrenLayouts[layoutIndex++] = m_args[i]->createLayout(displayMode); } ExpressionLayout * argumentLayouts = new HorizontalLayout(grandChildrenLayouts, 2*m_numberOfArguments-1); ExpressionLayout ** childrenLayouts = (ExpressionLayout **)malloc(2*sizeof(ExpressionLayout *)); diff --git a/poincare/src/integer.cpp b/poincare/src/integer.cpp index fa40731ff..ffa6be176 100644 --- a/poincare/src/integer.cpp +++ b/poincare/src/integer.cpp @@ -316,7 +316,7 @@ Expression::Type Integer::type() const { return Type::Integer; } -ExpressionLayout * Integer::createLayout() const { +ExpressionLayout * Integer::createLayout(DisplayMode displayMode) const { char buffer[255]; Integer base = Integer(10); diff --git a/poincare/src/integral.cpp b/poincare/src/integral.cpp index c853474a7..ad99cf7e6 100644 --- a/poincare/src/integral.cpp +++ b/poincare/src/integral.cpp @@ -41,11 +41,11 @@ float Integral::approximate(Context& context) const { #endif } -ExpressionLayout * Integral::createLayout() const { +ExpressionLayout * Integral::createLayout(DisplayMode displayMode) const { ExpressionLayout ** childrenLayouts = (ExpressionLayout **)malloc(2*sizeof(ExpressionLayout *)); - childrenLayouts[0] = m_args[0]->createLayout(); + childrenLayouts[0] = m_args[0]->createLayout(displayMode); childrenLayouts[1] = new StringLayout("dx", 2); - return new IntegralLayout(m_args[1]->createLayout(), m_args[2]->createLayout(), new HorizontalLayout(childrenLayouts, 2)); + return new IntegralLayout(m_args[1]->createLayout(displayMode), m_args[2]->createLayout(displayMode), new HorizontalLayout(childrenLayouts, 2)); } float Integral::functionValueAtAbscissa(float x, VariableContext xContext) const { diff --git a/poincare/src/logarithm.cpp b/poincare/src/logarithm.cpp index 3b3d3dcc5..55bb812c8 100644 --- a/poincare/src/logarithm.cpp +++ b/poincare/src/logarithm.cpp @@ -34,12 +34,12 @@ float Logarithm::approximate(Context& context) const { return log10f(m_args[1]->approximate(context))/log10f(m_args[0]->approximate(context)); } -ExpressionLayout * Logarithm::createLayout() const { +ExpressionLayout * Logarithm::createLayout(DisplayMode displayMode) const { if (m_numberOfArguments == 1) { - return Function::createLayout(); + return Function::createLayout(displayMode); } ExpressionLayout ** childrenLayouts = (ExpressionLayout **)malloc(2*sizeof(ExpressionLayout *)); - childrenLayouts[0] = new BaselineRelativeLayout(new StringLayout(m_name, strlen(m_name)), m_args[0]->createLayout(), BaselineRelativeLayout::Type::Subscript); - childrenLayouts[1] = new ParenthesisLayout(m_args[1]->createLayout()); + childrenLayouts[0] = new BaselineRelativeLayout(new StringLayout(m_name, strlen(m_name)), m_args[0]->createLayout(displayMode), BaselineRelativeLayout::Type::Subscript); + childrenLayouts[1] = new ParenthesisLayout(m_args[1]->createLayout(displayMode)); return new HorizontalLayout(childrenLayouts, 2); } diff --git a/poincare/src/matrix.cpp b/poincare/src/matrix.cpp index 976606b25..fc33c83fd 100644 --- a/poincare/src/matrix.cpp +++ b/poincare/src/matrix.cpp @@ -41,10 +41,10 @@ Expression * Matrix::clone() const { return this->cloneWithDifferentOperands(m_matrixData->operands(), numberOfOperands(), true); } -ExpressionLayout * Matrix::createLayout() const { +ExpressionLayout * Matrix::createLayout(DisplayMode displayMode) const { ExpressionLayout ** childrenLayouts = (ExpressionLayout **)malloc(numberOfOperands()*sizeof(ExpressionLayout *)); for (int i = 0; i < numberOfOperands(); i++) { - childrenLayouts[i] = operand(i)->createLayout(); + childrenLayouts[i] = operand(i)->createLayout(displayMode); } return new MatrixLayout(childrenLayouts, numberOfRows(), numberOfColumns()); } diff --git a/poincare/src/multiplication.cpp b/poincare/src/multiplication.cpp index f216e33ea..0d7a9f285 100644 --- a/poincare/src/multiplication.cpp +++ b/poincare/src/multiplication.cpp @@ -12,11 +12,11 @@ Expression::Type Multiplication::type() const { return Expression::Type::Multiplication; } -ExpressionLayout * Multiplication::createLayout() const { +ExpressionLayout * Multiplication::createLayout(DisplayMode displayMode) const { ExpressionLayout** children_layouts = (ExpressionLayout **)malloc(3*sizeof(ExpressionLayout *)); - children_layouts[0] = m_operands[0]->createLayout(); + children_layouts[0] = m_operands[0]->createLayout(displayMode); children_layouts[1] = new StringLayout("*", 1); - children_layouts[2] = m_operands[1]->type() == Type::Opposite ? new ParenthesisLayout(m_operands[1]->createLayout()) : m_operands[1]->createLayout(); + children_layouts[2] = m_operands[1]->type() == Type::Opposite ? new ParenthesisLayout(m_operands[1]->createLayout(displayMode)) : m_operands[1]->createLayout(displayMode); return new HorizontalLayout(children_layouts, 3); } diff --git a/poincare/src/nth_root.cpp b/poincare/src/nth_root.cpp index d379b065d..759f6c85d 100644 --- a/poincare/src/nth_root.cpp +++ b/poincare/src/nth_root.cpp @@ -28,6 +28,6 @@ float NthRoot::approximate(Context& context) const { return powf(m_args[0]->approximate(context), 1.0f/m_args[1]->approximate(context)); } -ExpressionLayout * NthRoot::createLayout() const { - return new NthRootLayout(m_args[0]->createLayout(), m_args[1]->createLayout()); +ExpressionLayout * NthRoot::createLayout(DisplayMode displayMode) const { + return new NthRootLayout(m_args[0]->createLayout(displayMode), m_args[1]->createLayout(displayMode)); } \ No newline at end of file diff --git a/poincare/src/opposite.cpp b/poincare/src/opposite.cpp index 99834ef16..fd1f355d1 100644 --- a/poincare/src/opposite.cpp +++ b/poincare/src/opposite.cpp @@ -49,11 +49,11 @@ Expression * Opposite::evaluate(Context& context) const { return result; } -ExpressionLayout * Opposite::createLayout() const { +ExpressionLayout * Opposite::createLayout(DisplayMode displayMode) const { ExpressionLayout** children_layouts = (ExpressionLayout **)malloc(2*sizeof(ExpressionLayout *)); char string[2] = {'-', '\0'}; children_layouts[0] = new StringLayout(string, 1); - children_layouts[1] = m_operand->type() == Type::Opposite ? new ParenthesisLayout(m_operand->createLayout()) : m_operand->createLayout(); + children_layouts[1] = m_operand->type() == Type::Opposite ? new ParenthesisLayout(m_operand->createLayout(displayMode)) : m_operand->createLayout(displayMode); return new HorizontalLayout(children_layouts, 2); } diff --git a/poincare/src/parenthesis.cpp b/poincare/src/parenthesis.cpp index 250f82a35..1bd678e05 100644 --- a/poincare/src/parenthesis.cpp +++ b/poincare/src/parenthesis.cpp @@ -31,8 +31,8 @@ Expression * Parenthesis::clone() const { return this->cloneWithDifferentOperands((Expression**) &m_operand, 1, true); } -ExpressionLayout * Parenthesis::createLayout() const { - return new ParenthesisLayout(m_operand->createLayout()); +ExpressionLayout * Parenthesis::createLayout(DisplayMode displayMode) const { + return new ParenthesisLayout(m_operand->createLayout(displayMode)); } float Parenthesis::approximate(Context& context) const { diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index 96bc42078..2beb35070 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -43,11 +43,11 @@ Expression * Power::cloneWithDifferentOperands(Expression** newOperands, return new Power(newOperands, cloneOperands); } -ExpressionLayout * Power::createLayout() const { +ExpressionLayout * Power::createLayout(DisplayMode displayMode) const { Expression * indiceOperand = m_operands[1]; // Delete eventual parentheses of the indice in the pretty print if (m_operands[1]->type() == Type::Parenthesis) { indiceOperand = (Expression *)m_operands[1]->operand(0); } - return new BaselineRelativeLayout(m_operands[0]->createLayout(),indiceOperand->createLayout(), BaselineRelativeLayout::Type::Superscript); + return new BaselineRelativeLayout(m_operands[0]->createLayout(displayMode),indiceOperand->createLayout(displayMode), BaselineRelativeLayout::Type::Superscript); } diff --git a/poincare/src/product.cpp b/poincare/src/product.cpp index 2765e736c..fb4f7dc79 100644 --- a/poincare/src/product.cpp +++ b/poincare/src/product.cpp @@ -42,9 +42,9 @@ float Product::approximate(Context& context) const { return result; } -ExpressionLayout * Product::createLayout() const { +ExpressionLayout * Product::createLayout(DisplayMode displayMode) const { ExpressionLayout ** childrenLayouts = (ExpressionLayout **)malloc(2*sizeof(ExpressionLayout *)); childrenLayouts[0] = new StringLayout("n=", 2); - childrenLayouts[1] = m_args[1]->createLayout(); - return new ProductLayout(new HorizontalLayout(childrenLayouts, 2), m_args[2]->createLayout(), m_args[0]->createLayout()); + childrenLayouts[1] = m_args[1]->createLayout(displayMode); + return new ProductLayout(new HorizontalLayout(childrenLayouts, 2), m_args[2]->createLayout(displayMode), m_args[0]->createLayout(displayMode)); } diff --git a/poincare/src/square_root.cpp b/poincare/src/square_root.cpp index 2456de922..ed07983e9 100644 --- a/poincare/src/square_root.cpp +++ b/poincare/src/square_root.cpp @@ -28,6 +28,6 @@ float SquareRoot::approximate(Context& context) const { return powf(m_args[0]->approximate(context), 1.0f/2.0f); } -ExpressionLayout * SquareRoot::createLayout() const { - return new NthRootLayout(m_args[0]->createLayout(),nullptr); +ExpressionLayout * SquareRoot::createLayout(DisplayMode displayMode) const { + return new NthRootLayout(m_args[0]->createLayout(displayMode),nullptr); } \ No newline at end of file diff --git a/poincare/src/subtraction.cpp b/poincare/src/subtraction.cpp index 7df835b29..a7f6a3e73 100644 --- a/poincare/src/subtraction.cpp +++ b/poincare/src/subtraction.cpp @@ -23,12 +23,12 @@ Expression::Type Subtraction::type() const { return Expression::Type::Subtraction; } -ExpressionLayout * Subtraction::createLayout() const { +ExpressionLayout * Subtraction::createLayout(DisplayMode displayMode) const { ExpressionLayout** children_layouts = (ExpressionLayout **)malloc(3*sizeof(ExpressionLayout *)); - children_layouts[0] = m_operands[0]->createLayout(); + children_layouts[0] = m_operands[0]->createLayout(displayMode); char string[2] = {'-', '\0'}; children_layouts[1] = new StringLayout(string, 1); - children_layouts[2] = m_operands[1]->type() == Type::Opposite ? new ParenthesisLayout(m_operands[1]->createLayout()) : m_operands[1]->createLayout(); + children_layouts[2] = m_operands[1]->type() == Type::Opposite ? new ParenthesisLayout(m_operands[1]->createLayout(displayMode)) : m_operands[1]->createLayout(displayMode); return new HorizontalLayout(children_layouts, 3); } diff --git a/poincare/src/sum.cpp b/poincare/src/sum.cpp index 4700b0257..49f005cbe 100644 --- a/poincare/src/sum.cpp +++ b/poincare/src/sum.cpp @@ -42,9 +42,9 @@ float Sum::approximate(Context& context) const { return result; } -ExpressionLayout * Sum::createLayout() const { +ExpressionLayout * Sum::createLayout(DisplayMode displayMode) const { ExpressionLayout ** childrenLayouts = (ExpressionLayout **)malloc(2*sizeof(ExpressionLayout *)); childrenLayouts[0] = new StringLayout("n=", 2); - childrenLayouts[1] = m_args[1]->createLayout(); - return new SumLayout(new HorizontalLayout(childrenLayouts, 2), m_args[2]->createLayout(), m_args[0]->createLayout()); + childrenLayouts[1] = m_args[1]->createLayout(displayMode); + return new SumLayout(new HorizontalLayout(childrenLayouts, 2), m_args[2]->createLayout(displayMode), m_args[0]->createLayout(displayMode)); } diff --git a/poincare/src/symbol.cpp b/poincare/src/symbol.cpp index 33aefd4c1..71bd034f2 100644 --- a/poincare/src/symbol.cpp +++ b/poincare/src/symbol.cpp @@ -31,7 +31,7 @@ const char Symbol::name() const { return m_name; } -ExpressionLayout * Symbol::createLayout() const { +ExpressionLayout * Symbol::createLayout(DisplayMode displayMode) const { if (m_name == SpecialSymbols::Ans) { return new StringLayout("ans", 4); } diff --git a/poincare/test/float.cpp b/poincare/test/float.cpp index ecc80170c..d65fc34c5 100644 --- a/poincare/test/float.cpp +++ b/poincare/test/float.cpp @@ -25,21 +25,21 @@ QUIZ_CASE(poincare_float_to_text) { assert(strcmp(buffer, "0.0E0") == 0); Float(10000000000000000000000000000.0f).convertFloatToText(buffer, 14, 7); assert(strcmp(buffer, "1.0E28") == 0); - Float(10000000000000000000000000000.0f).convertFloatToText(buffer, 14, 7, Float::DisplayMode::Decimal); + Float(10000000000000000000000000000.0f).convertFloatToText(buffer, 14, 7, Expression::DisplayMode::Auto); assert(strcmp(buffer, "1.0E28") == 0); - Float(1000000.0f).convertFloatToText(buffer, 14, 7, Float::DisplayMode::Decimal); + Float(1000000.0f).convertFloatToText(buffer, 14, 7, Expression::DisplayMode::Auto); assert(strcmp(buffer, "1000000") == 0); - Float(10000000.0f).convertFloatToText(buffer, 14, 7, Float::DisplayMode::Decimal); + Float(10000000.0f).convertFloatToText(buffer, 14, 7, Expression::DisplayMode::Auto); assert(strcmp(buffer, "1.0E7") == 0); - Float(0.000001f).convertFloatToText(buffer, 14, 7, Float::DisplayMode::Decimal); + Float(0.000001f).convertFloatToText(buffer, 14, 7, Expression::DisplayMode::Auto); assert(strcmp(buffer, "0.000001") == 0); - Float(0.0000001f).convertFloatToText(buffer, 14, 7, Float::DisplayMode::Decimal); + Float(0.0000001f).convertFloatToText(buffer, 14, 7, Expression::DisplayMode::Auto); assert(strcmp(buffer, "1.0E-7") == 0); char buffer2[6]; - Float(123.421f).convertFloatToText(buffer2, 6, 4, Float::DisplayMode::Decimal); + Float(123.421f).convertFloatToText(buffer2, 6, 4, Expression::DisplayMode::Auto); assert(strcmp(buffer2, "123.4") == 0); char buffer3[6]; - Float(123.421f).convertFloatToText(buffer3, 6, 5, Float::DisplayMode::Decimal); + Float(123.421f).convertFloatToText(buffer3, 6, 5, Expression::DisplayMode::Auto); assert(strcmp(buffer3, "1.2E2") == 0); }