[apps] Factorize SimpleInteractiveCurveView::moveCursorHorizontally

This commit is contained in:
Ruben Dashyan
2019-03-20 12:06:40 +01:00
committed by Émilie Feral
parent 67f9f79322
commit f6ceae3b8b
8 changed files with 8 additions and 10 deletions

View File

@@ -76,7 +76,6 @@ bool CalculationGraphController::moveCursorHorizontally(int direction) {
return false;
}
m_cursor->moveTo(newPointOfInterest.abscissa, newPointOfInterest.value);
m_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
return true;
}

View File

@@ -81,7 +81,7 @@ void GraphController::reloadBannerView() {
bool GraphController::moveCursorHorizontally(int direction) {
Ion::Storage::Record record = functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor());
App * myApp = static_cast<App *>(app());
return privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, record, myApp, cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
return privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, record, myApp);
}
InteractiveCurveViewRange * GraphController::interactiveCurveViewRange() {

View File

@@ -9,13 +9,12 @@ using namespace Poincare;
namespace Graph {
bool GraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCursor * cursor, int direction, Shared::InteractiveCurveViewRange * range, int numberOfStepsInGradUnit, Ion::Storage::Record record, App * app, float cursorTopMarginRatio, float cursorRightMarginRatio, float cursorBottomMarginRatio, float cursorLeftMarginRatio) {
bool GraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCursor * cursor, int direction, Shared::InteractiveCurveViewRange * range, int numberOfStepsInGradUnit, Ion::Storage::Record record, App * app) {
ExpiringPointer<CartesianFunction> function = app->functionStore()->modelForRecord(record);
double xCursorPosition = cursor->x();
double x = direction > 0 ? xCursorPosition + range->xGridUnit()/numberOfStepsInGradUnit : xCursorPosition - range->xGridUnit()/numberOfStepsInGradUnit;
double y = function->evaluateAtAbscissa(x, app->localContext());
cursor->moveTo(x, y);
range->panToMakePointVisible(x, y, cursorTopMarginRatio, cursorRightMarginRatio, cursorBottomMarginRatio, cursorLeftMarginRatio);
return true;
}

View File

@@ -11,7 +11,7 @@ class App;
class GraphControllerHelper {
protected:
bool privateMoveCursorHorizontally(Shared::CurveViewCursor * cursor, int direction, Shared::InteractiveCurveViewRange * range, int numberOfStepsInGradUnit, Ion::Storage::Record record, App * app, float cursorTopMarginRatio, float cursorRightMarginRatio, float cursorBottomMarginRatio, float cursorLeftMarginRatio);
bool privateMoveCursorHorizontally(Shared::CurveViewCursor * cursor, int direction, Shared::InteractiveCurveViewRange * range, int numberOfStepsInGradUnit, Ion::Storage::Record record, App * app);
void reloadDerivativeInBannerViewForCursorOnFunction(Shared::CurveViewCursor * cursor, Ion::Storage::Record record, App * app);
virtual BannerView * bannerView() = 0;
};

View File

@@ -61,7 +61,7 @@ void TangentGraphController::reloadBannerView() {
bool TangentGraphController::moveCursorHorizontally(int direction) {
App * myApp = static_cast<App *>(app());
return privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, m_record, myApp, cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
return privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, m_record, myApp);
}
bool TangentGraphController::handleEnter() {

View File

@@ -219,13 +219,11 @@ bool GraphController::moveCursorHorizontally(int direction) {
if (dotSelected >= 0 && dotSelected < m_store->numberOfPairsOfSeries(*m_selectedSeriesIndex)) {
*m_selectedDotIndex = dotSelected;
m_cursor->moveTo(m_store->get(*m_selectedSeriesIndex, 0, *m_selectedDotIndex), m_store->get(*m_selectedSeriesIndex, 1, *m_selectedDotIndex));
m_store->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
return true;
}
if (dotSelected == m_store->numberOfPairsOfSeries(*m_selectedSeriesIndex)) {
*m_selectedDotIndex = dotSelected;
m_cursor->moveTo(m_store->meanOfColumn(*m_selectedSeriesIndex, 0), m_store->meanOfColumn(*m_selectedSeriesIndex, 1));
m_store->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
return true;
}
return false;
@@ -234,7 +232,6 @@ bool GraphController::moveCursorHorizontally(int direction) {
m_cursor->x() - m_store->xGridUnit()/k_numberOfCursorStepsInGradUnit;
double y = yValue(*m_selectedSeriesIndex, x, globalContext());
m_cursor->moveTo(x, y);
m_store->panToMakePointVisible(x, y, cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
return true;
}

View File

@@ -84,7 +84,6 @@ bool GraphController::moveCursorHorizontally(int direction) {
TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
double y = s->evaluateAtAbscissa(x, myApp->localContext());
m_cursor->moveTo(x, y);
m_graphRange->panToMakePointVisible(x, y, cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
return true;
}

View File

@@ -39,6 +39,10 @@ bool SimpleInteractiveCurveViewController::handleZoom(Ion::Events::Event event)
bool SimpleInteractiveCurveViewController::handleLeftRightEvent(Ion::Events::Event event) {
int direction = event == Ion::Events::Left ? -1 : 1;
if (moveCursorHorizontally(direction)) {
interactiveCurveViewRange()->panToMakePointVisible(
m_cursor->x(), m_cursor->y(),
cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio
);
reloadBannerView();
curveView()->reload();
return true;