fix some focus issues

This commit is contained in:
Raphael Coeffic
2022-06-11 15:38:08 +02:00
committed by Raphael Coeffic
parent a87e1564ea
commit 09c7c0bf67
6 changed files with 32 additions and 113 deletions
-14
View File
@@ -61,19 +61,5 @@ ModelMenu::ModelMenu():
#endif #endif
addTab(new ModelTelemetryPage()); addTab(new ModelTelemetryPage());
addButton(&header);
} }
void ModelMenu::addButton(TabsGroupHeader* header)
{
OpenTxTheme::instance()->createTextButton(
header, {LCD_W / 2 + 5, MENU_TITLE_TOP, LCD_W / 2 - 5, MENU_TITLE_HEIGHT},
STR_OPEN_CHANNEL_MONITORS, [=]() {
calledFromModel = 1;
retTab = header->getCarousel()->getCurrentIndex();
// TRACE("currentTab=%d %s", calledFromModel, typeid(*currentTab).name());
new ChannelsViewMenu();
deleteLater();
return 0;
});
}
+6 -9
View File
@@ -24,18 +24,15 @@
#include "tabsgroup.h" #include "tabsgroup.h"
class ModelMenu: public TabsGroup { class ModelMenu : public TabsGroup
public: {
public:
ModelMenu();
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() const override std::string getName() const override { return "ModelMenu"; }
{
return "ModelMenu";
}
#endif #endif
ModelMenu();
protected:
void addButton(TabsGroupHeader* headerPtr);
}; };
#endif // _MENU_MODEL_H_ #endif // _MENU_MODEL_H_
+6 -38
View File
@@ -48,40 +48,9 @@ class LayoutChoice : public Button
update(); update();
} }
#if defined(HARDWARE_KEYS) void onPress() override
void onEvent(event_t event) override
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(),
event);
if (event == EVT_KEY_BREAK(KEY_ENTER)) {
editMode = true;
invalidate();
openMenu();
} else {
FormField::onEvent(event);
}
}
#endif
#if defined(HARDWARE_TOUCH)
bool onTouchEnd(coord_t, coord_t) override
{
if (enabled) {
if (!hasFocus()) {
setFocus(SET_FOCUS_DEFAULT);
}
onKeyPress();
openMenu();
}
return true;
}
#endif
void openMenu()
{ {
auto menu = new Menu(parent); auto menu = new Menu(parent);
for (auto layout : getRegisteredLayouts()) { for (auto layout : getRegisteredLayouts()) {
menu->addLine(layout->getBitmap(), layout->getName(), menu->addLine(layout->getBitmap(), layout->getName(),
[=]() { setValue(layout); }); [=]() { setValue(layout); });
@@ -91,11 +60,10 @@ class LayoutChoice : public Button
getRegisteredLayouts().end(), getValue()); getRegisteredLayouts().end(), getValue());
menu->select(std::distance(getRegisteredLayouts().begin(), it)); menu->select(std::distance(getRegisteredLayouts().begin(), it));
// menu->setCloseHandler([=]() { menu->setCloseHandler([=]() {
// editMode = false; editMode = false;
// update(); update();
// // setFocus(); });
// });
} }
protected: protected:
@@ -314,12 +282,12 @@ void ScreenSetupPage::build(FormWindow * form)
void ScreenSetupPage::clearLayoutOptions() void ScreenSetupPage::clearLayoutOptions()
{ {
if (!layoutOptions) return; if (!layoutOptions) return;
layoutOptions->clear();
} }
void ScreenSetupPage::buildLayoutOptions() void ScreenSetupPage::buildLayoutOptions()
{ {
if (!layoutOptions) return; if (!layoutOptions) return;
layoutOptions->clear();
FlexGridLayout grid(line_col_dsc, line_row_dsc); FlexGridLayout grid(line_col_dsc, line_row_dsc);
layoutOptions->setFlexLayout(); layoutOptions->setFlexLayout();
+17 -32
View File
@@ -22,12 +22,8 @@
#include "tabsgroup.h" #include "tabsgroup.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "view_channels.h"
#include "view_main.h" #include "view_main.h"
#include "model_outputs.h"
#include "model_mixes.h"
#include "static.h" #include "static.h"
#include "menu_model.h"
#if defined(HARDWARE_TOUCH) #if defined(HARDWARE_TOUCH)
#include "keyboard_base.h" #include "keyboard_base.h"
@@ -37,8 +33,6 @@
#include <algorithm> #include <algorithm>
int TabsGroup::calledFromModel = 0;
int TabsGroup::retTab = 0;
TabsGroupHeader::TabsGroupHeader(TabsGroup* parent, uint8_t icon) : TabsGroupHeader::TabsGroupHeader(TabsGroup* parent, uint8_t icon) :
FormGroup(parent, {0, 0, LCD_W, MENU_BODY_TOP}, OPAQUE), FormGroup(parent, {0, 0, LCD_W, MENU_BODY_TOP}, OPAQUE),
@@ -47,13 +41,6 @@ TabsGroupHeader::TabsGroupHeader(TabsGroup* parent, uint8_t icon) :
this, this,
{0, 0, MENU_HEADER_BACK_BUTTON_WIDTH, MENU_HEADER_BACK_BUTTON_HEIGHT}, {0, 0, MENU_HEADER_BACK_BUTTON_WIDTH, MENU_HEADER_BACK_BUTTON_HEIGHT},
[=]() -> uint8_t { [=]() -> uint8_t {
if (!parent->calledFromModel) {
ViewMain::instance()->setFocus(SET_FOCUS_DEFAULT);
} else {
auto menu = new ModelMenu();
menu->setCurrentTab(parent->retTab);
parent->calledFromModel = 0;
}
parent->deleteLater(); parent->deleteLater();
return 1; return 1;
}, },
@@ -128,6 +115,7 @@ TabsGroup::TabsGroup(uint8_t icon):
header(this, icon), header(this, icon),
body(this, { 0, MENU_BODY_TOP, LCD_W, MENU_BODY_HEIGHT }, FORM_FORWARD_FOCUS) body(this, { 0, MENU_BODY_TOP, LCD_W, MENU_BODY_HEIGHT }, FORM_FORWARD_FOCUS)
{ {
Layer::push(this);
} }
TabsGroup::~TabsGroup() TabsGroup::~TabsGroup()
@@ -137,6 +125,22 @@ TabsGroup::~TabsGroup()
} }
} }
void TabsGroup::deleteLater(bool detach, bool trash)
{
if (_deleted)
return;
#if defined(HARDWARE_TOUCH)
Keyboard::hide();
#endif
header.deleteLater(true, false);
body.deleteLater(true, false);
Window::deleteLater(detach, trash);
Layer::pop(this);
}
void TabsGroup::addTab(PageTab * page) void TabsGroup::addTab(PageTab * page)
{ {
tabs.push_back(page); tabs.push_back(page);
@@ -239,26 +243,7 @@ void TabsGroup::onEvent(event_t event)
} }
else if (event == EVT_KEY_FIRST(KEY_EXIT)) { else if (event == EVT_KEY_FIRST(KEY_EXIT)) {
killEvents(event); killEvents(event);
if (!calledFromModel) {
ViewMain::instance()->setFocus(SET_FOCUS_DEFAULT);
}
else {
auto menu = new ModelMenu();
menu->setCurrentTab(retTab);
calledFromModel = 0;
// TRACE("currentTab=%d %s", retTab, typeid(*currentTab).name());
}
deleteLater(); deleteLater();
} else if (event == EVT_KEY_FIRST(KEY_MODEL)) {
TRACE("TabGroup %s", typeid(*this).name());
if (typeid(*this) == typeid(ModelMenu) ) {
killEvents(event);
calledFromModel = 1;
retTab = header.carousel.getCurrentIndex();
// TRACE("currentTab=%d %s", calledFromModel, typeid(*currentTab).name());
new ChannelsViewMenu();
deleteLater();
}
} else if (parent) { } else if (parent) {
parent->onEvent(event); parent->onEvent(event);
} }
+1 -18
View File
@@ -150,7 +150,6 @@ class TabsGroupHeader: public FormGroup {
title = value; title = value;
} }
TabsCarousel* getCarousel() {return &carousel;}
protected: protected:
#if defined(HARDWARE_TOUCH) #if defined(HARDWARE_TOUCH)
@@ -167,23 +166,9 @@ class TabsGroup: public Window
public: public:
explicit TabsGroup(uint8_t icon); explicit TabsGroup(uint8_t icon);
~TabsGroup() override; ~TabsGroup() override;
void deleteLater(bool detach = true, bool trash = true) override void deleteLater(bool detach = true, bool trash = true) override;
{
if (_deleted)
return;
#if defined(HARDWARE_TOUCH)
Keyboard::hide();
#endif
header.deleteLater(true, false);
body.deleteLater(true, false);
Window::deleteLater(detach, trash);
}
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() const override std::string getName() const override
@@ -227,8 +212,6 @@ class TabsGroup: public Window
bool onTouchEnd(coord_t x, coord_t y) override; bool onTouchEnd(coord_t x, coord_t y) override;
#endif #endif
static int calledFromModel;
static int retTab;
protected: protected:
TabsGroupHeader header; TabsGroupHeader header;