summaryrefslogtreecommitdiff
path: root/src/displayapp/screens/settings
diff options
context:
space:
mode:
authorRiku Isokoski <riksu9000@gmail.com>2021-09-20 15:13:46 +0300
committerJF <JF002@users.noreply.github.com>2021-12-09 21:32:07 +0100
commit9ffd28f735fd2a184f03b2ce4a46a24b7de10ba4 (patch)
tree20ffc01294bc774b2169f27a45cb5c5dc4973afd /src/displayapp/screens/settings
parent589733d11e623ea66ee0bba231f53c67ce04ce7a (diff)
Style checkboxes as radio buttons
Diffstat (limited to 'src/displayapp/screens/settings')
-rw-r--r--src/displayapp/screens/settings/SettingDisplay.cpp67
-rw-r--r--src/displayapp/screens/settings/SettingDisplay.h7
-rw-r--r--src/displayapp/screens/settings/SettingTimeFormat.cpp32
-rw-r--r--src/displayapp/screens/settings/SettingTimeFormat.h8
-rw-r--r--src/displayapp/screens/settings/SettingWatchFace.cpp40
-rw-r--r--src/displayapp/screens/settings/SettingWatchFace.h8
6 files changed, 63 insertions, 99 deletions
diff --git a/src/displayapp/screens/settings/SettingDisplay.cpp b/src/displayapp/screens/settings/SettingDisplay.cpp
index 666dfb80..9e835f61 100644
--- a/src/displayapp/screens/settings/SettingDisplay.cpp
+++ b/src/displayapp/screens/settings/SettingDisplay.cpp
@@ -40,39 +40,24 @@ SettingDisplay::SettingDisplay(Pinetime::Applications::DisplayApp* app, Pinetime
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
- 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);
- }
- 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);
+ char buffer[12];
+ for (unsigned int i = 0; i < options.size(); i++) {
+ cbOption[i] = lv_checkbox_create(container1, nullptr);
+ sprintf(buffer, "%3d seconds", options[i] / 1000);
+ lv_checkbox_set_text(cbOption[i], buffer);
+ cbOption[i]->user_data = this;
+ lv_obj_set_event_cb(cbOption[i], event_handler);
+
+ // radio button style
+ lv_obj_set_style_local_radius(cbOption[i], LV_CHECKBOX_PART_BULLET, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
+ lv_obj_set_style_local_border_width(cbOption[i], LV_CHECKBOX_PART_BULLET, LV_STATE_CHECKED, 9);
+ lv_obj_set_style_local_border_color(cbOption[i], LV_CHECKBOX_PART_BULLET, LV_STATE_CHECKED, LV_COLOR_GREEN);
+ lv_obj_set_style_local_bg_color(cbOption[i], LV_CHECKBOX_PART_BULLET, LV_STATE_CHECKED, LV_COLOR_WHITE);
+
+ if (settingsController.GetScreenTimeOut() == options[i]) {
+ lv_checkbox_set_checked(cbOption[i], true);
+ }
}
- optionsTotal++;
}
SettingDisplay::~SettingDisplay() {
@@ -82,25 +67,11 @@ SettingDisplay::~SettingDisplay() {
void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) {
if (event == LV_EVENT_CLICKED) {
- for (int i = 0; i < optionsTotal; i++) {
+ for (unsigned int i = 0; i < options.size(); 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);
- };
-
+ settingsController.SetScreenTimeOut(options[i]);
app->PushMessage(Applications::Display::Messages::UpdateTimeOut);
-
} else {
lv_checkbox_set_checked(cbOption[i], false);
}
diff --git a/src/displayapp/screens/settings/SettingDisplay.h b/src/displayapp/screens/settings/SettingDisplay.h
index 51b23aca..dba6b435 100644
--- a/src/displayapp/screens/settings/SettingDisplay.h
+++ b/src/displayapp/screens/settings/SettingDisplay.h
@@ -1,9 +1,10 @@
#pragma once
-#include <cstdint>
-#include <lvgl/lvgl.h>
#include "components/settings/Settings.h"
#include "displayapp/screens/Screen.h"
+#include <array>
+#include <cstdint>
+#include <lvgl/lvgl.h>
namespace Pinetime {
@@ -18,8 +19,8 @@ namespace Pinetime {
void UpdateSelected(lv_obj_t* object, lv_event_t event);
private:
+ const std::array<uint16_t, 4> options = {5000, 15000, 20000, 30000};
Controllers::Settings& settingsController;
- uint8_t optionsTotal;
lv_obj_t* cbOption[4];
};
}
diff --git a/src/displayapp/screens/settings/SettingTimeFormat.cpp b/src/displayapp/screens/settings/SettingTimeFormat.cpp
index c6bdf401..52ce94ba 100644
--- a/src/displayapp/screens/settings/SettingTimeFormat.cpp
+++ b/src/displayapp/screens/settings/SettingTimeFormat.cpp
@@ -39,24 +39,24 @@ SettingTimeFormat::SettingTimeFormat(Pinetime::Applications::DisplayApp* app, Pi
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
- optionsTotal = 0;
- cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
- lv_checkbox_set_text_static(cbOption[optionsTotal], " 12-hour");
- cbOption[optionsTotal]->user_data = this;
- lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
- if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
- lv_checkbox_set_checked(cbOption[optionsTotal], true);
+ for (unsigned int i = 0; i < options.size(); i++) {
+ cbOption[i] = lv_checkbox_create(container1, nullptr);
+ lv_checkbox_set_text(cbOption[i], options[i].c_str());
+ cbOption[i]->user_data = this;
+ lv_obj_set_event_cb(cbOption[i], event_handler);
+
+ // radio button style
+ lv_obj_set_style_local_radius(cbOption[i], LV_CHECKBOX_PART_BULLET, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
+ lv_obj_set_style_local_border_width(cbOption[i], LV_CHECKBOX_PART_BULLET, LV_STATE_CHECKED, 9);
+ lv_obj_set_style_local_border_color(cbOption[i], LV_CHECKBOX_PART_BULLET, LV_STATE_CHECKED, LV_COLOR_GREEN);
+ lv_obj_set_style_local_bg_color(cbOption[i], LV_CHECKBOX_PART_BULLET, LV_STATE_CHECKED, LV_COLOR_WHITE);
}
- optionsTotal++;
- cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
- lv_checkbox_set_text_static(cbOption[optionsTotal], " 24-hour");
- cbOption[optionsTotal]->user_data = this;
- lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
- if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) {
- lv_checkbox_set_checked(cbOption[optionsTotal], true);
+ if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
+ lv_checkbox_set_checked(cbOption[0], true);
+ } else if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) {
+ lv_checkbox_set_checked(cbOption[1], true);
}
- optionsTotal++;
}
SettingTimeFormat::~SettingTimeFormat() {
@@ -66,7 +66,7 @@ SettingTimeFormat::~SettingTimeFormat() {
void SettingTimeFormat::UpdateSelected(lv_obj_t* object, lv_event_t event) {
if (event == LV_EVENT_VALUE_CHANGED) {
- for (int i = 0; i < optionsTotal; i++) {
+ for (unsigned int i = 0; i < options.size(); i++) {
if (object == cbOption[i]) {
lv_checkbox_set_checked(cbOption[i], true);
diff --git a/src/displayapp/screens/settings/SettingTimeFormat.h b/src/displayapp/screens/settings/SettingTimeFormat.h
index eac4bdc9..0113e35b 100644
--- a/src/displayapp/screens/settings/SettingTimeFormat.h
+++ b/src/displayapp/screens/settings/SettingTimeFormat.h
@@ -1,9 +1,10 @@
#pragma once
-#include <cstdint>
-#include <lvgl/lvgl.h>
#include "components/settings/Settings.h"
#include "displayapp/screens/Screen.h"
+#include <array>
+#include <cstdint>
+#include <lvgl/lvgl.h>
namespace Pinetime {
@@ -18,8 +19,9 @@ namespace Pinetime {
void UpdateSelected(lv_obj_t* object, lv_event_t event);
private:
+ const std::array<std::string, 2> options = {" 12-hour", " 24-hour"};
+
Controllers::Settings& settingsController;
- uint8_t optionsTotal;
lv_obj_t* cbOption[2];
};
}
diff --git a/src/displayapp/screens/settings/SettingWatchFace.cpp b/src/displayapp/screens/settings/SettingWatchFace.cpp
index 8e6e7cf4..8bb8759f 100644
--- a/src/displayapp/screens/settings/SettingWatchFace.cpp
+++ b/src/displayapp/screens/settings/SettingWatchFace.cpp
@@ -40,34 +40,22 @@ SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pine
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
- optionsTotal = 0;
- cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
- lv_checkbox_set_text_static(cbOption[optionsTotal], " Digital face");
- cbOption[optionsTotal]->user_data = this;
- lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
- if (settingsController.GetClockFace() == 0) {
- lv_checkbox_set_checked(cbOption[optionsTotal], true);
- }
+ for (unsigned int i = 0; i < options.size(); i++) {
+ cbOption[i] = lv_checkbox_create(container1, nullptr);
+ lv_checkbox_set_text(cbOption[i], options[i].c_str());
+ cbOption[i]->user_data = this;
+ lv_obj_set_event_cb(cbOption[i], event_handler);
- optionsTotal++;
- cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
- lv_checkbox_set_text_static(cbOption[optionsTotal], " Analog face");
- cbOption[optionsTotal]->user_data = this;
- lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
- if (settingsController.GetClockFace() == 1) {
- lv_checkbox_set_checked(cbOption[optionsTotal], true);
- }
+ // radio button style
+ lv_obj_set_style_local_radius(cbOption[i], LV_CHECKBOX_PART_BULLET, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
+ lv_obj_set_style_local_border_width(cbOption[i], LV_CHECKBOX_PART_BULLET, LV_STATE_CHECKED, 9);
+ lv_obj_set_style_local_border_color(cbOption[i], LV_CHECKBOX_PART_BULLET, LV_STATE_CHECKED, LV_COLOR_GREEN);
+ lv_obj_set_style_local_bg_color(cbOption[i], LV_CHECKBOX_PART_BULLET, LV_STATE_CHECKED, LV_COLOR_WHITE);
- optionsTotal++;
- cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
- lv_checkbox_set_text_static(cbOption[optionsTotal], " PineTimeStyle");
- cbOption[optionsTotal]->user_data = this;
- lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
- if (settingsController.GetClockFace() == 2) {
- lv_checkbox_set_checked(cbOption[optionsTotal], true);
+ if (settingsController.GetClockFace() == i) {
+ lv_checkbox_set_checked(cbOption[i], true);
+ }
}
-
- optionsTotal++;
}
SettingWatchFace::~SettingWatchFace() {
@@ -77,7 +65,7 @@ SettingWatchFace::~SettingWatchFace() {
void SettingWatchFace::UpdateSelected(lv_obj_t* object, lv_event_t event) {
if (event == LV_EVENT_VALUE_CHANGED) {
- for (uint8_t i = 0; i < optionsTotal; i++) {
+ for (unsigned int i = 0; i < options.size(); i++) {
if (object == cbOption[i]) {
lv_checkbox_set_checked(cbOption[i], true);
settingsController.SetClockFace(i);
diff --git a/src/displayapp/screens/settings/SettingWatchFace.h b/src/displayapp/screens/settings/SettingWatchFace.h
index d4a96c6d..18634582 100644
--- a/src/displayapp/screens/settings/SettingWatchFace.h
+++ b/src/displayapp/screens/settings/SettingWatchFace.h
@@ -1,9 +1,10 @@
#pragma once
-#include <cstdint>
-#include <lvgl/lvgl.h>
#include "components/settings/Settings.h"
#include "displayapp/screens/Screen.h"
+#include <array>
+#include <cstdint>
+#include <lvgl/lvgl.h>
namespace Pinetime {
@@ -18,8 +19,9 @@ namespace Pinetime {
void UpdateSelected(lv_obj_t* object, lv_event_t event);
private:
+ const std::array<std::string, 3> options = {" Digital face", " Analog face", " PineTimeStyle"};
Controllers::Settings& settingsController;
- uint8_t optionsTotal;
+
lv_obj_t* cbOption[2];
};
}