mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps/shared] EditableCellTableViewController: adjust column width to be
able to display float like "-1.234567E-123"
This commit is contained in:
committed by
LeaNumworks
parent
501f7ed8af
commit
d6ad694b76
@@ -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<double>(evaluationX, buffer+numberOfChar, bufferSize-numberOfChar, Preferences::LargeNumberOfSignificantDigits);
|
||||
assert(floatBufferSize <= bufferSize-numberOfChar);
|
||||
numberOfChar += PoincareHelpers::ConvertFloatToText<double>(evaluationX, buffer+numberOfChar, floatBufferSize, Preferences::LargeNumberOfSignificantDigits);
|
||||
assert(numberOfChar < bufferSize-1);
|
||||
buffer[numberOfChar++] = ';';
|
||||
}
|
||||
numberOfChar += PoincareHelpers::ConvertFloatToText<double>(evaluationY, buffer+numberOfChar, bufferSize-numberOfChar, Preferences::LargeNumberOfSignificantDigits);
|
||||
assert(floatBufferSize <= bufferSize-numberOfChar);
|
||||
numberOfChar += PoincareHelpers::ConvertFloatToText<double>(evaluationY, buffer+numberOfChar, floatBufferSize, Preferences::LargeNumberOfSignificantDigits);
|
||||
if (isParametric) {
|
||||
assert(numberOfChar+1 < bufferSize-1);
|
||||
buffer[numberOfChar++] = ')';
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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> sequence = functionStore()->modelForRecord(recordAtColumn(columnIndex));
|
||||
Poincare::Coordinate2D<double> xy = sequence->evaluateXYAtParameter(abscissa, textFieldDelegateApp()->localContext());
|
||||
Shared::PoincareHelpers::ConvertFloatToText<double>(xy.x2(), buffer, bufferSize, Poincare::Preferences::LargeNumberOfSignificantDigits);
|
||||
Coordinate2D<double> xy = sequence->evaluateXYAtParameter(abscissa, textFieldDelegateApp()->localContext());
|
||||
const int floatBufferSize = PrintFloat::bufferSizeForFloatsWithPrecision(Preferences::LargeNumberOfSignificantDigits);
|
||||
assert(floatBufferSize <= bufferSize);
|
||||
Shared::PoincareHelpers::ConvertFloatToText<double>(xy.x2(), buffer, floatBufferSize, Preferences::LargeNumberOfSignificantDigits);
|
||||
}
|
||||
|
||||
Shared::Interval * ValuesController::intervalAtColumn(int columnIndex) {
|
||||
|
||||
@@ -15,16 +15,12 @@ public:
|
||||
return const_cast<Button *>(&m_setIntervalButton);
|
||||
}
|
||||
KDCoordinate columnWidth(int i) override;
|
||||
KDCoordinate cumulatedWidthFromIndex(int i) override;
|
||||
int indexFromCumulatedWidth(KDCoordinate offsetX) override;
|
||||
void willDisplayCellAtLocation(HighlightCell * cell, int i, int j) override;
|
||||
I18n::Message emptyMessage() override;
|
||||
IntervalParameterController * intervalParameterController() override {
|
||||
return &m_intervalParameterController;
|
||||
}
|
||||
private:
|
||||
static constexpr KDCoordinate k_abscissaCellWidth = 100;
|
||||
static constexpr KDCoordinate k_ordinateCellWidth = 100;
|
||||
void setStartEndMessages(Shared::IntervalParameterController * controller, int column) override;
|
||||
bool setDataAtLocation(double floatBody, int columnIndex, int rowIndex) override;
|
||||
void printEvaluationOfAbscissaAtColumn(double abscissa, int columnIndex, char * buffer, const int bufferSize) override;
|
||||
|
||||
@@ -78,14 +78,15 @@ void EditableCellTableViewController::willDisplayCellAtLocationWithDisplayMode(H
|
||||
if (cellAtLocationIsEditable(i, j)) {
|
||||
EvenOddEditableTextCell * myEditableValueCell = (EvenOddEditableTextCell *)cell;
|
||||
assert(!myEditableValueCell->editableTextCell()->textField()->isEditing());
|
||||
char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Preferences::LargeNumberOfSignificantDigits)];
|
||||
const int bufferSize = PrintFloat::bufferSizeForFloatsWithPrecision(Preferences::LargeNumberOfSignificantDigits);
|
||||
char buffer[bufferSize];
|
||||
// Special case 1: last row
|
||||
if (j == numberOfElementsInColumn(i) + 1) {
|
||||
/* Display an empty line only if there is enough space for a new element in
|
||||
* data */
|
||||
buffer[0] = 0;
|
||||
} else {
|
||||
PrintFloat::ConvertFloatToText<double>(dataAtLocation(i, j), buffer, cellBufferSize(i), Preferences::LargeNumberOfSignificantDigits, floatDisplayMode);
|
||||
PrintFloat::ConvertFloatToText<double>(dataAtLocation(i, j), buffer, bufferSize, Preferences::LargeNumberOfSignificantDigits, floatDisplayMode);
|
||||
}
|
||||
myEditableValueCell->editableTextCell()->textField()->setText(buffer);
|
||||
}
|
||||
|
||||
@@ -24,11 +24,6 @@ protected:
|
||||
static constexpr KDCoordinate k_cellHeight = 20;
|
||||
static constexpr KDCoordinate k_margin = Metric::TableSeparatorThickness;
|
||||
static constexpr KDCoordinate k_scrollBarMargin = Metric::CommonRightMargin;
|
||||
/* Editable cell might be not wide enough to display
|
||||
* LargeNumberOfSignificantDigits, we update the buffer to the column width. */
|
||||
size_t cellBufferSize(int i) {
|
||||
return columnWidth(i)/KDFont::SmallFont->glyphSize().width()+1+Poincare::PrintFloat::k_specialECodePointByteLength-1;
|
||||
}
|
||||
private:
|
||||
virtual bool cellAtLocationIsEditable(int columnIndex, int rowIndex) = 0;
|
||||
virtual bool setDataAtLocation(double floatBody, int columnIndex, int rowIndex) = 0;
|
||||
|
||||
@@ -46,6 +46,8 @@ public:
|
||||
|
||||
protected:
|
||||
static constexpr KDCoordinate k_cellWidth = 116;
|
||||
static_assert((Poincare::PrintFloat::glyphLengthForFloatWithPrecision(Poincare::Preferences::LargeNumberOfSignificantDigits)) * 7 + 2*Metric::CellMargin < k_cellWidth, "Store controller cells are too small to hold values like '-1.234567E-123'"); // KDFont::SmallFont->glyphSize().width() = 7
|
||||
|
||||
constexpr static int k_maxNumberOfEditableCells = (Ion::Display::Width/k_cellWidth+2) * ((Ion::Display::Height - Metric::TitleBarHeight - Metric::TabHeight)/k_cellHeight+2);
|
||||
constexpr static int k_numberOfTitleCells = 4;
|
||||
static constexpr int k_titleCellType = 0;
|
||||
|
||||
@@ -124,13 +124,14 @@ void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, in
|
||||
willDisplayCellAtLocationWithDisplayMode(cell, i, j, Preferences::sharedPreferences()->displayMode());
|
||||
// The cell is not a title cell and not editable
|
||||
if (typeAtLocation(i,j) == k_notEditableValueCellType) {
|
||||
char buffer[2*PrintFloat::bufferSizeForFloatsWithPrecision(Preferences::LargeNumberOfSignificantDigits)+3];//(??;??)
|
||||
constexpr int bufferSize = 2*PrintFloat::bufferSizeForFloatsWithPrecision(Preferences::LargeNumberOfSignificantDigits)+3;
|
||||
char buffer[bufferSize]; // The largest buffer holds (-1.234567E-123;-1.234567E-123)
|
||||
// Special case: last row
|
||||
if (j == numberOfElementsInColumn(i) + 1) {
|
||||
buffer[0] = 0;
|
||||
} else {
|
||||
double x = intervalAtColumn(i)->element(j-1);
|
||||
printEvaluationOfAbscissaAtColumn(x, i, buffer, cellBufferSize(i));
|
||||
printEvaluationOfAbscissaAtColumn(x, i, buffer, bufferSize);
|
||||
}
|
||||
static_cast<EvenOddBufferTextCell *>(cell)->setText(buffer);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ public:
|
||||
void viewDidDisappear() override;
|
||||
|
||||
protected:
|
||||
static constexpr KDCoordinate k_cellWidth = (Poincare::PrintFloat::glyphLengthForFloatWithPrecision(Poincare::Preferences::LargeNumberOfSignificantDigits)) * 7 + 2*Metric::CellMargin; // KDFont::SmallFont->glyphSize().width() = 7
|
||||
static constexpr int k_abscissaTitleCellType = 0;
|
||||
static constexpr int k_functionTitleCellType = 1;
|
||||
static constexpr int k_editableValueCellType = 2;
|
||||
|
||||
Reference in New Issue
Block a user