fix: EM trigger / input focux loss in when editing outputs (#1657)

* handle events on the outputs screen (#1652)

* change background color instead of font color

* Auto formatting only (except for include order)

Co-authored-by: Peter Feerick <peter.feerick@gmail.com>
This commit is contained in:
eshifri
2022-03-06 11:15:58 +10:00
committed by GitHub
co-authored by Peter Feerick
parent a1fe0b709b
commit d1a5c7a819
+54 -52
View File
@@ -20,16 +20,19 @@
*/ */
#include "model_outputs.h" #include "model_outputs.h"
#include "opentx.h" #include "opentx.h"
#include "libopenui.h" #include "libopenui.h"
#include "gvar_numberedit.h" #include "gvar_numberedit.h"
#define SET_DIRTY() storageDirty(EE_MODEL) #define SET_DIRTY() storageDirty(EE_MODEL)
class OutputEditWindow : public Page { class OutputEditWindow : public Page
{
public: public:
explicit OutputEditWindow(uint8_t channel) : explicit OutputEditWindow(uint8_t channel) :
Page(ICON_MODEL_OUTPUTS), Page(ICON_MODEL_OUTPUTS), channel(channel)
channel(channel)
{ {
chanZero = calcRESXto100(channelOutputs[channel]); chanZero = calcRESXto100(channelOutputs[channel]);
buildBody(&body); buildBody(&body);
@@ -40,23 +43,31 @@ class OutputEditWindow : public Page {
uint8_t channel; uint8_t channel;
int value = 0; int value = 0;
int chanZero = 0; int chanZero = 0;
StaticText *minText;
StaticText *maxText;
void checkEvents() override void checkEvents() override
{ {
Window::checkEvents();
int newValue = channelOutputs[channel]; int newValue = channelOutputs[channel];
if (value != newValue) { if (value != newValue) {
value = newValue; value = newValue;
body.clear();
buildBody(&body); int chanVal = calcRESXto100(channelOutputs[channel]);
minText->setBackgroundColor(chanVal < chanZero - 1 ? COLOR_THEME_ACTIVE
: 0U);
minText->invalidate();
maxText->setBackgroundColor(chanVal > chanZero + 1 ? COLOR_THEME_ACTIVE
: 0U);
maxText->invalidate();
} }
Window::checkEvents();
} }
void buildHeader(Window *window) void buildHeader(Window *window)
{ {
new StaticText(window, new StaticText(window,
{PAGE_TITLE_LEFT, PAGE_TITLE_TOP, {PAGE_TITLE_LEFT, PAGE_TITLE_TOP, LCD_W - PAGE_TITLE_LEFT,
LCD_W - PAGE_TITLE_LEFT, PAGE_LINE_HEIGHT}, PAGE_LINE_HEIGHT},
STR_MENULIMITS, 0, COLOR_THEME_PRIMARY2); STR_MENULIMITS, 0, COLOR_THEME_PRIMARY2);
new StaticText(window, new StaticText(window,
{PAGE_TITLE_LEFT, PAGE_TITLE_TOP + PAGE_LINE_HEIGHT, {PAGE_TITLE_LEFT, PAGE_TITLE_TOP + PAGE_LINE_HEIGHT,
@@ -73,7 +84,6 @@ class OutputEditWindow : public Page {
int limit = (g_model.extendedLimits ? LIMIT_EXT_MAX : LIMIT_STD_MAX); int limit = (g_model.extendedLimits ? LIMIT_EXT_MAX : LIMIT_STD_MAX);
LimitData *output = limitAddress(channel); LimitData *output = limitAddress(channel);
int chanVal = calcRESXto100(channelOutputs[channel]);
// Name // Name
new StaticText(window, grid.getLabelSlot(), STR_NAME, 0, new StaticText(window, grid.getLabelSlot(), STR_NAME, 0,
@@ -83,8 +93,8 @@ class OutputEditWindow : public Page {
grid.nextLine(); grid.nextLine();
// Offset // Offset
new StaticText(window, grid.getLabelSlot(), TR_LIMITS_HEADERS_SUBTRIM, new StaticText(window, grid.getLabelSlot(), TR_LIMITS_HEADERS_SUBTRIM, 0,
0, COLOR_THEME_PRIMARY1); COLOR_THEME_PRIMARY1);
new GVarNumberEdit(window, grid.getFieldSlot(), -LIMIT_STD_MAX, new GVarNumberEdit(window, grid.getFieldSlot(), -LIMIT_STD_MAX,
+LIMIT_STD_MAX, GET_SET_DEFAULT(output->offset), 0, +LIMIT_STD_MAX, GET_SET_DEFAULT(output->offset), 0,
PREC1); PREC1);
@@ -93,28 +103,23 @@ class OutputEditWindow : public Page {
// TRACE("ch=%d cV=%d zero=%d", channel, chanVal, chanZero); // TRACE("ch=%d cV=%d zero=%d", channel, chanVal, chanZero);
// Min // Min
new StaticText( minText = new StaticText(window, grid.getLabelSlot(), TR_MIN, 0,
window, grid.getLabelSlot(), TR_MIN, 0, COLOR_THEME_PRIMARY1);
chanVal < chanZero - 1 ? COLOR_THEME_ACTIVE : COLOR_THEME_PRIMARY1);
new GVarNumberEdit(window, grid.getFieldSlot(), -limit, 0, new GVarNumberEdit(window, grid.getFieldSlot(), -limit, 0,
GET_SET_DEFAULT(output->min), 0, PREC1, GET_SET_DEFAULT(output->min), 0, PREC1, -LIMIT_STD_MAX);
-LIMIT_STD_MAX);
grid.nextLine(); grid.nextLine();
// Max // Max
new StaticText( maxText = new StaticText(window, grid.getLabelSlot(), TR_MAX, 0,
window, grid.getLabelSlot(), TR_MAX, 0, COLOR_THEME_PRIMARY1);
chanVal > chanZero + 1 ? COLOR_THEME_ACTIVE : COLOR_THEME_PRIMARY1);
new GVarNumberEdit(window, grid.getFieldSlot(), 0, +limit, new GVarNumberEdit(window, grid.getFieldSlot(), 0, +limit,
GET_SET_DEFAULT(output->max), 0, PREC1, GET_SET_DEFAULT(output->max), 0, PREC1, +LIMIT_STD_MAX);
+LIMIT_STD_MAX);
grid.nextLine(); grid.nextLine();
// Direction // Direction
new StaticText(window, grid.getLabelSlot(), STR_INVERTED, 0, new StaticText(window, grid.getLabelSlot(), STR_INVERTED, 0,
COLOR_THEME_PRIMARY1); COLOR_THEME_PRIMARY1);
new CheckBox(window, grid.getFieldSlot(), new CheckBox(window, grid.getFieldSlot(), GET_DEFAULT(output->revert),
GET_DEFAULT(output->revert),
[output, this](uint8_t newValue) { [output, this](uint8_t newValue) {
if (newValue != output->revert) chanZero = -chanZero; if (newValue != output->revert) chanZero = -chanZero;
output->revert = newValue; output->revert = newValue;
@@ -134,8 +139,8 @@ class OutputEditWindow : public Page {
grid.nextLine(); grid.nextLine();
// PPM center // PPM center
new StaticText(window, grid.getLabelSlot(), TR_LIMITS_HEADERS_PPMCENTER, new StaticText(window, grid.getLabelSlot(), TR_LIMITS_HEADERS_PPMCENTER, 0,
0, COLOR_THEME_PRIMARY1); COLOR_THEME_PRIMARY1);
new NumberEdit(window, grid.getFieldSlot(), PPM_CENTER - PPM_CENTER_MAX, new NumberEdit(window, grid.getFieldSlot(), PPM_CENTER - PPM_CENTER_MAX,
PPM_CENTER + PPM_CENTER_MAX, PPM_CENTER + PPM_CENTER_MAX,
GET_VALUE(output->ppmCenter + PPM_CENTER), GET_VALUE(output->ppmCenter + PPM_CENTER),
@@ -143,8 +148,8 @@ class OutputEditWindow : public Page {
grid.nextLine(); grid.nextLine();
// Subtrims mode // Subtrims mode
new StaticText(window, grid.getLabelSlot(), new StaticText(window, grid.getLabelSlot(), TR_LIMITS_HEADERS_SUBTRIMMODE,
TR_LIMITS_HEADERS_SUBTRIMMODE, 0, COLOR_THEME_PRIMARY1); 0, COLOR_THEME_PRIMARY1);
new Choice(window, grid.getFieldSlot(), STR_SUBTRIMMODES, 0, 1, new Choice(window, grid.getFieldSlot(), STR_SUBTRIMMODES, 0, 1,
GET_SET_DEFAULT(output->symetrical)); GET_SET_DEFAULT(output->symetrical));
grid.nextLine(); grid.nextLine();
@@ -153,12 +158,12 @@ class OutputEditWindow : public Page {
} }
}; };
class OutputLineButton : public Button { class OutputLineButton : public Button
{
public: public:
OutputLineButton(FormGroup * parent, const rect_t &rect, LimitData * output, int ch) : OutputLineButton(FormGroup *parent, const rect_t &rect, LimitData *output,
Button(parent, rect), int ch) :
output(output), Button(parent, rect), output(output), channel(ch)
channel(ch)
{ {
if (output->revert || output->curve || output->name[0]) { if (output->revert || output->curve || output->name[0]) {
setHeight(height() + PAGE_LINE_HEIGHT + FIELD_PADDING_TOP); setHeight(height() + PAGE_LINE_HEIGHT + FIELD_PADDING_TOP);
@@ -181,17 +186,14 @@ class OutputLineButton : public Button {
// Min // Min
textFlag = (chanVal < chanZero - 1) ? textColorActive : textColor; textFlag = (chanVal < chanZero - 1) ? textColorActive : textColor;
drawValueOrGVar( drawValueOrGVar(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, output->min,
dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, output->min,
-GV_RANGELARGE, 0, PREC1 | textFlag, nullptr, -GV_RANGELARGE, 0, PREC1 | textFlag, nullptr,
-LIMITS_MIN_MAX_OFFSET); -LIMITS_MIN_MAX_OFFSET);
// Max // Max
textFlag = (chanVal > chanZero + 1) ? textColorActive : textColor; textFlag = (chanVal > chanZero + 1) ? textColorActive : textColor;
drawValueOrGVar(dc, 68, FIELD_PADDING_TOP, drawValueOrGVar(dc, 68, FIELD_PADDING_TOP, output->max, 0, GV_RANGELARGE,
output->max, 0, PREC1 | textFlag, nullptr, +LIMITS_MIN_MAX_OFFSET);
GV_RANGELARGE, PREC1 | textFlag, nullptr,
+LIMITS_MIN_MAX_OFFSET);
// Offset // Offset
drawValueOrGVar(dc, 132, FIELD_PADDING_TOP, output->offset, -LIMIT_STD_MAX, drawValueOrGVar(dc, 132, FIELD_PADDING_TOP, output->offset, -LIMIT_STD_MAX,
@@ -217,8 +219,8 @@ class OutputLineButton : public Button {
if (output->name[0]) { if (output->name[0]) {
dc->drawMask(146, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, dc->drawMask(146, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP,
mixerSetupLabelIcon, textColor); mixerSetupLabelIcon, textColor);
dc->drawSizedText(166, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, dc->drawSizedText(166, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, output->name,
output->name, sizeof(output->name), textColor); sizeof(output->name), textColor);
} }
// bounding rect // bounding rect
@@ -263,29 +265,31 @@ void ModelOutputsPage::build(FormWindow * window, int8_t focusChannel)
grid.spacer(PAGE_PADDING); grid.spacer(PAGE_PADDING);
grid.setLabelWidth(66); grid.setLabelWidth(66);
new TextButton(window, grid.getLineSlot(), STR_ADD_ALL_TRIMS_TO_SUBTRIMS, new TextButton(
window, grid.getLineSlot(), STR_ADD_ALL_TRIMS_TO_SUBTRIMS,
[=]() { [=]() {
moveTrimsToOffsets(); // if highlighted and menu pressed - move trims to offsets moveTrimsToOffsets(); // if highlighted and menu pressed - move trims
// to offsets
rebuild(window, 0); rebuild(window, 0);
return 0; return 0;
}, 0, COLOR_THEME_PRIMARY1); },
0, COLOR_THEME_PRIMARY1);
grid.nextLine(); grid.nextLine();
for (uint8_t ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++) { for (uint8_t ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++) {
LimitData *output = limitAddress(ch); LimitData *output = limitAddress(ch);
// Channel label // Channel label
auto txt = new StaticText(window, grid.getLabelSlot(), auto txt = new StaticText(
getSourceString(MIXSRC_CH1 + ch), window, grid.getLabelSlot(), getSourceString(MIXSRC_CH1 + ch),
BUTTON_BACKGROUND, CENTERED | COLOR_THEME_PRIMARY1); BUTTON_BACKGROUND, CENTERED | COLOR_THEME_PRIMARY1);
// Channel settings // Channel settings
Button * button = new OutputLineButton(window, grid.getFieldSlot(), output, ch); Button *button =
new OutputLineButton(window, grid.getFieldSlot(), output, ch);
button->setPressHandler([=]() -> uint8_t { button->setPressHandler([=]() -> uint8_t {
Menu *menu = new Menu(window); Menu *menu = new Menu(window);
menu->addLine(STR_EDIT, [=]() { menu->addLine(STR_EDIT, [=]() { editOutput(window, ch); });
editOutput(window, ch);
});
menu->addLine(STR_RESET, [=]() { menu->addLine(STR_RESET, [=]() {
output->min = 0; output->min = 0;
output->max = 0; output->max = 0;
@@ -340,7 +344,5 @@ void ModelOutputsPage::editOutput(FormWindow * window, uint8_t channel)
{ {
Window::clearFocus(); Window::clearFocus();
Window *editWindow = new OutputEditWindow(channel); Window *editWindow = new OutputEditWindow(channel);
editWindow->setCloseHandler([=]() { editWindow->setCloseHandler([=]() { rebuild(window, channel); });
rebuild(window, channel);
});
} }