From f591816122e19dae3abc5675c30e8e9f3b6a9eea Mon Sep 17 00:00:00 2001 From: Laury Date: Sat, 15 Jan 2022 12:40:06 +0100 Subject: [PATCH] [apps/functions] Save if user want display derivative even when quitting the app --- apps/graph/app.cpp | 6 ++++-- apps/graph/app.h | 2 ++ apps/graph/graph/graph_controller.cpp | 6 +++--- apps/graph/graph/graph_controller.h | 10 +++++----- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/apps/graph/app.cpp b/apps/graph/app.cpp index 68a4b4a9e..b4a74d8e4 100644 --- a/apps/graph/app.cpp +++ b/apps/graph/app.cpp @@ -27,7 +27,8 @@ const Image * App::Descriptor::icon() { App::Snapshot::Snapshot() : Shared::FunctionApp::Snapshot::Snapshot(), m_functionStore(), - m_graphRange() + m_graphRange(), + m_shouldDisplayDerivative(false) { } @@ -40,6 +41,7 @@ void App::Snapshot::reset() { for (int i = 0; i < Shared::ContinuousFunction::k_numberOfPlotTypes; i++) { m_interval[i].reset(); } + m_shouldDisplayDerivative = false; } App::Descriptor * App::Snapshot::descriptor() { @@ -58,7 +60,7 @@ App::App(Snapshot * snapshot) : m_listFooter(&m_listHeader, &m_listController, &m_listController, ButtonRowController::Position::Bottom, ButtonRowController::Style::EmbossedGray), m_listHeader(&m_listStackViewController, &m_listFooter, &m_listController), m_listStackViewController(&m_tabViewController, &m_listHeader), - m_graphController(&m_graphAlternateEmptyViewController, this, snapshot->graphRange(), snapshot->cursor(), snapshot->indexFunctionSelectedByCursor(), snapshot->rangeVersion(), &m_graphHeader), + m_graphController(&m_graphAlternateEmptyViewController, this, snapshot->graphRange(), snapshot->cursor(), snapshot->indexFunctionSelectedByCursor(), snapshot->rangeVersion(), &m_graphHeader, snapshot->shouldDisplayDerivative()), m_graphAlternateEmptyViewController(&m_graphHeader, &m_graphController, &m_graphController), m_graphHeader(&m_graphStackViewController, &m_graphAlternateEmptyViewController, &m_graphController), m_graphStackViewController(&m_tabViewController, &m_graphHeader), diff --git a/apps/graph/app.h b/apps/graph/app.h index f92557329..715c8bd2d 100644 --- a/apps/graph/app.h +++ b/apps/graph/app.h @@ -31,11 +31,13 @@ public: Shared::Interval * intervalForType(Shared::ContinuousFunction::PlotType plotType) { return m_interval + static_cast(plotType); } + bool * shouldDisplayDerivative() { return &m_shouldDisplayDerivative; } private: void tidy() override; ContinuousFunctionStore m_functionStore; Shared::InteractiveCurveViewRange m_graphRange; Shared::Interval m_interval[Shared::ContinuousFunction::k_numberOfPlotTypes]; + bool m_shouldDisplayDerivative; }; static App * app() { return static_cast(Container::activeApp()); diff --git a/apps/graph/graph/graph_controller.cpp b/apps/graph/graph/graph_controller.cpp index a6de84268..a07d49b39 100644 --- a/apps/graph/graph/graph_controller.cpp +++ b/apps/graph/graph/graph_controller.cpp @@ -7,13 +7,13 @@ using namespace Shared; namespace Graph { -GraphController::GraphController(Responder * parentResponder, ::InputEventHandlerDelegate * inputEventHandlerDelegate, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * rangeVersion, ButtonRowController * header) : +GraphController::GraphController(Responder * parentResponder, ::InputEventHandlerDelegate * inputEventHandlerDelegate, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * rangeVersion, ButtonRowController * header, bool * shouldDisplayDerivative) : FunctionGraphController(parentResponder, inputEventHandlerDelegate, header, curveViewRange, &m_view, cursor, indexFunctionSelectedByCursor, rangeVersion), m_bannerView(this, inputEventHandlerDelegate, this), m_view(curveViewRange, m_cursor, &m_bannerView, &m_cursorView), m_graphRange(curveViewRange), m_curveParameterController(inputEventHandlerDelegate, curveViewRange, &m_bannerView, m_cursor, &m_view, this), - m_displayDerivativeInBanner(false) + m_displayDerivativeInBanner(shouldDisplayDerivative) { m_graphRange->setDelegate(this); } @@ -47,7 +47,7 @@ void GraphController::selectFunctionWithCursor(int functionIndex) { void GraphController::reloadBannerView() { Ion::Storage::Record record = functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor()); - bool displayDerivative = m_displayDerivativeInBanner && + bool displayDerivative = *m_displayDerivativeInBanner && functionStore()->modelForRecord(record)->plotType() == ContinuousFunction::PlotType::Cartesian; m_bannerView.setNumberOfSubviews(Shared::XYBannerView::k_numberOfSubviews + displayDerivative); FunctionGraphController::reloadBannerView(); diff --git a/apps/graph/graph/graph_controller.h b/apps/graph/graph/graph_controller.h index 433ab9ebe..a740f4adc 100644 --- a/apps/graph/graph/graph_controller.h +++ b/apps/graph/graph/graph_controller.h @@ -15,13 +15,13 @@ namespace Graph { class GraphController : public Shared::FunctionGraphController, public GraphControllerHelper { public: - GraphController(Responder * parentResponder, ::InputEventHandlerDelegate * inputEventHandlerDelegate, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * rangeVersion, ButtonRowController * header); + GraphController(Responder * parentResponder, ::InputEventHandlerDelegate * inputEventHandlerDelegate, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * rangeVersion, ButtonRowController * header, bool * shouldDisplayDerivative); I18n::Message emptyMessage() override; void viewWillAppear() override; - bool displayDerivativeInBanner() const { return m_displayDerivativeInBanner; } - void setDisplayDerivativeInBanner(bool displayDerivative) { m_displayDerivativeInBanner = displayDerivative; } + bool displayDerivativeInBanner() const { return *m_displayDerivativeInBanner; } + void setDisplayDerivativeInBanner(bool displayDerivative) { *m_displayDerivativeInBanner = displayDerivative; } private: - int estimatedBannerNumberOfLines() const override { return 1 + m_displayDerivativeInBanner; } + int estimatedBannerNumberOfLines() const override { return 1 + *m_displayDerivativeInBanner; } void selectFunctionWithCursor(int functionIndex) override; BannerView * bannerView() override { return &m_bannerView; } void reloadBannerView() override; @@ -41,7 +41,7 @@ private: GraphView m_view; Shared::InteractiveCurveViewRange * m_graphRange; CurveParameterController m_curveParameterController; - bool m_displayDerivativeInBanner; + bool * m_displayDerivativeInBanner; }; }