From c77db8f67ac95ce3449693c416bfa642ec695a98 Mon Sep 17 00:00:00 2001 From: gagarinlg Date: Sat, 6 May 2023 12:34:49 +0200 Subject: [PATCH] finalise interactive checklists for color LCD --- radio/src/gui/colorlcd/preflight_checks.cpp | 10 ++++-- radio/src/gui/colorlcd/view_text.cpp | 35 +++++++++++++++++++-- radio/src/gui/colorlcd/view_text.h | 5 ++- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/radio/src/gui/colorlcd/preflight_checks.cpp b/radio/src/gui/colorlcd/preflight_checks.cpp index ddea688756b..4644ee9bcc6 100644 --- a/radio/src/gui/colorlcd/preflight_checks.cpp +++ b/radio/src/gui/colorlcd/preflight_checks.cpp @@ -115,12 +115,18 @@ PreflightChecks::PreflightChecks() : Page(ICON_MODEL_SETUP) // Display checklist auto line = form->newLine(&grid); new StaticText(line, rect_t{}, STR_CHECKLIST, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_DEFAULT(g_model.displayChecklist)); + auto chkList = new CheckBox(line, rect_t{}, GET_SET_DEFAULT(g_model.displayChecklist)); // Interactive checklist line = form->newLine(&grid); new StaticText(line, rect_t{}, STR_CHECKLIST_INTERACTIVE, 0, COLOR_THEME_PRIMARY1); - new CheckBox(line, rect_t{}, GET_SET_DEFAULT(g_model.displayChecklist)); + auto interactiveChkList = new CheckBox(line, rect_t{}, GET_SET_DEFAULT(g_model.checklistInteractive)); + if(!chkList->getValue()) + interactiveChkList->disable(); + chkList->setSetValueHandler([=](int32_t newValue) { + g_model.displayChecklist = newValue; SET_DIRTY(); + (g_model.displayChecklist)?interactiveChkList->enable():interactiveChkList->disable(); + }); // Throttle warning line = form->newLine(&grid); diff --git a/radio/src/gui/colorlcd/view_text.cpp b/radio/src/gui/colorlcd/view_text.cpp index b451860b82c..1ff276b77fd 100644 --- a/radio/src/gui/colorlcd/view_text.cpp +++ b/radio/src/gui/colorlcd/view_text.cpp @@ -33,6 +33,12 @@ static void checkbox_event_handler(lv_event_t* e) if (vtw) vtw->updateCheckboxes(lv_obj_get_parent(target)); } +void ViewTextWindow::onCancel() +{ + if(!g_model.checklistInteractive || fromMenu || allChecked()) + Page::onCancel(); +} + void ViewTextWindow::extractNameSansExt() { uint8_t nameLength; @@ -79,7 +85,7 @@ void ViewTextWindow::buildBody(Window *window) lv_obj_clear_flag(obj, LV_OBJ_FLAG_CLICK_FOCUSABLE); auto g = lv_group_get_default(); - if(fromMenu) + if(fromMenu || !g_model.checklistInteractive) { lb = lv_label_create(obj); lv_obj_set_size(lb, lv_pct(100), LV_SIZE_CONTENT); @@ -117,6 +123,7 @@ void ViewTextWindow::buildBody(Window *window) cur++; lv_obj_add_event_cb(cb, checkbox_event_handler, LV_EVENT_VALUE_CHANGED, this); + lv_obj_add_flag(cb, LV_OBJ_FLAG_EVENT_BUBBLE); lv_obj_set_user_data(cb, this); if(first) { @@ -212,7 +219,7 @@ FRESULT ViewTextWindow::sdReadTextFileBlock(const uint32_t bufSize, void ViewTextWindow::onEvent(event_t event) { #if defined(HARDWARE_KEYS) - if (int(bufSize) < fileLength) { + if (fromMenu && int(bufSize) < fileLength) { TRACE("BEFORE offset=%d", offset); if (event == EVT_KEY_BREAK(KEY_PGDN)) { offset += bufSize; @@ -231,6 +238,9 @@ void ViewTextWindow::onEvent(event_t event) sdReadTextFileBlock(bufSize, offset); lv_label_set_text_static(lb, buffer); } + + if(event == EVT_KEY_BREAK(KEY_EXIT)) + onCancel(); #endif } @@ -264,6 +274,27 @@ void ViewTextWindow::updateCheckboxes(lv_obj_t* parent) } } +bool ViewTextWindow::allChecked() +{ + lv_obj_t* parent = body.getLvObj(); + int children = lv_obj_get_child_cnt(parent); + + for(int child = 0; child < children; child++) + { + lv_obj_t* chld = lv_obj_get_child(parent, child); + if(!chld) + continue; + if(!lv_obj_check_type(chld, &lv_checkbox_class)) + continue; + if(lv_obj_get_state(chld) & LV_STATE_USER_1) + continue; + + if(!(lv_obj_get_state(chld) & LV_STATE_CHECKED)) + return false; + } + return true; +} + #include "datastructs.h" static void replaceSpaceWithUnderscore(std::string &name) diff --git a/radio/src/gui/colorlcd/view_text.h b/radio/src/gui/colorlcd/view_text.h index d7e80f14bd3..597a59297c6 100644 --- a/radio/src/gui/colorlcd/view_text.h +++ b/radio/src/gui/colorlcd/view_text.h @@ -35,7 +35,7 @@ class ViewTextWindow : public Page { public: ViewTextWindow(const std::string path, const std::string name, - unsigned int icon = ICON_RADIO_SD_MANAGER, bool fromMenu = false) : + unsigned int icon = ICON_RADIO_SD_MANAGER, bool fromMenu = true) : Page(icon), path(std::move(path)), name(std::move(name)), fromMenu(fromMenu) { fullPath = this->path + std::string(PATH_SEPARATOR) + this->name; @@ -56,6 +56,8 @@ class ViewTextWindow : public Page } } + void onCancel() override; + void updateCheckboxes(lv_obj_t* parent); #if defined(DEBUG_WINDOWS) std::string getName() const override { return "ViewTextWindow"; }; @@ -81,6 +83,7 @@ class ViewTextWindow : public Page void buildBody(Window* window); void onEvent(event_t event) override; + bool allChecked(); }; void readModelNotes(bool fromMenu = false);