From e47ab69e533df2e5585048848de140ab0be31885 Mon Sep 17 00:00:00 2001 From: Ruben Dashyan Date: Fri, 22 Mar 2019 18:08:54 +0100 Subject: [PATCH] [apps/shared] Implement SumGraphController::handleLeftRightEvent --- apps/shared/sum_graph_controller.cpp | 41 ++++++++++------------------ apps/shared/sum_graph_controller.h | 1 + 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/apps/shared/sum_graph_controller.cpp b/apps/shared/sum_graph_controller.cpp index be632a886..f0335832e 100644 --- a/apps/shared/sum_graph_controller.cpp +++ b/apps/shared/sum_graph_controller.cpp @@ -51,31 +51,7 @@ void SumGraphController::didEnterResponderChain(Responder * previousFirstRespond } bool SumGraphController::handleEvent(Ion::Events::Event event) { - if (event == Ion::Events::Plus || event == Ion::Events::Minus) { - return handleZoom(event); - } - if ((int)m_step > 1 && event != Ion::Events::OK && event != Ion::Events::EXE && event != Ion::Events::Back) { - return false; - } - if (event == Ion::Events::Left && !m_legendView.textField()->isEditing()) { - if ((int)m_step > 0 && m_startSum >= m_cursor->x()) { - return false; - } - if (moveCursorHorizontallyToPosition(cursorNextStep(m_cursor->x(), -1))) { - return true; - } - return false; - } - if (event == Ion::Events::Right && !m_legendView.textField()->isEditing()) { - if (moveCursorHorizontallyToPosition(cursorNextStep(m_cursor->x(), 1))) { - return true; - } - return false; - } - if (event == Ion::Events::OK || event == Ion::Events::EXE) { - return handleEnter(); - } - if (event == Ion::Events::Back && (int)m_step > 0) { + if (event == Ion::Events::Back && m_step != Step::FirstParameter) { m_step = (Step)((int)m_step-1); m_legendView.setLegendMessage(legendMessageAtStep(m_step), m_step); if (m_step == Step::SecondParameter) { @@ -94,7 +70,7 @@ bool SumGraphController::handleEvent(Ion::Events::Event event) { } return true; } - return false; + return SimpleInteractiveCurveViewController::handleEvent(event); } bool SumGraphController::moveCursorHorizontallyToPosition(double x) { @@ -148,6 +124,19 @@ bool SumGraphController::textFieldDidReceiveEvent(TextField * textField, Ion::Ev return TextFieldDelegate::textFieldDidReceiveEvent(textField, event); } +bool SumGraphController::handleLeftRightEvent(Ion::Events::Event event) { + if (m_step == Step::Result) { + return false; + } + const double oldPosition = m_cursor->x(); + int direction = event == Ion::Events::Left ? -1 : 1; + double newPosition = cursorNextStep(oldPosition, direction); + if (m_step == Step::SecondParameter && newPosition < m_startSum) { + newPosition = m_startSum; + } + return moveCursorHorizontallyToPosition(newPosition); +} + bool SumGraphController::handleEnter() { if (m_step == Step::Result) { StackViewController * stack = (StackViewController *)parentResponder(); diff --git a/apps/shared/sum_graph_controller.h b/apps/shared/sum_graph_controller.h index dd9fa5052..7c8e830b4 100644 --- a/apps/shared/sum_graph_controller.h +++ b/apps/shared/sum_graph_controller.h @@ -36,6 +36,7 @@ protected: private: constexpr static float k_cursorTopMarginRatio = 0.06f; // (cursorHeight/2)/graphViewHeight constexpr static float k_cursorBottomMarginRatio = 0.28f; // (cursorHeight/2+bannerHeigh)/graphViewHeight + bool handleLeftRightEvent(Ion::Events::Event event) override; virtual I18n::Message legendMessageAtStep(Step step) = 0; virtual double cursorNextStep(double position, int direction) = 0; virtual Poincare::Layout createFunctionLayout(ExpiringPointer function) = 0;