diff --git a/apps/graph/values/values_controller.cpp b/apps/graph/values/values_controller.cpp index 6d9c000a6..6f729af42 100644 --- a/apps/graph/values/values_controller.cpp +++ b/apps/graph/values/values_controller.cpp @@ -44,8 +44,11 @@ ValuesController::ValuesController(Responder * parentResponder, InputEventHandle KDCoordinate ValuesController::columnWidth(int i) { ContinuousFunction::PlotType plotType = plotTypeAtColumn(&i); + if (i == 0) { + return k_abscissaCellWidth; + } if (i > 0 && plotType == ContinuousFunction::PlotType::Parametric) { - return 2*k_cellWidth; + return k_parametricCellWidth; } return k_cellWidth; } @@ -245,14 +248,17 @@ void ValuesController::printEvaluationOfAbscissaAtColumn(double abscissa, int co } } int numberOfChar = 0; + const int floatBufferSize = PrintFloat::bufferSizeForFloatsWithPrecision(Preferences::LargeNumberOfSignificantDigits); if (isParametric) { assert(numberOfChar < bufferSize-1); buffer[numberOfChar++] = '('; - numberOfChar += PoincareHelpers::ConvertFloatToText(evaluationX, buffer+numberOfChar, bufferSize-numberOfChar, Preferences::LargeNumberOfSignificantDigits); + assert(floatBufferSize <= bufferSize-numberOfChar); + numberOfChar += PoincareHelpers::ConvertFloatToText(evaluationX, buffer+numberOfChar, floatBufferSize, Preferences::LargeNumberOfSignificantDigits); assert(numberOfChar < bufferSize-1); buffer[numberOfChar++] = ';'; } - numberOfChar += PoincareHelpers::ConvertFloatToText(evaluationY, buffer+numberOfChar, bufferSize-numberOfChar, Preferences::LargeNumberOfSignificantDigits); + assert(floatBufferSize <= bufferSize-numberOfChar); + numberOfChar += PoincareHelpers::ConvertFloatToText(evaluationY, buffer+numberOfChar, floatBufferSize, Preferences::LargeNumberOfSignificantDigits); if (isParametric) { assert(numberOfChar+1 < bufferSize-1); buffer[numberOfChar++] = ')'; diff --git a/apps/graph/values/values_controller.h b/apps/graph/values/values_controller.h index 95da02dc2..ac7f34bc5 100644 --- a/apps/graph/values/values_controller.h +++ b/apps/graph/values/values_controller.h @@ -34,7 +34,9 @@ public: } void tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection = false) override; private: - static constexpr KDCoordinate k_cellWidth = 100; + static constexpr KDCoordinate k_abscissaCellWidth = k_cellWidth + Metric::TableSeparatorThickness; + static constexpr KDCoordinate k_parametricCellWidth = (2*Poincare::PrintFloat::glyphLengthForFloatWithPrecision(Poincare::Preferences::LargeNumberOfSignificantDigits)+3) * 7 + 2*Metric::CellMargin; // The largest cell is holding "(-1.234567E-123;-1.234567E-123)" and KDFont::SmallFont->glyphSize().width() = 7 + constexpr static int k_maxNumberOfFunctions = 5; constexpr static int k_maxNumberOfAbscissaCells = Shared::ContinuousFunction::k_numberOfPlotTypes * k_maxNumberOfRows; constexpr static int k_maxNumberOfCells = k_maxNumberOfFunctions * k_maxNumberOfRows; diff --git a/apps/sequence/values/values_controller.cpp b/apps/sequence/values/values_controller.cpp index e3c02b06c..847ff2363 100644 --- a/apps/sequence/values/values_controller.cpp +++ b/apps/sequence/values/values_controller.cpp @@ -4,6 +4,8 @@ #include "../../shared/poincare_helpers.h" #include "../app.h" +using namespace Poincare; + namespace Sequence { ValuesController::ValuesController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, ButtonRowController * header) : @@ -32,27 +34,7 @@ ValuesController::ValuesController(Responder * parentResponder, InputEventHandle } KDCoordinate ValuesController::columnWidth(int i) { - switch (i) { - case 0: - return k_abscissaCellWidth; - default: - return k_ordinateCellWidth; - } -} - -KDCoordinate ValuesController::cumulatedWidthFromIndex(int i) { - if (i == 0) { - return 0; - } else { - return k_abscissaCellWidth + (i-1)*k_ordinateCellWidth; - } -} - -int ValuesController::indexFromCumulatedWidth(KDCoordinate offsetX) { - if (offsetX <= k_abscissaCellWidth) { - return 0; - } - return (offsetX - k_abscissaCellWidth)/k_ordinateCellWidth+1; + return k_cellWidth; } void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { @@ -90,8 +72,10 @@ bool ValuesController::setDataAtLocation(double floatBody, int columnIndex, int void ValuesController::printEvaluationOfAbscissaAtColumn(double abscissa, int columnIndex, char * buffer, const int bufferSize) { Shared::ExpiringPointer sequence = functionStore()->modelForRecord(recordAtColumn(columnIndex)); - Poincare::Coordinate2D xy = sequence->evaluateXYAtParameter(abscissa, textFieldDelegateApp()->localContext()); - Shared::PoincareHelpers::ConvertFloatToText(xy.x2(), buffer, bufferSize, Poincare::Preferences::LargeNumberOfSignificantDigits); + Coordinate2D xy = sequence->evaluateXYAtParameter(abscissa, textFieldDelegateApp()->localContext()); + const int floatBufferSize = PrintFloat::bufferSizeForFloatsWithPrecision(Preferences::LargeNumberOfSignificantDigits); + assert(floatBufferSize <= bufferSize); + Shared::PoincareHelpers::ConvertFloatToText(xy.x2(), buffer, floatBufferSize, Preferences::LargeNumberOfSignificantDigits); } Shared::Interval * ValuesController::intervalAtColumn(int columnIndex) { diff --git a/apps/sequence/values/values_controller.h b/apps/sequence/values/values_controller.h index f4db4b8d9..b46723f5c 100644 --- a/apps/sequence/values/values_controller.h +++ b/apps/sequence/values/values_controller.h @@ -15,16 +15,12 @@ public: return const_cast