Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ list(APPEND SOURCE_FILES
displayapp/screens/BatteryInfo.cpp
displayapp/screens/Steps.cpp
displayapp/screens/Timer.cpp
displayapp/screens/CheckBoxes.cpp

## Settings
displayapp/screens/settings/QuickSettings.cpp
Expand Down
112 changes: 112 additions & 0 deletions src/displayapp/screens/CheckBoxes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#include "CheckBoxes.h"
#include <lvgl/lvgl.h>
#include "displayapp/DisplayApp.h"
#include "displayapp/screens/Screen.h"
#include "displayapp/screens/Symbols.h"

using namespace Pinetime::Applications::Screens;

namespace {
static void event_handler(lv_obj_t* obj, lv_event_t event) {
CheckBoxes* screen = static_cast<CheckBoxes*>(obj->user_data);
screen->UpdateSelected(obj, event);
}
}

CheckBoxes::CheckBoxes(const char* symbol, const char* titleText, Options* options, DisplayApp* app, bool (*UpdateArray)(Options*, uint8_t))
: Screen(app), options {options}, UpdateArray {UpdateArray} {

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, 0);
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 4);
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);

lv_obj_set_pos(container1, 0, 40);
lv_obj_set_width(container1, LV_HOR_RES);
lv_obj_set_height(container1, LV_VER_RES - 40);
lv_cont_set_layout(container1, LV_LAYOUT_GRID);

lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text(title, titleText);
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 5);

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(icon, symbol);
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);

for (optionsTotal = 0; optionsTotal < 6; optionsTotal++) {
if (strcmp(options[optionsTotal].title, "") == 0) {
break;
}
}

lv_style_init(&buttonStyle);
lv_style_set_bg_color(&buttonStyle, LV_STATE_DEFAULT, lv_color_hex(0x111111));
lv_style_set_bg_opa(&buttonStyle, LV_STATE_CHECKED, LV_OPA_30);
lv_style_set_bg_color(&buttonStyle, LV_STATE_CHECKED, LV_COLOR_AQUA);
if (optionsTotal <= 4) {
lv_style_set_radius(&buttonStyle, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
}

for (uint8_t i = 0; i < optionsTotal; i++) {
buttons[i] = lv_btn_create(container1, nullptr);
lv_obj_set_style_local_value_str(buttons[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, options[i].title);
lv_obj_add_style(buttons[i], LV_BTN_PART_MAIN, &buttonStyle);
if (optionsTotal <= 4) {
lv_obj_set_size(buttons[i], LV_HOR_RES, 47);
} else {
lv_obj_set_size(buttons[i], 117, 64);
}
if (options[i].state == true) {
lv_obj_add_state(buttons[i], LV_STATE_CHECKED);
}
buttons[i]->user_data = this;
lv_obj_set_event_cb(buttons[i], event_handler);
}
}

CheckBoxes::~CheckBoxes() {
lv_obj_clean(lv_scr_act());
}

bool CheckBoxes::Refresh() {
return running;
}

void CheckBoxes::UpdateSelected(lv_obj_t* object, lv_event_t event) {
if (event != LV_EVENT_CLICKED) {
return;
}

uint8_t clicked;
for (clicked = 0; clicked < optionsTotal; clicked++) {
if (object == buttons[clicked]) {
break;
}
}

if (UpdateArray(options, clicked)) {
for (uint8_t i = 0; i < optionsTotal; i++) {
if (options[i].state) {
lv_obj_add_state(buttons[i], LV_STATE_CHECKED);
} else {
lv_obj_clear_state(buttons[i], LV_STATE_CHECKED);
}
}
} else {
for (uint8_t i = 0; i < optionsTotal; i++) {
if (object == buttons[i]) {
lv_obj_add_state(buttons[i], LV_STATE_CHECKED);
options[i].state = true;
} else {
lv_obj_clear_state(buttons[i], LV_STATE_CHECKED);
options[i].state = false;
}
}
}
}
32 changes: 32 additions & 0 deletions src/displayapp/screens/CheckBoxes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

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

namespace Pinetime {
namespace Applications {
namespace Screens {
class CheckBoxes : public Screen {
public:
struct Options {
bool state;
const char* title;
};
CheckBoxes(const char* symbol, const char* titleText, Options *options, DisplayApp* app, bool (*UpdateArray)(Options*, uint8_t));
~CheckBoxes() override;

bool Refresh() override;
void UpdateSelected(lv_obj_t* object, lv_event_t event);

private:
struct Options* options;
bool (*UpdateArray)(Options* options, uint8_t clicked);

uint8_t optionsTotal;
lv_obj_t* buttons[6];
lv_style_t buttonStyle;
};
}
}
}
128 changes: 37 additions & 91 deletions src/displayapp/screens/settings/SettingDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,107 +7,53 @@

using namespace Pinetime::Applications::Screens;

namespace {
static void event_handler(lv_obj_t* obj, lv_event_t event) {
SettingDisplay* screen = static_cast<SettingDisplay*>(obj->user_data);
screen->UpdateSelected(obj, event);
}
}

SettingDisplay::SettingDisplay(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
: Screen(app), settingsController {settingsController} {

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, 60);
lv_obj_set_width(container1, LV_HOR_RES - 20);
lv_obj_set_height(container1, LV_VER_RES - 50);
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, "Display timeout");
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 10, 15);
: Screen(app), settingsController {settingsController}, screen {[this, &settingsController]() {
return CreateScreen();
}()} {
}

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::sun);
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
bool SettingDisplay::UpdateArray(Pinetime::Applications::Screens::CheckBoxes::Options* options, uint8_t clicked) {
return false;
}

optionsTotal = 0;
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text_static(cbOption[optionsTotal], " 5 seconds");
cbOption[optionsTotal]->user_data = this;
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
if (settingsController.GetScreenTimeOut() == 5000) {
lv_checkbox_set_checked(cbOption[optionsTotal], true);
}
optionsTotal++;
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text_static(cbOption[optionsTotal], " 15 seconds");
cbOption[optionsTotal]->user_data = this;
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
if (settingsController.GetScreenTimeOut() == 15000) {
lv_checkbox_set_checked(cbOption[optionsTotal], true);
}
optionsTotal++;
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text_static(cbOption[optionsTotal], " 20 seconds");
cbOption[optionsTotal]->user_data = this;
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
if (settingsController.GetScreenTimeOut() == 20000) {
lv_checkbox_set_checked(cbOption[optionsTotal], true);
std::unique_ptr<Screen> SettingDisplay::CreateScreen() {
switch (settingsController.GetScreenTimeOut()) {
case 5000:
options[0].state = true;
break;
case 10000:
options[1].state = true;
break;
case 15000:
options[2].state = true;
break;
case 20000:
options[3].state = true;
break;
case 25000:
options[4].state = true;
break;
case 30000:
options[5].state = true;
break;
}
optionsTotal++;
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text_static(cbOption[optionsTotal], " 30 seconds");
cbOption[optionsTotal]->user_data = this;
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
if (settingsController.GetScreenTimeOut() == 30000) {
lv_checkbox_set_checked(cbOption[optionsTotal], true);
}
optionsTotal++;

return std::make_unique<Screens::CheckBoxes>(Symbols::sun, "Display timeout", options, app, UpdateArray);
}

SettingDisplay::~SettingDisplay() {
for (uint8_t i = 0; i < 6; i++) {
if (options[i].state == true) {
settingsController.SetScreenTimeOut((i + 1) * 5000);
break;
}
}
app->PushMessage(Applications::Display::Messages::UpdateTimeOut);
lv_obj_clean(lv_scr_act());
settingsController.SaveSettings();
}

bool SettingDisplay::Refresh() {
return running;
return screen->Refresh();
}

void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) {
if (event == LV_EVENT_VALUE_CHANGED) {
for (int i = 0; i < optionsTotal; i++) {
if (object == cbOption[i]) {
lv_checkbox_set_checked(cbOption[i], true);

if (i == 0) {
settingsController.SetScreenTimeOut(5000);
};
if (i == 1) {
settingsController.SetScreenTimeOut(15000);
};
if (i == 2) {
settingsController.SetScreenTimeOut(20000);
};
if (i == 3) {
settingsController.SetScreenTimeOut(30000);
};

app->PushMessage(Applications::Display::Messages::UpdateTimeOut);

} else {
lv_checkbox_set_checked(cbOption[i], false);
}
}
}
}
20 changes: 15 additions & 5 deletions src/displayapp/screens/settings/SettingDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,36 @@

#include <cstdint>
#include <lvgl/lvgl.h>
#include <memory>
#include "components/settings/Settings.h"
#include "displayapp/screens/Screen.h"
#include "displayapp/screens/CheckBoxes.h"

namespace Pinetime {

namespace Applications {
namespace Screens {

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

bool Refresh() override;
void UpdateSelected(lv_obj_t* object, lv_event_t event);

static bool UpdateArray(Pinetime::Applications::Screens::CheckBoxes::Options* options, uint8_t clicked);

private:
CheckBoxes::Options options[6] = {
{false, "5s"},
{false, "10s"},
{false, "15s"},
{false, "20s"},
{false, "25s"},
{false, "30s"},
};

Controllers::Settings& settingsController;
uint8_t optionsTotal;
lv_obj_t* cbOption[4];
std::unique_ptr<Screen> screen;
std::unique_ptr<Screen> CreateScreen();
};
}
}
Expand Down
Loading