From 496a10aebdedac4a5fc4560a88de26f70b7e51e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 15 Sep 2016 10:04:35 +0200 Subject: [PATCH] [Graph/List] Add a stack controller to handle the parameter page Change-Id: I7d3f916b2f2ae981bc8cd16b70e6e841e687f2e7 --- apps/graph/graph_app.cpp | 5 ++++- apps/graph/graph_app.h | 1 + apps/probability/app.cpp | 3 +-- escher/include/escher/stack_view_controller.h | 5 +++-- escher/src/stack_view_controller.cpp | 22 +++++++++++++++++-- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/apps/graph/graph_app.cpp b/apps/graph/graph_app.cpp index 88f27b222..b9292e72e 100644 --- a/apps/graph/graph_app.cpp +++ b/apps/graph/graph_app.cpp @@ -4,11 +4,14 @@ GraphApp::GraphApp() : App(), m_functionStore(Graph::FunctionStore()), m_listController(ListController(nullptr, &m_functionStore)), + m_listStackViewController(StackViewController(&m_tabViewController, &m_listController)), m_graphController(GraphController(nullptr, &m_functionStore)), - m_tabViewController(this, &m_listController, &m_graphController) + m_tabViewController(this, &m_listStackViewController, &m_graphController) { m_functionStore.pushFunction("(x-1)*(x+1)*x"); m_functionStore.pushFunction("x*x"); + m_functionStore.pushFunction("3"); + m_functionStore.pushFunction("x*x*x"); } ViewController * GraphApp::rootViewController() { diff --git a/apps/graph/graph_app.h b/apps/graph/graph_app.h index 2efc47cc8..9bcb1329e 100644 --- a/apps/graph/graph_app.h +++ b/apps/graph/graph_app.h @@ -14,6 +14,7 @@ protected: private: Graph::FunctionStore m_functionStore; ListController m_listController; + StackViewController m_listStackViewController; GraphController m_graphController; TabViewController m_tabViewController; }; diff --git a/apps/probability/app.cpp b/apps/probability/app.cpp index 834e24e58..837e11a72 100644 --- a/apps/probability/app.cpp +++ b/apps/probability/app.cpp @@ -4,9 +4,8 @@ Probability::App::App() : ::App(), m_lawController(LawController(nullptr)), m_parametersController(ParametersController(nullptr)), - m_stackViewController(this) + m_stackViewController(this, &m_lawController) { - m_stackViewController.push(&m_lawController); } void Probability::App::setLaw(Law l) { diff --git a/escher/include/escher/stack_view_controller.h b/escher/include/escher/stack_view_controller.h index 7b78f86c5..b5261c485 100644 --- a/escher/include/escher/stack_view_controller.h +++ b/escher/include/escher/stack_view_controller.h @@ -8,7 +8,7 @@ constexpr uint8_t kMaxNumberOfStacks = 4; class StackViewController : public ViewController { public: - StackViewController(Responder * parentResponder); + StackViewController(Responder * parentResponder, ViewController * rootViewController); /* Push creates a new StackView and adds it */ void push(ViewController * vc); @@ -17,7 +17,7 @@ public: View * view() override; void handleKeyEvent(int key) override; - + const char * title() const override; bool handleEvent(Ion::Events::Event event) override; private: class ControllerView : public View { @@ -46,6 +46,7 @@ private: static constexpr uint8_t k_maxNumberOfChildren = 4; ViewController * m_children[k_maxNumberOfChildren]; uint8_t m_numberOfChildren; + ViewController * m_rootViewController; }; #endif diff --git a/escher/src/stack_view_controller.cpp b/escher/src/stack_view_controller.cpp index 31e793ede..6967a3833 100644 --- a/escher/src/stack_view_controller.cpp +++ b/escher/src/stack_view_controller.cpp @@ -60,21 +60,35 @@ const char * StackViewController::ControllerView::className() const { } #endif -StackViewController::StackViewController(Responder * parentResponder) : +StackViewController::StackViewController(Responder * parentResponder, ViewController * rootViewController) : ViewController(parentResponder), - m_numberOfChildren(0) + m_numberOfChildren(0), + m_rootViewController(rootViewController) { + // push(rootViewController); +} + +const char * StackViewController::title() const { + if (m_rootViewController) { + return m_rootViewController->title(); + } else { + ViewController * vc = m_children[m_numberOfChildren-1]; + return vc->title(); + } } void StackViewController::push(ViewController * vc) { m_view.pushStack("name"); m_children[m_numberOfChildren++] = vc; setupActiveViewController(); + vc->setParentResponder(this); } void StackViewController::pop() { m_view.popStack(); assert(m_numberOfChildren > 0); + ViewController * vc = m_children[m_numberOfChildren-1]; + vc->setParentResponder(nullptr); m_numberOfChildren--; setupActiveViewController(); } @@ -100,5 +114,9 @@ bool StackViewController::handleEvent(Ion::Events::Event event) { } View * StackViewController::view() { + if (m_rootViewController != nullptr) { + push(m_rootViewController); + m_rootViewController = nullptr; + } return &m_view; }