diff options
author | JF002 <JF002@users.noreply.github.com> | 2020-10-04 12:21:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-04 12:21:22 +0200 |
commit | 39954bbd3afb592a0c3109e3479594183e8d0778 (patch) | |
tree | 58efd04aa38b8dc7989c51fe3c9cdb9a3fb46a54 /src/displayapp/screens/ScreenList.h | |
parent | 5adc97702c326d0252df6da75ce4ac244a4b3553 (diff) | |
parent | 6c86d1d9d706706fcb6f214aba8259e61ed68755 (diff) |
Merge pull request #68 from Avamander/patch-1
Rename folders to follow a consistent style
Diffstat (limited to 'src/displayapp/screens/ScreenList.h')
-rw-r--r-- | src/displayapp/screens/ScreenList.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/displayapp/screens/ScreenList.h b/src/displayapp/screens/ScreenList.h new file mode 100644 index 00000000..b198634f --- /dev/null +++ b/src/displayapp/screens/ScreenList.h @@ -0,0 +1,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; + }; + } + } +}
\ No newline at end of file |