chore(color): simplify the code for the mix line multiplex icon (#7820)

This commit is contained in:
philmoz
2026-09-26 08:05:11 +10:00
committed by GitHub
parent fd3b0f8271
commit 942255d93f
7 changed files with 37 additions and 100 deletions
@@ -218,6 +218,20 @@ void InputMixButtonBase::updateHeight()
#endif
}
void InputMixButtonBase::swapLvglGroup(InputMixButtonBase* swapWith)
{
// Swap elements (focus + line list)
lv_obj_t* obj1 = getLvObj();
lv_obj_t* obj2 = swapWith->getLvObj();
if (lv_obj_get_parent(obj1) == lv_obj_get_parent(obj2)) {
// same input group: swap obj + focus group
lv_obj_swap(obj1, obj2);
} else {
// different input group: swap only focus group
lv_group_swap_obj(obj1, obj2);
}
}
static void group_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj)
{
etx_std_style(obj, LV_PART_MAIN, PAD_TINY);
@@ -58,7 +58,7 @@ class InputMixButtonBase : public ListLineButton
void updateHeight();
virtual void updatePos(coord_t x, coord_t y) = 0;
virtual void swapLvglGroup(InputMixButtonBase* line2) = 0;
void swapLvglGroup(InputMixButtonBase* swapWith);
void checkEvents() override;
+7 -4
View File
@@ -193,10 +193,13 @@ void StaticIcon::setColor(LcdColorIndex color)
void StaticIcon::setIcon(EdgeTxIcon icon)
{
auto newMask = getBuiltinIcon(icon);
setSize(newMask->width, newMask->height);
lv_canvas_set_buffer(lvobj, (void*)newMask->data, newMask->width, newMask->height,
LV_IMG_CF_ALPHA_8BIT);
if (currentIcon != icon) {
currentIcon = icon;
auto newMask = getBuiltinIcon(icon);
setSize(newMask->width, newMask->height);
lv_canvas_set_buffer(lvobj, (void*)newMask->data, newMask->width, newMask->height,
LV_IMG_CF_ALPHA_8BIT);
}
}
void StaticIcon::center(coord_t w, coord_t h)
+1
View File
@@ -136,6 +136,7 @@ class StaticIcon : public Window
protected:
LcdColorIndex currentColor;
EdgeTxIcon currentIcon = EDGETX_ICONS_COUNT;
MaskBitmap* mask = nullptr;
};
@@ -166,22 +166,6 @@ class InputLineButton : public InputMixButtonBase
setPos(x, y);
}
void swapLvglGroup(InputMixButtonBase* line2) override
{
InputLineButton* swapWith = (InputLineButton*)line2;
// Swap elements (focus + line list)
lv_obj_t* obj1 = getLvObj();
lv_obj_t* obj2 = swapWith->getLvObj();
if (lv_obj_get_parent(obj1) == lv_obj_get_parent(obj2)) {
// same input group: swap obj + focus group
lv_obj_swap(obj1, obj2);
} else {
// different input group: swap only focus group
lv_group_swap_obj(obj1, obj2);
}
}
bool isActive() const override { return isExpoActive(index); }
protected:
+13 -79
View File
@@ -33,65 +33,25 @@
#define SET_DIRTY() storageDirty(EE_MODEL)
class MPlexIcon : public Window
{
public:
MPlexIcon(Window* parent, uint8_t index) :
Window(parent, {0, 0, MPLEX_ICON_W, MPLEX_ICON_H}),
index(index)
{
}
void refresh()
{
MixData* mix = mixAddress(index);
EdgeTxIcon n = ICON_MPLEX_ADD;
if (mix->mltpx == MLTPX_MUL) {
n = ICON_MPLEX_MULTIPLY;
} else if (mix->mltpx == MLTPX_REPL) {
n = ICON_MPLEX_REPLACE;
}
if (!icon) {
icon = new StaticIcon(this, 0, 0, n, COLOR_THEME_SECONDARY1_INDEX);
icon->center(width(), height());
}
icon->show(lv_obj_get_index(lvobj) != 0);
icon->setIcon(n);
}
void setIndex(uint8_t i)
{
index = i;
}
static LAYOUT_VAL_SCALED(MPLEX_ICON_W, 25)
static LAYOUT_VAL_SCALED(MPLEX_ICON_H, 29)
protected:
uint8_t index;
StaticIcon* icon = nullptr;
};
class MixLineButton : public InputMixButtonBase
{
public:
MixLineButton(Window* parent, uint8_t index) :
InputMixButtonBase(parent, index)
{
mplex = new MPlexIcon(parent, index);
// mplex is a sibling (not a child) so must be closed explicitly
onClosing([=]() {
mplex->closeWindow();
});
// Allow multiplex icon to render outside this window
lv_obj_add_flag(lvobj, LV_OBJ_FLAG_OVERFLOW_VISIBLE);
delayLoad();
}
void delayedInit() override
{
// Add multiplex icon
mplex = new StaticIcon(this, 0, 0, ICON_MPLEX_ADD, COLOR_THEME_SECONDARY1_INDEX);
// Position multiplex icon to the left of the parent mix line
mplex->setPos(-mplex->width() - PAD_MEDIUM, PAD_SMALL);
refresh();
((InputMixGroupBase*)parent)->adjustHeight();
}
@@ -125,50 +85,24 @@ class MixLineButton : public InputMixButtonBase
setOpts(tmp_str);
mplex->refresh();
if (mplex)
mplex->setIcon((EdgeTxIcon)(ICON_MPLEX_ADD + line.mltpx));
setFlightModes(line.flightModes);
}
void setIndex(uint8_t i) override
{
ListLineButton::setIndex(i);
mplex->setIndex(i);
}
void updatePos(coord_t x, coord_t y) override
{
setPos(x, y);
mplex->setPos(x - MPLEX_XO, y);
mplex->show(y > ListLineButton::BTN_H);
}
lv_obj_t* mplexLvObj() const { return mplex->getLvObj(); }
void swapLvglGroup(InputMixButtonBase* line2) override
{
MixLineButton* swapWith = (MixLineButton*)line2;
// Swap elements (focus + line list)
lv_obj_t* obj1 = getLvObj();
lv_obj_t* obj2 = swapWith->getLvObj();
if (lv_obj_get_parent(obj1) == lv_obj_get_parent(obj2)) {
// same input group: swap obj + focus group
lv_obj_swap(obj1, obj2);
lv_obj_swap(mplexLvObj(), swapWith->mplexLvObj());
} else {
// different input group: swap only focus group
lv_group_swap_obj(obj1, obj2);
lv_group_swap_obj(mplexLvObj(), swapWith->mplexLvObj());
}
// Don't show multiplex icon for first line
if (mplex)
mplex->show(y > ListLineButton::BTN_H);
}
bool isActive() const override { return isMixActive(index); }
static LAYOUT_VAL_SCALED(MPLEX_XO, 28)
protected:
MPlexIcon* mplex = nullptr;
StaticIcon* mplex = nullptr;
};
class MixGroup : public InputMixGroupBase
+1
View File
@@ -636,6 +636,7 @@ TEST_F(ModelCellManagerFsTest, RenameLabelOntoExistingLabelWithProgressDialog)
// Dialogs are always shown over the main view
ViewMain::instance();
MainWindow::instance()->run();
lcdFlushed();
auto rndialog = new ProgressDialog(STR_RENAME_LABEL, [=]() {});
lv_obj_t* bar = findProgressBar(rndialog->getLvObj());