feat: Add "Enable" button to all SF/GF (#3024) (#3601)

Co-authored-by: eshifri <eshifri@hotmail.com>
Co-authored-by: philmoz <philmoz@users.noreply.github.com>
This commit is contained in:
Peter Feerick
2023-12-03 12:23:34 +10:00
committed by GitHub
co-authored by eshifri philmoz
parent 878a365e72
commit ee73fa47f0
33 changed files with 262 additions and 194 deletions
+28 -29
View File
@@ -328,12 +328,7 @@ class SpecialFunctionEditPage : public Page
}
}
if (HAS_ENABLE_PARAM(func)) {
line = specialFunctionOneWindow->newLine(&grid);
new StaticText(line, rect_t{}, STR_ENABLE, 0, COLOR_THEME_PRIMARY1);
new ToggleSwitch(line, rect_t{},
GET_SET_DEFAULT(CFN_ACTIVE(cfn)));
} else if (HAS_REPEAT_PARAM(func)) { // !1x 1x 1s 2s 3s ...
if (HAS_REPEAT_PARAM(func)) { // !1x 1x 1s 2s 3s ...
line = specialFunctionOneWindow->newLine(&grid);
new StaticText(line, rect_t{}, STR_REPEAT,
0, COLOR_THEME_PRIMARY1);
@@ -360,6 +355,11 @@ class SpecialFunctionEditPage : public Page
});
}
}
line = specialFunctionOneWindow->newLine(&grid);
new StaticText(line, rect_t{}, STR_ENABLE, 0, COLOR_THEME_PRIMARY1);
new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(CFN_ACTIVE(cfn)));
}
void buildBody(FormWindow *window)
@@ -375,6 +375,10 @@ class SpecialFunctionEditPage : public Page
CustomFunctionData *cfn = &functions[index];
// Set new function to "disabled" by default
if (!CFN_SWITCH(cfn))
CFN_ACTIVE(cfn) = false;
// Switch
auto line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_SF_SWITCH, 0, COLOR_THEME_PRIMARY1);
@@ -516,7 +520,6 @@ class SpecialFunctionButton : public Button
sfEnable = lv_obj_create(lvobj);
lv_obj_set_size(sfEnable, 22, 22);
lv_obj_add_flag(sfEnable, LV_OBJ_FLAG_HIDDEN);
lv_obj_set_style_border_width(sfEnable, 3, 0);
lv_obj_set_style_border_color(sfEnable, makeLvColor(COLOR_THEME_PRIMARY2), 0);
lv_obj_set_style_border_opa(sfEnable, LV_OPA_100, 0);
@@ -665,16 +668,14 @@ class SpecialFunctionButton : public Button
lv_label_set_text(sfFunc, s);
lv_obj_add_flag(sfEnable, LV_OBJ_FLAG_HIDDEN);
s[0] = 0;
if (HAS_ENABLE_PARAM(func)) {
if (CFN_ACTIVE(cfn))
lv_obj_add_state(sfEnable, LV_STATE_CHECKED);
else
lv_obj_clear_state(sfEnable, LV_STATE_CHECKED);
lv_obj_clear_flag(sfEnable, LV_OBJ_FLAG_HIDDEN);
} else if (HAS_REPEAT_PARAM(func)) {
if (CFN_ACTIVE(cfn))
lv_obj_add_state(sfEnable, LV_STATE_CHECKED);
else
lv_obj_clear_state(sfEnable, LV_STATE_CHECKED);
if (HAS_REPEAT_PARAM(func)) {
if (func == FUNC_PLAY_SCRIPT) {
sprintf(s, "(%s)", (CFN_PLAY_REPEAT(cfn) == 0) ? "On" : "1x");
} else {
@@ -867,20 +868,18 @@ void SpecialFunctionsPage::build(FormWindow *window)
}
CustomFunctionData *cfn = &functions[i];
uint8_t func = CFN_FUNC(cfn);
if (HAS_ENABLE_PARAM(func)) {
if (CFN_ACTIVE(cfn)) {
menu->addLine(STR_DISABLE, [=]() {
CFN_ACTIVE(cfn) = 0;
SET_DIRTY();
rebuild(window);
});
} else {
menu->addLine(STR_ENABLE, [=]() {
CFN_ACTIVE(cfn) = 1;
SET_DIRTY();
rebuild(window);
});
}
if (CFN_ACTIVE(cfn)) {
menu->addLine(STR_DISABLE, [=]() {
CFN_ACTIVE(cfn) = 0;
SET_DIRTY();
rebuild(window);
});
} else {
menu->addLine(STR_ENABLE, [=]() {
CFN_ACTIVE(cfn) = 1;
SET_DIRTY();
rebuild(window);
});
}
if (functions[MAX_SPECIAL_FUNCTIONS - 1].isEmpty()) {
for (int j = i; j < MAX_SPECIAL_FUNCTIONS; j++) {