fix(color): Make "Add New" curve handling work more like SF (#3103)
* Make new curve handling work like special functions & logical switches - show popup of available curve slots. * chore: Formatting, comment typo
This commit is contained in:
@@ -135,6 +135,7 @@ void ModelCurvesPage::editCurve(FormWindow * window, uint8_t curve)
|
|||||||
void ModelCurvesPage::presetMenu(FormWindow * window, uint8_t index)
|
void ModelCurvesPage::presetMenu(FormWindow * window, uint8_t index)
|
||||||
{
|
{
|
||||||
Menu *menu = new Menu(window);
|
Menu *menu = new Menu(window);
|
||||||
|
menu->setTitle(STR_CURVE_PRESET);
|
||||||
for (int angle = -45; angle <= 45; angle += 15) {
|
for (int angle = -45; angle <= 45; angle += 15) {
|
||||||
char label[16];
|
char label[16];
|
||||||
strAppend(strAppendSigned(label, angle), "°");
|
strAppend(strAppendSigned(label, angle), "°");
|
||||||
@@ -158,22 +159,38 @@ void ModelCurvesPage::presetMenu(FormWindow * window, uint8_t index)
|
|||||||
menu->updateLines();
|
menu->updateLines();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModelCurvesPage::newCV(FormWindow *window, bool presetCV)
|
||||||
|
{
|
||||||
|
Menu *menu = new Menu(Layer::back());
|
||||||
|
menu->setTitle(STR_CURVE);
|
||||||
|
char s[6] = "CVxx";
|
||||||
|
|
||||||
|
// search for unused slot
|
||||||
|
for (uint8_t i = 0; i < MAX_CURVES; i += 1) {
|
||||||
|
if (!isCurveUsed(i)) {
|
||||||
|
strAppendUnsigned(&s[2], i + 1);
|
||||||
|
menu->addLineBuffered(s, [=]() {
|
||||||
|
focusIndex = i;
|
||||||
|
if (presetCV) {
|
||||||
|
presetMenu(window, i);
|
||||||
|
} else {
|
||||||
|
CurveHeader &curve = g_model.curves[i];
|
||||||
|
int8_t *points = curveAddress(i);
|
||||||
|
initPoints(curve, points);
|
||||||
|
editCurve(window, i);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
menu->updateLines();
|
||||||
|
}
|
||||||
|
|
||||||
void ModelCurvesPage::plusPopup(FormWindow * window)
|
void ModelCurvesPage::plusPopup(FormWindow * window)
|
||||||
{
|
{
|
||||||
CurveHeader &curve = g_model.curves[addIndex];
|
|
||||||
int8_t * points = curveAddress(addIndex);
|
|
||||||
|
|
||||||
Menu *menu = new Menu(window);
|
Menu *menu = new Menu(window);
|
||||||
menu->setTitle(STR_NEW);
|
menu->setTitle(STR_NEW);
|
||||||
menu->addLine(STR_EDIT, [=]() {
|
menu->addLine(STR_EDIT, [=]() { newCV(window, false); });
|
||||||
focusIndex = addIndex;
|
menu->addLine(STR_CURVE_PRESET, [=]() { newCV(window, true); });
|
||||||
initPoints(curve, points);
|
|
||||||
editCurve(window, addIndex);
|
|
||||||
});
|
|
||||||
menu->addLine(STR_CURVE_PRESET, [=]() {
|
|
||||||
focusIndex = addIndex;
|
|
||||||
presetMenu(window, addIndex);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelCurvesPage::build(FormWindow * window)
|
void ModelCurvesPage::build(FormWindow * window)
|
||||||
@@ -263,23 +280,19 @@ void ModelCurvesPage::build(FormWindow * window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (curveIndex < MAX_CURVES) {
|
if (curveIndex < MAX_CURVES) {
|
||||||
for (uint8_t n = 0; n < MAX_CURVES; n += 1) {
|
if ((curveIndex % PER_ROW) == 0) {
|
||||||
if (!isCurveUsed(n)) {
|
line = form->newLine(&grid);
|
||||||
if ((curveIndex % PER_ROW) == 0) {
|
lv_obj_set_grid_align(line->getLvObj(), LV_GRID_ALIGN_SPACE_BETWEEN,
|
||||||
line = form->newLine(&grid);
|
LV_GRID_ALIGN_SPACE_BETWEEN);
|
||||||
lv_obj_set_grid_align(line->getLvObj(), LV_GRID_ALIGN_SPACE_BETWEEN, LV_GRID_ALIGN_SPACE_BETWEEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
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(addButton->getLvObj(), LV_GRID_ALIGN_CENTER, curveIndex % PER_ROW, 1, LV_GRID_ALIGN_CENTER, 0, 1);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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(addButton->getLvObj(), LV_GRID_ALIGN_CENTER,
|
||||||
|
curveIndex % PER_ROW, 1, LV_GRID_ALIGN_CENTER, 0, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,12 +34,12 @@ class ModelCurvesPage: public PageTab {
|
|||||||
protected:
|
protected:
|
||||||
uint8_t focusIndex = -1;
|
uint8_t focusIndex = -1;
|
||||||
Button* addButton = nullptr;
|
Button* addButton = nullptr;
|
||||||
uint8_t addIndex = -1;
|
|
||||||
|
|
||||||
void rebuild(FormWindow * window);
|
void rebuild(FormWindow * window);
|
||||||
void editCurve(FormWindow * window, uint8_t curve);
|
void editCurve(FormWindow * window, uint8_t curve);
|
||||||
void presetMenu(FormWindow * window, uint8_t index);
|
void presetMenu(FormWindow * window, uint8_t index);
|
||||||
void plusPopup(FormWindow * window);
|
void plusPopup(FormWindow * window);
|
||||||
|
void newCV(FormWindow * window, bool presetCV);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _MODEL_CURVES_H_
|
#endif // _MODEL_CURVES_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user