ref: 45e65b66b11b6b8533b225067ce4c2a4b5eac653
src/displayapp/screens/ScreenList.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
#pragma once #include <vector> #include <functional> #include "components/ble/NimbleController.h" #include "Screen.h" #include "Label.h" namespace Pinetime { namespace Applications { namespace Screens { template <size_t N> class ScreenList : public Screen { public: ScreenList(DisplayApp* app, std::array<std::function<std::unique_ptr<Screen>()>, N>&& screens) : Screen(app), screens{std::move(screens)}, current{this->screens[0]()} { } ~ScreenList() override { } bool Refresh() override { running = current->Refresh(); return running; } bool OnButtonPushed() override { running = false; return true; } bool OnTouchEvent(TouchEvents event) override { switch (event) { case TouchEvents::SwipeDown: if (screenIndex > 0) { current.reset(nullptr); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down); screenIndex--; current = screens[screenIndex](); } return true; case TouchEvents::SwipeUp: if (screenIndex < screens.size() - 1) { current.reset(nullptr); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up); screenIndex++; current = screens[screenIndex](); } return true; default: return false; } return false; } private: bool running = true; uint8_t screenIndex = 0; std::array<std::function<std::unique_ptr<Screen>()>, N> screens; std::unique_ptr<Screen> current; }; } } } |