feat(color): channel monitor only shows active channels, page buttons if more pages (#6732)

This commit is contained in:
philmoz
2025-10-30 19:20:07 +10:00
committed by GitHub
parent 7530b3a442
commit 1bf2af9f0d
25 changed files with 103 additions and 103 deletions
@@ -32,8 +32,7 @@ class ChannelsViewFooter : public Window
{
public:
explicit ChannelsViewFooter(Window* parent) :
Window(parent, {0, parent->height() - LEG_COLORBOX - PAD_SMALL * 2 - 2, LCD_W,
LEG_COLORBOX + PAD_SMALL * 2 + 2})
Window(parent, {0, parent->height() - FOOTER_H, LCD_W, FOOTER_H})
{
etx_solid_bg(lvobj, COLOR_THEME_SECONDARY1_INDEX);
@@ -62,6 +61,7 @@ class ChannelsViewFooter : public Window
static LAYOUT_VAL_SCALED(LEG_COLORBOX, 14)
static LAYOUT_VAL_SCALED(TXT_H, 18)
static constexpr coord_t FOOTER_H = LEG_COLORBOX + PAD_SMALL * 2 + PAD_TINY;
};
//-----------------------------------------------------------------------------
@@ -69,36 +69,45 @@ class ChannelsViewFooter : public Window
class ChannelsViewPage : public PageGroupItem
{
public:
explicit ChannelsViewPage(uint8_t pageIndex = 0) :
PageGroupItem(STR_MONITOR_CHANNELS[pageIndex]),
pageIndex(pageIndex)
explicit ChannelsViewPage(uint8_t startChan, int rows, int cols, const char* title) :
PageGroupItem(title), startChan(startChan), rows(rows), cols(cols)
{
icon = ICON_MONITOR;
}
static constexpr coord_t CHANS_H = 3 * ChannelBar::BAR_HEIGHT + PAD_THREE;
protected:
uint8_t pageIndex = 0;
uint8_t startChan;
int rows;
int cols;
void build(Window* window) override
{
constexpr coord_t hmargin = PAD_SMALL;
window->padAll(PAD_ZERO);
// Channels bars
for (uint8_t chan = pageIndex * 8; chan < 8 + pageIndex * 8; chan++) {
#if PORTRAIT
coord_t width = window->width() - (hmargin * 2);
coord_t xPos = hmargin;
coord_t yPos = (chan % 8) *
((window->height() - PAD_LARGE* 3) / 8);
coord_t w = window->width() - (PAD_SMALL * 2);
#else
coord_t width = window->width() / 2 - (hmargin * 2);
coord_t xPos = (chan % 8) >= 4 ? width + (hmargin * 2) : hmargin;
coord_t yPos = (chan % 4) *
((window->height() - (PAD_LARGE * 3 - 1)) / 4);
coord_t w = window->width() / 2 - (PAD_SMALL * 2);
#endif
new ComboChannelBar(window, {xPos, yPos, width, 3 * ChannelBar::BAR_HEIGHT + PAD_THREE},
chan);
// Channels bars
for (uint8_t i = 0, j = 0; j < rows * cols; i += 1) {
uint8_t chan = startChan + i;
if (chan >= MAX_OUTPUT_CHANNELS) break;
if (isChannelUsed(chan)) {
#if PORTRAIT
coord_t xPos = PAD_SMALL;
coord_t yPos = j * ((window->height() - PAD_LARGE * 3) / rows);
#else
coord_t xPos = (j & 1) ? w + (PAD_SMALL * 2) : PAD_SMALL;
coord_t yPos = (j / cols) * ((window->height() - ChannelsViewFooter::FOOTER_H) / rows);
#endif
new ComboChannelBar(window, {xPos, yPos, w, CHANS_H}, chan);
j += 1;
}
}
// Footer
@@ -113,8 +122,41 @@ ChannelsViewMenu::ChannelsViewMenu() :
{
QuickMenu::setCurrentPage(QuickMenu::TOOLS_CHAN_MON);
addTab(new ChannelsViewPage(0));
addTab(new ChannelsViewPage(1));
addTab(new ChannelsViewPage(2));
addTab(new ChannelsViewPage(3));
#if PORTRAIT
int cols = 1;
int rows = 8;
#else
int cols = 2;
int rows = (LCD_H - EdgeTxStyles::MENU_HEADER_HEIGHT - ChannelsViewFooter::FOOTER_H) / ChannelsViewPage::CHANS_H;
#endif
int pages = 0;
int chansPerPage = rows * cols;
char s[50];
for (int i = 0; i < MAX_OUTPUT_CHANNELS;) {
int start = i;
while (!isChannelUsed(start)) {
start += 1;
if (start >= MAX_OUTPUT_CHANNELS) break;
}
if (start >= MAX_OUTPUT_CHANNELS) break;
int count = 1;
int last = start;
int end = start + 1;
while (end < MAX_OUTPUT_CHANNELS && count < chansPerPage) {
if (isChannelUsed(end)) {
count += 1;
last = end;
}
end += 1;
}
sprintf(s, STR_MONITOR_CHANNELS, start + 1, last + 1);
addTab(new ChannelsViewPage(start, rows, cols, s));
pages += 1;
i = end;
}
if (pages < 2) hidePageButtons();
}
@@ -381,12 +381,12 @@ class TabsGroupHeader : public PageGroupHeaderBase
lv_obj_set_size(titleLabel, LCD_W, TabsGroup::PAGE_ALT_TITLE_H);
#endif
new IconButton(this, ICON_BTN_PREV, LCD_W - PageGroup::PAGE_TOP_BAR_H * 3, PAD_MEDIUM, [=]() {
prevBtn = new IconButton(this, ICON_BTN_PREV, LCD_W - PageGroup::PAGE_TOP_BAR_H * 3, PAD_MEDIUM, [=]() {
prevTab();
return 0;
});
new IconButton(this, ICON_BTN_NEXT, LCD_W - PageGroup::PAGE_TOP_BAR_H * 2, PAD_MEDIUM, [=]() {
nextBtn = new IconButton(this, ICON_BTN_NEXT, LCD_W - PageGroup::PAGE_TOP_BAR_H * 2, PAD_MEDIUM, [=]() {
nextTab();
return 0;
});
@@ -405,7 +405,15 @@ class TabsGroupHeader : public PageGroupHeaderBase
menu->setCurrentTab(idx);
}
void hidePageButtons()
{
if (prevBtn) prevBtn->hide();
if (nextBtn) nextBtn->hide();
}
protected:
IconButton* nextBtn = nullptr;
IconButton* prevBtn = nullptr;
};
//-----------------------------------------------------------------------------
@@ -444,3 +452,8 @@ void TabsGroup::openMenu()
}
}, p, subMenu);
}
void TabsGroup::hidePageButtons()
{
((TabsGroupHeader*)header)->hidePageButtons();
}
@@ -218,6 +218,8 @@ class TabsGroup : public PageGroupBase
std::string getName() const override { return "TabsGroup"; }
#endif
void hidePageButtons();
static LAYOUT_ORIENTATION_SCALED(PAGE_TOP_BAR_H, 45, 48)
static LAYOUT_ORIENTATION(PAGE_ALT_TITLE_H, 0, EdgeTxStyles::STD_FONT_HEIGHT)
static constexpr coord_t TABS_GROUP_BODY_Y = PAGE_TOP_BAR_H + PAGE_ALT_TITLE_H;
+1
View File
@@ -53,6 +53,7 @@ enum SwitchContext
int getFirstAvailable(int min, int max, IsValueAvailable isValueAvailable);
bool isChannelUsed(int channel);
bool checkSourceAvailable(int source, uint32_t sourceTypes);
bool checkSwitchAvailable(int swtch, uint32_t swtchTypes);
bool isInputAvailable(int input);