feat(color): Improved hardware key navigation (TELE) (#4219)

This commit is contained in:
philmoz
2023-10-31 10:28:57 +10:00
committed by GitHub
parent b6a691fbcb
commit 8fb69b8041
18 changed files with 713 additions and 628 deletions
+27 -24
View File
@@ -22,6 +22,7 @@
#include "menu_model.h" #include "menu_model.h"
#include "menu_radio.h" #include "menu_radio.h"
#include "menu_screen.h"
#include "model_curves.h" #include "model_curves.h"
#include "model_flightmodes.h" #include "model_flightmodes.h"
#include "model_gvars.h" #include "model_gvars.h"
@@ -96,30 +97,6 @@ void ModelMenu::checkEvents()
} }
} }
void ModelMenu::onEvent(event_t event)
{
#if defined(HARDWARE_KEYS)
if (event == EVT_KEY_BREAK(KEY_MODEL)) {
killEvents(event);
new ChannelsViewMenu(this);
} else if (event == EVT_KEY_LONG(KEY_MODEL)) {
killEvents(KEY_MODEL);
onCancel();
new ModelLabelsWindow();
} else if (event == EVT_KEY_BREAK(KEY_SYS)) {
onCancel();
new RadioMenu();
} else if (event == EVT_KEY_LONG(KEY_SYS)) {
onCancel();
killEvents(KEY_SYS);
// Radio setup
(new RadioMenu())->setCurrentTab(2);
} else {
TabsGroup::onEvent(event);
}
#endif
}
#if defined(PCBNV14) || defined(PCBPL18) #if defined(PCBNV14) || defined(PCBPL18)
void ModelMenu::addGoToMonitorsButton() void ModelMenu::addGoToMonitorsButton()
{ {
@@ -132,3 +109,29 @@ void ModelMenu::addGoToMonitorsButton()
}); });
} }
#endif #endif
#if defined(HARDWARE_KEYS)
void ModelMenu::onPressSYS()
{
onCancel();
new RadioMenu();
}
void ModelMenu::onLongPressSYS()
{
onCancel();
// Radio setup
(new RadioMenu())->setCurrentTab(2);
}
void ModelMenu::onPressMDL() { new ChannelsViewMenu(this); }
void ModelMenu::onLongPressMDL()
{
onCancel();
new ModelLabelsWindow();
}
void ModelMenu::onPressTELE()
{
onCancel();
new ScreenMenu();
}
void ModelMenu::onLongPressTELE() { new ChannelsViewMenu(this); }
#endif
+9 -1
View File
@@ -47,5 +47,13 @@ class ModelMenu : public TabsGroup
void build(); void build();
void checkEvents() override; void checkEvents() override;
void onEvent(event_t event) override;
#if defined(HARDWARE_KEYS)
void onPressSYS() override;
void onLongPressSYS() override;
void onPressMDL() override;
void onLongPressMDL() override;
void onPressTELE() override;
void onLongPressTELE() override;
#endif
}; };
+19 -8
View File
@@ -22,6 +22,7 @@
#include "menu_radio.h" #include "menu_radio.h"
#include "menu_model.h" #include "menu_model.h"
#include "menu_screen.h"
#include "model_select.h" #include "model_select.h"
#include "myeeprom.h" #include "myeeprom.h"
#include "opentx.h" #include "opentx.h"
@@ -34,6 +35,7 @@
#include "radio_trainer.h" #include "radio_trainer.h"
#include "radio_version.h" #include "radio_version.h"
#include "special_functions.h" #include "special_functions.h"
#include "view_channels.h"
RadioMenu::RadioMenu() : TabsGroup(ICON_RADIO) { build(); } RadioMenu::RadioMenu() : TabsGroup(ICON_RADIO) { build(); }
@@ -70,18 +72,27 @@ void RadioMenu::checkEvents()
} }
} }
void RadioMenu::onEvent(event_t event)
{
#if defined(HARDWARE_KEYS) #if defined(HARDWARE_KEYS)
if (event == EVT_KEY_BREAK(KEY_MODEL)) { void RadioMenu::onPressSYS() { setCurrentTab(0); }
void RadioMenu::onLongPressSYS() { setCurrentTab(2); }
void RadioMenu::onPressMDL()
{
onCancel(); onCancel();
new ModelMenu(); new ModelMenu();
} else if (event == EVT_KEY_LONG(KEY_MODEL)) { }
void RadioMenu::onLongPressMDL()
{
onCancel(); onCancel();
killEvents(KEY_MODEL);
new ModelLabelsWindow(); new ModelLabelsWindow();
} else { }
TabsGroup::onEvent(event); void RadioMenu::onPressTELE()
{
onCancel();
new ScreenMenu();
}
void RadioMenu::onLongPressTELE()
{
onCancel();
new ChannelsViewMenu();
} }
#endif #endif
}
+9 -1
View File
@@ -36,5 +36,13 @@ class RadioMenu : public TabsGroup
void build(); void build();
void checkEvents() override; void checkEvents() override;
void onEvent(event_t event) override;
#if defined(HARDWARE_KEYS)
void onPressSYS() override;
void onLongPressSYS() override;
void onPressMDL() override;
void onLongPressMDL() override;
void onPressTELE() override;
void onLongPressTELE() override;
#endif
}; };
+42 -13
View File
@@ -19,14 +19,18 @@
* GNU General Public License for more details. * GNU General Public License for more details.
*/ */
#include "opentx.h"
#include "menu_screen.h" #include "menu_screen.h"
#include "screen_setup.h"
#include "view_main.h"
#include "storage/storage.h"
ScreenMenu::ScreenMenu(int8_t tabIdx): #include "menu_model.h"
TabsGroup(ICON_THEME) #include "menu_radio.h"
#include "model_select.h"
#include "opentx.h"
#include "screen_setup.h"
#include "storage/storage.h"
#include "view_channels.h"
#include "view_main.h"
ScreenMenu::ScreenMenu(int8_t tabIdx) : TabsGroup(ICON_THEME)
{ {
updateTabs(tabIdx); updateTabs(tabIdx);
@@ -46,13 +50,10 @@ void ScreenMenu::updateTabs(int8_t tabIdx)
if (customScreens[index]) { if (customScreens[index]) {
auto tab = new ScreenSetupPage(this, getTabs(), index); auto tab = new ScreenSetupPage(this, getTabs(), index);
std::string title(STR_MAIN_VIEW_X); std::string title(STR_MAIN_VIEW_X);
if (index >= 9) if (index >= 9) {
{
title[title.size() - 2] = '1'; title[title.size() - 2] = '1';
title.back() = (index - 9) + '0'; title.back() = (index - 9) + '0';
} } else {
else
{
title[title.size() - 2] = index + '1'; title[title.size() - 2] = index + '1';
title.back() = ' '; title.back() = ' ';
} }
@@ -60,8 +61,7 @@ void ScreenMenu::updateTabs(int8_t tabIdx)
tab->setIcon(ICON_THEME_VIEW1 + index); tab->setIcon(ICON_THEME_VIEW1 + index);
addTab(tab); addTab(tab);
} } else {
else {
addTab(new ScreenAddPage(this, getTabs())); addTab(new ScreenAddPage(this, getTabs()));
break; break;
} }
@@ -77,3 +77,32 @@ void ScreenMenu::updateTabs(int8_t tabIdx)
setCurrentTab(tab); setCurrentTab(tab);
} }
#if defined(HARDWARE_KEYS)
void ScreenMenu::onPressSYS()
{
onCancel();
new RadioMenu();
}
void ScreenMenu::onLongPressSYS()
{
onCancel();
// Radio setup
(new RadioMenu())->setCurrentTab(2);
}
void ScreenMenu::onPressMDL()
{
onCancel();
new ModelMenu();
}
void ScreenMenu::onLongPressMDL()
{
onCancel();
new ModelLabelsWindow();
}
void ScreenMenu::onLongPressTELE()
{
onCancel();
new ChannelsViewMenu();
}
#endif
+10 -4
View File
@@ -19,8 +19,7 @@
* GNU General Public License for more details. * GNU General Public License for more details.
*/ */
#ifndef _MENU_SCREEN_H_ #pragma once
#define _MENU_SCREEN_H_
#include "tabsgroup.h" #include "tabsgroup.h"
@@ -29,6 +28,13 @@ class ScreenMenu : public TabsGroup
public: public:
ScreenMenu(int8_t tabIdx = -1); ScreenMenu(int8_t tabIdx = -1);
void updateTabs(int8_t tabIdx); void updateTabs(int8_t tabIdx);
};
#endif // _MENU_SCREEN_H_ protected:
#if defined(HARDWARE_KEYS)
void onPressSYS() override;
void onLongPressSYS() override;
void onPressMDL() override;
void onLongPressMDL() override;
void onLongPressTELE() override;
#endif
};
+33 -23
View File
@@ -29,10 +29,12 @@
#include "listbox.h" #include "listbox.h"
#include "menu_model.h" #include "menu_model.h"
#include "menu_radio.h" #include "menu_radio.h"
#include "menu_screen.h"
#include "model_templates.h" #include "model_templates.h"
#include "opentx.h" #include "opentx.h"
#include "standalone_lua.h" #include "standalone_lua.h"
#include "str_functions.h" #include "str_functions.h"
#include "view_channels.h"
// bitmaps for toolbar // bitmaps for toolbar
const uint8_t _mask_sort_alpha_up[] = { const uint8_t _mask_sort_alpha_up[] = {
@@ -661,23 +663,42 @@ ModelLabelsWindow::ModelLabelsWindow() : Page(ICON_MODEL)
} }
#if defined(HARDWARE_KEYS) #if defined(HARDWARE_KEYS)
void ModelLabelsWindow::onEvent(event_t event) void ModelLabelsWindow::onPressSYS()
{
onCancel();
new RadioMenu();
}
void ModelLabelsWindow::onLongPressSYS()
{
onCancel();
// Radio setup
(new RadioMenu())->setCurrentTab(2);
}
void ModelLabelsWindow::onPressMDL()
{
onCancel();
new ModelMenu();
}
void ModelLabelsWindow::onPressTELE()
{
onCancel();
new ScreenMenu();
}
void ModelLabelsWindow::onLongPressTELE()
{
onCancel();
new ChannelsViewMenu();
}
void ModelLabelsWindow::onPressPG(bool isNext)
{ {
#if defined(KEYS_GPIO_REG_PAGEUP)
if (event == EVT_KEY_BREAK(KEY_PAGEUP) ||
event == EVT_KEY_BREAK(KEY_PAGEDN)) {
#else
if (event == EVT_KEY_LONG(KEY_PAGEDN) || event == EVT_KEY_BREAK(KEY_PAGEDN)) {
#endif
std::set<uint32_t> curSel = lblselector->getSelection(); std::set<uint32_t> curSel = lblselector->getSelection();
std::set<uint32_t> sellist; std::set<uint32_t> sellist;
int select = 0; int select = 0;
int rowcount = lblselector->getRowCount(); int rowcount = lblselector->getRowCount();
if (event == EVT_KEY_BREAK(KEY_PAGEDN)) { if (isNext) {
if (curSel.size()) select = (*curSel.rbegin() + 1) % rowcount; if (curSel.size()) select = (*curSel.rbegin() + 1) % rowcount;
} else { } else {
killEvents(event);
if (curSel.size()) { if (curSel.size()) {
select = (int)*curSel.begin() - 1; select = (int)*curSel.begin() - 1;
if (select < 0) select += rowcount; if (select < 0) select += rowcount;
@@ -685,25 +706,14 @@ void ModelLabelsWindow::onEvent(event_t event)
select = rowcount - 1; select = rowcount - 1;
} }
} }
sellist.insert(select); sellist.insert(select);
lblselector->setSelected(sellist); // Check the items lblselector->setSelected(sellist); // Check the items
lblselector->setSelected(select); // Causes the list to scroll lblselector->setSelected(select); // Causes the list to scroll
updateFilteredLabels(sellist); // Update the models updateFilteredLabels(sellist); // Update the models
} else if (event == EVT_KEY_BREAK(KEY_MODEL)) {
onCancel();
new ModelMenu();
} else if (event == EVT_KEY_BREAK(KEY_SYS)) {
onCancel();
new RadioMenu();
} else if (event == EVT_KEY_LONG(KEY_SYS)) {
onCancel();
killEvents(KEY_SYS);
// Radio setup
(new RadioMenu())->setCurrentTab(2);
} else {
Page::onEvent(event);
}
} }
void ModelLabelsWindow::onPressPGUP() { onPressPG(false); }
void ModelLabelsWindow::onPressPGDN() { onPressPG(true); }
#endif #endif
void ModelLabelsWindow::newModel() void ModelLabelsWindow::newModel()
+11 -4
View File
@@ -93,10 +93,6 @@ class ModelLabelsWindow : public Page
return labels; return labels;
} }
#if defined(HARDWARE_KEYS)
void onEvent(event_t event) override;
#endif
void newModel(); void newModel();
void newLabel(); void newLabel();
void buildHead(PageHeader *window); void buildHead(PageHeader *window);
@@ -104,6 +100,17 @@ class ModelLabelsWindow : public Page
void updateFilteredLabels(std::set<uint32_t> selected, bool setdirty = true); void updateFilteredLabels(std::set<uint32_t> selected, bool setdirty = true);
void labelRefreshRequest(); void labelRefreshRequest();
void setTitle(); void setTitle();
#if defined(HARDWARE_KEYS)
void onPressSYS() override;
void onLongPressSYS() override;
void onPressMDL() override;
void onPressTELE() override;
void onLongPressTELE() override;
void onPressPG(bool isNext);
void onPressPGUP() override;
void onPressPGDN() override;
#endif
}; };
#endif // _MODEL_SELECT_H_ #endif // _MODEL_SELECT_H_
+1 -6
View File
@@ -67,7 +67,7 @@ static constexpr rect_t _get_body_rect()
} }
Page::Page(unsigned icon): Page::Page(unsigned icon):
Window(Layer::back(), {0, 0, LCD_W, LCD_H}, OPAQUE), NavWindow(Layer::back(), {0, 0, LCD_W, LCD_H}, OPAQUE),
header(this, icon), header(this, icon),
body(this, _get_body_rect()) body(this, _get_body_rect())
{ {
@@ -97,8 +97,3 @@ void Page::onClicked()
{ {
Keyboard::hide(); Keyboard::hide();
} }
void Page::onEvent(event_t event)
{
// block event bubbling
}
+2 -2
View File
@@ -45,7 +45,7 @@ class PageHeader : public FormWindow
StaticText* title2 = nullptr; StaticText* title2 = nullptr;
}; };
class Page : public Window class Page : public NavWindow
{ {
public: public:
explicit Page(unsigned icon); explicit Page(unsigned icon);
@@ -63,7 +63,7 @@ class Page : public Window
PageHeader header; PageHeader header;
FormWindow body; FormWindow body;
void onEvent(event_t event) override; bool bubbleEvents() override { return false; }
}; };
#endif // _PAGE_H_ #endif // _PAGE_H_
+8 -22
View File
@@ -135,7 +135,7 @@ static constexpr rect_t _get_body_rect()
TabsGroup* TabsGroup::activeTabsGroup = nullptr; TabsGroup* TabsGroup::activeTabsGroup = nullptr;
TabsGroup::TabsGroup(uint8_t icon) : TabsGroup::TabsGroup(uint8_t icon) :
Window(Layer::back(), {0, 0, LCD_W, LCD_H}, OPAQUE), NavWindow(Layer::back(), {0, 0, LCD_W, LCD_H}, OPAQUE),
header(this, icon), header(this, icon),
body(this, _get_body_rect(), NO_FOCUS) body(this, _get_body_rect(), NO_FOCUS)
{ {
@@ -264,32 +264,18 @@ void TabsGroup::checkEvents()
} }
} }
void TabsGroup::onEvent(event_t event)
{
#if defined(HARDWARE_KEYS) #if defined(HARDWARE_KEYS)
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), void TabsGroup::onPressPGUP()
event); {
#if defined(KEYS_GPIO_REG_PAGEUP) || defined(USE_HATS_AS_KEYS)
if (event == EVT_KEY_FIRST(KEY_PAGEDN)) {
#else
if (event == EVT_KEY_BREAK(KEY_PAGEDN)) {
#endif
killEvents(event);
uint8_t current = header.carousel.getCurrentIndex() + 1;
setCurrentTab(current >= tabs.size() ? 0 : current);
}
#if defined(KEYS_GPIO_REG_PAGEUP) || defined(USE_HATS_AS_KEYS)
else if (event == EVT_KEY_FIRST(KEY_PAGEUP)) {
#else
else if (event == EVT_KEY_LONG(KEY_PAGEDN)) {
#endif
killEvents(event);
uint8_t current = header.carousel.getCurrentIndex(); uint8_t current = header.carousel.getCurrentIndex();
setCurrentTab(current == 0 ? tabs.size() - 1 : current - 1); setCurrentTab(current == 0 ? tabs.size() - 1 : current - 1);
} }
#endif void TabsGroup::onPressPGDN()
{
uint8_t current = header.carousel.getCurrentIndex() + 1;
setCurrentTab(current >= tabs.size() ? 0 : current);
} }
#endif
void TabsGroup::onClicked() { Keyboard::hide(); } void TabsGroup::onClicked() { Keyboard::hide(); }
+26 -46
View File
@@ -21,24 +21,23 @@
#define _TABSGROUP_H_ #define _TABSGROUP_H_
#include <vector> #include <vector>
#include "button.h" #include "button.h"
#include "form.h" #include "form.h"
#include "keyboard_base.h" #include "keyboard_base.h"
class TabsGroup; class TabsGroup;
class PageTab { class PageTab
{
friend class TabsCarousel; friend class TabsCarousel;
friend class TabsGroup; friend class TabsGroup;
public: public:
PageTab() PageTab() {}
{
}
PageTab(std::string title, unsigned icon) : PageTab(std::string title, unsigned icon) :
title(std::move(title)), title(std::move(title)), icon(icon)
icon(icon)
{ {
} }
@@ -46,29 +45,18 @@ class PageTab {
virtual void build(FormWindow* window) = 0; virtual void build(FormWindow* window) = 0;
virtual void checkEvents() virtual void checkEvents() {}
{
}
void setOnSetVisibleHandler(std::function<void()> handler) void setOnSetVisibleHandler(std::function<void()> handler)
{ {
onSetVisible = std::move(handler); onSetVisible = std::move(handler);
} }
void setTitle(std::string value) void setTitle(std::string value) { title = std::move(value); }
{
title = std::move(value);
}
void setIcon(unsigned icon) void setIcon(unsigned icon) { this->icon = icon; }
{
this->icon = icon;
}
unsigned getIcon() const unsigned getIcon() const { return icon; }
{
return icon;
}
protected: protected:
std::string title; std::string title;
@@ -79,7 +67,8 @@ class PageTab {
class TabCarouselButton : public Button class TabCarouselButton : public Button
{ {
public: public:
TabCarouselButton(Window* parent, const rect_t& rect, std::vector<PageTab *>& tabs, uint8_t index, TabCarouselButton(Window* parent, const rect_t& rect,
std::vector<PageTab*>& tabs, uint8_t index,
std::function<uint8_t(void)> pressHandler, std::function<uint8_t(void)> pressHandler,
WindowFlags flags = 0); WindowFlags flags = 0);
@@ -99,23 +88,18 @@ protected:
uint8_t index; uint8_t index;
}; };
class TabsCarousel: public Window { class TabsCarousel : public Window
{
public: public:
TabsCarousel(Window* parent, TabsGroup* menu); TabsCarousel(Window* parent, TabsGroup* menu);
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() const override std::string getName() const override { return "TabsCarousel"; }
{
return "TabsCarousel";
}
#endif #endif
void setCurrentIndex(uint8_t index); void setCurrentIndex(uint8_t index);
inline uint8_t getCurrentIndex() inline uint8_t getCurrentIndex() { return currentIndex; }
{
return currentIndex;
}
void update(); void update();
@@ -131,7 +115,8 @@ class TabsCarousel: public Window {
#endif #endif
}; };
class TabsGroupHeader: public FormWindow { class TabsGroupHeader : public FormWindow
{
friend class TabsGroup; friend class TabsGroup;
public: public:
@@ -140,10 +125,7 @@ class TabsGroupHeader: public FormWindow {
void setTitle(const char* value) { title = value; } void setTitle(const char* value) { title = value; }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() const override std::string getName() const override { return "TabsGroupHeader"; }
{
return "TabsGroupHeader";
}
#endif #endif
void deleteLater(bool detach = true, bool trash = true) override void deleteLater(bool detach = true, bool trash = true) override
@@ -167,7 +149,7 @@ class TabsGroupHeader: public FormWindow {
std::string title; std::string title;
}; };
class TabsGroup: public Window class TabsGroup : public NavWindow
{ {
friend class TabsCarousel; friend class TabsCarousel;
@@ -178,16 +160,10 @@ class TabsGroup: public Window
void deleteLater(bool detach = true, bool trash = true) override; void deleteLater(bool detach = true, bool trash = true) override;
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() const override std::string getName() const override { return "TabsGroup"; }
{
return "TabsGroup";
}
#endif #endif
unsigned getTabs() const unsigned getTabs() const { return tabs.size(); }
{
return tabs.size();
}
void addTab(PageTab* page); void addTab(PageTab* page);
@@ -208,7 +184,6 @@ class TabsGroup: public Window
} }
void checkEvents() override; void checkEvents() override;
void onEvent(event_t event) override;
void onClicked() override; void onClicked() override;
void onCancel() override; void onCancel() override;
@@ -227,6 +202,11 @@ class TabsGroup: public Window
static TabsGroup* activeTabsGroup; static TabsGroup* activeTabsGroup;
void setVisibleTab(PageTab* tab); void setVisibleTab(PageTab* tab);
#if defined(HARDWARE_KEYS)
void onPressPGUP() override;
void onPressPGDN() override;
#endif
}; };
#endif #endif
+25 -19
View File
@@ -25,6 +25,7 @@
#include "libopenui.h" #include "libopenui.h"
#include "menu_model.h" #include "menu_model.h"
#include "menu_radio.h" #include "menu_radio.h"
#include "menu_screen.h"
#include "model_select.h" #include "model_select.h"
#include "opentx.h" #include "opentx.h"
#include "view_logical_switches.h" #include "view_logical_switches.h"
@@ -41,35 +42,40 @@ ChannelsViewMenu::ChannelsViewMenu(ModelMenu* parent) :
addTab(new LogicalSwitchesViewPage()); addTab(new LogicalSwitchesViewPage());
} }
void ChannelsViewMenu::onEvent(event_t event)
{
#if defined(HARDWARE_KEYS) #if defined(HARDWARE_KEYS)
if (event == EVT_KEY_BREAK(KEY_MODEL)) { void ChannelsViewMenu::onPressSYS()
killEvents(event); {
onCancel();
if (!parentMenu) {
new ModelMenu();
}
} else if (event == EVT_KEY_LONG(KEY_MODEL)) {
killEvents(KEY_MODEL);
onCancel();
if (parentMenu) parentMenu->onCancel();
new ModelLabelsWindow();
} else if (event == EVT_KEY_BREAK(KEY_SYS)) {
onCancel(); onCancel();
if (parentMenu) parentMenu->onCancel(); if (parentMenu) parentMenu->onCancel();
new RadioMenu(); new RadioMenu();
} else if (event == EVT_KEY_LONG(KEY_SYS)) { }
killEvents(KEY_SYS); void ChannelsViewMenu::onLongPressSYS()
{
onCancel(); onCancel();
if (parentMenu) parentMenu->onCancel(); if (parentMenu) parentMenu->onCancel();
// Radio setup // Radio setup
(new RadioMenu())->setCurrentTab(2); (new RadioMenu())->setCurrentTab(2);
} else { }
TabsGroup::onEvent(event); void ChannelsViewMenu::onPressMDL()
{
onCancel();
if (!parentMenu) {
new ModelMenu();
}
}
void ChannelsViewMenu::onLongPressMDL()
{
onCancel();
if (parentMenu) parentMenu->onCancel();
new ModelLabelsWindow();
}
void ChannelsViewMenu::onPressTELE()
{
onCancel();
if (parentMenu) parentMenu->onCancel();
new ScreenMenu();
} }
#endif #endif
}
class ChannelsViewFooter : public Window class ChannelsViewFooter : public Window
{ {
+7 -1
View File
@@ -47,5 +47,11 @@ class ChannelsViewMenu: public TabsGroup {
protected: protected:
ModelMenu* parentMenu = nullptr; ModelMenu* parentMenu = nullptr;
void onEvent(event_t event) override; #if defined(HARDWARE_KEYS)
void onPressSYS() override;
void onLongPressSYS() override;
void onPressMDL() override;
void onLongPressMDL() override;
void onPressTELE() override;
#endif
}; };
+63 -93
View File
@@ -20,15 +20,16 @@
*/ */
#include "view_main.h" #include "view_main.h"
#include "model_select.h"
#include "menu_model.h" #include "menu_model.h"
#include "menu_radio.h" #include "menu_radio.h"
#include "menu_screen.h" #include "menu_screen.h"
#include "topbar_impl.h" #include "model_select.h"
#include "view_main_menu.h"
#include "theme.h"
#include "opentx.h" #include "opentx.h"
#include "theme.h"
#include "topbar_impl.h"
#include "view_channels.h"
#include "view_main_menu.h"
static void tile_view_deleted_cb(lv_event_t* e) static void tile_view_deleted_cb(lv_event_t* e)
{ {
@@ -38,7 +39,9 @@ static void tile_view_deleted_cb(lv_event_t* e)
// LV_EVENT_CHILD_DELETED is bubbled to all parents, so // LV_EVENT_CHILD_DELETED is bubbled to all parents, so
// we'd better make sure this is one of our own. // we'd better make sure this is one of our own.
if (obj == target) { lv_obj_del(obj); } if (obj == target) {
lv_obj_del(obj);
}
} }
static void saveViewId(unsigned view) static void saveViewId(unsigned view)
@@ -67,7 +70,7 @@ static void tile_view_scroll(lv_event_t* e)
ViewMain* ViewMain::_instance = nullptr; ViewMain* ViewMain::_instance = nullptr;
ViewMain::ViewMain() : ViewMain::ViewMain() :
Window(MainWindow::instance(), MainWindow::instance()->getRect(), OPAQUE) NavWindow(MainWindow::instance(), MainWindow::instance()->getRect(), OPAQUE)
{ {
Layer::push(this); Layer::push(this);
@@ -81,17 +84,16 @@ ViewMain::ViewMain():
lv_obj_add_flag(tile_view, LV_OBJ_FLAG_EVENT_BUBBLE); lv_obj_add_flag(tile_view, LV_OBJ_FLAG_EVENT_BUBBLE);
lv_obj_set_user_data(tile_view, this); lv_obj_set_user_data(tile_view, this);
lv_obj_add_event_cb(tile_view, tile_view_scroll, LV_EVENT_SCROLL, nullptr); lv_obj_add_event_cb(tile_view, tile_view_scroll, LV_EVENT_SCROLL, nullptr);
lv_obj_add_event_cb(tile_view, tile_view_scroll, LV_EVENT_SCROLL_END, nullptr); lv_obj_add_event_cb(tile_view, tile_view_scroll, LV_EVENT_SCROLL_END,
lv_obj_add_event_cb(lvobj, ViewMain::long_pressed, LV_EVENT_LONG_PRESSED, nullptr); nullptr);
lv_obj_add_event_cb(lvobj, ViewMain::long_pressed, LV_EVENT_LONG_PRESSED,
nullptr);
// create last to be on top // create last to be on top
topbar = TopbarFactory::create(this); topbar = TopbarFactory::create(this);
} }
ViewMain::~ViewMain() ViewMain::~ViewMain() { _instance = nullptr; }
{
_instance = nullptr;
}
void ViewMain::deleteLater(bool detach, bool trash) void ViewMain::deleteLater(bool detach, bool trash)
{ {
@@ -103,19 +105,18 @@ void ViewMain::addMainView(Window* view, uint32_t viewId)
{ {
TRACE("addMainView(0x%p, %d)", view, viewId); TRACE("addMainView(0x%p, %d)", view, viewId);
auto tile = lv_tileview_add_tile(tile_view, viewId, 0, LV_DIR_LEFT | LV_DIR_RIGHT); auto tile =
lv_tileview_add_tile(tile_view, viewId, 0, LV_DIR_LEFT | LV_DIR_RIGHT);
auto view_obj = view->getLvObj(); auto view_obj = view->getLvObj();
lv_obj_set_parent(view_obj, tile); lv_obj_set_parent(view_obj, tile);
auto user_data = (void*)(intptr_t)viewId; auto user_data = (void*)(intptr_t)viewId;
lv_obj_add_event_cb(tile, tile_view_deleted_cb, LV_EVENT_CHILD_DELETED, user_data); lv_obj_add_event_cb(tile, tile_view_deleted_cb, LV_EVENT_CHILD_DELETED,
user_data);
} }
void ViewMain::setTopbarVisible(float visible) void ViewMain::setTopbarVisible(float visible) { topbar->setVisible(visible); }
{
topbar->setVisible(visible);
}
unsigned ViewMain::getMainViewsCount() const unsigned ViewMain::getMainViewsCount() const
{ {
@@ -141,16 +142,12 @@ void ViewMain::setCurrentMainView(unsigned viewId)
lv_obj_set_tile_id(tile_view, viewId, 0, LV_ANIM_OFF); lv_obj_set_tile_id(tile_view, viewId, 0, LV_ANIM_OFF);
} }
void setRequestedMainView(uint8_t view) void setRequestedMainView(uint8_t view) { g_model.view = view; }
{
g_model.view = view;
}
void ViewMain::nextMainView() void ViewMain::nextMainView()
{ {
auto view = getCurrentMainView(); auto view = getCurrentMainView();
if (++view >= getMainViewsCount()) if (++view >= getMainViewsCount()) view = 0;
view = 0;
setCurrentMainView(view); setCurrentMainView(view);
saveViewId(view); saveViewId(view);
@@ -168,10 +165,7 @@ void ViewMain::previousMainView()
saveViewId(view); saveViewId(view);
} }
TopBar* ViewMain::getTopbar() TopBar* ViewMain::getTopbar() { return topbar; }
{
return topbar;
}
static bool hasTopbar(unsigned view) static bool hasTopbar(unsigned view)
{ {
@@ -209,23 +203,19 @@ void ViewMain::updateTopbarVisibility()
if (leftScroll == 0) { if (leftScroll == 0) {
int view = scrollPos / pageWidth; int view = scrollPos / pageWidth;
setTopbarVisible(hasTopbar(view)); setTopbarVisible(hasTopbar(view));
if (customScreens[view]) if (customScreens[view]) customScreens[view]->adjustLayout();
customScreens[view]->adjustLayout(); } else {
}
else {
int leftIdx = scrollPos / pageWidth; int leftIdx = scrollPos / pageWidth;
bool leftTopbar = hasTopbar(leftIdx); bool leftTopbar = hasTopbar(leftIdx);
bool rightTopbar = hasTopbar(leftIdx + 1); bool rightTopbar = hasTopbar(leftIdx + 1);
if (leftTopbar != rightTopbar) { if (leftTopbar != rightTopbar) {
float ratio = (float)leftScroll / (float)pageWidth; float ratio = (float)leftScroll / (float)pageWidth;
if (leftTopbar) { if (leftTopbar) {
// scrolling from a screen with Topbar // scrolling from a screen with Topbar
ratio = 1.0 - ratio; ratio = 1.0 - ratio;
} } else {
else {
// scrolling to a screen with Topbar // scrolling to a screen with Topbar
// -> ratio is ok // -> ratio is ok
} }
@@ -241,75 +231,59 @@ void ViewMain::updateTopbarVisibility()
void ViewMain::updateFromTheme() void ViewMain::updateFromTheme()
{ {
for (int i = 0; i < MAX_CUSTOM_SCREENS; i += 1) { for (int i = 0; i < MAX_CUSTOM_SCREENS; i += 1) {
if (customScreens[i]) if (customScreens[i]) customScreens[i]->updateFromTheme();
customScreens[i]->updateFromTheme();
} }
} }
void ViewMain::onEvent(event_t event)
{
#if defined(HARDWARE_KEYS) #if defined(HARDWARE_KEYS)
switch (event) { void ViewMain::onPressSYS()
case EVT_KEY_BREAK(KEY_MODEL): {
if (viewMainMenu) viewMainMenu->onCancel();
new ModelMenu();
break;
case EVT_KEY_LONG(KEY_MODEL):
killEvents(KEY_MODEL);
if (viewMainMenu) viewMainMenu->onCancel();
new ModelLabelsWindow();
break;
case EVT_KEY_BREAK(KEY_SYS):
if (viewMainMenu) viewMainMenu->onCancel(); if (viewMainMenu) viewMainMenu->onCancel();
new RadioMenu(); new RadioMenu();
break; }
void ViewMain::onLongPressSYS()
case EVT_KEY_LONG(KEY_SYS): {
killEvents(KEY_SYS);
if (viewMainMenu) viewMainMenu->onCancel(); if (viewMainMenu) viewMainMenu->onCancel();
// Radio setup // Radio setup
(new RadioMenu())->setCurrentTab(2); (new RadioMenu())->setCurrentTab(2);
break; }
void ViewMain::onPressMDL()
case EVT_KEY_FIRST(KEY_TELE): {
if (viewMainMenu) viewMainMenu->onCancel();
new ModelMenu();
}
void ViewMain::onLongPressMDL()
{
if (viewMainMenu) viewMainMenu->onCancel();
new ModelLabelsWindow();
}
void ViewMain::onPressTELE()
{
if (viewMainMenu) viewMainMenu->onCancel(); if (viewMainMenu) viewMainMenu->onCancel();
new ScreenMenu(); new ScreenMenu();
break;
#if defined(KEYS_GPIO_REG_PAGEUP) || defined(USE_HATS_AS_KEYS)
case EVT_KEY_FIRST(KEY_PAGEDN):
#else
case EVT_KEY_BREAK(KEY_PAGEDN):
#endif
if (!widget_select) {
if (viewMainMenu) viewMainMenu->onCancel();
nextMainView();
} }
break; void ViewMain::onLongPressTELE()
{
//TODO: these need to go away! if (viewMainMenu) viewMainMenu->onCancel();
// -> board code should map the keys as required new ChannelsViewMenu();
#if defined(KEYS_GPIO_REG_PAGEUP) || defined(USE_HATS_AS_KEYS) }
case EVT_KEY_FIRST(KEY_PAGEUP): void ViewMain::onPressPGUP()
#else {
case EVT_KEY_LONG(KEY_PAGEDN):
#endif
killEvents(event);
if (!widget_select) { if (!widget_select) {
if (viewMainMenu) viewMainMenu->onCancel(); if (viewMainMenu) viewMainMenu->onCancel();
previousMainView(); previousMainView();
} }
break; }
void ViewMain::onPressPGDN()
{
if (!widget_select) {
if (viewMainMenu) viewMainMenu->onCancel();
nextMainView();
}
} }
#endif #endif
}
void ViewMain::onClicked() void ViewMain::onClicked() { openMenu(); }
{
openMenu();
}
void ViewMain::onCancel() void ViewMain::onCancel()
{ {
@@ -335,12 +309,10 @@ bool ViewMain::enableWidgetSelect(bool enable)
widget_select = enable; widget_select = enable;
lv_obj_t* tile = lv_tileview_get_tile_act(tile_view); lv_obj_t* tile = lv_tileview_get_tile_act(tile_view);
if(!tile) if (!tile) return true;
return true;
auto cont_obj = lv_obj_get_child(tile, 0); auto cont_obj = lv_obj_get_child(tile, 0);
if(!cont_obj) if (!cont_obj) return true;
return true;
auto cont = (WidgetsContainer*)lv_obj_get_user_data(cont_obj); auto cont = (WidgetsContainer*)lv_obj_get_user_data(cont_obj);
@@ -376,9 +348,7 @@ bool ViewMain::enableWidgetSelect(bool enable)
void ViewMain::openMenu() void ViewMain::openMenu()
{ {
viewMainMenu = new ViewMainMenu(this, [=]() { viewMainMenu = new ViewMainMenu(this, [=]() { viewMainMenu = nullptr; });
viewMainMenu = nullptr;
});
} }
void ViewMain::paint(BitmapBuffer* dc) void ViewMain::paint(BitmapBuffer* dc)
+15 -9
View File
@@ -23,15 +23,15 @@
#define _VIEW_MAIN_H_ #define _VIEW_MAIN_H_
#include <memory> #include <memory>
#include "form.h" #include "form.h"
#include "topbar.h" #include "topbar.h"
class SetupWidgetsPage; class SetupWidgetsPage;
class SetupTopBarWidgetsPage; class SetupTopBarWidgetsPage;
class ViewMainMenu; class ViewMainMenu;
class ViewMain: public Window class ViewMain : public NavWindow
{ {
// singleton // singleton
explicit ViewMain(); explicit ViewMain();
@@ -41,8 +41,7 @@ class ViewMain: public Window
static ViewMain* instance() static ViewMain* instance()
{ {
if (!_instance) if (!_instance) _instance = new ViewMain();
_instance = new ViewMain();
return _instance; return _instance;
} }
@@ -50,10 +49,7 @@ class ViewMain: public Window
static ViewMain* getInstance() { return _instance; } static ViewMain* getInstance() { return _instance; }
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() const override std::string getName() const override { return "ViewMain"; }
{
return "ViewMain";
}
#endif #endif
void addMainView(Window* view, uint32_t viewId); void addMainView(Window* view, uint32_t viewId);
@@ -79,7 +75,6 @@ class ViewMain: public Window
TopBar* getTopbar(); TopBar* getTopbar();
void onEvent(event_t event) override;
void onClicked() override; void onClicked() override;
void onCancel() override; void onCancel() override;
@@ -107,6 +102,17 @@ class ViewMain: public Window
static void long_pressed(lv_event_t* e); static void long_pressed(lv_event_t* e);
static void ws_timer(lv_timer_t* t); static void ws_timer(lv_timer_t* t);
#if defined(HARDWARE_KEYS)
void onPressSYS() override;
void onLongPressSYS() override;
void onPressMDL() override;
void onLongPressMDL() override;
void onPressTELE() override;
void onLongPressTELE() override;
void onPressPGUP() override;
void onPressPGDN() override;
#endif
}; };
#endif // _VIEW_MAIN_H_ #endif // _VIEW_MAIN_H_
+58
View File
@@ -463,3 +463,61 @@ void Window::invalidate(const rect_t & rect)
{ {
if (lvobj) lv_obj_invalidate(lvobj); if (lvobj) lv_obj_invalidate(lvobj);
} }
void NavWindow::onEvent(event_t event)
{
switch (event) {
#if defined(HARDWARE_KEYS)
case EVT_KEY_BREAK(KEY_MODEL):
onPressMDL();
break;
case EVT_KEY_LONG(KEY_MODEL):
killEvents(KEY_MODEL);
onLongPressMDL();
break;
case EVT_KEY_BREAK(KEY_SYS):
onPressSYS();
break;
case EVT_KEY_LONG(KEY_SYS):
killEvents(KEY_SYS);
onLongPressSYS();
break;
case EVT_KEY_BREAK(KEY_TELE):
onPressTELE();
break;
case EVT_KEY_LONG(KEY_TELE):
killEvents(KEY_TELE);
onLongPressTELE();
break;
#if defined(KEYS_GPIO_REG_PAGEUP) || defined(USE_HATS_AS_KEYS)
case EVT_KEY_FIRST(KEY_PAGEDN):
#else
case EVT_KEY_BREAK(KEY_PAGEDN):
#endif
killEvents(event);
onPressPGDN();
break;
// TODO: these need to go away!
// -> board code should map the keys as required
#if defined(KEYS_GPIO_REG_PAGEUP) || defined(USE_HATS_AS_KEYS)
case EVT_KEY_FIRST(KEY_PAGEUP):
#else
case EVT_KEY_LONG(KEY_PAGEDN):
#endif
killEvents(event);
onPressPGUP();
break;
#endif
default:
if (bubbleEvents())
Window::onEvent(event);
}
}
+37 -41
View File
@@ -18,22 +18,21 @@
#pragma once #pragma once
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <functional>
#include <list> #include <list>
#include <string> #include <string>
#include <utility> #include <utility>
#include <functional>
#include "LvglWrapper.h"
#include "bitmapbuffer.h" #include "bitmapbuffer.h"
#include "libopenui_defines.h" #include "libopenui_defines.h"
#include "opentx_helpers.h" #include "opentx_helpers.h"
#include "widgets/etx_obj_create.h" #include "widgets/etx_obj_create.h"
#include "LvglWrapper.h"
typedef uint32_t WindowFlags; typedef uint32_t WindowFlags;
#if !defined(_GNUC_) #if !defined(_GNUC_)
@@ -124,40 +123,19 @@ class Window
lv_obj_set_pos(lvobj, rect.x, rect.y); lv_obj_set_pos(lvobj, rect.x, rect.y);
} }
coord_t left() const coord_t left() const { return rect.x; }
{
return rect.x;
}
coord_t right() const coord_t right() const { return rect.x + rect.w; }
{
return rect.x + rect.w;
}
coord_t top() const coord_t top() const { return rect.y; }
{
return rect.y;
}
coord_t bottom() const coord_t bottom() const { return rect.y + rect.h; }
{
return rect.y + rect.h;
}
coord_t width() const coord_t width() const { return rect.w; }
{
return rect.w;
}
coord_t height() const coord_t height() const { return rect.h; }
{
return rect.h;
}
rect_t getRect() const rect_t getRect() const { return rect; }
{
return rect;
}
void padLeft(coord_t pad); void padLeft(coord_t pad);
void padRight(coord_t pad); void padRight(coord_t pad);
@@ -174,10 +152,7 @@ class Window
virtual void updateSize(); virtual void updateSize();
void invalidate() void invalidate() { invalidate({0, 0, rect.w, rect.h}); }
{
invalidate({0, 0, rect.w, rect.h});
}
void bringToTop(); void bringToTop();
@@ -187,10 +162,7 @@ class Window
void detach(); void detach();
bool deleted() const bool deleted() const { return _deleted; }
{
return _deleted;
}
virtual void paint(BitmapBuffer *) {} virtual void paint(BitmapBuffer *) {}
@@ -231,3 +203,27 @@ class Window
virtual void invalidate(const rect_t &rect); virtual void invalidate(const rect_t &rect);
}; };
class NavWindow : public Window
{
public:
NavWindow(Window *parent, const rect_t &rect, WindowFlags windowFlags = 0,
LcdFlags textFlags = 0, LvglCreate objConstruct = nullptr) :
Window(parent, rect, windowFlags, textFlags, objConstruct)
{
}
protected:
#if defined(HARDWARE_KEYS)
virtual void onPressSYS() {}
virtual void onLongPressSYS() {}
virtual void onPressMDL() {}
virtual void onLongPressMDL() {}
virtual void onPressTELE() {}
virtual void onLongPressTELE() {}
virtual void onPressPGUP() {}
virtual void onPressPGDN() {}
#endif
virtual bool bubbleEvents() { return true; }
void onEvent(event_t event) override;
};