feat(color): Improved hardware key navigation (TELE) (#4219)
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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); }
|
||||||
onCancel();
|
void RadioMenu::onLongPressSYS() { setCurrentTab(2); }
|
||||||
new ModelMenu();
|
void RadioMenu::onPressMDL()
|
||||||
} else if (event == EVT_KEY_LONG(KEY_MODEL)) {
|
{
|
||||||
onCancel();
|
onCancel();
|
||||||
killEvents(KEY_MODEL);
|
new ModelMenu();
|
||||||
new ModelLabelsWindow();
|
|
||||||
} else {
|
|
||||||
TabsGroup::onEvent(event);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
void RadioMenu::onLongPressMDL()
|
||||||
|
{
|
||||||
|
onCancel();
|
||||||
|
new ModelLabelsWindow();
|
||||||
|
}
|
||||||
|
void RadioMenu::onPressTELE()
|
||||||
|
{
|
||||||
|
onCancel();
|
||||||
|
new ScreenMenu();
|
||||||
|
}
|
||||||
|
void RadioMenu::onLongPressTELE()
|
||||||
|
{
|
||||||
|
onCancel();
|
||||||
|
new ChannelsViewMenu();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -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
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,20 +19,24 @@
|
|||||||
* 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);
|
||||||
|
|
||||||
setCloseHandler([]{
|
setCloseHandler([] {
|
||||||
ViewMain::instance()->updateTopbarVisibility();
|
ViewMain::instance()->updateTopbarVisibility();
|
||||||
storageDirty(EE_MODEL);
|
storageDirty(EE_MODEL);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
};
|
||||||
|
|||||||
@@ -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,49 +663,57 @@ ModelLabelsWindow::ModelLabelsWindow() : Page(ICON_MODEL)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HARDWARE_KEYS)
|
#if defined(HARDWARE_KEYS)
|
||||||
void ModelLabelsWindow::onEvent(event_t event)
|
void ModelLabelsWindow::onPressSYS()
|
||||||
{
|
{
|
||||||
#if defined(KEYS_GPIO_REG_PAGEUP)
|
onCancel();
|
||||||
if (event == EVT_KEY_BREAK(KEY_PAGEUP) ||
|
new RadioMenu();
|
||||||
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> sellist;
|
|
||||||
int select = 0;
|
|
||||||
int rowcount = lblselector->getRowCount();
|
|
||||||
|
|
||||||
if (event == EVT_KEY_BREAK(KEY_PAGEDN)) {
|
|
||||||
if (curSel.size()) select = (*curSel.rbegin() + 1) % rowcount;
|
|
||||||
} else {
|
|
||||||
killEvents(event);
|
|
||||||
if (curSel.size()) {
|
|
||||||
select = (int)*curSel.begin() - 1;
|
|
||||||
if (select < 0) select += rowcount;
|
|
||||||
} else {
|
|
||||||
select = rowcount - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sellist.insert(select);
|
|
||||||
lblselector->setSelected(sellist); // Check the items
|
|
||||||
lblselector->setSelected(select); // Causes the list to scroll
|
|
||||||
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::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)
|
||||||
|
{
|
||||||
|
std::set<uint32_t> curSel = lblselector->getSelection();
|
||||||
|
std::set<uint32_t> sellist;
|
||||||
|
int select = 0;
|
||||||
|
int rowcount = lblselector->getRowCount();
|
||||||
|
|
||||||
|
if (isNext) {
|
||||||
|
if (curSel.size()) select = (*curSel.rbegin() + 1) % rowcount;
|
||||||
|
} else {
|
||||||
|
if (curSel.size()) {
|
||||||
|
select = (int)*curSel.begin() - 1;
|
||||||
|
if (select < 0) select += rowcount;
|
||||||
|
} else {
|
||||||
|
select = rowcount - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sellist.insert(select);
|
||||||
|
lblselector->setSelected(sellist); // Check the items
|
||||||
|
lblselector->setSelected(select); // Causes the list to scroll
|
||||||
|
updateFilteredLabels(sellist); // Update the models
|
||||||
|
}
|
||||||
|
void ModelLabelsWindow::onPressPGUP() { onPressPG(false); }
|
||||||
|
void ModelLabelsWindow::onPressPGDN() { onPressPG(true); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void ModelLabelsWindow::newModel()
|
void ModelLabelsWindow::newModel()
|
||||||
|
|||||||
@@ -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_
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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_
|
||||||
|
|||||||
@@ -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);
|
{
|
||||||
|
uint8_t current = header.carousel.getCurrentIndex();
|
||||||
#if defined(KEYS_GPIO_REG_PAGEUP) || defined(USE_HATS_AS_KEYS)
|
setCurrentTab(current == 0 ? tabs.size() - 1 : current - 1);
|
||||||
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();
|
|
||||||
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(); }
|
||||||
|
|
||||||
|
|||||||
+137
-157
@@ -21,67 +21,56 @@
|
|||||||
#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)
|
{
|
||||||
{
|
}
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~PageTab() = default;
|
virtual ~PageTab() = default;
|
||||||
|
|
||||||
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;
|
||||||
unsigned icon = 0;
|
unsigned icon = 0;
|
||||||
std::function<void()> onSetVisible;
|
std::function<void()> onSetVisible;
|
||||||
};
|
};
|
||||||
|
|
||||||
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::function<uint8_t(void)> pressHandler,
|
std::vector<PageTab*>& tabs, uint8_t index,
|
||||||
WindowFlags flags = 0);
|
std::function<uint8_t(void)> pressHandler,
|
||||||
|
WindowFlags flags = 0);
|
||||||
|
|
||||||
#if defined(DEBUG_WINDOWS)
|
#if defined(DEBUG_WINDOWS)
|
||||||
std::string getName() const override
|
std::string getName() const override
|
||||||
@@ -90,143 +79,134 @@ public:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void paint(BitmapBuffer * dc);
|
void paint(BitmapBuffer* dc);
|
||||||
|
|
||||||
void check(bool checked = true);
|
void check(bool checked = true);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<PageTab *> tabs;
|
std::vector<PageTab*> tabs;
|
||||||
uint8_t index;
|
uint8_t index;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TabsCarousel: public Window {
|
class TabsCarousel : public Window
|
||||||
public:
|
|
||||||
TabsCarousel(Window * parent, TabsGroup * menu);
|
|
||||||
|
|
||||||
#if defined(DEBUG_WINDOWS)
|
|
||||||
std::string getName() const override
|
|
||||||
{
|
|
||||||
return "TabsCarousel";
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void setCurrentIndex(uint8_t index);
|
|
||||||
|
|
||||||
inline uint8_t getCurrentIndex()
|
|
||||||
{
|
|
||||||
return currentIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
void update();
|
|
||||||
|
|
||||||
void paint(BitmapBuffer * dc) override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
std::vector<TabCarouselButton*> buttons;
|
|
||||||
constexpr static uint8_t padding_left = 3;
|
|
||||||
TabsGroup * menu;
|
|
||||||
uint8_t currentIndex = 0;
|
|
||||||
#if defined(HARDWARE_TOUCH)
|
|
||||||
bool sliding = false;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
class TabsGroupHeader: public FormWindow {
|
|
||||||
friend class TabsGroup;
|
|
||||||
|
|
||||||
public:
|
|
||||||
TabsGroupHeader(TabsGroup * menu, uint8_t icon);
|
|
||||||
|
|
||||||
void setTitle(const char * value) { title = value; }
|
|
||||||
|
|
||||||
#if defined(DEBUG_WINDOWS)
|
|
||||||
std::string getName() const override
|
|
||||||
{
|
|
||||||
return "TabsGroupHeader";
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void deleteLater(bool detach = true, bool trash = true) override
|
|
||||||
{
|
|
||||||
if (_deleted) return;
|
|
||||||
#if defined(HARDWARE_TOUCH)
|
|
||||||
back.deleteLater(true, false);
|
|
||||||
#endif
|
|
||||||
carousel.deleteLater(true, false);
|
|
||||||
FormWindow::deleteLater(detach, trash);
|
|
||||||
}
|
|
||||||
|
|
||||||
void paint(BitmapBuffer * dc) override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
#if defined(HARDWARE_TOUCH)
|
|
||||||
Button back;
|
|
||||||
#endif
|
|
||||||
uint8_t icon;
|
|
||||||
TabsCarousel carousel;
|
|
||||||
std::string title;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TabsGroup: public Window
|
|
||||||
{
|
{
|
||||||
friend class TabsCarousel;
|
public:
|
||||||
|
TabsCarousel(Window* parent, TabsGroup* menu);
|
||||||
public:
|
|
||||||
explicit TabsGroup(uint8_t icon);
|
|
||||||
~TabsGroup() 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 "TabsCarousel"; }
|
||||||
{
|
|
||||||
return "TabsGroup";
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
unsigned getTabs() const
|
void setCurrentIndex(uint8_t index);
|
||||||
{
|
|
||||||
return tabs.size();
|
inline uint8_t getCurrentIndex() { return currentIndex; }
|
||||||
|
|
||||||
|
void update();
|
||||||
|
|
||||||
|
void paint(BitmapBuffer* dc) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::vector<TabCarouselButton*> buttons;
|
||||||
|
constexpr static uint8_t padding_left = 3;
|
||||||
|
TabsGroup* menu;
|
||||||
|
uint8_t currentIndex = 0;
|
||||||
|
#if defined(HARDWARE_TOUCH)
|
||||||
|
bool sliding = false;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
class TabsGroupHeader : public FormWindow
|
||||||
|
{
|
||||||
|
friend class TabsGroup;
|
||||||
|
|
||||||
|
public:
|
||||||
|
TabsGroupHeader(TabsGroup* menu, uint8_t icon);
|
||||||
|
|
||||||
|
void setTitle(const char* value) { title = value; }
|
||||||
|
|
||||||
|
#if defined(DEBUG_WINDOWS)
|
||||||
|
std::string getName() const override { return "TabsGroupHeader"; }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void deleteLater(bool detach = true, bool trash = true) override
|
||||||
|
{
|
||||||
|
if (_deleted) return;
|
||||||
|
#if defined(HARDWARE_TOUCH)
|
||||||
|
back.deleteLater(true, false);
|
||||||
|
#endif
|
||||||
|
carousel.deleteLater(true, false);
|
||||||
|
FormWindow::deleteLater(detach, trash);
|
||||||
|
}
|
||||||
|
|
||||||
|
void paint(BitmapBuffer* dc) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
#if defined(HARDWARE_TOUCH)
|
||||||
|
Button back;
|
||||||
|
#endif
|
||||||
|
uint8_t icon;
|
||||||
|
TabsCarousel carousel;
|
||||||
|
std::string title;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TabsGroup : public NavWindow
|
||||||
|
{
|
||||||
|
friend class TabsCarousel;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit TabsGroup(uint8_t icon);
|
||||||
|
~TabsGroup() override;
|
||||||
|
|
||||||
|
void deleteLater(bool detach = true, bool trash = true) override;
|
||||||
|
|
||||||
|
#if defined(DEBUG_WINDOWS)
|
||||||
|
std::string getName() const override { return "TabsGroup"; }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
unsigned getTabs() const { return tabs.size(); }
|
||||||
|
|
||||||
|
void addTab(PageTab* page);
|
||||||
|
|
||||||
|
// Return the index of the found tab
|
||||||
|
// or -1 if the tab could not be found
|
||||||
|
int removeTab(PageTab* page);
|
||||||
|
|
||||||
|
void removeTab(unsigned index);
|
||||||
|
|
||||||
|
void removeAllTabs();
|
||||||
|
|
||||||
|
void setCurrentTab(unsigned index)
|
||||||
|
{
|
||||||
|
if (index < tabs.size()) {
|
||||||
|
header.carousel.setCurrentIndex(index);
|
||||||
|
setVisibleTab(tabs[index]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void addTab(PageTab * page);
|
void checkEvents() override;
|
||||||
|
|
||||||
// Return the index of the found tab
|
void onClicked() override;
|
||||||
// or -1 if the tab could not be found
|
void onCancel() override;
|
||||||
int removeTab(PageTab * page);
|
|
||||||
|
|
||||||
void removeTab(unsigned index);
|
|
||||||
|
|
||||||
void removeAllTabs();
|
|
||||||
|
|
||||||
void setCurrentTab(unsigned index)
|
|
||||||
{
|
|
||||||
if (index < tabs.size()) {
|
|
||||||
header.carousel.setCurrentIndex(index);
|
|
||||||
setVisibleTab(tabs[index]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void checkEvents() override;
|
|
||||||
void onEvent(event_t event) override;
|
|
||||||
|
|
||||||
void onClicked() override;
|
|
||||||
void onCancel() override;
|
|
||||||
|
|
||||||
#if defined(HARDWARE_TOUCH)
|
#if defined(HARDWARE_TOUCH)
|
||||||
bool onTouchEnd(coord_t x, coord_t y) override;
|
bool onTouchEnd(coord_t x, coord_t y) override;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void refreshTheme();
|
static void refreshTheme();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TabsGroupHeader header;
|
TabsGroupHeader header;
|
||||||
FormWindow body;
|
FormWindow body;
|
||||||
std::vector<PageTab *> tabs;
|
std::vector<PageTab*> tabs;
|
||||||
PageTab * currentTab = nullptr;
|
PageTab* currentTab = nullptr;
|
||||||
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,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);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
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
|
||||||
|
|
||||||
class ChannelsViewFooter : public Window
|
class ChannelsViewFooter : public Window
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -64,10 +67,10 @@ 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)
|
||||||
{
|
{
|
||||||
@@ -205,34 +199,30 @@ void ViewMain::updateTopbarVisibility()
|
|||||||
coord_t pageWidth = width();
|
coord_t pageWidth = width();
|
||||||
if (!pageWidth) return;
|
if (!pageWidth) return;
|
||||||
|
|
||||||
int leftScroll = scrollPos % width();
|
int leftScroll = scrollPos % width();
|
||||||
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 {
|
||||||
}
|
int leftIdx = scrollPos / pageWidth;
|
||||||
else {
|
bool leftTopbar = hasTopbar(leftIdx);
|
||||||
int leftIdx = scrollPos / pageWidth;
|
bool rightTopbar = hasTopbar(leftIdx + 1);
|
||||||
bool leftTopbar = hasTopbar(leftIdx);
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
setTopbarVisible(ratio);
|
setTopbarVisible(ratio);
|
||||||
customScreens[leftIdx]->adjustLayout();
|
customScreens[leftIdx]->adjustLayout();
|
||||||
customScreens[leftIdx+1]->adjustLayout();
|
customScreens[leftIdx + 1]->adjustLayout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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();
|
|
||||||
new RadioMenu();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EVT_KEY_LONG(KEY_SYS):
|
|
||||||
killEvents(KEY_SYS);
|
|
||||||
if (viewMainMenu) viewMainMenu->onCancel();
|
|
||||||
// Radio setup
|
|
||||||
(new RadioMenu())->setCurrentTab(2);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EVT_KEY_FIRST(KEY_TELE):
|
|
||||||
if (viewMainMenu) viewMainMenu->onCancel();
|
|
||||||
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;
|
|
||||||
|
|
||||||
//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);
|
|
||||||
if (!widget_select) {
|
|
||||||
if (viewMainMenu) viewMainMenu->onCancel();
|
|
||||||
previousMainView();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void ViewMain::onClicked()
|
|
||||||
{
|
{
|
||||||
openMenu();
|
if (viewMainMenu) viewMainMenu->onCancel();
|
||||||
|
new RadioMenu();
|
||||||
}
|
}
|
||||||
|
void ViewMain::onLongPressSYS()
|
||||||
|
{
|
||||||
|
if (viewMainMenu) viewMainMenu->onCancel();
|
||||||
|
// Radio setup
|
||||||
|
(new RadioMenu())->setCurrentTab(2);
|
||||||
|
}
|
||||||
|
void ViewMain::onPressMDL()
|
||||||
|
{
|
||||||
|
if (viewMainMenu) viewMainMenu->onCancel();
|
||||||
|
new ModelMenu();
|
||||||
|
}
|
||||||
|
void ViewMain::onLongPressMDL()
|
||||||
|
{
|
||||||
|
if (viewMainMenu) viewMainMenu->onCancel();
|
||||||
|
new ModelLabelsWindow();
|
||||||
|
}
|
||||||
|
void ViewMain::onPressTELE()
|
||||||
|
{
|
||||||
|
if (viewMainMenu) viewMainMenu->onCancel();
|
||||||
|
new ScreenMenu();
|
||||||
|
}
|
||||||
|
void ViewMain::onLongPressTELE()
|
||||||
|
{
|
||||||
|
if (viewMainMenu) viewMainMenu->onCancel();
|
||||||
|
new ChannelsViewMenu();
|
||||||
|
}
|
||||||
|
void ViewMain::onPressPGUP()
|
||||||
|
{
|
||||||
|
if (!widget_select) {
|
||||||
|
if (viewMainMenu) viewMainMenu->onCancel();
|
||||||
|
previousMainView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void ViewMain::onPressPGDN()
|
||||||
|
{
|
||||||
|
if (!widget_select) {
|
||||||
|
if (viewMainMenu) viewMainMenu->onCancel();
|
||||||
|
nextMainView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void ViewMain::onClicked() { 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,15 +348,13 @@ 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)
|
||||||
{
|
{
|
||||||
TRACE_WINDOWS("### ViewMain::paint(offset_x=%d;offset_y=%d) ###",
|
TRACE_WINDOWS("### ViewMain::paint(offset_x=%d;offset_y=%d) ###",
|
||||||
dc->getOffsetX(), dc->getOffsetY());
|
dc->getOffsetX(), dc->getOffsetY());
|
||||||
|
|
||||||
// TODO: set it as "window background" w/ LVGL
|
// TODO: set it as "window background" w/ LVGL
|
||||||
EdgeTxTheme::instance()->drawBackground(dc);
|
EdgeTxTheme::instance()->drawBackground(dc);
|
||||||
|
|||||||
@@ -23,90 +23,96 @@
|
|||||||
#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();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~ViewMain() override;
|
~ViewMain() override;
|
||||||
|
|
||||||
static ViewMain * instance()
|
static ViewMain* instance()
|
||||||
{
|
{
|
||||||
if (!_instance)
|
if (!_instance) _instance = new ViewMain();
|
||||||
_instance = new ViewMain();
|
|
||||||
|
|
||||||
return _instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
void enableTopbar();
|
void enableTopbar();
|
||||||
void disableTopbar();
|
void disableTopbar();
|
||||||
void updateTopbarVisibility();
|
void updateTopbarVisibility();
|
||||||
bool enableWidgetSelect(bool enable);
|
bool enableWidgetSelect(bool enable);
|
||||||
|
|
||||||
// Update after theme loaded / changed
|
// Update after theme loaded / changed
|
||||||
void updateFromTheme();
|
void updateFromTheme();
|
||||||
|
|
||||||
// Get the available space in the middle of the screen
|
// Get the available space in the middle of the screen
|
||||||
// (without topbar)
|
// (without topbar)
|
||||||
rect_t getMainZone(rect_t zone, bool hasTopbar) const;
|
rect_t getMainZone(rect_t zone, bool hasTopbar) const;
|
||||||
|
|
||||||
unsigned getMainViewsCount() const;
|
unsigned getMainViewsCount() const;
|
||||||
unsigned getCurrentMainView() const;
|
unsigned getCurrentMainView() const;
|
||||||
void setCurrentMainView(unsigned view);
|
void setCurrentMainView(unsigned view);
|
||||||
|
|
||||||
void nextMainView();
|
void nextMainView();
|
||||||
void previousMainView();
|
void previousMainView();
|
||||||
|
|
||||||
TopBar* getTopbar();
|
TopBar* getTopbar();
|
||||||
|
|
||||||
void onEvent(event_t event) override;
|
void onClicked() override;
|
||||||
void onClicked() override;
|
void onCancel() override;
|
||||||
void onCancel() override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static ViewMain * _instance;
|
static ViewMain* _instance;
|
||||||
|
|
||||||
lv_obj_t* tile_view = nullptr;
|
lv_obj_t* tile_view = nullptr;
|
||||||
TopBar* topbar = nullptr;
|
TopBar* topbar = nullptr;
|
||||||
bool widget_select = false;
|
bool widget_select = false;
|
||||||
lv_timer_t* widget_select_timer = nullptr;
|
lv_timer_t* widget_select_timer = nullptr;
|
||||||
ViewMainMenu* viewMainMenu = nullptr;
|
ViewMainMenu* viewMainMenu = nullptr;
|
||||||
|
|
||||||
void paint(BitmapBuffer * dc) override;
|
void paint(BitmapBuffer* dc) override;
|
||||||
void deleteLater(bool detach = true, bool trash = true) override;
|
void deleteLater(bool detach = true, bool trash = true) override;
|
||||||
|
|
||||||
// Widget setup requires special permissions ;-)
|
// Widget setup requires special permissions ;-)
|
||||||
friend class SetupWidgetsPage;
|
friend class SetupWidgetsPage;
|
||||||
friend class SetupTopBarWidgetsPage;
|
friend class SetupTopBarWidgetsPage;
|
||||||
|
|
||||||
// Set topbar visibility [0.0 -> 1.0]
|
// Set topbar visibility [0.0 -> 1.0]
|
||||||
void setTopbarVisible(float visible);
|
void setTopbarVisible(float visible);
|
||||||
|
|
||||||
void openMenu();
|
void openMenu();
|
||||||
void refreshWidgetSelectTimer();
|
void refreshWidgetSelectTimer();
|
||||||
|
|
||||||
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
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+134
-138
@@ -18,216 +18,212 @@
|
|||||||
|
|
||||||
#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_)
|
||||||
#undef OPAQUE
|
#undef OPAQUE
|
||||||
#undef TRANSPARENT
|
#undef TRANSPARENT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
constexpr WindowFlags OPAQUE = 1u << 0u;
|
constexpr WindowFlags OPAQUE = 1u << 0u;
|
||||||
constexpr WindowFlags TRANSPARENT = 1u << 1u;
|
constexpr WindowFlags TRANSPARENT = 1u << 1u;
|
||||||
constexpr WindowFlags NO_FOCUS = 1u << 2u;
|
constexpr WindowFlags NO_FOCUS = 1u << 2u;
|
||||||
constexpr WindowFlags REFRESH_ALWAYS = 1u << 3u;
|
constexpr WindowFlags REFRESH_ALWAYS = 1u << 3u;
|
||||||
constexpr WindowFlags WINDOW_FLAGS_LAST = REFRESH_ALWAYS;
|
constexpr WindowFlags WINDOW_FLAGS_LAST = REFRESH_ALWAYS;
|
||||||
|
|
||||||
typedef lv_obj_t *(*LvglCreate)(lv_obj_t *);
|
typedef lv_obj_t *(*LvglCreate)(lv_obj_t *);
|
||||||
extern "C" void window_event_cb(lv_event_t * e);
|
extern "C" void window_event_cb(lv_event_t *e);
|
||||||
|
|
||||||
class Window
|
class Window
|
||||||
{
|
{
|
||||||
friend void window_event_cb(lv_event_t * e);
|
friend void window_event_cb(lv_event_t *e);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Window(Window *parent, const rect_t &rect, WindowFlags windowFlags = 0,
|
Window(Window *parent, const rect_t &rect, WindowFlags windowFlags = 0,
|
||||||
LcdFlags textFlags = 0, LvglCreate objConstruct = nullptr);
|
LcdFlags textFlags = 0, LvglCreate objConstruct = nullptr);
|
||||||
|
|
||||||
Window(Window *parent, lv_obj_t* lvobj);
|
Window(Window *parent, lv_obj_t *lvobj);
|
||||||
|
|
||||||
virtual ~Window();
|
virtual ~Window();
|
||||||
|
|
||||||
#if defined(DEBUG_WINDOWS)
|
#if defined(DEBUG_WINDOWS)
|
||||||
virtual std::string getName() const;
|
virtual std::string getName() const;
|
||||||
std::string getRectString() const;
|
std::string getRectString() const;
|
||||||
std::string getIndentString() const;
|
std::string getIndentString() const;
|
||||||
std::string getWindowDebugString(const char * name = nullptr) const;
|
std::string getWindowDebugString(const char *name = nullptr) const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Window *getParent() const { return parent; }
|
Window *getParent() const { return parent; }
|
||||||
|
|
||||||
Window *getFullScreenWindow();
|
Window *getFullScreenWindow();
|
||||||
|
|
||||||
WindowFlags getWindowFlags() const { return windowFlags; }
|
WindowFlags getWindowFlags() const { return windowFlags; }
|
||||||
void setWindowFlags(WindowFlags flags);
|
void setWindowFlags(WindowFlags flags);
|
||||||
|
|
||||||
LcdFlags getTextFlags() const { return textFlags; }
|
LcdFlags getTextFlags() const { return textFlags; }
|
||||||
void setTextFlags(LcdFlags flags);
|
void setTextFlags(LcdFlags flags);
|
||||||
|
|
||||||
typedef std::function<void()> CloseHandler;
|
typedef std::function<void()> CloseHandler;
|
||||||
void setCloseHandler(CloseHandler h) { closeHandler = std::move(h); }
|
void setCloseHandler(CloseHandler h) { closeHandler = std::move(h); }
|
||||||
|
|
||||||
typedef std::function<void(bool)> FocusHandler;
|
typedef std::function<void(bool)> FocusHandler;
|
||||||
void setFocusHandler(FocusHandler h) { focusHandler = std::move(h); }
|
void setFocusHandler(FocusHandler h) { focusHandler = std::move(h); }
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
virtual void deleteLater(bool detach = true, bool trash = true);
|
virtual void deleteLater(bool detach = true, bool trash = true);
|
||||||
|
|
||||||
bool hasFocus() const;
|
bool hasFocus() const;
|
||||||
|
|
||||||
void setRect(rect_t value)
|
void setRect(rect_t value)
|
||||||
{
|
{
|
||||||
rect = value;
|
rect = value;
|
||||||
lv_obj_enable_style_refresh(false);
|
lv_obj_enable_style_refresh(false);
|
||||||
lv_obj_set_pos(lvobj, rect.x, rect.y);
|
lv_obj_set_pos(lvobj, rect.x, rect.y);
|
||||||
lv_obj_set_size(lvobj, rect.w, rect.h);
|
lv_obj_set_size(lvobj, rect.w, rect.h);
|
||||||
lv_obj_enable_style_refresh(true);
|
lv_obj_enable_style_refresh(true);
|
||||||
lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY);
|
lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setWidth(coord_t value)
|
void setWidth(coord_t value)
|
||||||
{
|
{
|
||||||
rect.w = value;
|
rect.w = value;
|
||||||
lv_obj_set_width(lvobj, rect.w);
|
lv_obj_set_width(lvobj, rect.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setHeight(coord_t value)
|
void setHeight(coord_t value)
|
||||||
{
|
{
|
||||||
rect.h = value;
|
rect.h = value;
|
||||||
lv_obj_set_height(lvobj, rect.h);
|
lv_obj_set_height(lvobj, rect.h);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLeft(coord_t x)
|
void setLeft(coord_t x)
|
||||||
{
|
{
|
||||||
rect.x = x;
|
rect.x = x;
|
||||||
lv_obj_set_pos(lvobj, rect.x, rect.y);
|
lv_obj_set_pos(lvobj, rect.x, rect.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTop(coord_t y)
|
void setTop(coord_t y)
|
||||||
{
|
{
|
||||||
rect.y = y;
|
rect.y = y;
|
||||||
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);
|
||||||
void padTop(coord_t pad);
|
void padTop(coord_t pad);
|
||||||
void padBottom(coord_t pad);
|
void padBottom(coord_t pad);
|
||||||
void padAll(coord_t pad);
|
void padAll(coord_t pad);
|
||||||
|
|
||||||
void padRow(coord_t pad);
|
void padRow(coord_t pad);
|
||||||
void padColumn(coord_t pad);
|
void padColumn(coord_t pad);
|
||||||
|
|
||||||
virtual void onEvent(event_t event);
|
virtual void onEvent(event_t event);
|
||||||
virtual void onClicked();
|
virtual void onClicked();
|
||||||
virtual void onCancel();
|
virtual void onCancel();
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
virtual void checkEvents();
|
virtual void checkEvents();
|
||||||
|
|
||||||
void attach(Window * window);
|
void attach(Window *window);
|
||||||
|
|
||||||
void detach();
|
void detach();
|
||||||
|
|
||||||
bool deleted() const
|
bool deleted() const { return _deleted; }
|
||||||
{
|
|
||||||
return _deleted;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void paint(BitmapBuffer *) {}
|
virtual void paint(BitmapBuffer *) {}
|
||||||
|
|
||||||
#if defined(HARDWARE_TOUCH)
|
#if defined(HARDWARE_TOUCH)
|
||||||
virtual bool onTouchStart(coord_t x, coord_t y);
|
virtual bool onTouchStart(coord_t x, coord_t y);
|
||||||
virtual bool onTouchEnd(coord_t x, coord_t y);
|
virtual bool onTouchEnd(coord_t x, coord_t y);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline lv_obj_t *getLvObj() { return lvobj; }
|
inline lv_obj_t *getLvObj() { return lvobj; }
|
||||||
|
|
||||||
virtual bool isTopBar() { return false; }
|
virtual bool isTopBar() { return false; }
|
||||||
virtual bool isWidgetsContainer() { return false; }
|
virtual bool isWidgetsContainer() { return false; }
|
||||||
|
|
||||||
virtual bool isBubblePopup() { return false; }
|
virtual bool isBubblePopup() { return false; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static std::list<Window*> trash;
|
static std::list<Window *> trash;
|
||||||
|
|
||||||
rect_t rect;
|
rect_t rect;
|
||||||
|
|
||||||
Window* parent = nullptr;
|
Window *parent = nullptr;
|
||||||
lv_obj_t* lvobj = nullptr;
|
lv_obj_t *lvobj = nullptr;
|
||||||
|
|
||||||
std::list<Window *> children;
|
std::list<Window *> children;
|
||||||
|
|
||||||
WindowFlags windowFlags = 0;
|
WindowFlags windowFlags = 0;
|
||||||
LcdFlags textFlags = 0;
|
LcdFlags textFlags = 0;
|
||||||
|
|
||||||
bool _deleted = false;
|
bool _deleted = false;
|
||||||
|
|
||||||
std::function<void()> closeHandler;
|
std::function<void()> closeHandler;
|
||||||
std::function<void(bool)> focusHandler;
|
std::function<void(bool)> focusHandler;
|
||||||
|
|
||||||
void deleteChildren();
|
void deleteChildren();
|
||||||
|
|
||||||
virtual void addChild(Window * window);
|
virtual void addChild(Window *window);
|
||||||
void removeChild(Window * window);
|
void removeChild(Window *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;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user