Skip to content

Commit

Permalink
feat(color): Add long press handler for new model curves page (EdgeTX…
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz authored and mha1 committed Jan 27, 2023
1 parent 3ec1855 commit f41b048
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
46 changes: 31 additions & 15 deletions radio/src/gui/colorlcd/model_curves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,24 @@ void ModelCurvesPage::presetMenu(FormWindow * window, uint8_t index)
menu->updateLines();
}

void ModelCurvesPage::plusPopup(FormWindow * window)
{
CurveHeader &curve = g_model.curves[addIndex];
int8_t * points = curveAddress(addIndex);

Menu *menu = new Menu(window);
menu->setTitle(STR_NEW);
menu->addLine(STR_EDIT, [=]() {
focusIndex = addIndex;
initPoints(curve, points);
editCurve(window, addIndex);
});
menu->addLine(STR_CURVE_PRESET, [=]() {
focusIndex = addIndex;
presetMenu(window, addIndex);
});
}

void ModelCurvesPage::build(FormWindow * window)
{
#if LCD_W > LCD_H
Expand Down Expand Up @@ -194,6 +212,7 @@ void ModelCurvesPage::build(FormWindow * window)
auto button = new CurveButton(line, rect_t{0, 0, CURVE_BTN_W, CURVE_BTH_H}, index);
button->setPressHandler([=]() -> uint8_t {
Menu * menu = new Menu(window);
menu->setTitle(STR_CURVE);
menu->addLine(STR_EDIT, [=]() {
editCurve(window, index);
});
Expand All @@ -215,6 +234,14 @@ void ModelCurvesPage::build(FormWindow * window)
focusIndex = index;
});

button->setLongPressHandler([=]() -> uint8_t {
if (addButton) {
lv_group_focus_obj(addButton->getLvObj());
plusPopup(window);
}
return 0;
});

if (!firstCurveButton) {
firstCurveIndex = index;
firstCurveButton = button;
Expand Down Expand Up @@ -243,24 +270,13 @@ void ModelCurvesPage::build(FormWindow * window)
lv_obj_set_grid_align(line->getLvObj(), LV_GRID_ALIGN_SPACE_BETWEEN, LV_GRID_ALIGN_SPACE_BETWEEN);
}

CurveHeader &curve = g_model.curves[n];
int8_t * points = curveAddress(n);

auto button = new TextButton(line, rect_t{0, 0, CURVE_BTN_W, CURVE_BTH_H}, LV_SYMBOL_PLUS, [=]() {
Menu *menu = new Menu(window);
menu->addLine(STR_EDIT, [=]() {
focusIndex = n;
initPoints(curve, points);
editCurve(window, n);
});
menu->addLine(STR_CURVE_PRESET, [=]() {
focusIndex = n;
presetMenu(window, n);
});
addIndex = n;
addButton = new TextButton(line, rect_t{0, 0, CURVE_BTN_W, CURVE_BTH_H}, LV_SYMBOL_PLUS, [=]() {
plusPopup(window);
return 0;
});

lv_obj_set_grid_cell(button->getLvObj(), LV_GRID_ALIGN_CENTER, curveIndex % PER_ROW, 1, LV_GRID_ALIGN_CENTER, 0, 1);
lv_obj_set_grid_cell(addButton->getLvObj(), LV_GRID_ALIGN_CENTER, curveIndex % PER_ROW, 1, LV_GRID_ALIGN_CENTER, 0, 1);

break;
}
Expand Down
3 changes: 3 additions & 0 deletions radio/src/gui/colorlcd/model_curves.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ class ModelCurvesPage: public PageTab {

protected:
uint8_t focusIndex = -1;
Button* addButton = nullptr;
uint8_t addIndex = -1;

void rebuild(FormWindow * window);
void editCurve(FormWindow * window, uint8_t curve);
void presetMenu(FormWindow * window, uint8_t index);
void plusPopup(FormWindow * window);
};

#endif // _MODEL_CURVES_H_

0 comments on commit f41b048

Please sign in to comment.