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