Skip to content

Commit

Permalink
Cleanup layout code.
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz committed Apr 27, 2024
1 parent 2620ce1 commit a44df63
Show file tree
Hide file tree
Showing 104 changed files with 893 additions and 906 deletions.
18 changes: 5 additions & 13 deletions radio/src/gui/colorlcd/channel_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@

#define CHANNELS_LIMIT (g_model.extendedLimits ? LIMIT_EXT_MAX : LIMIT_STD_MAX)

LAYOUT_VAL1(VAL_W, 45)
LAYOUT_VAL1(VAL_H, 12)
LAYOUT_VAL1(VAL_XO, 5)
LAYOUT_VAL1(VAL_YO, -2)
LAYOUT_VAL1(VAL_XT, -54)

ChannelBar::ChannelBar(Window* parent, const rect_t& rect,
std::function<int16_t()> getValueFunc, LcdFlags barColor,
LcdFlags txtColor) :
Expand Down Expand Up @@ -216,8 +210,6 @@ void OutputChannelBar::checkEvents()

//-----------------------------------------------------------------------------

LAYOUT_VAL3(ICON_SZ, 25, 16, 25)

ComboChannelBar::ComboChannelBar(Window* parent, const rect_t& rect,
uint8_t _channel, bool isInHeader) :
Window(parent, rect), channel(_channel)
Expand All @@ -226,31 +218,31 @@ ComboChannelBar::ComboChannelBar(Window* parent, const rect_t& rect,
isInHeader ? COLOR_THEME_PRIMARY2 : COLOR_THEME_SECONDARY1;

outputChannelBar = new OutputChannelBar(
this, {LMARGIN, BAR_HEIGHT + TMARGIN, width() - LMARGIN, BAR_HEIGHT},
this, {ChannelBar::LMARGIN, ChannelBar::BAR_HEIGHT + ChannelBar::TMARGIN, width() - ChannelBar::LMARGIN, ChannelBar::BAR_HEIGHT},
channel, isInHeader);

new MixerChannelBar(
this,
{LMARGIN, (2 * BAR_HEIGHT) + TMARGIN + 1, width() - LMARGIN, BAR_HEIGHT},
{ChannelBar::LMARGIN, (2 * ChannelBar::BAR_HEIGHT) + ChannelBar::TMARGIN + 1, width() - ChannelBar::LMARGIN, ChannelBar::BAR_HEIGHT},
channel);

// Channel number
char chanString[] = TR_CH "32 ";
strAppendSigned(&chanString[2], channel + 1, 2);
new StaticText(this, {LMARGIN, 0, LV_SIZE_CONTENT, 12}, chanString,
new StaticText(this, {ChannelBar::LMARGIN, 0, LV_SIZE_CONTENT, 12}, chanString,
textColor | FONT(XS) | LEFT);

// Channel name
if (g_model.limitData[channel].name[0]) {
char nm[LEN_CHANNEL_NAME + 1];
strAppend(nm, g_model.limitData[channel].name, LEN_CHANNEL_NAME);
new StaticText(this, {LMARGIN + VAL_W, 0, LV_SIZE_CONTENT, VAL_H}, nm,
new StaticText(this, {ChannelBar::LMARGIN + ChannelBar::VAL_W, 0, LV_SIZE_CONTENT, ChannelBar::VAL_H}, nm,
textColor | FONT(XS) | LEFT);
}

// Channel value in µS
new DynamicNumber<int16_t>(
this, {width() - VAL_W, 0, VAL_W, VAL_H},
this, {width() - ChannelBar::VAL_W, 0, ChannelBar::VAL_W, ChannelBar::VAL_H},
[=] { return PPM_CH_CENTER(channel) + channelOutputs[channel] / 2; },
textColor | FONT(XS) | RIGHT, "", STR_US);

Expand Down
17 changes: 12 additions & 5 deletions radio/src/gui/colorlcd/channel_bar.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,23 @@

#include "opentx.h"

LAYOUT_VAL1(ROW_HEIGHT, 42)
LAYOUT_VAL3(BAR_HEIGHT, 13, 9, 13)
LAYOUT_VAL1(LMARGIN, 15)
constexpr coord_t TMARGIN = 2;

class ChannelBar : public Window
{
public:
ChannelBar(Window* parent, const rect_t& rect,
std::function<int16_t()> getValue, LcdFlags barColor,
LcdFlags textColor = COLOR_THEME_SECONDARY1);

static LAYOUT_VAL(BAR_HEIGHT, 13, 13, 9)
static LAYOUT_VAL(LMARGIN, 15, 15, LS(15))
static LAYOUT_VAL(TMARGIN, 2, 2, 2)

static LAYOUT_VAL(VAL_W, 45, 45, LS(45))
static LAYOUT_VAL(VAL_H, 12, 12, LS(12))
static LAYOUT_VAL(VAL_XO, 5, 5, LS(5))
static LAYOUT_VAL(VAL_YO, -2, -2, LS(-2))
static LAYOUT_VAL(VAL_XT, -54, -54, LS(-54))

protected:
int16_t value = -10000;
std::function<int16_t()> getValue;
Expand Down Expand Up @@ -78,6 +83,8 @@ class ComboChannelBar : public Window
ComboChannelBar(Window* parent, const rect_t& rect, uint8_t channel,
bool isInHeader = false);

static LAYOUT_VAL(ICON_SZ, 25, 25, 16)

protected:
uint8_t channel;
OutputChannelBar* outputChannelBar = nullptr;
Expand Down
27 changes: 10 additions & 17 deletions radio/src/gui/colorlcd/color_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
#include "button.h"
#include "themes/etx_lv_theme.h"

LAYOUT_VAL3(BAR_MARGIN, 5, 4, 5)
LAYOUT_VAL3(BAR_TOP_MARGIN, 5, 4, 5)
LAYOUT_VAL3(BAR_HEIGHT_OFFSET, 25, 16, 25)
LAYOUT_VAL3(LBL_YO, 9, 5, 9)
LAYOUT_VAL3(VAL_XO, 10, 6, 10)
LAYOUT_VAL1(VAL_YO, 3)

static const char* const RGBChars[MAX_BARS] = {"R", "G", "B"};
static const char* const HSVChars[MAX_BARS] = {"H", "S", "V"};

Expand Down Expand Up @@ -172,12 +165,12 @@ class ColorBar : public Window

// draw cursor
lv_area_t cursor_area;
cursor_area.x1 = area->x1 + (lv_area_get_width(area) / 2) - 5;
cursor_area.x2 = cursor_area.x1 + 10 - 1;
cursor_area.x1 = area->x1 + (lv_area_get_width(area) / 2) - ColorEditor::CRSR_SZ / 2;
cursor_area.x2 = cursor_area.x1 + ColorEditor::CRSR_SZ - 1;

auto pos = bar->valueToScreen(bar->value);
cursor_area.y1 = area->y1 + pos - 3;
cursor_area.y2 = cursor_area.y1 + 10 - 1;
cursor_area.y1 = area->y1 + pos - ColorEditor::CRSR_YO;
cursor_area.y2 = cursor_area.y1 + ColorEditor::CRSR_SZ - 1;

lv_draw_rect_dsc_t cursor_dsc;
lv_draw_rect_dsc_init(&cursor_dsc);
Expand Down Expand Up @@ -276,12 +269,12 @@ BarColorType::BarColorType(Window* parent)

int leftPos = 0;
rect_t r;
r.y = BAR_TOP_MARGIN;
r.w = spacePerBar - BAR_MARGIN - 5;
r.h = parent->height() - (BAR_TOP_MARGIN + BAR_HEIGHT_OFFSET);
r.y = ColorEditor::BAR_TOP_MARGIN;
r.w = spacePerBar - ColorEditor::BAR_MARGIN - 5;
r.h = parent->height() - (ColorEditor::BAR_TOP_MARGIN + ColorEditor::BAR_HEIGHT_OFFSET);

for (int i = 0; i < MAX_BARS; i++) {
r.x = leftPos + BAR_MARGIN;
r.x = leftPos + ColorEditor::BAR_MARGIN;

bars[i] = new ColorBar(parent, r);
leftPos += spacePerBar;
Expand All @@ -291,8 +284,8 @@ BarColorType::BarColorType(Window* parent)
auto x = bar->left();
auto y = bar->bottom();

barLabels[i] = create_bar_label(parent->getLvObj(), x, y + LBL_YO);
barValLabels[i] = create_bar_value_label(parent->getLvObj(), x + VAL_XO, y + VAL_YO);
barLabels[i] = create_bar_label(parent->getLvObj(), x, y + ColorEditor::LBL_YO);
barValLabels[i] = create_bar_value_label(parent->getLvObj(), x + ColorEditor::VAL_XO, y + ColorEditor::VAL_YO);
}
}

Expand Down
9 changes: 9 additions & 0 deletions radio/src/gui/colorlcd/color_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ class ColorEditor : public Window

void setColorEditorType(COLOR_EDITOR_TYPE colorType);

static LAYOUT_VAL(BAR_MARGIN, 5, 5, 4)
static LAYOUT_VAL(BAR_TOP_MARGIN, 5, 5, 4)
static LAYOUT_VAL(BAR_HEIGHT_OFFSET, 25, 25, 16)
static LAYOUT_VAL(LBL_YO, 9, 9, 5)
static LAYOUT_VAL(VAL_XO, 10, 10, 6)
static LAYOUT_VAL(VAL_YO, 3, 3, LS(3))
static LAYOUT_VAL(CRSR_SZ, 10, 10, 8)
static LAYOUT_VAL(CRSR_YO, 3, 3, 2)

protected:
ColorType* _colorType = nullptr;
std::function<void(uint32_t)> _setValue;
Expand Down
31 changes: 16 additions & 15 deletions radio/src/gui/colorlcd/color_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,18 @@
#include "color_list.h"
#include "themes/etx_lv_theme.h"

// based on LVGL default switch size
constexpr lv_coord_t COLOR_PAD_WIDTH = (4 * LV_DPI_DEF) / 10;
constexpr lv_coord_t COLOR_PAD_HEIGHT = 32;

#if !PORTRAIT_LCD
// Landscape
static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1),
LV_GRID_TEMPLATE_LAST};
static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST};

#define COLOR_EDIT_WIDTH LCD_W * 0.8

#else
// Portrait
static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_CONTENT,
LV_GRID_TEMPLATE_LAST};

#define COLOR_EDIT_WIDTH LCD_W * 0.7

#endif

class ColorEditorPopup : public BaseDialog
Expand Down Expand Up @@ -74,7 +66,7 @@ class ColorEditorPopup : public BaseDialog
FlexGridLayout grid(col_dsc, row_dsc);
auto line = form->newLine(grid);

rect_t r{0, 0, 7 * LV_DPI_DEF / 5, 7 * LV_DPI_DEF / 5};
rect_t r{0, 0, CE_SZ, CE_SZ};
auto cedit =
new ColorEditor(line, r, color, [=](uint32_t c) { updateColor(c); });
lv_obj_set_style_grid_cell_x_align(cedit->getLvObj(), LV_GRID_ALIGN_CENTER,
Expand All @@ -94,7 +86,7 @@ class ColorEditorPopup : public BaseDialog
colorPad = new ColorSwatch(hbox, {0, 0, COLOR_PAD_WIDTH, COLOR_PAD_HEIGHT},
COLOR_THEME_PRIMARY1);

hexStr = new StaticText(hbox, {0, 0, 100, 0}, "", COLOR_THEME_PRIMARY1 | FONT(L));
hexStr = new StaticText(hbox, {0, 0, CVAL_W, 0}, "", COLOR_THEME_PRIMARY1 | FONT(L));

updateColor(color);

Expand Down Expand Up @@ -135,29 +127,38 @@ class ColorEditorPopup : public BaseDialog
hsvBtn->check(true);

hbox = new Window(vbox, rect_t{});
hbox->padTop(60);
hbox->setFlexLayout(LV_FLEX_FLOW_ROW, 20);
hbox->padTop(BTN_PAD_TOP);
hbox->setFlexLayout(LV_FLEX_FLOW_ROW, BTN_PAD_ROW);
lv_obj_set_flex_align(hbox->getLvObj(), LV_FLEX_ALIGN_CENTER,
LV_FLEX_ALIGN_END, LV_FLEX_ALIGN_SPACE_BETWEEN);
lv_obj_set_flex_grow(hbox->getLvObj(), 1);

new TextButton(hbox, rect_t{0, 0, 80, 0}, STR_CANCEL, [=]() -> int8_t {
new TextButton(hbox, rect_t{0, 0, BTN_W, 0}, STR_CANCEL, [=]() -> int8_t {
this->deleteLater();
return 0;
});

new TextButton(hbox, rect_t{0, 0, 80, 0}, STR_SAVE, [=]() -> int8_t {
new TextButton(hbox, rect_t{0, 0, BTN_W, 0}, STR_SAVE, [=]() -> int8_t {
if (_setValue) _setValue(m_color);
this->deleteLater();
return 0;
});
}

static LAYOUT_VAL(CE_SZ, 182, 182, LS(182))
static LAYOUT_VAL(COLOR_EDIT_WIDTH, LCD_W * 0.8, LCD_W * 0.7, LCD_W * 0.8)
static LAYOUT_VAL(COLOR_PAD_WIDTH, 52, 52, LS(52))
static LAYOUT_VAL(COLOR_PAD_HEIGHT, 32, 32, LS(32))
static LAYOUT_VAL(CVAL_W, 100, 100, LS(100))
static LAYOUT_VAL(BTN_W, 80, 80, LS(80))
static LAYOUT_VAL(BTN_PAD_TOP, 60, 60, LS(60))
static LAYOUT_VAL(BTN_PAD_ROW, 20, 20, LS(20))
};

ColorPicker::ColorPicker(Window* parent, const rect_t& rect,
std::function<uint16_t()> getValue,
std::function<void(uint16_t)> setValue) :
Button(parent, {0, 0, COLOR_PAD_WIDTH, COLOR_PAD_HEIGHT}),
Button(parent, {0, 0, ColorEditorPopup::COLOR_PAD_WIDTH, ColorEditorPopup::COLOR_PAD_HEIGHT}),
setValue(std::move(setValue))
{
updateColor(getValue());
Expand Down
4 changes: 2 additions & 2 deletions radio/src/gui/colorlcd/custom_failsafe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ class ChannelFailsafeBargraph : public Window
etx_obj_add_style(lvobj, styles->border_thin, LV_PART_MAIN);
etx_obj_add_style(lvobj, styles->border_color_black, LV_PART_MAIN);

outputsBar = new OutputChannelBar(this, {0, 1, width() - 2, BAR_HEIGHT},
outputsBar = new OutputChannelBar(this, {0, 1, width() - 2, ChannelBar::BAR_HEIGHT},
channel, false, false);
outputsBar->hide();

failsafeBar = new ChannelBar(
this, {0, BAR_HEIGHT + 3, width() - 2, BAR_HEIGHT},
this, {0, ChannelBar::BAR_HEIGHT + 3, width() - 2, ChannelBar::BAR_HEIGHT},
[=] { return calcRESXto100(g_model.failsafeChannels[channel]); },
COLOR_THEME_WARNING, COLOR_THEME_WARNING);
failsafeBar->hide();
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/file_carosell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ FileCarosell::FileCarosell(Window *parent, const rect_t &rect,
{
setWindowFlag(NO_FOCUS);

message = new StaticText(this, {0, rect.h/2, rect.w, PAGE_LINE_HEIGHT}, "", CENTERED | FONT(L) | COLOR_THEME_PRIMARY1);
message = new StaticText(this, {0, rect.h/2, rect.w, EdgeTxStyles::PAGE_LINE_HEIGHT}, "", CENTERED | FONT(L) | COLOR_THEME_PRIMARY1);

setFileNames(fileNames);
}
Expand Down
4 changes: 1 addition & 3 deletions radio/src/gui/colorlcd/fm_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
#define FM_ROWS 2
#endif

LAYOUT_VAL1(FM_BTN_W, 48)

template <class T>
FMMatrix<T>::FMMatrix(Window* parent, const rect_t& r, T* input) :
ButtonMatrix(parent, r), input(input)
Expand All @@ -47,7 +45,7 @@ FMMatrix<T>::FMMatrix(Window* parent, const rect_t& r, T* input) :
update();

lv_obj_set_width(lvobj, FM_COLS * (FM_BTN_W + 3) + 3);
lv_obj_set_height(lvobj, FM_ROWS * (UI_ELEMENT_HEIGHT + 3) +3);
lv_obj_set_height(lvobj, FM_ROWS * (EdgeTxStyles::UI_ELEMENT_HEIGHT + 3) +3);

padAll(PAD_SMALL);
}
Expand Down
2 changes: 2 additions & 0 deletions radio/src/gui/colorlcd/fm_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ struct FMMatrix : public ButtonMatrix {
void onPress(uint8_t btn_id);
bool isActive(uint8_t btn_id);
void setTextAndState(uint8_t btn_id);

static LAYOUT_VAL(FM_BTN_W, 48, 48, LS(48))
};

extern template struct FMMatrix<ExpoData>;
Expand Down
2 changes: 0 additions & 2 deletions radio/src/gui/colorlcd/gvar_numberedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include "gvar_numberedit.h"
#include "opentx.h"

LAYOUT_VAL1(NUM_EDIT_W, 70)

void GVarNumberEdit::value_changed(lv_event_t* e)
{
auto obj = lv_event_get_target(e);
Expand Down
6 changes: 3 additions & 3 deletions radio/src/gui/colorlcd/gvar_numberedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#include "numberedit.h"
#include "gvars.h"

constexpr coord_t GVAR_BUTTON_WIDTH = 30;

class TextButton;

class GVarNumberEdit : public Window
Expand All @@ -43,7 +41,9 @@ class GVarNumberEdit : public Window

void setFastStep(int value) { num_field->setFastStep(value); }
void setAccelFactor(int value) { num_field->setAccelFactor(value); }


static LAYOUT_VAL(NUM_EDIT_W, 70, 70, LS(70))

protected:
Choice* gvar_field = nullptr;
NumberEdit* num_field = nullptr;
Expand Down
Loading

0 comments on commit a44df63

Please sign in to comment.