Limit backlight when flashlight is off (#1212)

This commit is contained in:
Riku Isokoski 2022-07-21 22:22:14 +03:00 committed by GitHub
parent cea81fea9c
commit 0f4233003e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,17 +18,17 @@ FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app,
Controllers::BrightnessController& brightnessController) Controllers::BrightnessController& brightnessController)
: Screen(app), systemTask {systemTask}, brightnessController {brightnessController} { : Screen(app), systemTask {systemTask}, brightnessController {brightnessController} {
brightnessController.Set(brightnessLevel); brightnessController.Set(Controllers::BrightnessController::Levels::Low);
flashLight = lv_label_create(lv_scr_act(), nullptr); flashLight = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48); lv_obj_set_style_local_text_font(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48);
lv_label_set_text_static(flashLight, Symbols::highlight); lv_label_set_text_static(flashLight, Symbols::highlight);
lv_obj_align(flashLight, nullptr, LV_ALIGN_CENTER, 0, 0); lv_obj_align(flashLight, nullptr, LV_ALIGN_CENTER, 0, 0);
for (auto& i : indicators) { for (auto& indicator : indicators) {
i = lv_obj_create(lv_scr_act(), nullptr); indicator = lv_obj_create(lv_scr_act(), nullptr);
lv_obj_set_size(i, 15, 10); lv_obj_set_size(indicator, 15, 10);
lv_obj_set_style_local_border_width(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 2); lv_obj_set_style_local_border_width(indicator, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 2);
} }
lv_obj_align(indicators[1], flashLight, LV_ALIGN_OUT_BOTTOM_MID, 0, 5); lv_obj_align(indicators[1], flashLight, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
@ -57,22 +57,15 @@ FlashLight::~FlashLight() {
} }
void FlashLight::SetColors() { void FlashLight::SetColors() {
if (isOn) { lv_color_t bgColor = isOn ? LV_COLOR_WHITE : LV_COLOR_BLACK;
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_color_t fgColor = isOn ? LV_COLOR_MAKE(0xb0, 0xb0, 0xb0) : LV_COLOR_WHITE;
lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xb0, 0xb0, 0xb0));
for (auto& i : indicators) { lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, bgColor);
lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xb0, 0xb0, 0xb0)); lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, fgColor);
lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DISABLED, LV_COLOR_WHITE); for (auto& indicator : indicators) {
lv_obj_set_style_local_border_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xb0, 0xb0, 0xb0)); lv_obj_set_style_local_bg_color(indicator, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, fgColor);
} lv_obj_set_style_local_bg_color(indicator, LV_OBJ_PART_MAIN, LV_STATE_DISABLED, bgColor);
} else { lv_obj_set_style_local_border_color(indicator, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, fgColor);
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
for (auto& i : indicators) {
lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DISABLED, LV_COLOR_BLACK);
lv_obj_set_style_local_border_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
}
} }
} }
@ -94,32 +87,40 @@ void FlashLight::SetIndicators() {
void FlashLight::Toggle() { void FlashLight::Toggle() {
isOn = !isOn; isOn = !isOn;
SetColors(); SetColors();
if (isOn) {
brightnessController.Set(brightnessLevel);
} else {
brightnessController.Set(Controllers::BrightnessController::Levels::Low);
}
} }
bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) { bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
using namespace Pinetime::Controllers; using namespace Pinetime::Controllers;
auto SetState = [this]() {
if (isOn) {
brightnessController.Set(brightnessLevel);
}
SetIndicators();
};
if (event == TouchEvents::SwipeLeft) { if (event == TouchEvents::SwipeLeft) {
if (brightnessLevel == BrightnessController::Levels::High) { if (brightnessLevel == BrightnessController::Levels::High) {
brightnessLevel = BrightnessController::Levels::Medium; brightnessLevel = BrightnessController::Levels::Medium;
brightnessController.Set(brightnessLevel); SetState();
SetIndicators();
} else if (brightnessLevel == BrightnessController::Levels::Medium) { } else if (brightnessLevel == BrightnessController::Levels::Medium) {
brightnessLevel = BrightnessController::Levels::Low; brightnessLevel = BrightnessController::Levels::Low;
brightnessController.Set(brightnessLevel); SetState();
SetIndicators();
} }
return true; return true;
} }
if (event == TouchEvents::SwipeRight) { if (event == TouchEvents::SwipeRight) {
if (brightnessLevel == BrightnessController::Levels::Low) { if (brightnessLevel == BrightnessController::Levels::Low) {
brightnessLevel = BrightnessController::Levels::Medium; brightnessLevel = BrightnessController::Levels::Medium;
brightnessController.Set(brightnessLevel); SetState();
SetIndicators();
} else if (brightnessLevel == BrightnessController::Levels::Medium) { } else if (brightnessLevel == BrightnessController::Levels::Medium) {
brightnessLevel = BrightnessController::Levels::High; brightnessLevel = BrightnessController::Levels::High;
brightnessController.Set(brightnessLevel); SetState();
SetIndicators();
} }
return true; return true;
} }