Skip to content

Commit

Permalink
fix(color): Close menu popup on main view when switching to other vie…
Browse files Browse the repository at this point in the history
…ws (#3090)
  • Loading branch information
philmoz authored Jan 24, 2023
1 parent 80f3cbe commit c2dff94
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
18 changes: 15 additions & 3 deletions radio/src/gui/colorlcd/view_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,13 @@ 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;

Expand All @@ -263,10 +265,12 @@ void ViewMain::onEvent(event_t event)
// - use LONG for "Tools" page
//
case EVT_KEY_FIRST(KEY_RADIO):
if (viewMainMenu) viewMainMenu->onCancel();
new RadioMenu();
break;

case EVT_KEY_FIRST(KEY_TELEM):
if (viewMainMenu) viewMainMenu->onCancel();
new ScreenMenu();
break;

Expand All @@ -275,7 +279,10 @@ void ViewMain::onEvent(event_t event)
#else
case EVT_KEY_BREAK(KEY_PGDN):
#endif
if (!widget_select) nextMainView();
if (!widget_select) {
if (viewMainMenu) viewMainMenu->onCancel();
nextMainView();
}
break;

//TODO: these need to go away!
Expand All @@ -286,7 +293,10 @@ void ViewMain::onEvent(event_t event)
case EVT_KEY_LONG(KEY_PGDN):
#endif
killEvents(event);
if (!widget_select) previousMainView();
if (!widget_select) {
if (viewMainMenu) viewMainMenu->onCancel();
previousMainView();
}
break;
}
#endif
Expand Down Expand Up @@ -362,7 +372,9 @@ bool ViewMain::enableWidgetSelect(bool enable)

void ViewMain::openMenu()
{
new ViewMainMenu(this);
viewMainMenu = new ViewMainMenu(this, [=]() {
viewMainMenu = nullptr;
});
}

void ViewMain::paint(BitmapBuffer * dc)
Expand Down
2 changes: 2 additions & 0 deletions radio/src/gui/colorlcd/view_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

class SetupWidgetsPage;
class SetupTopBarWidgetsPage;
class ViewMainMenu;

class ViewMain: public Window
{
Expand Down Expand Up @@ -89,6 +90,7 @@ class ViewMain: public Window
TopbarImpl* topbar = nullptr;
bool widget_select = false;
lv_timer_t* widget_select_timer = nullptr;
ViewMainMenu* viewMainMenu = nullptr;

void paint(BitmapBuffer * dc) override;
void deleteLater(bool detach = true, bool trash = true) override;
Expand Down
5 changes: 4 additions & 1 deletion radio/src/gui/colorlcd/view_main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
#include "select_fab_carousel.h"
#include "view_text.h"

ViewMainMenu::ViewMainMenu(Window* parent) :
ViewMainMenu::ViewMainMenu(Window* parent, std::function<void()> closeHandler) :
Window(parent->getFullScreenWindow(), rect_t{})
{
this->closeHandler = std::move(closeHandler);

// Save focus
Layer::push(this);

Expand Down Expand Up @@ -131,6 +133,7 @@ void ViewMainMenu::paint(BitmapBuffer* dc)

void ViewMainMenu::deleteLater(bool detach, bool trash)
{
if (closeHandler) closeHandler();
Layer::pop(this);
Window::deleteLater(detach, trash);
}
Expand Down
3 changes: 2 additions & 1 deletion radio/src/gui/colorlcd/view_main_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class ViewMainMenu : public Window
{
public:
ViewMainMenu(Window* parent);
ViewMainMenu(Window* parent, std::function<void()> closeHandler);

void onCancel() override;
void onClicked() override;
Expand All @@ -35,4 +35,5 @@ class ViewMainMenu : public Window

protected:
rect_t carouselRect;
std::function<void()> closeHandler = nullptr;
};

0 comments on commit c2dff94

Please sign in to comment.