Skip to content

Commit

Permalink
Split the WakeUp settings into 2 pages
Browse files Browse the repository at this point in the history
  • Loading branch information
tgcfoss committed Nov 28, 2023
1 parent 99d1686 commit 2405657
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
currentScreen = std::make_unique<Screens::SettingTimeFormat>(settingsController);
break;
case Apps::SettingWakeUp:
currentScreen = std::make_unique<Screens::SettingWakeUp>(settingsController);
currentScreen = std::make_unique<Screens::SettingWakeUp>(this, settingsController);
break;
case Apps::SettingDisplay:
currentScreen = std::make_unique<Screens::SettingDisplay>(this, settingsController);
Expand Down
29 changes: 29 additions & 0 deletions src/displayapp/screens/Page.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <cstdint>
#include <lvgl/lvgl.h>
#include "displayapp/screens/Screen.h"
#include "displayapp/widgets/PageIndicator.h"

namespace Pinetime {

namespace Applications {
namespace Screens {

class Page : public Screen {
public:
Page(uint8_t screenID, uint8_t numScreens, lv_obj_t* contentObj)
: contentObj {contentObj}, pageIndicator(screenID, numScreens) {
pageIndicator.Create();
}
~Page() override {
lv_obj_clean(lv_scr_act());
}

private:
lv_obj_t* contentObj = nullptr;
Widgets::PageIndicator pageIndicator;
};
}
}
}
53 changes: 43 additions & 10 deletions src/displayapp/screens/settings/SettingWakeUp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@

using namespace Pinetime::Applications::Screens;

constexpr std::array<SettingWakeUp::Option, 6> SettingWakeUp::options;
constexpr std::array<SettingWakeUp::Option, SettingWakeUp::numOptions> SettingWakeUp::options;

auto SettingWakeUp::CreateScreenList() {
std::array<std::function<std::unique_ptr<Screen>()>, nScreens> screens;
for (size_t i = 0; i < screens.size(); i++) {
screens[i] = [this, i]() -> std::unique_ptr<Screen> {
return CreateScreen(i);
};
}
return screens;
}

namespace {
void event_handler(lv_obj_t* obj, lv_event_t event) {
Expand All @@ -19,44 +29,65 @@ namespace {
}
}

SettingWakeUp::SettingWakeUp(Pinetime::Controllers::Settings& settingsController) : settingsController {settingsController} {
SettingWakeUp::SettingWakeUp(Pinetime::Applications::DisplayApp* app,
Pinetime::Controllers::Settings& settingsController)
: settingsController {settingsController}
, screens {app, 0, CreateScreenList(), Screens::ScreenListModes::UpDown} {
}


SettingWakeUp::~SettingWakeUp() {
lv_obj_clean(lv_scr_act());
settingsController.SaveSettings();
}

std::unique_ptr<Screen> SettingWakeUp::CreateScreen(size_t screenNum) {
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr);

lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10);
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);

lv_obj_set_pos(container1, 10, 0);
lv_obj_set_pos(container1, 10, 35);
lv_obj_set_width(container1, LV_HOR_RES - 20);
lv_obj_set_height(container1, LV_VER_RES - 20);
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);

lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(title, "Wake Up");
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, -4);
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15);

lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
lv_label_set_text_static(icon, Symbols::eye);
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);

for (unsigned int i = 0; i < options.size(); i++) {
// cleanup any old pointers
cbOption.fill(nullptr);

// only loop as far as the list size aĺlows
unsigned int loopMax = screenNum * optionsPerScreen + optionsPerScreen;
if (loopMax > options.size()) {
loopMax = options.size();
}

for (unsigned int i = screenNum * optionsPerScreen; i < loopMax; i++) {
cbOption[i] = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text(cbOption[i], options[i].name);
if (settingsController.isWakeUpModeOn(static_cast<Controllers::Settings::WakeUpMode>(i))) {
if (settingsController.isWakeUpModeOn(options[i].wakeUpMode)) {
lv_checkbox_set_checked(cbOption[i], true);
}
cbOption[i]->user_data = this;
lv_obj_set_event_cb(cbOption[i], event_handler);
}
return std::make_unique<Screens::Page>(screenNum, nScreens, container1);
}

SettingWakeUp::~SettingWakeUp() {
lv_obj_clean(lv_scr_act());
settingsController.SaveSettings();
bool SettingWakeUp::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
return screens.OnTouchEvent(event);
}

void SettingWakeUp::UpdateSelected(lv_obj_t* object) {
Expand All @@ -74,6 +105,8 @@ void SettingWakeUp::UpdateSelected(lv_obj_t* object) {
// for example, when setting SingleTap, DoubleTap is unset and vice versa.
auto modes = settingsController.getWakeUpModes();
for (size_t i = 0; i < options.size(); ++i) {
lv_checkbox_set_checked(cbOption[i], modes[i]);
if (cbOption[i]) {
lv_checkbox_set_checked(cbOption[i], modes[i]);
}
}
}
22 changes: 19 additions & 3 deletions src/displayapp/screens/settings/SettingWakeUp.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#include <cstdint>
#include <lvgl/lvgl.h>
#include "components/settings/Settings.h"
#include "displayapp/screens/Page.h"
#include "displayapp/screens/Screen.h"
#include "displayapp/screens/ScreenList.h"
#include "displayapp/widgets/PageIndicator.h"

namespace Pinetime {

Expand All @@ -13,19 +16,32 @@ namespace Pinetime {

class SettingWakeUp : public Screen {
public:
SettingWakeUp(Pinetime::Controllers::Settings& settingsController);
SettingWakeUp(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController);
~SettingWakeUp() override;

void UpdateSelected(lv_obj_t* object);

bool OnTouchEvent(TouchEvents event) override;

private:

auto CreateScreenList();
std::unique_ptr<Screen> CreateScreen(size_t screenNum);

struct Option {
Controllers::Settings::WakeUpMode wakeUpMode;
const char* name;
};

static constexpr size_t numOptions = 6;
static constexpr size_t optionsPerScreen = 4;
static constexpr size_t nScreens = 2;

Controllers::Settings& settingsController;
static constexpr std::array<Option, 6> options = {{

ScreenList<nScreens> screens;

static constexpr std::array<Option, numOptions> options = {{
{Controllers::Settings::WakeUpMode::SingleTap, "Single Tap"},
{Controllers::Settings::WakeUpMode::DoubleTap, "Double Tap"},
{Controllers::Settings::WakeUpMode::RaiseWrist, "Raise Wrist"},
Expand All @@ -34,7 +50,7 @@ namespace Pinetime {
{Controllers::Settings::WakeUpMode::ButtonUnlocks, "Button Unlock"},
}};

lv_obj_t* cbOption[options.size()];
std::array<lv_obj_t*, numOptions> cbOption;
};
}
}
Expand Down

0 comments on commit 2405657

Please sign in to comment.