From ccb34ee94906c2be8a8a1c4c1eeb672b0b7f84b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 19 Dec 2016 10:03:14 +0100 Subject: [PATCH] [escher] In tab view controller, implement lazy loaded for tab titles Change-Id: I6ad14f2a523c075951cd8ca0382fe90e4b99eb06 --- escher/include/escher/tab_view.h | 2 +- escher/src/tab_view.cpp | 4 ++++ escher/src/tab_view_controller.cpp | 33 +++++++++++++++--------------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/escher/include/escher/tab_view.h b/escher/include/escher/tab_view.h index dd6fbb583..801f71d3f 100644 --- a/escher/include/escher/tab_view.h +++ b/escher/include/escher/tab_view.h @@ -9,7 +9,7 @@ class TabViewController; class TabView : public View { public: TabView(); - + int numberOfTabs() const; void drawRect(KDContext * ctx, KDRect rect) const override; void addTabNamed(const char * name); diff --git a/escher/src/tab_view.cpp b/escher/src/tab_view.cpp index 3afac59dc..98fc789b2 100644 --- a/escher/src/tab_view.cpp +++ b/escher/src/tab_view.cpp @@ -12,6 +12,10 @@ TabView::TabView() : { } +int TabView::numberOfTabs() const { + return m_numberOfTabs; +} + void TabView::drawRect(KDContext * ctx, KDRect rect) const { KDCoordinate height = bounds().height(); KDCoordinate width = bounds().width(); diff --git a/escher/src/tab_view_controller.cpp b/escher/src/tab_view_controller.cpp index 452b03bff..9d1626c32 100644 --- a/escher/src/tab_view_controller.cpp +++ b/escher/src/tab_view_controller.cpp @@ -66,13 +66,20 @@ TabViewController::TabViewController(Responder * parentResponder, ViewController one->setParentResponder(this); two->setParentResponder(this); three->setParentResponder(this); +} - // TODO: This should be lazy loaded! - // So this code should live in view() - for (int i=0; ititle()); +/* +TabViewController::TabViewController(ViewController ** children, uint8_t numberOfChildren) : + m_children(children), + m_numberOfChildren(numberOfChildren), + m_activeChildIndex(-1) +{ + for (int i=0; isetParentResponder(this); + m_view.m_tabView.addTabNamed(children[i]->title()); } } +*/ bool TabViewController::handleEvent(Ion::Events::Event event) { if (app()->firstResponder() != this) { @@ -97,18 +104,6 @@ bool TabViewController::handleEvent(Ion::Events::Event event) { return false; } -/* -TabViewController::TabViewController(ViewController ** children, uint8_t numberOfChildren) : - m_children(children), - m_numberOfChildren(numberOfChildren), - m_activeChildIndex(-1) -{ - for (int i=0; ititle()); - } -} -*/ - void TabViewController::setActiveTab(int8_t i) { ViewController * activeVC = m_children[i]; if (i != m_activeChildIndex) { @@ -141,10 +136,14 @@ void TabViewController::didResignFirstResponder() { View * TabViewController::view() { // We're asked for a view! // Let's populate our tabview + if (m_view.m_tabView.numberOfTabs() != m_numberOfChildren) { + for (int i=0; ititle()); + } + } if (m_activeChildIndex < 0) { setActiveTab(0); } - return &m_view; }