flight modes: use pop-up for trim settings

This commit is contained in:
Raphael Coeffic
2022-06-11 15:38:08 +02:00
committed by Raphael Coeffic
parent ccfce12556
commit 90c5f8565e
+52 -33
View File
@@ -42,7 +42,7 @@ static const lv_coord_t line_col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1),
static const lv_coord_t line_row_dsc[] = {LV_GRID_CONTENT, static const lv_coord_t line_row_dsc[] = {LV_GRID_CONTENT,
LV_GRID_TEMPLATE_LAST}; LV_GRID_TEMPLATE_LAST};
static const lv_coord_t trims_col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(2), LV_GRID_FR(2), static const lv_coord_t trims_col_dsc[] = {LV_GRID_FR(2), LV_GRID_FR(2),
LV_GRID_TEMPLATE_LAST}; LV_GRID_TEMPLATE_LAST};
static const lv_coord_t trims_row_dsc[] = {LV_GRID_CONTENT, static const lv_coord_t trims_row_dsc[] = {LV_GRID_CONTENT,
@@ -91,43 +91,22 @@ static std::string getFMTrimStr(uint8_t mode)
return str; return str;
} }
FlightModeEdit::FlightModeEdit(uint8_t index) : struct FMTrimSettings : public Dialog {
Page(ICON_MODEL_FLIGHT_MODES) FMTrimSettings(Window* parent, FlightModeData* p_fm) :
Dialog(parent->getFullScreenWindow(), STR_TRIMS, rect_t{})
{ {
std::string title = auto lv_content = content->getLvObj();
std::string(TR_MENUFLIGHTMODE) + " " + std::to_string(index); lv_obj_set_flex_flow(lv_content, LV_FLEX_FLOW_COLUMN);
new StaticText(&header,
{PAGE_TITLE_LEFT, PAGE_TITLE_TOP, LCD_W - PAGE_TITLE_LEFT,
PAGE_LINE_HEIGHT},
title, 0, COLOR_THEME_PRIMARY2);
auto form = new FormWindow(&body, rect_t{0, 0, body.width(), body.height()}, setCloseWhenClickOutside(true);
NO_FOCUS | FORM_FORWARD_FOCUS);
auto form = &content->form;
form->setFlexLayout(); form->setFlexLayout();
FlexGridLayout grid(line_col_dsc, line_row_dsc, 2);
FlightModeData* p_fm = &g_model.flightModeData[index];
// Flight mode name
auto line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_NAME, 0, COLOR_THEME_PRIMARY1);
new ModelTextEdit(line, rect_t{}, p_fm->name, LEN_FLIGHT_MODE_NAME);
if (index > 0) {
// Switch
line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_SWITCH, 0, COLOR_THEME_PRIMARY1);
new SwitchChoice(line, rect_t{}, SWSRC_FIRST_IN_MIXES, SWSRC_LAST_IN_MIXES,
GET_SET_DEFAULT(p_fm->swtch));
}
FlexGridLayout trim_grid(trims_col_dsc, trims_row_dsc); FlexGridLayout trim_grid(trims_col_dsc, trims_row_dsc);
line = form->newLine(&trim_grid); auto line = form->newLine(&trim_grid);
new StaticText(line, rect_t{}, STR_TRIMS, 0, COLOR_THEME_PRIMARY1);
for (int t = 0; t < NUM_TRIMS; t++) { for (int t = 0; t < NUM_TRIMS; t++) {
auto trim_obj = window_create(line->getLvObj()); auto trim_obj = window_create(line->getLvObj());
auto trim = new FormGroup::Line(line, trim_obj, nullptr, form); auto trim = new FormGroup::Line(line, trim_obj, nullptr, form);
lv_obj_set_layout(trim_obj, LV_LAYOUT_FLEX); lv_obj_set_layout(trim_obj, LV_LAYOUT_FLEX);
@@ -161,10 +140,42 @@ FlightModeEdit::FlightModeEdit(uint8_t index) :
// show trim value choice iff btn->checked() // show trim value choice iff btn->checked()
make_conditional(tr_mode, btn); make_conditional(tr_mode, btn);
if (t % 2 == 1) {
trim_grid.nextCell();
} }
content->setWidth(LCD_W * 0.8);
content->updateSize();
}
};
FlightModeEdit::FlightModeEdit(uint8_t index) :
Page(ICON_MODEL_FLIGHT_MODES)
{
std::string title =
std::string(TR_MENUFLIGHTMODE) + " " + std::to_string(index);
new StaticText(&header,
{PAGE_TITLE_LEFT, PAGE_TITLE_TOP, LCD_W - PAGE_TITLE_LEFT,
PAGE_LINE_HEIGHT},
title, 0, COLOR_THEME_PRIMARY2);
auto form = new FormWindow(&body, rect_t{0, 0, body.width(), body.height()},
NO_FOCUS | FORM_FORWARD_FOCUS);
form->setFlexLayout();
FlexGridLayout grid(line_col_dsc, line_row_dsc, 2);
FlightModeData* p_fm = &g_model.flightModeData[index];
// Flight mode name
auto line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_NAME, 0, COLOR_THEME_PRIMARY1);
new ModelTextEdit(line, rect_t{}, p_fm->name, LEN_FLIGHT_MODE_NAME);
if (index > 0) {
// Switch
line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_SWITCH, 0, COLOR_THEME_PRIMARY1);
new SwitchChoice(line, rect_t{}, SWSRC_FIRST_IN_MIXES, SWSRC_LAST_IN_MIXES,
GET_SET_DEFAULT(p_fm->swtch));
} }
// Fade in // Fade in
@@ -178,6 +189,14 @@ FlightModeEdit::FlightModeEdit(uint8_t index) :
new StaticText(line, rect_t{}, STR_FADEOUT, 0, COLOR_THEME_PRIMARY1); new StaticText(line, rect_t{}, STR_FADEOUT, 0, COLOR_THEME_PRIMARY1);
new NumberEdit(line, rect_t{}, 0, DELAY_MAX, GET_DEFAULT(p_fm->fadeOut), new NumberEdit(line, rect_t{}, 0, DELAY_MAX, GET_DEFAULT(p_fm->fadeOut),
SET_VALUE(p_fm->fadeOut, newValue), 0, PREC1); SET_VALUE(p_fm->fadeOut, newValue), 0, PREC1);
// Trims
line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_TRIMS, 0, COLOR_THEME_PRIMARY1);
new TextButton(line, rect_t{}, STR_SETUP, [=]() {
new FMTrimSettings(this, p_fm);
return 0;
});
} }
class FlightModeBtn: public Button class FlightModeBtn: public Button