Skip to content

Commit

Permalink
Adjust landscape layout, increase preview size.
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Mitchell committed Dec 28, 2022
1 parent 8cae092 commit 1e5dec1
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 80 deletions.
106 changes: 27 additions & 79 deletions radio/src/gui/colorlcd/input_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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();

Expand All @@ -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
Expand All @@ -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<ExpoData>(hbox, rect_t{}, inputData, 9);
#endif

CurveEdit::SetCurrentSource(expoAddress(index)->srcRaw);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -208,52 +151,57 @@ 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<ExpoData>(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<ExpoData>(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};
applyExpos(anas, e_perout_mode_inactive_flight_mode, line->srcRaw, x);
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);
Expand Down
3 changes: 3 additions & 0 deletions radio/src/gui/colorlcd/page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
48 changes: 48 additions & 0 deletions radio/src/gui/colorlcd/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
2 changes: 1 addition & 1 deletion radio/src/targets/horus/libopenui_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1e5dec1

Please sign in to comment.