2020-03-22 07:03:17 -04:00
|
|
|
#pragma once
|
|
|
|
|
2020-11-15 10:49:36 -05:00
|
|
|
#include <array>
|
2020-08-14 03:46:37 -04:00
|
|
|
#include <functional>
|
2020-11-15 10:49:36 -05:00
|
|
|
#include <memory>
|
2020-03-22 07:03:17 -04:00
|
|
|
#include "Screen.h"
|
2020-11-15 10:49:36 -05:00
|
|
|
#include "../DisplayApp.h"
|
2020-03-22 07:03:17 -04:00
|
|
|
|
|
|
|
namespace Pinetime {
|
|
|
|
namespace Applications {
|
|
|
|
namespace Screens {
|
2021-02-24 14:40:24 -05:00
|
|
|
|
|
|
|
enum class ScreenListModes {UpDown, RightLeft, LongPress};
|
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
|
|
|
|
2021-02-24 14:40:24 -05:00
|
|
|
ScreenList(
|
|
|
|
DisplayApp* app,
|
|
|
|
uint8_t initScreen,
|
|
|
|
std::array<std::function<std::unique_ptr<Screen>()>, N>&& screens,
|
|
|
|
ScreenListModes mode
|
|
|
|
)
|
|
|
|
: Screen(app),
|
|
|
|
initScreen{initScreen},
|
|
|
|
screens{std::move(screens)},
|
|
|
|
mode{mode},
|
|
|
|
current{this->screens[initScreen]()}
|
|
|
|
{
|
|
|
|
screenIndex = initScreen;
|
2020-08-14 03:46:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
~ScreenList() override {
|
2021-02-24 14:40:24 -05:00
|
|
|
current.reset(nullptr);
|
|
|
|
/*for(uint8_t i = 0; i < screens.size(); i++) {
|
|
|
|
screens[i]().reset(nullptr);
|
|
|
|
}*/
|
|
|
|
lv_obj_clean(lv_scr_act());
|
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 {
|
2021-02-24 14:40:24 -05: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]();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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]();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 03:46:37 -04:00
|
|
|
}
|
2021-02-24 14:40:24 -05:00
|
|
|
|
2020-08-14 03:46:37 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-02-24 14:40:24 -05:00
|
|
|
|
|
|
|
uint8_t initScreen = 0;
|
2020-08-14 03:46:37 -04:00
|
|
|
std::array<std::function<std::unique_ptr<Screen>()>, N> screens;
|
2021-02-24 14:40:24 -05:00
|
|
|
ScreenListModes mode = ScreenListModes::UpDown;
|
|
|
|
|
|
|
|
uint8_t screenIndex = 0;
|
2020-08-14 03:46:37 -04:00
|
|
|
std::unique_ptr<Screen> current;
|
2021-02-24 14:40:24 -05:00
|
|
|
|
|
|
|
bool running = true;
|
2020-03-22 07:03:17 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|