Style checkboxes as radio buttons
This commit is contained in:
parent
589733d11e
commit
9ffd28f735
|
@ -119,7 +119,6 @@ static void basic_init(void) {
|
||||||
lv_style_set_bg_color(&style_btn, LV_STATE_DISABLED | LV_STATE_CHECKED, lv_color_hex3(0x888));
|
lv_style_set_bg_color(&style_btn, LV_STATE_DISABLED | LV_STATE_CHECKED, lv_color_hex3(0x888));
|
||||||
lv_style_set_border_color(&style_btn, LV_STATE_DEFAULT, theme.color_primary);
|
lv_style_set_border_color(&style_btn, LV_STATE_DEFAULT, theme.color_primary);
|
||||||
lv_style_set_border_width(&style_btn, LV_STATE_DEFAULT, 0);
|
lv_style_set_border_width(&style_btn, LV_STATE_DEFAULT, 0);
|
||||||
lv_style_set_border_opa(&style_btn, LV_STATE_CHECKED, LV_OPA_TRANSP);
|
|
||||||
|
|
||||||
lv_style_set_text_color(&style_btn, LV_STATE_DEFAULT, lv_color_hex(0xffffff));
|
lv_style_set_text_color(&style_btn, LV_STATE_DEFAULT, lv_color_hex(0xffffff));
|
||||||
lv_style_set_text_color(&style_btn, LV_STATE_CHECKED, lv_color_hex(0xffffff));
|
lv_style_set_text_color(&style_btn, LV_STATE_CHECKED, lv_color_hex(0xffffff));
|
||||||
|
|
|
@ -40,39 +40,24 @@ SettingDisplay::SettingDisplay(Pinetime::Applications::DisplayApp* app, Pinetime
|
||||||
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
|
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
|
||||||
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
|
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
|
||||||
|
|
||||||
optionsTotal = 0;
|
char buffer[12];
|
||||||
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
|
for (unsigned int i = 0; i < options.size(); i++) {
|
||||||
lv_checkbox_set_text_static(cbOption[optionsTotal], " 5 seconds");
|
cbOption[i] = lv_checkbox_create(container1, nullptr);
|
||||||
cbOption[optionsTotal]->user_data = this;
|
sprintf(buffer, "%3d seconds", options[i] / 1000);
|
||||||
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
|
lv_checkbox_set_text(cbOption[i], buffer);
|
||||||
if (settingsController.GetScreenTimeOut() == 5000) {
|
cbOption[i]->user_data = this;
|
||||||
lv_checkbox_set_checked(cbOption[optionsTotal], true);
|
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++;
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
optionsTotal++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingDisplay::~SettingDisplay() {
|
SettingDisplay::~SettingDisplay() {
|
||||||
|
@ -82,25 +67,11 @@ SettingDisplay::~SettingDisplay() {
|
||||||
|
|
||||||
void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
||||||
if (event == LV_EVENT_CLICKED) {
|
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]) {
|
if (object == cbOption[i]) {
|
||||||
lv_checkbox_set_checked(cbOption[i], true);
|
lv_checkbox_set_checked(cbOption[i], true);
|
||||||
|
settingsController.SetScreenTimeOut(options[i]);
|
||||||
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);
|
app->PushMessage(Applications::Display::Messages::UpdateTimeOut);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
lv_checkbox_set_checked(cbOption[i], false);
|
lv_checkbox_set_checked(cbOption[i], false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <lvgl/lvgl.h>
|
|
||||||
#include "components/settings/Settings.h"
|
#include "components/settings/Settings.h"
|
||||||
#include "displayapp/screens/Screen.h"
|
#include "displayapp/screens/Screen.h"
|
||||||
|
#include <array>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <lvgl/lvgl.h>
|
||||||
|
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
|
|
||||||
|
@ -18,8 +19,8 @@ namespace Pinetime {
|
||||||
void UpdateSelected(lv_obj_t* object, lv_event_t event);
|
void UpdateSelected(lv_obj_t* object, lv_event_t event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const std::array<uint16_t, 4> options = {5000, 15000, 20000, 30000};
|
||||||
Controllers::Settings& settingsController;
|
Controllers::Settings& settingsController;
|
||||||
uint8_t optionsTotal;
|
|
||||||
lv_obj_t* cbOption[4];
|
lv_obj_t* cbOption[4];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,24 +39,24 @@ SettingTimeFormat::SettingTimeFormat(Pinetime::Applications::DisplayApp* app, Pi
|
||||||
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
|
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
|
||||||
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
|
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
|
||||||
|
|
||||||
optionsTotal = 0;
|
for (unsigned int i = 0; i < options.size(); i++) {
|
||||||
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
|
cbOption[i] = lv_checkbox_create(container1, nullptr);
|
||||||
lv_checkbox_set_text_static(cbOption[optionsTotal], " 12-hour");
|
lv_checkbox_set_text(cbOption[i], options[i].c_str());
|
||||||
cbOption[optionsTotal]->user_data = this;
|
cbOption[i]->user_data = this;
|
||||||
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
|
lv_obj_set_event_cb(cbOption[i], event_handler);
|
||||||
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
|
|
||||||
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++;
|
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
|
||||||
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
|
lv_checkbox_set_checked(cbOption[0], true);
|
||||||
lv_checkbox_set_text_static(cbOption[optionsTotal], " 24-hour");
|
} else if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) {
|
||||||
cbOption[optionsTotal]->user_data = this;
|
lv_checkbox_set_checked(cbOption[1], true);
|
||||||
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
|
|
||||||
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) {
|
|
||||||
lv_checkbox_set_checked(cbOption[optionsTotal], true);
|
|
||||||
}
|
}
|
||||||
optionsTotal++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingTimeFormat::~SettingTimeFormat() {
|
SettingTimeFormat::~SettingTimeFormat() {
|
||||||
|
@ -66,7 +66,7 @@ SettingTimeFormat::~SettingTimeFormat() {
|
||||||
|
|
||||||
void SettingTimeFormat::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
void SettingTimeFormat::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
||||||
if (event == LV_EVENT_VALUE_CHANGED) {
|
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]) {
|
if (object == cbOption[i]) {
|
||||||
lv_checkbox_set_checked(cbOption[i], true);
|
lv_checkbox_set_checked(cbOption[i], true);
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <lvgl/lvgl.h>
|
|
||||||
#include "components/settings/Settings.h"
|
#include "components/settings/Settings.h"
|
||||||
#include "displayapp/screens/Screen.h"
|
#include "displayapp/screens/Screen.h"
|
||||||
|
#include <array>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <lvgl/lvgl.h>
|
||||||
|
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
|
|
||||||
|
@ -18,8 +19,9 @@ namespace Pinetime {
|
||||||
void UpdateSelected(lv_obj_t* object, lv_event_t event);
|
void UpdateSelected(lv_obj_t* object, lv_event_t event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const std::array<std::string, 2> options = {" 12-hour", " 24-hour"};
|
||||||
|
|
||||||
Controllers::Settings& settingsController;
|
Controllers::Settings& settingsController;
|
||||||
uint8_t optionsTotal;
|
|
||||||
lv_obj_t* cbOption[2];
|
lv_obj_t* cbOption[2];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,34 +40,22 @@ SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pine
|
||||||
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
|
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
|
||||||
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
|
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
|
||||||
|
|
||||||
optionsTotal = 0;
|
for (unsigned int i = 0; i < options.size(); i++) {
|
||||||
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
|
cbOption[i] = lv_checkbox_create(container1, nullptr);
|
||||||
lv_checkbox_set_text_static(cbOption[optionsTotal], " Digital face");
|
lv_checkbox_set_text(cbOption[i], options[i].c_str());
|
||||||
cbOption[optionsTotal]->user_data = this;
|
cbOption[i]->user_data = this;
|
||||||
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
|
lv_obj_set_event_cb(cbOption[i], event_handler);
|
||||||
if (settingsController.GetClockFace() == 0) {
|
|
||||||
lv_checkbox_set_checked(cbOption[optionsTotal], true);
|
|
||||||
}
|
|
||||||
|
|
||||||
optionsTotal++;
|
// radio button style
|
||||||
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
|
lv_obj_set_style_local_radius(cbOption[i], LV_CHECKBOX_PART_BULLET, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
|
||||||
lv_checkbox_set_text_static(cbOption[optionsTotal], " Analog face");
|
lv_obj_set_style_local_border_width(cbOption[i], LV_CHECKBOX_PART_BULLET, LV_STATE_CHECKED, 9);
|
||||||
cbOption[optionsTotal]->user_data = this;
|
lv_obj_set_style_local_border_color(cbOption[i], LV_CHECKBOX_PART_BULLET, LV_STATE_CHECKED, LV_COLOR_GREEN);
|
||||||
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
|
lv_obj_set_style_local_bg_color(cbOption[i], LV_CHECKBOX_PART_BULLET, LV_STATE_CHECKED, LV_COLOR_WHITE);
|
||||||
if (settingsController.GetClockFace() == 1) {
|
|
||||||
lv_checkbox_set_checked(cbOption[optionsTotal], true);
|
|
||||||
}
|
|
||||||
|
|
||||||
optionsTotal++;
|
if (settingsController.GetClockFace() == i) {
|
||||||
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
|
lv_checkbox_set_checked(cbOption[i], true);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
optionsTotal++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingWatchFace::~SettingWatchFace() {
|
SettingWatchFace::~SettingWatchFace() {
|
||||||
|
@ -77,7 +65,7 @@ SettingWatchFace::~SettingWatchFace() {
|
||||||
|
|
||||||
void SettingWatchFace::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
void SettingWatchFace::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
||||||
if (event == LV_EVENT_VALUE_CHANGED) {
|
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]) {
|
if (object == cbOption[i]) {
|
||||||
lv_checkbox_set_checked(cbOption[i], true);
|
lv_checkbox_set_checked(cbOption[i], true);
|
||||||
settingsController.SetClockFace(i);
|
settingsController.SetClockFace(i);
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <lvgl/lvgl.h>
|
|
||||||
#include "components/settings/Settings.h"
|
#include "components/settings/Settings.h"
|
||||||
#include "displayapp/screens/Screen.h"
|
#include "displayapp/screens/Screen.h"
|
||||||
|
#include <array>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <lvgl/lvgl.h>
|
||||||
|
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
|
|
||||||
|
@ -18,8 +19,9 @@ namespace Pinetime {
|
||||||
void UpdateSelected(lv_obj_t* object, lv_event_t event);
|
void UpdateSelected(lv_obj_t* object, lv_event_t event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const std::array<std::string, 3> options = {" Digital face", " Analog face", " PineTimeStyle"};
|
||||||
Controllers::Settings& settingsController;
|
Controllers::Settings& settingsController;
|
||||||
uint8_t optionsTotal;
|
|
||||||
lv_obj_t* cbOption[2];
|
lv_obj_t* cbOption[2];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user