2020-03-22 12:03:17 +01:00
|
|
|
#pragma once
|
|
|
|
|
2020-11-15 16:49:36 +01:00
|
|
|
#include <array>
|
2020-08-14 09:46:37 +02:00
|
|
|
#include <functional>
|
2020-11-15 16:49:36 +01:00
|
|
|
#include <memory>
|
2021-10-13 22:08:35 +02:00
|
|
|
#include "displayapp/screens/Screen.h"
|
|
|
|
#include "displayapp/DisplayApp.h"
|
2020-03-22 12:03:17 +01:00
|
|
|
|
|
|
|
namespace Pinetime {
|
|
|
|
namespace Applications {
|
|
|
|
namespace Screens {
|
2021-02-24 20:40:24 +01:00
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
enum class ScreenListModes { UpDown, RightLeft, LongPress };
|
|
|
|
template <size_t N> class ScreenList : public Screen {
|
2021-04-24 11:00:45 +02:00
|
|
|
public:
|
2021-04-18 19:28:14 +02:00
|
|
|
ScreenList(DisplayApp* app,
|
|
|
|
uint8_t initScreen,
|
2021-06-06 15:56:03 +02:00
|
|
|
const std::array<std::function<std::unique_ptr<Screen>()>, N>&& screens,
|
2021-04-18 19:28:14 +02:00
|
|
|
ScreenListModes mode)
|
2021-06-06 15:56:03 +02:00
|
|
|
: Screen(app), initScreen {initScreen}, screens {std::move(screens)}, mode {mode}, screenIndex{initScreen}, current {this->screens[initScreen]()} {
|
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
}
|
2020-08-14 09:46:37 +02:00
|
|
|
|
2021-06-06 15:56:03 +02:00
|
|
|
ScreenList(const ScreenList&) = delete;
|
|
|
|
ScreenList& operator=(const ScreenList&) = delete;
|
|
|
|
ScreenList(ScreenList&&) = delete;
|
|
|
|
ScreenList& operator=(ScreenList&&) = delete;
|
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
~ScreenList() override {
|
|
|
|
lv_obj_clean(lv_scr_act());
|
|
|
|
}
|
2020-08-14 09:46:37 +02:00
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
bool OnTouchEvent(TouchEvents event) override {
|
2020-06-08 21:51:34 +02:00
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
if (mode == ScreenListModes::UpDown) {
|
|
|
|
switch (event) {
|
|
|
|
case TouchEvents::SwipeDown:
|
|
|
|
if (screenIndex > 0) {
|
|
|
|
current.reset(nullptr);
|
|
|
|
app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down);
|
|
|
|
screenIndex--;
|
|
|
|
current = screens[screenIndex]();
|
2021-02-24 20:40:24 +01:00
|
|
|
return true;
|
2021-04-18 19:28:14 +02:00
|
|
|
} else {
|
2021-02-24 20:40:24 +01:00
|
|
|
return false;
|
2021-04-18 19:28:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
} else if (mode == ScreenListModes::RightLeft) {
|
|
|
|
switch (event) {
|
|
|
|
case TouchEvents::SwipeRight:
|
|
|
|
if (screenIndex > 0) {
|
|
|
|
current.reset(nullptr);
|
|
|
|
app->SetFullRefresh(DisplayApp::FullRefreshDirections::None);
|
|
|
|
screenIndex--;
|
|
|
|
current = screens[screenIndex]();
|
2021-02-24 20:40:24 +01:00
|
|
|
return true;
|
2021-04-18 19:28:14 +02:00
|
|
|
} else {
|
2021-02-24 20:40:24 +01:00
|
|
|
return false;
|
2021-04-18 19:28:14 +02:00
|
|
|
}
|
2021-02-24 20:40:24 +01:00
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
case TouchEvents::SwipeLeft:
|
|
|
|
if (screenIndex < screens.size() - 1) {
|
|
|
|
current.reset(nullptr);
|
|
|
|
app->SetFullRefresh(DisplayApp::FullRefreshDirections::None);
|
|
|
|
screenIndex++;
|
|
|
|
current = screens[screenIndex]();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (event == TouchEvents::LongTap) {
|
|
|
|
if (screenIndex < screens.size() - 1) {
|
|
|
|
screenIndex++;
|
|
|
|
} else {
|
|
|
|
screenIndex = 0;
|
|
|
|
}
|
|
|
|
current.reset(nullptr);
|
|
|
|
app->SetFullRefresh(DisplayApp::FullRefreshDirections::None);
|
|
|
|
current = screens[screenIndex]();
|
|
|
|
return true;
|
2020-08-14 09:46:37 +02:00
|
|
|
}
|
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
return false;
|
|
|
|
}
|
2021-02-24 20:40:24 +01:00
|
|
|
|
2021-04-24 11:00:45 +02:00
|
|
|
private:
|
2021-04-18 19:28:14 +02:00
|
|
|
uint8_t initScreen = 0;
|
2021-06-06 15:56:03 +02:00
|
|
|
const std::array<std::function<std::unique_ptr<Screen>()>, N> screens;
|
2021-04-18 19:28:14 +02:00
|
|
|
ScreenListModes mode = ScreenListModes::UpDown;
|
2021-02-24 20:40:24 +01:00
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
uint8_t screenIndex = 0;
|
|
|
|
std::unique_ptr<Screen> current;
|
2020-03-22 12:03:17 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2021-07-19 15:26:12 +02:00
|
|
|
}
|