2020-03-22 11:03:17 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-11-15 15:49:36 +00:00
|
|
|
#include <array>
|
2020-08-14 07:46:37 +00:00
|
|
|
#include <functional>
|
2020-11-15 15:49:36 +00:00
|
|
|
#include <memory>
|
2020-03-22 11:03:17 +00:00
|
|
|
#include "Screen.h"
|
2020-11-15 15:49:36 +00:00
|
|
|
#include "../DisplayApp.h"
|
2020-03-22 11:03:17 +00:00
|
|
|
|
|
|
|
namespace Pinetime {
|
|
|
|
namespace Applications {
|
|
|
|
namespace Screens {
|
2020-08-14 07:46:37 +00:00
|
|
|
template <size_t N>
|
2020-03-22 11:03:17 +00:00
|
|
|
class ScreenList : public Screen {
|
|
|
|
public:
|
2020-08-14 07:46:37 +00:00
|
|
|
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 {
|
2020-03-22 11:03:17 +00:00
|
|
|
|
2020-08-14 07:46:37 +00:00
|
|
|
}
|
2020-03-22 11:14:38 +00:00
|
|
|
|
2020-08-14 07:46:37 +00:00
|
|
|
bool Refresh() override {
|
|
|
|
running = current->Refresh();
|
|
|
|
return running;
|
|
|
|
}
|
2020-06-08 19:51:34 +00:00
|
|
|
|
2020-08-14 07:46:37 +00:00
|
|
|
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;
|
2020-03-22 11:03:17 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|