2020-03-22 12:03:17 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
2020-06-08 21:51:34 +02:00
|
|
|
#include <Components/Ble/NimbleController.h>
|
2020-08-14 09:46:37 +02:00
|
|
|
#include <functional>
|
2020-03-22 12:03:17 +01:00
|
|
|
#include "Screen.h"
|
|
|
|
#include "Label.h"
|
|
|
|
|
|
|
|
namespace Pinetime {
|
|
|
|
namespace Applications {
|
|
|
|
namespace Screens {
|
2020-08-14 09:46:37 +02:00
|
|
|
template <size_t N>
|
2020-03-22 12:03:17 +01:00
|
|
|
class ScreenList : public Screen {
|
|
|
|
public:
|
2020-08-14 09:46:37 +02: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 12:03:17 +01:00
|
|
|
|
2020-08-14 09:46:37 +02:00
|
|
|
}
|
2020-03-22 12:14:38 +01:00
|
|
|
|
2020-08-14 09:46:37 +02:00
|
|
|
bool Refresh() override {
|
|
|
|
running = current->Refresh();
|
|
|
|
return running;
|
|
|
|
}
|
2020-06-08 21:51:34 +02:00
|
|
|
|
2020-08-14 09:46:37 +02: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 12:03:17 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|