feat(color): Improved hardware key navigation (TELE) (#4219)
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "menu_model.h"
|
||||
|
||||
#include "menu_radio.h"
|
||||
#include "menu_screen.h"
|
||||
#include "model_curves.h"
|
||||
#include "model_flightmodes.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)
|
||||
void ModelMenu::addGoToMonitorsButton()
|
||||
{
|
||||
@@ -132,3 +109,29 @@ void ModelMenu::addGoToMonitorsButton()
|
||||
});
|
||||
}
|
||||
#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 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_model.h"
|
||||
#include "menu_screen.h"
|
||||
#include "model_select.h"
|
||||
#include "myeeprom.h"
|
||||
#include "opentx.h"
|
||||
@@ -34,6 +35,7 @@
|
||||
#include "radio_trainer.h"
|
||||
#include "radio_version.h"
|
||||
#include "special_functions.h"
|
||||
#include "view_channels.h"
|
||||
|
||||
RadioMenu::RadioMenu() : TabsGroup(ICON_RADIO) { build(); }
|
||||
|
||||
@@ -70,18 +72,27 @@ void RadioMenu::checkEvents()
|
||||
}
|
||||
}
|
||||
|
||||
void RadioMenu::onEvent(event_t event)
|
||||
{
|
||||
#if defined(HARDWARE_KEYS)
|
||||
if (event == EVT_KEY_BREAK(KEY_MODEL)) {
|
||||
onCancel();
|
||||
new ModelMenu();
|
||||
} else if (event == EVT_KEY_LONG(KEY_MODEL)) {
|
||||
onCancel();
|
||||
killEvents(KEY_MODEL);
|
||||
new ModelLabelsWindow();
|
||||
} else {
|
||||
TabsGroup::onEvent(event);
|
||||
}
|
||||
#endif
|
||||
void RadioMenu::onPressSYS() { setCurrentTab(0); }
|
||||
void RadioMenu::onLongPressSYS() { setCurrentTab(2); }
|
||||
void RadioMenu::onPressMDL()
|
||||
{
|
||||
onCancel();
|
||||
new ModelMenu();
|
||||
}
|
||||
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 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.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include "menu_screen.h"
|
||||
#include "screen_setup.h"
|
||||
#include "view_main.h"
|
||||
#include "storage/storage.h"
|
||||
|
||||
ScreenMenu::ScreenMenu(int8_t tabIdx):
|
||||
TabsGroup(ICON_THEME)
|
||||
#include "menu_model.h"
|
||||
#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);
|
||||
|
||||
setCloseHandler([]{
|
||||
ViewMain::instance()->updateTopbarVisibility();
|
||||
storageDirty(EE_MODEL);
|
||||
setCloseHandler([] {
|
||||
ViewMain::instance()->updateTopbarVisibility();
|
||||
storageDirty(EE_MODEL);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -46,13 +50,10 @@ void ScreenMenu::updateTabs(int8_t tabIdx)
|
||||
if (customScreens[index]) {
|
||||
auto tab = new ScreenSetupPage(this, getTabs(), index);
|
||||
std::string title(STR_MAIN_VIEW_X);
|
||||
if (index >= 9)
|
||||
{
|
||||
if (index >= 9) {
|
||||
title[title.size() - 2] = '1';
|
||||
title.back() = (index - 9) + '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
title[title.size() - 2] = index + '1';
|
||||
title.back() = ' ';
|
||||
}
|
||||
@@ -60,8 +61,7 @@ void ScreenMenu::updateTabs(int8_t tabIdx)
|
||||
tab->setIcon(ICON_THEME_VIEW1 + index);
|
||||
|
||||
addTab(tab);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
addTab(new ScreenAddPage(this, getTabs()));
|
||||
break;
|
||||
}
|
||||
@@ -77,3 +77,32 @@ void ScreenMenu::updateTabs(int8_t tabIdx)
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef _MENU_SCREEN_H_
|
||||
#define _MENU_SCREEN_H_
|
||||
#pragma once
|
||||
|
||||
#include "tabsgroup.h"
|
||||
|
||||
@@ -29,6 +28,13 @@ class ScreenMenu : public TabsGroup
|
||||
public:
|
||||
ScreenMenu(int8_t tabIdx = -1);
|
||||
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 "menu_model.h"
|
||||
#include "menu_radio.h"
|
||||
#include "menu_screen.h"
|
||||
#include "model_templates.h"
|
||||
#include "opentx.h"
|
||||
#include "standalone_lua.h"
|
||||
#include "str_functions.h"
|
||||
#include "view_channels.h"
|
||||
|
||||
// bitmaps for toolbar
|
||||
const uint8_t _mask_sort_alpha_up[] = {
|
||||
@@ -661,49 +663,57 @@ ModelLabelsWindow::ModelLabelsWindow() : Page(ICON_MODEL)
|
||||
}
|
||||
|
||||
#if defined(HARDWARE_KEYS)
|
||||
void ModelLabelsWindow::onEvent(event_t event)
|
||||
void ModelLabelsWindow::onPressSYS()
|
||||
{
|
||||
#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> 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);
|
||||
}
|
||||
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)
|
||||
{
|
||||
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
|
||||
|
||||
void ModelLabelsWindow::newModel()
|
||||
|
||||
@@ -93,10 +93,6 @@ class ModelLabelsWindow : public Page
|
||||
return labels;
|
||||
}
|
||||
|
||||
#if defined(HARDWARE_KEYS)
|
||||
void onEvent(event_t event) override;
|
||||
#endif
|
||||
|
||||
void newModel();
|
||||
void newLabel();
|
||||
void buildHead(PageHeader *window);
|
||||
@@ -104,6 +100,17 @@ class ModelLabelsWindow : public Page
|
||||
void updateFilteredLabels(std::set<uint32_t> selected, bool setdirty = true);
|
||||
void labelRefreshRequest();
|
||||
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_
|
||||
|
||||
@@ -67,7 +67,7 @@ static constexpr rect_t _get_body_rect()
|
||||
}
|
||||
|
||||
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),
|
||||
body(this, _get_body_rect())
|
||||
{
|
||||
@@ -97,8 +97,3 @@ void Page::onClicked()
|
||||
{
|
||||
Keyboard::hide();
|
||||
}
|
||||
|
||||
void Page::onEvent(event_t event)
|
||||
{
|
||||
// block event bubbling
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class PageHeader : public FormWindow
|
||||
StaticText* title2 = nullptr;
|
||||
};
|
||||
|
||||
class Page : public Window
|
||||
class Page : public NavWindow
|
||||
{
|
||||
public:
|
||||
explicit Page(unsigned icon);
|
||||
@@ -63,7 +63,7 @@ class Page : public Window
|
||||
PageHeader header;
|
||||
FormWindow body;
|
||||
|
||||
void onEvent(event_t event) override;
|
||||
bool bubbleEvents() override { return false; }
|
||||
};
|
||||
|
||||
#endif // _PAGE_H_
|
||||
|
||||
@@ -135,7 +135,7 @@ static constexpr rect_t _get_body_rect()
|
||||
TabsGroup* TabsGroup::activeTabsGroup = nullptr;
|
||||
|
||||
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),
|
||||
body(this, _get_body_rect(), NO_FOCUS)
|
||||
{
|
||||
@@ -264,32 +264,18 @@ void TabsGroup::checkEvents()
|
||||
}
|
||||
}
|
||||
|
||||
void TabsGroup::onEvent(event_t event)
|
||||
{
|
||||
#if defined(HARDWARE_KEYS)
|
||||
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(),
|
||||
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();
|
||||
setCurrentTab(current == 0 ? tabs.size() - 1 : current - 1);
|
||||
}
|
||||
#endif
|
||||
void TabsGroup::onPressPGUP()
|
||||
{
|
||||
uint8_t current = header.carousel.getCurrentIndex();
|
||||
setCurrentTab(current == 0 ? tabs.size() - 1 : current - 1);
|
||||
}
|
||||
void TabsGroup::onPressPGDN()
|
||||
{
|
||||
uint8_t current = header.carousel.getCurrentIndex() + 1;
|
||||
setCurrentTab(current >= tabs.size() ? 0 : current);
|
||||
}
|
||||
#endif
|
||||
|
||||
void TabsGroup::onClicked() { Keyboard::hide(); }
|
||||
|
||||
|
||||
+137
-157
@@ -21,67 +21,56 @@
|
||||
#define _TABSGROUP_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "button.h"
|
||||
#include "form.h"
|
||||
#include "keyboard_base.h"
|
||||
|
||||
class TabsGroup;
|
||||
|
||||
class PageTab {
|
||||
class PageTab
|
||||
{
|
||||
friend class TabsCarousel;
|
||||
friend class TabsGroup;
|
||||
|
||||
public:
|
||||
PageTab()
|
||||
{
|
||||
}
|
||||
public:
|
||||
PageTab() {}
|
||||
|
||||
PageTab(std::string title, unsigned icon):
|
||||
title(std::move(title)),
|
||||
icon(icon)
|
||||
{
|
||||
}
|
||||
PageTab(std::string title, unsigned icon) :
|
||||
title(std::move(title)), 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)
|
||||
{
|
||||
onSetVisible = std::move(handler);
|
||||
}
|
||||
void setOnSetVisibleHandler(std::function<void()> handler)
|
||||
{
|
||||
onSetVisible = std::move(handler);
|
||||
}
|
||||
|
||||
void setTitle(std::string value)
|
||||
{
|
||||
title = std::move(value);
|
||||
}
|
||||
void setTitle(std::string value) { title = std::move(value); }
|
||||
|
||||
void setIcon(unsigned icon)
|
||||
{
|
||||
this->icon = icon;
|
||||
}
|
||||
void setIcon(unsigned icon) { this->icon = icon; }
|
||||
|
||||
unsigned getIcon() const
|
||||
{
|
||||
return icon;
|
||||
}
|
||||
unsigned getIcon() const { return icon; }
|
||||
|
||||
protected:
|
||||
std::string title;
|
||||
unsigned icon = 0;
|
||||
std::function<void()> onSetVisible;
|
||||
protected:
|
||||
std::string title;
|
||||
unsigned icon = 0;
|
||||
std::function<void()> onSetVisible;
|
||||
};
|
||||
|
||||
class TabCarouselButton: public Button
|
||||
class TabCarouselButton : public Button
|
||||
{
|
||||
public:
|
||||
TabCarouselButton(Window* parent, const rect_t& rect, std::vector<PageTab *>& tabs, uint8_t index,
|
||||
std::function<uint8_t(void)> pressHandler,
|
||||
WindowFlags flags = 0);
|
||||
public:
|
||||
TabCarouselButton(Window* parent, const rect_t& rect,
|
||||
std::vector<PageTab*>& tabs, uint8_t index,
|
||||
std::function<uint8_t(void)> pressHandler,
|
||||
WindowFlags flags = 0);
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const override
|
||||
@@ -90,143 +79,134 @@ public:
|
||||
}
|
||||
#endif
|
||||
|
||||
void paint(BitmapBuffer * dc);
|
||||
void paint(BitmapBuffer* dc);
|
||||
|
||||
void check(bool checked = true);
|
||||
|
||||
protected:
|
||||
std::vector<PageTab *> tabs;
|
||||
protected:
|
||||
std::vector<PageTab*> tabs;
|
||||
uint8_t index;
|
||||
};
|
||||
|
||||
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
|
||||
class TabsCarousel : public Window
|
||||
{
|
||||
friend class TabsCarousel;
|
||||
|
||||
public:
|
||||
explicit TabsGroup(uint8_t icon);
|
||||
~TabsGroup() override;
|
||||
|
||||
void deleteLater(bool detach = true, bool trash = true) override;
|
||||
public:
|
||||
TabsCarousel(Window* parent, TabsGroup* menu);
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const override
|
||||
{
|
||||
return "TabsGroup";
|
||||
}
|
||||
std::string getName() const override { return "TabsCarousel"; }
|
||||
#endif
|
||||
|
||||
unsigned getTabs() const
|
||||
{
|
||||
return tabs.size();
|
||||
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 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);
|
||||
}
|
||||
|
||||
// Return the index of the found tab
|
||||
// or -1 if the tab could not be found
|
||||
int removeTab(PageTab * page);
|
||||
void checkEvents() override;
|
||||
|
||||
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;
|
||||
void onClicked() override;
|
||||
void onCancel() override;
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
bool onTouchEnd(coord_t x, coord_t y) override;
|
||||
bool onTouchEnd(coord_t x, coord_t y) override;
|
||||
#endif
|
||||
|
||||
static void refreshTheme();
|
||||
static void refreshTheme();
|
||||
|
||||
protected:
|
||||
TabsGroupHeader header;
|
||||
FormWindow body;
|
||||
std::vector<PageTab *> tabs;
|
||||
PageTab * currentTab = nullptr;
|
||||
static TabsGroup* activeTabsGroup;
|
||||
protected:
|
||||
TabsGroupHeader header;
|
||||
FormWindow body;
|
||||
std::vector<PageTab*> tabs;
|
||||
PageTab* currentTab = nullptr;
|
||||
static TabsGroup* activeTabsGroup;
|
||||
|
||||
void setVisibleTab(PageTab * tab);
|
||||
void setVisibleTab(PageTab* tab);
|
||||
|
||||
#if defined(HARDWARE_KEYS)
|
||||
void onPressPGUP() override;
|
||||
void onPressPGDN() override;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "libopenui.h"
|
||||
#include "menu_model.h"
|
||||
#include "menu_radio.h"
|
||||
#include "menu_screen.h"
|
||||
#include "model_select.h"
|
||||
#include "opentx.h"
|
||||
#include "view_logical_switches.h"
|
||||
@@ -41,35 +42,40 @@ ChannelsViewMenu::ChannelsViewMenu(ModelMenu* parent) :
|
||||
addTab(new LogicalSwitchesViewPage());
|
||||
}
|
||||
|
||||
void ChannelsViewMenu::onEvent(event_t event)
|
||||
{
|
||||
#if defined(HARDWARE_KEYS)
|
||||
if (event == EVT_KEY_BREAK(KEY_MODEL)) {
|
||||
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)) {
|
||||
void ChannelsViewMenu::onPressSYS()
|
||||
{
|
||||
onCancel();
|
||||
if (parentMenu) parentMenu->onCancel();
|
||||
new RadioMenu();
|
||||
} else if (event == EVT_KEY_LONG(KEY_SYS)) {
|
||||
killEvents(KEY_SYS);
|
||||
}
|
||||
void ChannelsViewMenu::onLongPressSYS()
|
||||
{
|
||||
onCancel();
|
||||
if (parentMenu) parentMenu->onCancel();
|
||||
// Radio setup
|
||||
(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
|
||||
{
|
||||
|
||||
@@ -47,5 +47,11 @@ class ChannelsViewMenu: public TabsGroup {
|
||||
protected:
|
||||
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 "model_select.h"
|
||||
|
||||
#include "menu_model.h"
|
||||
#include "menu_radio.h"
|
||||
#include "menu_screen.h"
|
||||
#include "topbar_impl.h"
|
||||
#include "view_main_menu.h"
|
||||
#include "theme.h"
|
||||
|
||||
#include "model_select.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)
|
||||
{
|
||||
@@ -38,7 +39,9 @@ static void tile_view_deleted_cb(lv_event_t* e)
|
||||
|
||||
// LV_EVENT_CHILD_DELETED is bubbled to all parents, so
|
||||
// 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)
|
||||
@@ -64,10 +67,10 @@ static void tile_view_scroll(lv_event_t* e)
|
||||
}
|
||||
}
|
||||
|
||||
ViewMain * ViewMain::_instance = nullptr;
|
||||
ViewMain* ViewMain::_instance = nullptr;
|
||||
|
||||
ViewMain::ViewMain():
|
||||
Window(MainWindow::instance(), MainWindow::instance()->getRect(), OPAQUE)
|
||||
ViewMain::ViewMain() :
|
||||
NavWindow(MainWindow::instance(), MainWindow::instance()->getRect(), OPAQUE)
|
||||
{
|
||||
Layer::push(this);
|
||||
|
||||
@@ -81,17 +84,16 @@ ViewMain::ViewMain():
|
||||
lv_obj_add_flag(tile_view, LV_OBJ_FLAG_EVENT_BUBBLE);
|
||||
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_END, nullptr);
|
||||
lv_obj_add_event_cb(lvobj, ViewMain::long_pressed, LV_EVENT_LONG_PRESSED, nullptr);
|
||||
|
||||
lv_obj_add_event_cb(tile_view, tile_view_scroll, LV_EVENT_SCROLL_END,
|
||||
nullptr);
|
||||
lv_obj_add_event_cb(lvobj, ViewMain::long_pressed, LV_EVENT_LONG_PRESSED,
|
||||
nullptr);
|
||||
|
||||
// create last to be on top
|
||||
topbar = TopbarFactory::create(this);
|
||||
}
|
||||
|
||||
ViewMain::~ViewMain()
|
||||
{
|
||||
_instance = nullptr;
|
||||
}
|
||||
ViewMain::~ViewMain() { _instance = nullptr; }
|
||||
|
||||
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);
|
||||
|
||||
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();
|
||||
lv_obj_set_parent(view_obj, tile);
|
||||
|
||||
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)
|
||||
{
|
||||
topbar->setVisible(visible);
|
||||
}
|
||||
void ViewMain::setTopbarVisible(float visible) { topbar->setVisible(visible); }
|
||||
|
||||
unsigned ViewMain::getMainViewsCount() const
|
||||
{
|
||||
@@ -127,7 +128,7 @@ rect_t ViewMain::getMainZone(rect_t zone, bool hasTopbar) const
|
||||
auto visibleHeight = topbar->getVisibleHeight(hasTopbar ? 1.0 : 0.0);
|
||||
zone.y += visibleHeight;
|
||||
zone.h -= visibleHeight;
|
||||
|
||||
|
||||
return zone;
|
||||
}
|
||||
|
||||
@@ -141,16 +142,12 @@ void ViewMain::setCurrentMainView(unsigned viewId)
|
||||
lv_obj_set_tile_id(tile_view, viewId, 0, LV_ANIM_OFF);
|
||||
}
|
||||
|
||||
void setRequestedMainView(uint8_t view)
|
||||
{
|
||||
g_model.view = view;
|
||||
}
|
||||
void setRequestedMainView(uint8_t view) { g_model.view = view; }
|
||||
|
||||
void ViewMain::nextMainView()
|
||||
{
|
||||
auto view = getCurrentMainView();
|
||||
if (++view >= getMainViewsCount())
|
||||
view = 0;
|
||||
if (++view >= getMainViewsCount()) view = 0;
|
||||
|
||||
setCurrentMainView(view);
|
||||
saveViewId(view);
|
||||
@@ -160,7 +157,7 @@ void ViewMain::previousMainView()
|
||||
{
|
||||
auto view = getCurrentMainView();
|
||||
if (view > 0)
|
||||
view--;
|
||||
view--;
|
||||
else
|
||||
view = getMainViewsCount() - 1;
|
||||
|
||||
@@ -168,10 +165,7 @@ void ViewMain::previousMainView()
|
||||
saveViewId(view);
|
||||
}
|
||||
|
||||
TopBar* ViewMain::getTopbar()
|
||||
{
|
||||
return topbar;
|
||||
}
|
||||
TopBar* ViewMain::getTopbar() { return topbar; }
|
||||
|
||||
static bool hasTopbar(unsigned view)
|
||||
{
|
||||
@@ -205,34 +199,30 @@ void ViewMain::updateTopbarVisibility()
|
||||
coord_t pageWidth = width();
|
||||
if (!pageWidth) return;
|
||||
|
||||
int leftScroll = scrollPos % width();
|
||||
int leftScroll = scrollPos % width();
|
||||
if (leftScroll == 0) {
|
||||
int view = scrollPos / pageWidth;
|
||||
setTopbarVisible(hasTopbar(view));
|
||||
if (customScreens[view])
|
||||
customScreens[view]->adjustLayout();
|
||||
}
|
||||
else {
|
||||
int leftIdx = scrollPos / pageWidth;
|
||||
bool leftTopbar = hasTopbar(leftIdx);
|
||||
bool rightTopbar = hasTopbar(leftIdx+1);
|
||||
if (customScreens[view]) customScreens[view]->adjustLayout();
|
||||
} else {
|
||||
int leftIdx = scrollPos / pageWidth;
|
||||
bool leftTopbar = hasTopbar(leftIdx);
|
||||
bool rightTopbar = hasTopbar(leftIdx + 1);
|
||||
|
||||
if (leftTopbar != rightTopbar) {
|
||||
|
||||
float ratio = (float)leftScroll / (float)pageWidth;
|
||||
|
||||
if (leftTopbar) {
|
||||
// scrolling from a screen with Topbar
|
||||
ratio = 1.0 - ratio;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// scrolling to a screen with Topbar
|
||||
// -> ratio is ok
|
||||
}
|
||||
|
||||
setTopbarVisible(ratio);
|
||||
customScreens[leftIdx]->adjustLayout();
|
||||
customScreens[leftIdx+1]->adjustLayout();
|
||||
customScreens[leftIdx + 1]->adjustLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -241,75 +231,59 @@ void ViewMain::updateTopbarVisibility()
|
||||
void ViewMain::updateFromTheme()
|
||||
{
|
||||
for (int i = 0; i < MAX_CUSTOM_SCREENS; i += 1) {
|
||||
if (customScreens[i])
|
||||
customScreens[i]->updateFromTheme();
|
||||
if (customScreens[i]) customScreens[i]->updateFromTheme();
|
||||
}
|
||||
}
|
||||
|
||||
void ViewMain::onEvent(event_t event)
|
||||
{
|
||||
#if defined(HARDWARE_KEYS)
|
||||
switch (event) {
|
||||
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()
|
||||
void ViewMain::onPressSYS()
|
||||
{
|
||||
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()
|
||||
{
|
||||
@@ -335,12 +309,10 @@ bool ViewMain::enableWidgetSelect(bool enable)
|
||||
widget_select = enable;
|
||||
|
||||
lv_obj_t* tile = lv_tileview_get_tile_act(tile_view);
|
||||
if(!tile)
|
||||
return true;
|
||||
if (!tile) return true;
|
||||
|
||||
auto cont_obj = lv_obj_get_child(tile, 0);
|
||||
if(!cont_obj)
|
||||
return true;
|
||||
if (!cont_obj) return true;
|
||||
|
||||
auto cont = (WidgetsContainer*)lv_obj_get_user_data(cont_obj);
|
||||
|
||||
@@ -376,15 +348,13 @@ bool ViewMain::enableWidgetSelect(bool enable)
|
||||
|
||||
void ViewMain::openMenu()
|
||||
{
|
||||
viewMainMenu = new ViewMainMenu(this, [=]() {
|
||||
viewMainMenu = nullptr;
|
||||
});
|
||||
viewMainMenu = new ViewMainMenu(this, [=]() { viewMainMenu = nullptr; });
|
||||
}
|
||||
|
||||
void ViewMain::paint(BitmapBuffer * dc)
|
||||
void ViewMain::paint(BitmapBuffer* dc)
|
||||
{
|
||||
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
|
||||
EdgeTxTheme::instance()->drawBackground(dc);
|
||||
|
||||
@@ -23,90 +23,96 @@
|
||||
#define _VIEW_MAIN_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "form.h"
|
||||
#include "topbar.h"
|
||||
|
||||
|
||||
class SetupWidgetsPage;
|
||||
class SetupTopBarWidgetsPage;
|
||||
class ViewMainMenu;
|
||||
|
||||
class ViewMain: public Window
|
||||
class ViewMain : public NavWindow
|
||||
{
|
||||
// singleton
|
||||
explicit ViewMain();
|
||||
// singleton
|
||||
explicit ViewMain();
|
||||
|
||||
public:
|
||||
~ViewMain() override;
|
||||
public:
|
||||
~ViewMain() override;
|
||||
|
||||
static ViewMain * instance()
|
||||
{
|
||||
if (!_instance)
|
||||
_instance = new ViewMain();
|
||||
static ViewMain* instance()
|
||||
{
|
||||
if (!_instance) _instance = new ViewMain();
|
||||
|
||||
return _instance;
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
static ViewMain* getInstance() { return _instance; }
|
||||
static ViewMain* getInstance() { return _instance; }
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const override
|
||||
{
|
||||
return "ViewMain";
|
||||
}
|
||||
std::string getName() const override { return "ViewMain"; }
|
||||
#endif
|
||||
|
||||
void addMainView(Window* view, uint32_t viewId);
|
||||
void addMainView(Window* view, uint32_t viewId);
|
||||
|
||||
void enableTopbar();
|
||||
void disableTopbar();
|
||||
void updateTopbarVisibility();
|
||||
bool enableWidgetSelect(bool enable);
|
||||
|
||||
// Update after theme loaded / changed
|
||||
void updateFromTheme();
|
||||
void enableTopbar();
|
||||
void disableTopbar();
|
||||
void updateTopbarVisibility();
|
||||
bool enableWidgetSelect(bool enable);
|
||||
|
||||
// Get the available space in the middle of the screen
|
||||
// (without topbar)
|
||||
rect_t getMainZone(rect_t zone, bool hasTopbar) const;
|
||||
// Update after theme loaded / changed
|
||||
void updateFromTheme();
|
||||
|
||||
unsigned getMainViewsCount() const;
|
||||
unsigned getCurrentMainView() const;
|
||||
void setCurrentMainView(unsigned view);
|
||||
// Get the available space in the middle of the screen
|
||||
// (without topbar)
|
||||
rect_t getMainZone(rect_t zone, bool hasTopbar) const;
|
||||
|
||||
void nextMainView();
|
||||
void previousMainView();
|
||||
unsigned getMainViewsCount() const;
|
||||
unsigned getCurrentMainView() const;
|
||||
void setCurrentMainView(unsigned view);
|
||||
|
||||
TopBar* getTopbar();
|
||||
void nextMainView();
|
||||
void previousMainView();
|
||||
|
||||
void onEvent(event_t event) override;
|
||||
void onClicked() override;
|
||||
void onCancel() override;
|
||||
TopBar* getTopbar();
|
||||
|
||||
protected:
|
||||
static ViewMain * _instance;
|
||||
void onClicked() override;
|
||||
void onCancel() override;
|
||||
|
||||
lv_obj_t* tile_view = nullptr;
|
||||
TopBar* topbar = nullptr;
|
||||
bool widget_select = false;
|
||||
lv_timer_t* widget_select_timer = nullptr;
|
||||
ViewMainMenu* viewMainMenu = nullptr;
|
||||
protected:
|
||||
static ViewMain* _instance;
|
||||
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
void deleteLater(bool detach = true, bool trash = true) override;
|
||||
lv_obj_t* tile_view = nullptr;
|
||||
TopBar* topbar = nullptr;
|
||||
bool widget_select = false;
|
||||
lv_timer_t* widget_select_timer = nullptr;
|
||||
ViewMainMenu* viewMainMenu = nullptr;
|
||||
|
||||
// Widget setup requires special permissions ;-)
|
||||
friend class SetupWidgetsPage;
|
||||
friend class SetupTopBarWidgetsPage;
|
||||
void paint(BitmapBuffer* dc) override;
|
||||
void deleteLater(bool detach = true, bool trash = true) override;
|
||||
|
||||
// Set topbar visibility [0.0 -> 1.0]
|
||||
void setTopbarVisible(float visible);
|
||||
// Widget setup requires special permissions ;-)
|
||||
friend class SetupWidgetsPage;
|
||||
friend class SetupTopBarWidgetsPage;
|
||||
|
||||
void openMenu();
|
||||
void refreshWidgetSelectTimer();
|
||||
// Set topbar visibility [0.0 -> 1.0]
|
||||
void setTopbarVisible(float visible);
|
||||
|
||||
static void long_pressed(lv_event_t* e);
|
||||
static void ws_timer(lv_timer_t* t);
|
||||
void openMenu();
|
||||
void refreshWidgetSelectTimer();
|
||||
|
||||
static void long_pressed(lv_event_t* e);
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
+135
-139
@@ -18,216 +18,212 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <functional>
|
||||
|
||||
#include "LvglWrapper.h"
|
||||
#include "bitmapbuffer.h"
|
||||
#include "libopenui_defines.h"
|
||||
#include "opentx_helpers.h"
|
||||
|
||||
#include "widgets/etx_obj_create.h"
|
||||
|
||||
#include "LvglWrapper.h"
|
||||
|
||||
typedef uint32_t WindowFlags;
|
||||
|
||||
#if !defined(_GNUC_)
|
||||
#undef OPAQUE
|
||||
#undef TRANSPARENT
|
||||
#undef OPAQUE
|
||||
#undef TRANSPARENT
|
||||
#endif
|
||||
|
||||
constexpr WindowFlags OPAQUE = 1u << 0u;
|
||||
constexpr WindowFlags TRANSPARENT = 1u << 1u;
|
||||
constexpr WindowFlags NO_FOCUS = 1u << 2u;
|
||||
constexpr WindowFlags REFRESH_ALWAYS = 1u << 3u;
|
||||
constexpr WindowFlags WINDOW_FLAGS_LAST = REFRESH_ALWAYS;
|
||||
constexpr WindowFlags OPAQUE = 1u << 0u;
|
||||
constexpr WindowFlags TRANSPARENT = 1u << 1u;
|
||||
constexpr WindowFlags NO_FOCUS = 1u << 2u;
|
||||
constexpr WindowFlags REFRESH_ALWAYS = 1u << 3u;
|
||||
constexpr WindowFlags WINDOW_FLAGS_LAST = REFRESH_ALWAYS;
|
||||
|
||||
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
|
||||
{
|
||||
friend void window_event_cb(lv_event_t * e);
|
||||
friend void window_event_cb(lv_event_t *e);
|
||||
|
||||
public:
|
||||
Window(Window *parent, const rect_t &rect, WindowFlags windowFlags = 0,
|
||||
LcdFlags textFlags = 0, LvglCreate objConstruct = nullptr);
|
||||
public:
|
||||
Window(Window *parent, const rect_t &rect, WindowFlags windowFlags = 0,
|
||||
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)
|
||||
virtual std::string getName() const;
|
||||
std::string getRectString() const;
|
||||
std::string getIndentString() const;
|
||||
std::string getWindowDebugString(const char * name = nullptr) const;
|
||||
virtual std::string getName() const;
|
||||
std::string getRectString() const;
|
||||
std::string getIndentString() const;
|
||||
std::string getWindowDebugString(const char *name = nullptr) const;
|
||||
#endif
|
||||
|
||||
Window *getParent() const { return parent; }
|
||||
Window *getParent() const { return parent; }
|
||||
|
||||
Window *getFullScreenWindow();
|
||||
Window *getFullScreenWindow();
|
||||
|
||||
WindowFlags getWindowFlags() const { return windowFlags; }
|
||||
void setWindowFlags(WindowFlags flags);
|
||||
WindowFlags getWindowFlags() const { return windowFlags; }
|
||||
void setWindowFlags(WindowFlags flags);
|
||||
|
||||
LcdFlags getTextFlags() const { return textFlags; }
|
||||
void setTextFlags(LcdFlags flags);
|
||||
LcdFlags getTextFlags() const { return textFlags; }
|
||||
void setTextFlags(LcdFlags flags);
|
||||
|
||||
typedef std::function<void()> CloseHandler;
|
||||
void setCloseHandler(CloseHandler h) { closeHandler = std::move(h); }
|
||||
typedef std::function<void()> CloseHandler;
|
||||
void setCloseHandler(CloseHandler h) { closeHandler = std::move(h); }
|
||||
|
||||
typedef std::function<void(bool)> FocusHandler;
|
||||
void setFocusHandler(FocusHandler h) { focusHandler = std::move(h); }
|
||||
typedef std::function<void(bool)> FocusHandler;
|
||||
void setFocusHandler(FocusHandler h) { focusHandler = std::move(h); }
|
||||
|
||||
void clear();
|
||||
virtual void deleteLater(bool detach = true, bool trash = true);
|
||||
void clear();
|
||||
virtual void deleteLater(bool detach = true, bool trash = true);
|
||||
|
||||
bool hasFocus() const;
|
||||
bool hasFocus() const;
|
||||
|
||||
void setRect(rect_t value)
|
||||
{
|
||||
rect = value;
|
||||
lv_obj_enable_style_refresh(false);
|
||||
lv_obj_set_pos(lvobj, rect.x, rect.y);
|
||||
lv_obj_set_size(lvobj, rect.w, rect.h);
|
||||
lv_obj_enable_style_refresh(true);
|
||||
lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY);
|
||||
}
|
||||
void setRect(rect_t value)
|
||||
{
|
||||
rect = value;
|
||||
lv_obj_enable_style_refresh(false);
|
||||
lv_obj_set_pos(lvobj, rect.x, rect.y);
|
||||
lv_obj_set_size(lvobj, rect.w, rect.h);
|
||||
lv_obj_enable_style_refresh(true);
|
||||
lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY);
|
||||
}
|
||||
|
||||
void setWidth(coord_t value)
|
||||
{
|
||||
rect.w = value;
|
||||
lv_obj_set_width(lvobj, rect.w);
|
||||
}
|
||||
void setWidth(coord_t value)
|
||||
{
|
||||
rect.w = value;
|
||||
lv_obj_set_width(lvobj, rect.w);
|
||||
}
|
||||
|
||||
void setHeight(coord_t value)
|
||||
{
|
||||
rect.h = value;
|
||||
lv_obj_set_height(lvobj, rect.h);
|
||||
}
|
||||
void setHeight(coord_t value)
|
||||
{
|
||||
rect.h = value;
|
||||
lv_obj_set_height(lvobj, rect.h);
|
||||
}
|
||||
|
||||
void setLeft(coord_t x)
|
||||
{
|
||||
rect.x = x;
|
||||
lv_obj_set_pos(lvobj, rect.x, rect.y);
|
||||
}
|
||||
void setLeft(coord_t x)
|
||||
{
|
||||
rect.x = x;
|
||||
lv_obj_set_pos(lvobj, rect.x, rect.y);
|
||||
}
|
||||
|
||||
void setTop(coord_t y)
|
||||
{
|
||||
rect.y = y;
|
||||
lv_obj_set_pos(lvobj, rect.x, rect.y);
|
||||
}
|
||||
void setTop(coord_t y)
|
||||
{
|
||||
rect.y = y;
|
||||
lv_obj_set_pos(lvobj, rect.x, rect.y);
|
||||
}
|
||||
|
||||
coord_t left() const
|
||||
{
|
||||
return rect.x;
|
||||
}
|
||||
coord_t left() const { return rect.x; }
|
||||
|
||||
coord_t right() const
|
||||
{
|
||||
return rect.x + rect.w;
|
||||
}
|
||||
coord_t right() const { return rect.x + rect.w; }
|
||||
|
||||
coord_t top() const
|
||||
{
|
||||
return rect.y;
|
||||
}
|
||||
coord_t top() const { return rect.y; }
|
||||
|
||||
coord_t bottom() const
|
||||
{
|
||||
return rect.y + rect.h;
|
||||
}
|
||||
coord_t bottom() const { return rect.y + rect.h; }
|
||||
|
||||
coord_t width() const
|
||||
{
|
||||
return rect.w;
|
||||
}
|
||||
coord_t width() const { return rect.w; }
|
||||
|
||||
coord_t height() const
|
||||
{
|
||||
return rect.h;
|
||||
}
|
||||
coord_t height() const { return rect.h; }
|
||||
|
||||
rect_t getRect() const
|
||||
{
|
||||
return rect;
|
||||
}
|
||||
rect_t getRect() const { return rect; }
|
||||
|
||||
void padLeft(coord_t pad);
|
||||
void padRight(coord_t pad);
|
||||
void padTop(coord_t pad);
|
||||
void padBottom(coord_t pad);
|
||||
void padAll(coord_t pad);
|
||||
void padLeft(coord_t pad);
|
||||
void padRight(coord_t pad);
|
||||
void padTop(coord_t pad);
|
||||
void padBottom(coord_t pad);
|
||||
void padAll(coord_t pad);
|
||||
|
||||
void padRow(coord_t pad);
|
||||
void padColumn(coord_t pad);
|
||||
void padRow(coord_t pad);
|
||||
void padColumn(coord_t pad);
|
||||
|
||||
virtual void onEvent(event_t event);
|
||||
virtual void onClicked();
|
||||
virtual void onCancel();
|
||||
virtual void onEvent(event_t event);
|
||||
virtual void onClicked();
|
||||
virtual void onCancel();
|
||||
|
||||
virtual void updateSize();
|
||||
virtual void updateSize();
|
||||
|
||||
void invalidate()
|
||||
{
|
||||
invalidate({0, 0, rect.w, rect.h});
|
||||
}
|
||||
void invalidate() { 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
|
||||
{
|
||||
return _deleted;
|
||||
}
|
||||
bool deleted() const { return _deleted; }
|
||||
|
||||
virtual void paint(BitmapBuffer *) {}
|
||||
virtual void paint(BitmapBuffer *) {}
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
virtual bool onTouchStart(coord_t x, coord_t y);
|
||||
virtual bool onTouchEnd(coord_t x, coord_t y);
|
||||
virtual bool onTouchStart(coord_t x, coord_t y);
|
||||
virtual bool onTouchEnd(coord_t x, coord_t y);
|
||||
#endif
|
||||
|
||||
inline lv_obj_t *getLvObj() { return lvobj; }
|
||||
|
||||
virtual bool isTopBar() { return false; }
|
||||
virtual bool isWidgetsContainer() { return false; }
|
||||
inline lv_obj_t *getLvObj() { return lvobj; }
|
||||
|
||||
virtual bool isBubblePopup() { return false; }
|
||||
virtual bool isTopBar() { return false; }
|
||||
virtual bool isWidgetsContainer() { return false; }
|
||||
|
||||
protected:
|
||||
static std::list<Window*> trash;
|
||||
virtual bool isBubblePopup() { return false; }
|
||||
|
||||
rect_t rect;
|
||||
protected:
|
||||
static std::list<Window *> trash;
|
||||
|
||||
Window* parent = nullptr;
|
||||
lv_obj_t* lvobj = nullptr;
|
||||
rect_t rect;
|
||||
|
||||
std::list<Window *> children;
|
||||
Window *parent = nullptr;
|
||||
lv_obj_t *lvobj = nullptr;
|
||||
|
||||
WindowFlags windowFlags = 0;
|
||||
LcdFlags textFlags = 0;
|
||||
std::list<Window *> children;
|
||||
|
||||
bool _deleted = false;
|
||||
WindowFlags windowFlags = 0;
|
||||
LcdFlags textFlags = 0;
|
||||
|
||||
std::function<void()> closeHandler;
|
||||
std::function<void(bool)> focusHandler;
|
||||
bool _deleted = false;
|
||||
|
||||
void deleteChildren();
|
||||
std::function<void()> closeHandler;
|
||||
std::function<void(bool)> focusHandler;
|
||||
|
||||
virtual void addChild(Window * window);
|
||||
void removeChild(Window * window);
|
||||
void deleteChildren();
|
||||
|
||||
virtual void invalidate(const rect_t & rect);
|
||||
virtual void addChild(Window *window);
|
||||
void removeChild(Window *window);
|
||||
|
||||
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