feat(color): use PAGE keys to cycle through top level quick menu items (#6723)

This commit is contained in:
philmoz
2025-10-26 12:42:55 +10:00
committed by GitHub
parent da706e0c30
commit ffabbe2186
4 changed files with 77 additions and 5 deletions
@@ -37,11 +37,7 @@ ButtonBase* QuickSubMenu::addButton()
{
menuButton = quickMenu->getTopMenu()->addButton(icon, title,
[=]() -> uint8_t {
if (!subMenu) buildSubMenu();
quickMenu->getTopMenu()->setCurrent(menuButton);
quickMenu->getTopMenu()->setDisabled(false);
quickMenu->getTopMenu()->clearFocus();
enableSubMenu();
activate();
return 0;
});
@@ -68,6 +64,13 @@ bool QuickSubMenu::isSubMenu(QuickMenu::SubMenu n)
return false;
}
bool QuickSubMenu::isSubMenu(ButtonBase* b)
{
for (int i = 0; items[i].icon < EDGETX_ICONS_COUNT; i += 1)
if (menuButton == b) return true;
return false;
}
int QuickSubMenu::getIndex(QuickMenu::SubMenu n)
{
for (int i = 0; items[i].icon < EDGETX_ICONS_COUNT; i += 1)
@@ -99,6 +102,15 @@ void QuickSubMenu::setCurrent(QuickMenu::SubMenu n)
enableSubMenu();
}
void QuickSubMenu::activate()
{
if (!subMenu) buildSubMenu();
quickMenu->getTopMenu()->setCurrent(menuButton);
quickMenu->getTopMenu()->setDisabled(false);
quickMenu->getTopMenu()->clearFocus();
enableSubMenu();
}
void QuickSubMenu::doLayout()
{
if (subMenu)
@@ -344,4 +356,31 @@ void QuickMenu::onLongPressMDL() { onSelect(true); new ModelLabelsWindow(); }
void QuickMenu::onPressTELE() { subMenus[2]->onPress(ScreenSetupPage::FIRST_SCREEN_OFFSET); }
void QuickMenu::onLongPressTELE() { onSelect(true); new ChannelsViewMenu(); }
void QuickMenu::onLongPressRTN() { closeMenu(); }
void QuickMenu::afterPG()
{
auto b = mainMenu->getFocusedButton();
if (b) {
for(auto sub : subMenus) {
if (sub->isSubMenu(b)) {
sub->activate();
return;
}
}
focusMainMenu();
curPage = QuickMenu::NONE;
}
}
void QuickMenu::onPressPGDN()
{
mainMenu->nextEntry();
afterPG();
}
void QuickMenu::onPressPGUP()
{
mainMenu->prevEntry();
afterPG();
}
#endif
@@ -117,6 +117,9 @@ class QuickMenu : public NavWindow
void onPressTELE() override;
void onLongPressTELE() override;
void onLongPressRTN() override;
void onPressPGDN() override;
void onPressPGUP() override;
void afterPG();
#endif
static constexpr int QM_MAIN_BTNS = 6;
@@ -164,12 +167,14 @@ class QuickSubMenu
{}
bool isSubMenu(QuickMenu::SubMenu n);
bool isSubMenu(ButtonBase* b);
int getIndex(QuickMenu::SubMenu n);
ButtonBase* addButton();
void enableSubMenu();
void setDisabled(bool all);
void setCurrent(QuickMenu::SubMenu n);
void activate();
void buildSubMenu();
uint8_t onPress(int n);
void onSelect(bool close);
@@ -232,3 +232,28 @@ void QuickMenuGroup::doLayout(int cols)
}
}
}
void QuickMenuGroup::nextEntry()
{
if (group)
lv_group_focus_next(group);
}
void QuickMenuGroup::prevEntry()
{
if (group)
lv_group_focus_prev(group);
}
ButtonBase* QuickMenuGroup::getFocusedButton()
{
if (group) {
lv_obj_t* b = lv_group_get_focused(group);
if (b) {
for (size_t i = 0; i < btns.size(); i += 1)
if (btns[i]->getLvObj() == b)
return btns[i];
}
}
return nullptr;
}
@@ -50,6 +50,9 @@ class QuickMenuGroup : public Window
void setCurrent(ButtonBase* b);
void setCurrent(int b) { setCurrent(btns[b]); }
void doLayout(int cols);
void nextEntry();
void prevEntry();
ButtonBase* getFocusedButton();
#if PORTRAIT
static LAYOUT_VAL_SCALED(QM_BUTTON_WIDTH, 72)