mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[apps/range_parameter_controller] Remove YAuto
This allows for a great deal of simplifications in the class RangeParamterController. Change-Id: I5de55d4e8e1f598eb13b08fb8f042907f55b2fa8
This commit is contained in:
committed by
Émilie Feral
parent
5a07db3452
commit
1a5661fd4c
@@ -256,9 +256,6 @@ void GraphController::initCursorParameters() {
|
||||
double x = m_store->meanOfColumn(*m_selectedSeriesIndex, 0);
|
||||
double y = m_store->meanOfColumn(*m_selectedSeriesIndex, 1);
|
||||
m_cursor->moveTo(x, x, y);
|
||||
if (m_store->yAuto()) {
|
||||
m_store->panToMakePointVisible(x, y, cursorTopMarginRatio(), cursorRightMarginRatio(), cursorBottomMarginRatio(), cursorLeftMarginRatio(), curveView()->pixelWidth());
|
||||
}
|
||||
*m_selectedDotIndex = m_store->numberOfPairsOfSeries(*m_selectedSeriesIndex);
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,6 @@ int Store::nextDot(int series, int direction, int dot) {
|
||||
/* Window */
|
||||
|
||||
void Store::setDefault() {
|
||||
m_yAuto = true;
|
||||
float minX = FLT_MAX;
|
||||
float maxX = -FLT_MAX;
|
||||
for (int series = 0; series < k_numberOfSeries; series++) {
|
||||
|
||||
@@ -36,7 +36,6 @@ void CurveViewRange::normalize() {
|
||||
}
|
||||
|
||||
// Compute the Y
|
||||
m_yAuto = false;
|
||||
const float newYHalfRange = NormalizedYHalfRange(unit);
|
||||
float newYMin = yMean - newYHalfRange;
|
||||
float newYMax = clipped(yMean + newYHalfRange, true);
|
||||
|
||||
@@ -59,7 +59,6 @@ void GraphController::interestingRanges(InteractiveCurveViewRange * range) const
|
||||
assert(nmax - nmin >= k_defaultXHalfRange);
|
||||
|
||||
range->setXMin(nmin);
|
||||
range->setYAuto(true);
|
||||
range->setXMax(nmax);
|
||||
}
|
||||
|
||||
|
||||
@@ -187,7 +187,6 @@ TransposeCommandWithArg = "transpose(M)"
|
||||
XMax = "Xmax"
|
||||
XMin = "Xmin"
|
||||
X = "x"
|
||||
YAuto = "Y auto"
|
||||
YMax = "Ymax"
|
||||
YMin = "Ymin"
|
||||
Y = "y"
|
||||
|
||||
@@ -93,9 +93,6 @@ void FunctionGraphController::initCursorParameters() {
|
||||
functionIndex = 0;
|
||||
}
|
||||
m_cursor->moveTo(t, xy.x1(), xy.x2());
|
||||
if (interactiveCurveViewRange()->yAuto()) {
|
||||
interactiveCurveViewRange()->panToMakePointVisible(xy.x1(), xy.x2(), cursorTopMarginRatio(), cursorRightMarginRatio(), cursorBottomMarginRatio(), cursorLeftMarginRatio(), curveView()->pixelWidth());
|
||||
}
|
||||
selectFunctionWithCursor(functionIndex);
|
||||
}
|
||||
|
||||
@@ -153,7 +150,6 @@ void FunctionGraphController::interestingRanges(InteractiveCurveViewRange * rang
|
||||
|
||||
Shared::InteractiveCurveViewRangeDelegate::Range FunctionGraphController::computeYRange(Shared::InteractiveCurveViewRange * interactiveCurveViewRange) {
|
||||
InteractiveCurveViewRange tempRange = *interactiveCurveViewRange;
|
||||
tempRange.setYAuto(false);
|
||||
privateComputeRanges(false, &tempRange);
|
||||
return Shared::InteractiveCurveViewRangeDelegate::Range{.min = tempRange.yMin(), .max = tempRange.yMax()};
|
||||
}
|
||||
|
||||
@@ -11,17 +11,12 @@ using namespace Poincare;
|
||||
namespace Shared {
|
||||
|
||||
uint32_t InteractiveCurveViewRange::rangeChecksum() {
|
||||
float data[5] = {xMin(), xMax(), yMin(), yMax(), m_yAuto ? 1.0f : 0.0f};
|
||||
size_t dataLengthInBytes = 5*sizeof(float);
|
||||
float data[] = {xMin(), xMax(), yMin(), yMax()};
|
||||
size_t dataLengthInBytes = sizeof(data);
|
||||
assert((dataLengthInBytes & 0x3) == 0); // Assert that dataLengthInBytes is a multiple of 4
|
||||
return Ion::crc32Word((uint32_t *)data, dataLengthInBytes/sizeof(uint32_t));
|
||||
}
|
||||
|
||||
void InteractiveCurveViewRange::setYAuto(bool yAuto) {
|
||||
m_yAuto = yAuto;
|
||||
notifyRangeChange();
|
||||
}
|
||||
|
||||
void InteractiveCurveViewRange::setXMin(float xMin) {
|
||||
MemoizedCurveViewRange::protectedSetXMin(xMin, k_lowerMaxFloat, k_upperMaxFloat);
|
||||
notifyRangeChange();
|
||||
@@ -52,7 +47,6 @@ void InteractiveCurveViewRange::zoom(float ratio, float x, float y) {
|
||||
float centerY = std::isnan(y) || std::isinf(y) ? yCenter() : y;
|
||||
float newXMin = centerX*(1.0f-ratio)+ratio*xMi;
|
||||
float newXMax = centerX*(1.0f-ratio)+ratio*xMa;
|
||||
m_yAuto = false;
|
||||
if (!std::isnan(newXMin) && !std::isnan(newXMax)) {
|
||||
m_xRange.setMax(newXMax, k_lowerMaxFloat, k_upperMaxFloat);
|
||||
MemoizedCurveViewRange::protectedSetXMin(newXMin, k_lowerMaxFloat, k_upperMaxFloat);
|
||||
@@ -66,7 +60,6 @@ void InteractiveCurveViewRange::zoom(float ratio, float x, float y) {
|
||||
}
|
||||
|
||||
void InteractiveCurveViewRange::panWithVector(float x, float y) {
|
||||
m_yAuto = false;
|
||||
if (clipped(xMin() + x, false) != xMin() + x || clipped(xMax() + x, true) != xMax() + x || clipped(yMin() + y, false) != yMin() + y || clipped(yMax() + y, true) != yMax() + y || std::isnan(clipped(xMin() + x, false)) || std::isnan(clipped(xMax() + x, true)) || std::isnan(clipped(yMin() + y, false)) || std::isnan(clipped(yMax() + y, true))) {
|
||||
return;
|
||||
}
|
||||
@@ -80,8 +73,6 @@ void InteractiveCurveViewRange::normalize() {
|
||||
/* We center the ranges on the current range center, and put each axis so that
|
||||
* 1cm = 2 current units. */
|
||||
|
||||
m_yAuto = false;
|
||||
|
||||
float xRange = xMax() - xMin();
|
||||
float yRange = yMax() - yMin();
|
||||
float xyRatio = xRange/yRange;
|
||||
@@ -111,7 +102,6 @@ void InteractiveCurveViewRange::setDefault() {
|
||||
}
|
||||
|
||||
// Compute the interesting range
|
||||
m_yAuto = false;
|
||||
m_delegate->interestingRanges(this);
|
||||
|
||||
// Add margins
|
||||
@@ -143,7 +133,6 @@ void InteractiveCurveViewRange::centerAxisAround(Axis axis, float position) {
|
||||
m_xRange.setMax(position + range/2.0f, k_lowerMaxFloat, k_upperMaxFloat);
|
||||
MemoizedCurveViewRange::protectedSetXMin(position - range/2.0f, k_lowerMaxFloat, k_upperMaxFloat);
|
||||
} else {
|
||||
m_yAuto = false;
|
||||
float range = yMax() - yMin();
|
||||
if (std::fabs(position/range) > k_maxRatioPositionRange) {
|
||||
range = Range1D::defaultRangeLengthFor(position);
|
||||
@@ -158,7 +147,6 @@ void InteractiveCurveViewRange::panToMakePointVisible(float x, float y, float to
|
||||
const float xRange = xMax() - xMin();
|
||||
const float leftMargin = leftMarginRatio * xRange;
|
||||
if (x < xMin() + leftMargin) {
|
||||
m_yAuto = false;
|
||||
/* The panning increment is a whole number of pixels so that the caching
|
||||
* for cartesian functions is not invalidated. */
|
||||
const float newXMin = std::floor((x - leftMargin - xMin()) / pixelWidth) * pixelWidth + xMin();
|
||||
@@ -167,7 +155,6 @@ void InteractiveCurveViewRange::panToMakePointVisible(float x, float y, float to
|
||||
}
|
||||
const float rightMargin = rightMarginRatio * xRange;
|
||||
if (x > xMax() - rightMargin) {
|
||||
m_yAuto = false;
|
||||
const float newXMax = std::ceil((x + rightMargin - xMax()) / pixelWidth) * pixelWidth + xMax();
|
||||
m_xRange.setMax(newXMax, k_lowerMaxFloat, k_upperMaxFloat);
|
||||
MemoizedCurveViewRange::protectedSetXMin(xMax() - xRange, k_lowerMaxFloat, k_upperMaxFloat);
|
||||
@@ -177,14 +164,12 @@ void InteractiveCurveViewRange::panToMakePointVisible(float x, float y, float to
|
||||
const float yRange = yMax() - yMin();
|
||||
const float bottomMargin = bottomMarginRatio * yRange;
|
||||
if (y < yMin() + bottomMargin) {
|
||||
m_yAuto = false;
|
||||
const float newYMin = y - bottomMargin;
|
||||
m_yRange.setMax(newYMin + yRange, k_lowerMaxFloat, k_upperMaxFloat);
|
||||
MemoizedCurveViewRange::protectedSetYMin(newYMin, k_lowerMaxFloat, k_upperMaxFloat);
|
||||
}
|
||||
const float topMargin = topMarginRatio * yRange;
|
||||
if (y > yMax() - topMargin) {
|
||||
m_yAuto = false;
|
||||
m_yRange.setMax(y + topMargin, k_lowerMaxFloat, k_upperMaxFloat);
|
||||
MemoizedCurveViewRange::protectedSetYMin(yMax() - yRange, k_lowerMaxFloat, k_upperMaxFloat);
|
||||
}
|
||||
|
||||
@@ -13,16 +13,12 @@ class InteractiveCurveViewRange : public MemoizedCurveViewRange {
|
||||
public:
|
||||
InteractiveCurveViewRange(InteractiveCurveViewRangeDelegate * delegate = nullptr) :
|
||||
MemoizedCurveViewRange(),
|
||||
m_yAuto(true),
|
||||
m_delegate(delegate)
|
||||
{}
|
||||
|
||||
void setDelegate(InteractiveCurveViewRangeDelegate * delegate) { m_delegate = delegate; }
|
||||
uint32_t rangeChecksum() override;
|
||||
|
||||
bool yAuto() const { return m_yAuto; }
|
||||
void setYAuto(bool yAuto);
|
||||
|
||||
// CurveViewWindow
|
||||
void setXMin(float f) override;
|
||||
void setXMax(float f) override;
|
||||
@@ -55,7 +51,6 @@ protected:
|
||||
* 2 * 1 unit -> 10.0mm
|
||||
* So normalizedYHalfRange = 43.2mm * 170/240 * 1 unit / 10.0mm */
|
||||
constexpr static float NormalizedYHalfRange(float unit) { return 3.06f * unit; }
|
||||
bool m_yAuto;
|
||||
InteractiveCurveViewRangeDelegate * m_delegate;
|
||||
private:
|
||||
void notifyRangeChange();
|
||||
|
||||
@@ -6,42 +6,9 @@
|
||||
namespace Shared {
|
||||
|
||||
bool InteractiveCurveViewRangeDelegate::didChangeRange(InteractiveCurveViewRange * interactiveCurveViewRange) {
|
||||
/* When y auto is ticked, top and bottom margins are added to ensure that
|
||||
* the cursor can be move along the curve, in the current x-range,
|
||||
* without panning the window. */
|
||||
if (!interactiveCurveViewRange->yAuto()) {
|
||||
return false;
|
||||
}
|
||||
Range yRange = computeYRange(interactiveCurveViewRange);
|
||||
float max = yRange.max;
|
||||
float min = yRange.min;
|
||||
float range = max - min;
|
||||
if (max < min) {
|
||||
range = 0.0f;
|
||||
}
|
||||
if (interactiveCurveViewRange->yMin() == addMargin(min, range, true, true) && interactiveCurveViewRange->yMax() == addMargin(max, range, true, false)) {
|
||||
return false;
|
||||
}
|
||||
if (min == max) {
|
||||
// Add same margin on top of / below the curve, to center it on the screen
|
||||
float step = max != 0.0f ? 2.0f * Range1D::defaultRangeLengthFor(max) : 1.0f;
|
||||
min = min - step;
|
||||
max = max + step;
|
||||
}
|
||||
if (min == FLT_MAX && max == -FLT_MAX) {
|
||||
min = -1.0f;
|
||||
max = 1.0f;
|
||||
}
|
||||
range = max - min;
|
||||
interactiveCurveViewRange->setYMin(addMargin(min, range, true, true));
|
||||
interactiveCurveViewRange->setYMax(addMargin(max, range, true, false));
|
||||
if (std::isinf(interactiveCurveViewRange->xMin())) {
|
||||
interactiveCurveViewRange->setYMin(-FLT_MAX);
|
||||
}
|
||||
if (std::isinf(interactiveCurveViewRange->xMax())) {
|
||||
interactiveCurveViewRange->setYMax(FLT_MAX);
|
||||
}
|
||||
return true;
|
||||
/*TODO : De we want to keep this method ?
|
||||
* We might want to put some computations in here, like the new Auto and Normailzed statuses. */
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,23 +9,16 @@ RangeParameterController::RangeParameterController(Responder * parentResponder,
|
||||
FloatParameterController<float>(parentResponder),
|
||||
m_interactiveRange(interactiveRange),
|
||||
m_tempInteractiveRange(*interactiveRange),
|
||||
m_xRangeCells{},
|
||||
m_yRangeCells{},
|
||||
m_yAutoCell(I18n::Message::YAuto),
|
||||
m_rangeCells{},
|
||||
m_confirmPopUpController(Invocation([](void * context, void * sender) {
|
||||
Container::activeApp()->dismissModalViewController();
|
||||
((RangeParameterController *)context)->stackController()->pop();
|
||||
return true;
|
||||
}, this))
|
||||
{
|
||||
for (int i = 0; i < k_numberOfEditableTextCell; i++) {
|
||||
m_xRangeCells[i].setParentResponder(&m_selectableTableView);
|
||||
m_xRangeCells[i].textField()->setDelegates(inputEventHandlerDelegate, this);
|
||||
}
|
||||
for (int i = 0; i < k_numberOfConvertibleTextCell; i++) {
|
||||
m_yRangeCells[i].setParentResponder(&m_selectableTableView);
|
||||
m_yRangeCells[i].setInteractiveCurveViewRange(&m_tempInteractiveRange);
|
||||
m_yRangeCells[i].textField()->setDelegates(inputEventHandlerDelegate, this);
|
||||
for (int i = 0; i < k_numberOfTextCell; i++) {
|
||||
m_rangeCells[i].setParentResponder(&m_selectableTableView);
|
||||
m_rangeCells[i].textField()->setDelegates(inputEventHandlerDelegate, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,59 +27,26 @@ const char * RangeParameterController::title() {
|
||||
}
|
||||
|
||||
int RangeParameterController::numberOfRows() const {
|
||||
return k_numberOfTextCell+2;
|
||||
}
|
||||
|
||||
int RangeParameterController::typeAtLocation(int i, int j) {
|
||||
if (j == numberOfRows()-1) {
|
||||
return 0;
|
||||
}
|
||||
if (j >= 0 && j < 2) {
|
||||
return 1;
|
||||
}
|
||||
if (j == 2) {
|
||||
return 2;
|
||||
}
|
||||
return 3;
|
||||
return k_numberOfTextCell+1;
|
||||
}
|
||||
|
||||
void RangeParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) {
|
||||
if (index == numberOfRows()-1) {
|
||||
return;
|
||||
}
|
||||
if (index == 2) {
|
||||
SwitchView * switchView = (SwitchView *)m_yAutoCell.accessoryView();
|
||||
switchView->setState(m_tempInteractiveRange.yAuto());
|
||||
return;
|
||||
}
|
||||
MessageTableCellWithEditableText * myCell = (MessageTableCellWithEditableText *)cell;
|
||||
I18n::Message labels[k_numberOfTextCell+1] = {I18n::Message::XMin, I18n::Message::XMax, I18n::Message::Default, I18n::Message::YMin, I18n::Message::YMax};
|
||||
I18n::Message labels[k_numberOfTextCell] = {I18n::Message::XMin, I18n::Message::XMax, I18n::Message::YMin, I18n::Message::YMax};
|
||||
myCell->setMessage(labels[index]);
|
||||
KDColor yColor = m_tempInteractiveRange.yAuto() ? Palette::GrayDark : KDColorBlack;
|
||||
KDColor colors[k_numberOfTextCell+1] = {KDColorBlack, KDColorBlack, KDColorBlack, yColor, yColor};
|
||||
myCell->setTextColor(colors[index]);
|
||||
myCell->setTextColor(KDColorBlack);
|
||||
FloatParameterController::willDisplayCellForIndex(cell, index);
|
||||
}
|
||||
|
||||
bool RangeParameterController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {
|
||||
if (FloatParameterController::textFieldDidFinishEditing(textField, text, event)) {
|
||||
m_selectableTableView.reloadData();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void RangeParameterController::setRange(InteractiveCurveViewRange * range){
|
||||
m_interactiveRange = range;
|
||||
m_tempInteractiveRange = *range;
|
||||
}
|
||||
|
||||
bool RangeParameterController::handleEvent(Ion::Events::Event event) {
|
||||
if (activeCell() == 2 && (event == Ion::Events::OK || event == Ion::Events::EXE)) {
|
||||
m_tempInteractiveRange.setYAuto(!m_tempInteractiveRange.yAuto());
|
||||
m_selectableTableView.reloadData();
|
||||
return true;
|
||||
}
|
||||
if (event == Ion::Events::Back && m_interactiveRange->rangeChecksum() != m_tempInteractiveRange.rangeChecksum()) {
|
||||
// Open pop-up to confirm discarding values
|
||||
Container::activeApp()->displayModalViewController(&m_confirmPopUpController, 0.f, 0.f, Metric::ExamPopUpTopMargin, Metric::PopUpRightMargin, Metric::ExamPopUpBottomMargin, Metric::PopUpLeftMargin);
|
||||
@@ -98,41 +58,25 @@ bool RangeParameterController::handleEvent(Ion::Events::Event event) {
|
||||
float RangeParameterController::parameterAtIndex(int parameterIndex) {
|
||||
ParameterGetterPointer getters[k_numberOfTextCell] = {&InteractiveCurveViewRange::xMin,
|
||||
&InteractiveCurveViewRange::xMax, &InteractiveCurveViewRange::yMin, &InteractiveCurveViewRange::yMax};
|
||||
int index = parameterIndex > 2 ? parameterIndex - 1 : parameterIndex;
|
||||
return (m_tempInteractiveRange.*getters[index])();
|
||||
return (m_tempInteractiveRange.*getters[parameterIndex])();
|
||||
}
|
||||
|
||||
bool RangeParameterController::setParameterAtIndex(int parameterIndex, float f) {
|
||||
ParameterSetterPointer setters[k_numberOfTextCell] = {&InteractiveCurveViewRange::setXMin,
|
||||
&InteractiveCurveViewRange::setXMax, &InteractiveCurveViewRange::setYMin, &InteractiveCurveViewRange::setYMax};
|
||||
int index = parameterIndex > 2 ? parameterIndex - 1 : parameterIndex;
|
||||
(m_tempInteractiveRange.*setters[index])(f);
|
||||
(m_tempInteractiveRange.*setters[parameterIndex])(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
HighlightCell * RangeParameterController::reusableParameterCell(int index, int type) {
|
||||
if (type == 2) {
|
||||
assert(index == 0);
|
||||
return &m_yAutoCell;
|
||||
}
|
||||
if (type == 1) {
|
||||
assert(index >= 0);
|
||||
assert(index < k_numberOfEditableTextCell);
|
||||
return &m_xRangeCells[index];
|
||||
}
|
||||
assert(index >= 0);
|
||||
assert(index < k_numberOfConvertibleTextCell);
|
||||
return &m_yRangeCells[index];
|
||||
assert(type == 1);
|
||||
assert(index >= 0 && index < k_numberOfTextCell);
|
||||
return m_rangeCells + index;
|
||||
}
|
||||
|
||||
int RangeParameterController::reusableParameterCellCount(int type) {
|
||||
if (type == 2) {
|
||||
return 1;
|
||||
}
|
||||
if (type == 1) {
|
||||
return k_numberOfEditableTextCell;
|
||||
}
|
||||
return k_numberOfConvertibleTextCell;
|
||||
assert(type == 1);
|
||||
return k_numberOfTextCell;
|
||||
}
|
||||
|
||||
void RangeParameterController::buttonAction() {
|
||||
|
||||
@@ -13,39 +13,20 @@ public:
|
||||
RangeParameterController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, InteractiveCurveViewRange * interactiveCurveViewRange);
|
||||
const char * title() override;
|
||||
int numberOfRows() const override;
|
||||
int typeAtLocation(int i, int j) override;
|
||||
void willDisplayCellForIndex(HighlightCell * cell, int index) override;
|
||||
bool textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) override;
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
void setRange(InteractiveCurveViewRange * range);
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
TELEMETRY_ID("Range");
|
||||
private:
|
||||
class MessageTableCellWithConvertibleEditableText : public MessageTableCellWithEditableText {
|
||||
public:
|
||||
Responder * responder() override {
|
||||
if (m_interactiveRange->yAuto()) {
|
||||
return nullptr;
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
void setInteractiveCurveViewRange(InteractiveCurveViewRange * interactiveCurveViewRange) { m_interactiveRange = interactiveCurveViewRange; }
|
||||
private:
|
||||
InteractiveCurveViewRange * m_interactiveRange;
|
||||
};
|
||||
HighlightCell * reusableParameterCell(int index, int type) override;
|
||||
int reusableParameterCellCount(int type) override;
|
||||
float parameterAtIndex(int index) override;
|
||||
bool setParameterAtIndex(int parameterIndex, float f) override;
|
||||
void buttonAction() override;
|
||||
constexpr static int k_numberOfEditableTextCell = 2;
|
||||
constexpr static int k_numberOfConvertibleTextCell = 2;
|
||||
constexpr static int k_numberOfTextCell = k_numberOfEditableTextCell+k_numberOfConvertibleTextCell;
|
||||
constexpr static int k_numberOfTextCell = 4;
|
||||
InteractiveCurveViewRange * m_interactiveRange;
|
||||
InteractiveCurveViewRange m_tempInteractiveRange;
|
||||
MessageTableCellWithEditableText m_xRangeCells[k_numberOfEditableTextCell];
|
||||
MessageTableCellWithConvertibleEditableText m_yRangeCells[k_numberOfConvertibleTextCell];
|
||||
MessageTableCellWithSwitch m_yAutoCell;
|
||||
MessageTableCellWithEditableText m_rangeCells[k_numberOfTextCell];
|
||||
DiscardPopUpController m_confirmPopUpController;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user