From 1e5dec1577c2f6cacd6aac3d86a239b2903f9de1 Mon Sep 17 00:00:00 2001 From: Phil Mitchell Date: Wed, 28 Dec 2022 14:20:36 +1100 Subject: [PATCH] Adjust landscape layout, increase preview size. --- radio/src/gui/colorlcd/input_edit.cpp | 106 ++++++--------------- radio/src/gui/colorlcd/page.cpp | 3 + radio/src/gui/colorlcd/page.h | 48 ++++++++++ radio/src/targets/horus/libopenui_config.h | 2 +- 4 files changed, 79 insertions(+), 80 deletions(-) diff --git a/radio/src/gui/colorlcd/input_edit.cpp b/radio/src/gui/colorlcd/input_edit.cpp index f469f7e85fd..717400daa94 100644 --- a/radio/src/gui/colorlcd/input_edit.cpp +++ b/radio/src/gui/colorlcd/input_edit.cpp @@ -31,45 +31,7 @@ #define SET_DIRTY() storageDirty(EE_MODEL) -// Helper for building layout -class FormBuilder -{ -public: - FormBuilder(Window* box, const lv_coord_t col_dsc[], const lv_coord_t row_dsc[]) : grid(col_dsc, row_dsc) - { - form = new FormWindow(box, rect_t{}); - form->padAll(0); - form->setFlexLayout(); - } - - FormGroup::Line* newLine(uint8_t pad = 0) - { - line = form->newLine(&grid); - line->padAll(lv_dpx(pad)); - return line; - } - - Window* newBox(coord_t w, coord_t h) - { - auto box = new Window(line, rect_t{}); - box->padLeft(lv_dpx(4)); - box->padRight(lv_dpx(4)); - box->setWidth(w); - box->setHeight(h); - return box; - } - -private: - FlexGridLayout grid; - FormWindow* form = nullptr; - FormGroup::Line* line = nullptr; -}; - -// Grid description for preview and outer grids -static const lv_coord_t cv_col_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; -static const lv_coord_t cv_row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; - -// Grid description for inner grid - main controls +// Grid description for inner and outer grids static const lv_coord_t col_dsc[] = {LV_GRID_FR(2), LV_GRID_FR(3), LV_GRID_FR(2), LV_GRID_FR(3), LV_GRID_TEMPLATE_LAST}; static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; @@ -83,29 +45,22 @@ InputEditWindow::InputEditWindow(int8_t input, uint8_t index) : buildHeader(inputData); // Outer grid form - FormBuilder form(&body, cv_col_dsc, cv_row_dsc); + FormBuilder form(&body, 4, col_dsc, row_dsc); auto line = form.newLine(2); - - // Box for input name and line name - auto hbox = new FormGroup(line, rect_t{}); - hbox->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(8)); - hbox->padLeft(lv_dpx(4)); - hbox->padRight(lv_dpx(4)); - lv_obj_set_flex_align(hbox->getLvObj(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_AROUND); + line->padLeft(4); // Input Name auto inputName = g_model.inputNames[inputData->chn]; - lv_obj_set_flex_grow((new StaticText(hbox, rect_t{}, STR_INPUTNAME, 0, COLOR_THEME_PRIMARY1))->getLvObj(), 2); - auto nameFld = new ModelTextEdit(hbox, rect_t{}, inputName, LEN_INPUT_NAME); - lv_obj_set_flex_grow(nameFld->getLvObj(), 3); + new StaticText(line, rect_t{}, STR_INPUTNAME, 0, COLOR_THEME_PRIMARY1); + auto nameFld = new ModelTextEdit(line, rect_t{}, inputName, LEN_INPUT_NAME); nameFld->setChangeHandler([=]() { setTitle(); SET_DIRTY(); }); // Line Name - lv_obj_set_flex_grow((new StaticText(hbox, rect_t{}, STR_EXPONAME, 0, COLOR_THEME_PRIMARY1))->getLvObj(), 2); - lv_obj_set_flex_grow((new ModelTextEdit(hbox, rect_t{}, inputData->name, LEN_EXPOMIX_NAME))->getLvObj(), 3); + new StaticText(line, rect_t{}, STR_EXPONAME, 0, COLOR_THEME_PRIMARY1); + new ModelTextEdit(line, rect_t{}, inputData->name, LEN_EXPOMIX_NAME); line = form.newLine(); @@ -119,7 +74,7 @@ InputEditWindow::InputEditWindow(int8_t input, uint8_t index) : #if LCD_H > LCD_W // portrait auto box = form.newBox(body.width(), body.height() - INPUT_EDIT_CURVE_HEIGHT - 92); #else - auto box = form.newBox(body.width() - INPUT_EDIT_CURVE_WIDTH - 16, INPUT_EDIT_CURVE_HEIGHT + 34); + auto box = form.newBox(body.width() - INPUT_EDIT_CURVE_WIDTH - 16, body.height() - 29); #endif // Add main controls @@ -134,19 +89,6 @@ InputEditWindow::InputEditWindow(int8_t input, uint8_t index) : // Add preview and buttons buildPreview(box, inputData); - -#if LCD_W > LCD_H // Landscape - // Box for flight modes - line = form.newLine(); - hbox = new FormGroup(line, rect_t{}); - hbox->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(0)); - hbox->padLeft(lv_dpx(8)); - lv_obj_set_flex_align(hbox->getLvObj(), LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_BETWEEN); - - // Flight modes - new StaticText(hbox, rect_t{}, STR_FLMODE, 0, COLOR_THEME_PRIMARY1); - new FMMatrix(hbox, rect_t{}, inputData, 9); -#endif CurveEdit::SetCurrentSource(expoAddress(index)->srcRaw); } @@ -178,8 +120,9 @@ void InputEditWindow::buildHeader(ExpoData* inputData) void InputEditWindow::buildBody(Window* box, ExpoData* inputData) { - FormBuilder form(box, col_dsc, row_dsc); + FormBuilder form(box, 4, col_dsc, row_dsc); auto line = form.newLine(2); + line->padTop(0); // Switch new StaticText(line, rect_t{}, STR_SWITCH, 0, COLOR_THEME_PRIMARY1); @@ -208,26 +151,35 @@ void InputEditWindow::buildBody(Window* box, ExpoData* inputData) // Curve line = form.newLine(2); + line->padBottom(0); new StaticText(line, rect_t{}, STR_CURVE, 0, COLOR_THEME_PRIMARY1); new CurveParam(line, rect_t{}, &inputData->curve); -#if LCD_W < LCD_H // Portrait // Flight modes line = form.newLine(2); +#if LCD_H > LCD_W // Portrait new StaticText(line, rect_t{}, STR_FLMODE, 0, COLOR_THEME_PRIMARY1); new FMMatrix(line, rect_t{}, inputData, 5); +#else + line->padTop(0); + line->padBottom(0); + new StaticText(line, rect_t{}, STR_FLMODE, 0, COLOR_THEME_PRIMARY1); + line = form.newLine(); + line->padTop(0); + line->padBottom(0); + new FMMatrix(line, rect_t{}, inputData, 9); #endif } void InputEditWindow::buildPreview(Window* box, ExpoData* inputData) { - FormBuilder form(box, cv_col_dsc, cv_row_dsc); + FormBuilder form(box, 4, col_dsc, row_dsc); auto line = form.newLine(); lv_obj_set_flex_align(line->getLvObj(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_BETWEEN); line->padAll(lv_dpx(4)); - preview = new Curve(line, rect_t{}, + preview = new Curve(line, rect_t{ 0, 0, INPUT_EDIT_CURVE_WIDTH, INPUT_EDIT_CURVE_HEIGHT }, [=](int x) -> int { ExpoData* line = expoAddress(index); int16_t anas[MAX_INPUTS] = {0}; @@ -235,25 +187,21 @@ void InputEditWindow::buildPreview(Window* box, ExpoData* inputData) return anas[line->chn]; }, [=]() -> int { return getValue(expoAddress(index)->srcRaw); }); - - preview->setWidth(INPUT_EDIT_CURVE_WIDTH); - preview->setHeight(INPUT_EDIT_CURVE_HEIGHT); + form.cell(preview, LV_GRID_ALIGN_CENTER, 0, 4); line = form.newLine(); - auto hbox = new FormGroup(line, rect_t{}); - hbox->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(4)); - lv_obj_set_flex_align(hbox->getLvObj(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_BETWEEN); - - auto sBtn1 = new TextButton(hbox, rect_t{}, STR_VCURVEFUNC[2]); + auto sBtn1 = new TextButton(line, rect_t{}, STR_VCURVEFUNC[2]); sBtn1->setWidth(INPUT_EDIT_CURVE_WIDTH/2-4); sBtn1->setHeight(24); sBtn1->padAll(0); + form.cell(sBtn1, LV_GRID_ALIGN_CENTER, 0, 2); - auto sBtn2 = new TextButton(hbox, rect_t{}, STR_VCURVEFUNC[1]); + auto sBtn2 = new TextButton(line, rect_t{}, STR_VCURVEFUNC[1]); sBtn2->setWidth(INPUT_EDIT_CURVE_WIDTH/2-4); sBtn2->setHeight(24); sBtn2->padAll(0); + form.cell(sBtn2, LV_GRID_ALIGN_CENTER, 2, 2); sBtn1->setPressHandler([=]() { ExpoData* inputData = expoAddress(index); diff --git a/radio/src/gui/colorlcd/page.cpp b/radio/src/gui/colorlcd/page.cpp index ec95c8546b3..fa8f3a13f8b 100644 --- a/radio/src/gui/colorlcd/page.cpp +++ b/radio/src/gui/colorlcd/page.cpp @@ -88,3 +88,6 @@ void Page::onEvent(event_t event) { // block event bubbling } + +const lv_coord_t FormBuilder::default_col_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; +const lv_coord_t FormBuilder::default_row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; diff --git a/radio/src/gui/colorlcd/page.h b/radio/src/gui/colorlcd/page.h index ee85f14d4ae..e9fa8a06dbd 100644 --- a/radio/src/gui/colorlcd/page.h +++ b/radio/src/gui/colorlcd/page.h @@ -65,4 +65,52 @@ class Page : public Window void onEvent(event_t event) override; }; +// Helper for building layout +class FormBuilder +{ +public: + static const lv_coord_t default_col_dsc[]; + static const lv_coord_t default_row_dsc[]; + + FormBuilder(Window* box, lv_coord_t padding = 4, const lv_coord_t col_dsc[] = default_col_dsc, const lv_coord_t row_dsc[] = default_row_dsc) : m_grid(col_dsc, row_dsc, padding) + { + m_form = new FormWindow(box, rect_t{}); + m_form->padAll(0); + m_form->setFlexLayout(); + } + + FormGroup::Line* newLine(uint8_t pad = 0) + { + m_line = m_form->newLine(&m_grid); + m_line->padAll(lv_dpx(pad)); + lv_obj_set_grid_align(m_line->getLvObj(), LV_GRID_ALIGN_SPACE_BETWEEN, LV_GRID_ALIGN_SPACE_BETWEEN); + return m_line; + } + + Window* newBox(coord_t w = 0, coord_t h = 0) + { + auto box = new Window(m_line, rect_t{}); + box->padLeft(lv_dpx(4)); + box->padRight(lv_dpx(4)); + if (w) + box->setWidth(w); + if (h) + box->setHeight(h); + return box; + } + + void cell(Window* part, lv_grid_align_t x_align, uint8_t col_pos, uint8_t col_span, + lv_grid_align_t y_align = LV_GRID_ALIGN_CENTER, uint8_t row_pos = 0, uint8_t row_span = 1) + { + lv_obj_set_grid_cell(part->getLvObj(), x_align, col_pos, col_span, y_align, row_pos, row_span); + } + + FormWindow* form() const { return m_form; } + +private: + FlexGridLayout m_grid; + FormWindow* m_form = nullptr; + FormGroup::Line* m_line = nullptr; +}; + #endif // _PAGE_H_ diff --git a/radio/src/targets/horus/libopenui_config.h b/radio/src/targets/horus/libopenui_config.h index 901ce206c46..502d3fa8df1 100644 --- a/radio/src/targets/horus/libopenui_config.h +++ b/radio/src/targets/horus/libopenui_config.h @@ -117,7 +117,7 @@ constexpr uint32_t PAGE_TITLE_LEFT = 50; constexpr uint32_t INPUT_EDIT_LABELS_WIDTH = 120; -constexpr coord_t INPUT_EDIT_CURVE_WIDTH = 132; +constexpr coord_t INPUT_EDIT_CURVE_WIDTH = 154; constexpr coord_t INPUT_EDIT_CURVE_HEIGHT = INPUT_EDIT_CURVE_WIDTH; constexpr coord_t INPUT_EDIT_CURVE_LEFT = PAGE_PADDING; constexpr coord_t INPUT_EDIT_CURVE_TOP = MENU_HEADER_HEIGHT + PAGE_PADDING;