trainer page: flex layout
This commit is contained in:
committed by
Raphael Coeffic
parent
5de7a77720
commit
10615b0201
@@ -30,78 +30,87 @@ RadioTrainerPage::RadioTrainerPage():
|
||||
{
|
||||
}
|
||||
|
||||
class StaticNumber : public StaticText
|
||||
{
|
||||
public:
|
||||
StaticNumber(Window * parent, const rect_t & rect, std::function<int()> getValue, WindowFlags windowFlags = 0, LcdFlags textFlags = 0) :
|
||||
StaticText(parent, rect, "", windowFlags, textFlags),
|
||||
_getValue(std::move(getValue))
|
||||
{
|
||||
}
|
||||
static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(2),
|
||||
LV_GRID_TEMPLATE_LAST};
|
||||
|
||||
void paint(BitmapBuffer * dc) {
|
||||
auto curval = _getValue();
|
||||
char buf[20];
|
||||
if(textFlags & PREC1)
|
||||
snprintf(buf, sizeof(buf), "%d.%.1d", curval / 10, abs(curval % 10));
|
||||
else if(textFlags & PREC2)
|
||||
snprintf(buf, sizeof(buf), "%d.%.2d", curval / 100, abs(curval % 100));
|
||||
else
|
||||
snprintf(buf, sizeof(buf), "%d", curval);
|
||||
text = buf;
|
||||
StaticText::paint(dc);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::function<int()> _getValue;
|
||||
};
|
||||
|
||||
void RadioTrainerPage::build(FormWindow * window)
|
||||
{
|
||||
#if LCD_W > LCD_H
|
||||
#define TRAINER_LABEL_WIDTH 180
|
||||
#else
|
||||
#define TRAINER_LABEL_WIDTH 100
|
||||
#if LCD_H >= LCD_W
|
||||
static const lv_coord_t col4_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1),
|
||||
LV_GRID_FR(1), LV_GRID_FR(1),
|
||||
LV_GRID_TEMPLATE_LAST};
|
||||
#endif
|
||||
FormGridLayout grid;
|
||||
grid.spacer(PAGE_PADDING);
|
||||
grid.setLabelWidth(TRAINER_LABEL_WIDTH);
|
||||
|
||||
for (uint8_t i=0; i<NUM_STICKS; i++) {
|
||||
uint8_t chan = channelOrder(i+1);
|
||||
TrainerMix * td = &g_eeGeneral.trainer.mix[chan-1];
|
||||
new StaticText(window, grid.getLabelSlot(), TEXT_AT_INDEX(STR_VSRCRAW, (i + 1)), 0, COLOR_THEME_PRIMARY1);
|
||||
new Choice(window, grid.getFieldSlot(3,0), STR_TRNMODE, 0, 2, GET_SET_DEFAULT(td->mode));
|
||||
auto weight = new NumberEdit(window, grid.getFieldSlot(3, 1), -125, 125, GET_SET_DEFAULT(td->studWeight));
|
||||
static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST};
|
||||
|
||||
#if defined(PPM_UNIT_PERCENT_PREC1)
|
||||
#define PPM_PRECISION PREC1
|
||||
#else
|
||||
#define PPM_PRECISION 0
|
||||
#endif
|
||||
|
||||
void RadioTrainerPage::build(FormWindow * form)
|
||||
{
|
||||
FlexGridLayout grid(col_dsc, row_dsc, 2);
|
||||
form->setFlexLayout();
|
||||
|
||||
for (uint8_t i = 0; i < NUM_STICKS; i++) {
|
||||
uint8_t chan = channelOrder(i + 1);
|
||||
TrainerMix* td = &g_eeGeneral.trainer.mix[chan - 1];
|
||||
|
||||
auto line = form->newLine(&grid);
|
||||
new StaticText(line, rect_t{}, STR_VSRCRAW[i + 1], 0, COLOR_THEME_PRIMARY1);
|
||||
|
||||
auto box = new FormGroup(line, rect_t{});
|
||||
box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(4));
|
||||
auto box_obj = box->getLvObj();
|
||||
lv_obj_set_width(box_obj, LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_flex_cross_place(box_obj, LV_FLEX_ALIGN_CENTER, 0);
|
||||
|
||||
new Choice(box, rect_t{}, STR_TRNMODE, 0, 2, GET_SET_DEFAULT(td->mode));
|
||||
new Choice(box, rect_t{}, STR_TRNCHN, 0, 3, GET_SET_DEFAULT(td->srcChn));
|
||||
auto weight = new NumberEdit(box, rect_t{}, -125, 125,
|
||||
GET_SET_DEFAULT(td->studWeight));
|
||||
weight->setSuffix("%");
|
||||
new Choice(window, grid.getFieldSlot(3,2), STR_TRNCHN, 0, 3, GET_SET_DEFAULT(td->srcChn));
|
||||
grid.nextLine();
|
||||
}
|
||||
grid.nextLine();
|
||||
|
||||
// Trainer multiplier
|
||||
new StaticText(window, grid.getLabelSlot(), STR_MULTIPLIER, 0, COLOR_THEME_PRIMARY1);
|
||||
auto multiplier = new NumberEdit(window, grid.getFieldSlot(3, 0), -10, 40, GET_SET_DEFAULT(g_eeGeneral.PPM_Multiplier));
|
||||
multiplier->setDisplayHandler([](int32_t value) {
|
||||
return formatNumberAsString(value+10, PREC1);
|
||||
});
|
||||
grid.nextLine();
|
||||
grid.nextLine();
|
||||
#if LCD_W > LCD_H
|
||||
new DynamicNumber<int16_t>(box, rect_t{},
|
||||
[=]() { return (ppmInput[i] - g_eeGeneral.trainer.calib[i]) * 2; },
|
||||
LEFT | PPM_PRECISION | COLOR_THEME_PRIMARY1);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if LCD_H >= LCD_W
|
||||
{
|
||||
FlexGridLayout grid4(col4_dsc, row_dsc, 2);
|
||||
auto line = form->newLine(&grid4);
|
||||
|
||||
for (uint8_t i = 0; i < NUM_STICKS; i++) {
|
||||
new DynamicNumber<int16_t>(line, rect_t{},
|
||||
[=]() { return (ppmInput[i] - g_eeGeneral.trainer.calib[i]) * 2; },
|
||||
CENTERED | PPM_PRECISION | COLOR_THEME_PRIMARY1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Trainer calibration
|
||||
new TextButton(window, grid.getLabelSlot(), std::string(STR_CAL), [=]() -> uint8_t {
|
||||
memcpy(g_eeGeneral.trainer.calib, ppmInput, sizeof(g_eeGeneral.trainer.calib));
|
||||
auto line = form->newLine(&grid);
|
||||
auto btn = new TextButton(line, rect_t{}, std::string(STR_CAL), [=]() -> uint8_t {
|
||||
memcpy(g_eeGeneral.trainer.calib, ppmInput,
|
||||
sizeof(g_eeGeneral.trainer.calib));
|
||||
SET_DIRTY();
|
||||
return 0;
|
||||
});
|
||||
});
|
||||
lv_obj_set_style_min_width(btn->getLvObj(), 2*LV_DPI_DEF/3, 0);
|
||||
|
||||
for (int i = 0; i < NUM_STICKS; i++) {
|
||||
#if defined (PPM_UNIT_PERCENT_PREC1)
|
||||
auto calib = new StaticNumber(window, grid.getFieldSlot(4, i), [=]() { return (ppmInput[i]-g_eeGeneral.trainer.calib[i]) * 2; }, 0, LEFT | PREC1 | COLOR_THEME_PRIMARY1);
|
||||
#else
|
||||
auto calib = new StaticNumber(window, grid.getFieldSlot(4, i), [=]() { return (ppmInput[i]-g_eeGeneral.trainer.calib[i]) / 5; }, 0, LEFT | COLOR_THEME_PRIMARY1);
|
||||
#endif
|
||||
|
||||
calib->setWindowFlags(REFRESH_ALWAYS);
|
||||
}
|
||||
// Trainer multiplier
|
||||
auto box = new FormGroup(line, rect_t{});
|
||||
box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(4));
|
||||
auto box_obj = box->getLvObj();
|
||||
lv_obj_set_width(box_obj, LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_flex_cross_place(box_obj, LV_FLEX_ALIGN_CENTER, 0);
|
||||
|
||||
new StaticText(box, rect_t{}, STR_MULTIPLIER, 0, COLOR_THEME_PRIMARY1);
|
||||
auto multiplier = new NumberEdit(box, rect_t{}, -10, 40,
|
||||
GET_SET_DEFAULT(g_eeGeneral.PPM_Multiplier));
|
||||
multiplier->setDisplayHandler(
|
||||
[](int32_t value) { return formatNumberAsString(value + 10, PREC1); });
|
||||
}
|
||||
|
||||
@@ -21,12 +21,9 @@
|
||||
|
||||
#include "tabsgroup.h"
|
||||
|
||||
class RadioTrainerPage: public PageTab {
|
||||
public:
|
||||
RadioTrainerPage();
|
||||
|
||||
void build(FormWindow * window) override;
|
||||
|
||||
protected:
|
||||
|
||||
class RadioTrainerPage : public PageTab
|
||||
{
|
||||
public:
|
||||
RadioTrainerPage();
|
||||
void build(FormWindow* window) override;
|
||||
};
|
||||
|
||||
Vendored
+1
-1
Submodule radio/src/thirdparty/libopenui updated: bc7012e944...3eb6cf38fb
Reference in New Issue
Block a user