Skip to content

Commit

Permalink
finalise interactive checklists for color LCD
Browse files Browse the repository at this point in the history
  • Loading branch information
gagarinlg committed May 6, 2023
1 parent 2d42f3f commit c77db8f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
10 changes: 8 additions & 2 deletions radio/src/gui/colorlcd/preflight_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
35 changes: 33 additions & 2 deletions radio/src/gui/colorlcd/view_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion radio/src/gui/colorlcd/view_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"; };
Expand All @@ -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);

0 comments on commit c77db8f

Please sign in to comment.