Merge changes I1e27e39c,I4eda3763,Ie5ca7555,I5bc97824,I79e8bee7, ...

* changes:
  [apps/regression][apps/graph/graph] Jump to the graph view once setting a new abscissa/ ordinate in the go to page
  [apps] Select the first editable cell at initiation in store controllers and values controller
  [escher] Reorder actions to first do all frame layouts and then all "become first responder" (Thereby, enable to select a cell in becomefirstresponder without any weird scrolling due to wrong framing)
  [apps] Force the display mode to auto in all float parameter controller
  [apps/graph/values] Adjust display mode in values page according to preferences
  [apps/graph/graph] Adjust display mode in banner view according to preferences
  [apps/probability] Improve stack title colors
  [apps] Clean typo
  [apps/probability] Improve colors
  [apps/probability] Improve titles and parameter definitions layout
  [apps/prbability] Use special char for parameter names
  [apps/calculation] Create input and output layout according to display mode set in preference
  [kandinsky] [apps/probability] Clean deleted files
  [poincare] Change method createLayout() to createLayout(DisplayMode)
  [apps/calculation] Enable to recompute calculation in history
  [poincare] [apps] Merge Display mode enum class of Float and Preferences
  [apps] Display the preferences in the title bar
This commit is contained in:
Émilie Feral
2017-02-13 11:00:14 +01:00
committed by Gerrit
98 changed files with 450 additions and 320 deletions

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -5,16 +5,19 @@
#include "local_context.h"
#include "history_controller.h"
#include "../text_field_delegate_app.h"
#include "../preferences.h"
#include <escher.h>
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;

View File

@@ -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;

View File

@@ -2,20 +2,27 @@
#define CALCULATION_CALCULATION_H
#include <poincare.h>
#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:

View File

@@ -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++;
}

View File

@@ -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();

View File

@@ -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("");

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -2,6 +2,7 @@
#define APPS_EDITABLE_CELL_TABLE_VIEW_CONTROLLER_H
#include <escher.h>
#include <poincare.h>
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;

View File

@@ -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);
}

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -1,22 +1,20 @@
#ifndef APPS_PREFERENCES_H
#define APPS_PREFERENCES_H
#include <poincare.h>
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;

View File

@@ -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)
{
}

View File

@@ -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;
}
}

View File

@@ -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];
};
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 440 B

View File

@@ -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) {

View File

@@ -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;
}
}

View File

@@ -1,6 +1,7 @@
#include "poisson_law.h"
#include <assert.h>
#include <math.h>
#include <ion.h>
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() {

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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();
}

View File

@@ -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];
};
}

View File

@@ -23,7 +23,7 @@ CalculationController::CalculationController(Responder * parentResponder, Header
}
const char * CalculationController::title() const {
return "Statistics";
return "Statistiques";
}
View * CalculationController::view() {

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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) :

View File

@@ -1,11 +1,13 @@
#include "sub_controller.h"
#include "../apps_container.h"
#include <assert.h>
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);

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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();

View File

@@ -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;

View File

@@ -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();
}

View File

@@ -3,6 +3,7 @@
#include <escher.h>
#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

View File

@@ -224,6 +224,7 @@ VariableBoxController::VariableBoxController(Context * context) :
}
void VariableBoxController::didBecomeFirstResponder() {
StackViewController::didBecomeFirstResponder();
app()->setFirstResponder(&m_contentViewController);
}

View File

@@ -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

View File

@@ -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();
}

View File

@@ -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() {

View File

@@ -4,14 +4,11 @@ extern "C" {
#include <escher/stack_view_controller.h>
#include <escher/app.h>
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;
}

View File

@@ -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;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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)*/

View File

@@ -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,

View File

@@ -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;

View File

@@ -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:

View File

@@ -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
{

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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

View File

@@ -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,

View File

@@ -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;

View File

@@ -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,

View File

@@ -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

View File

@@ -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

View File

@@ -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,

View File

@@ -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

View File

@@ -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;

View File

@@ -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));
}

View File

@@ -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; i<m_numberOfOperands; i++) {
children_layouts[2*i-1] = new StringLayout("+", 1);
children_layouts[2*i] = m_operands[i]->type() == 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);
}

View File

@@ -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;
}

View File

@@ -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 {

View File

@@ -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 *));

View File

@@ -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);

View File

@@ -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 {

View File

@@ -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);
}

View File

@@ -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());
}

View File

@@ -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);
}

View File

@@ -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));
}

View File

@@ -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);
}

View File

@@ -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 {

View File

@@ -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);
}

View File

@@ -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));
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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));
}

View File

@@ -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);
}

View File

@@ -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);
}