Skip to content

Commit

Permalink
Fix top bar buttons not working correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz committed Feb 12, 2025
1 parent 6e5ff46 commit 8f6aa0b
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 14 deletions.
17 changes: 11 additions & 6 deletions radio/src/gui/colorlcd/libui/page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,29 @@
#include "pagegroup.h"
#include "tabsgroup.h"

PageHeader::PageHeader(Window* parent, EdgeTxIcon icon, std::function<void()> tlAction) :
PageHeader::PageHeader(Window* parent, EdgeTxIcon icon) :
Window(parent, {0, 0, LCD_W, EdgeTxStyles::MENU_HEADER_HEIGHT})
{
setWindowFlag(NO_FOCUS | OPAQUE);

etx_solid_bg(lvobj, COLOR_THEME_SECONDARY1_INDEX);

new HeaderIcon(this, icon, tlAction);
new HeaderIcon(this, icon);

title = new StaticText(this,
{PAGE_TITLE_LEFT, PAGE_TITLE_TOP,
LCD_W - PAGE_TITLE_LEFT, EdgeTxStyles::PAGE_LINE_HEIGHT},
"", COLOR_THEME_PRIMARY2_INDEX);
}

PageHeader::PageHeader(Window* parent, const char* iconFile, std::function<void()> tlAction) :
PageHeader::PageHeader(Window* parent, const char* iconFile) :
Window(parent, {0, 0, LCD_W, EdgeTxStyles::MENU_HEADER_HEIGHT})
{
setWindowFlag(NO_FOCUS | OPAQUE);

etx_solid_bg(lvobj, COLOR_THEME_SECONDARY1_INDEX);

new HeaderIcon(this, iconFile, tlAction);
new HeaderIcon(this, iconFile);

title = new StaticText(this,
{PAGE_TITLE_LEFT, PAGE_TITLE_TOP,
Expand All @@ -76,9 +76,14 @@ Page::Page(EdgeTxIcon icon, PaddingSize padding, bool pauseRefresh) :
if (pauseRefresh)
lv_obj_enable_style_refresh(false);

header = new PageHeader(this, icon, [=]() { openMenu(); });
header = new PageHeader(this, icon);

new HeaderBackIcon(header, [=]() { onCancel(); });
new HeaderBackIcon(header);

#if defined(HARDWARE_TOUCH)
addCustomButton(0, 0, [=]() { openMenu(); });
addCustomButton(LCD_W - EdgeTxStyles::MENU_HEADER_HEIGHT, 0, [=]() { onCancel(); });
#endif

body = new Window(this,
{0, EdgeTxStyles::MENU_HEADER_HEIGHT, LCD_W, LCD_H - EdgeTxStyles::MENU_HEADER_HEIGHT});
Expand Down
4 changes: 2 additions & 2 deletions radio/src/gui/colorlcd/libui/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class QuickMenu;
class PageHeader : public Window
{
public:
PageHeader(Window* parent, EdgeTxIcon icon, std::function<void()> tlAction = nullptr);
PageHeader(Window* parent, const char* iconFile, std::function<void()> tlAction = nullptr);
PageHeader(Window* parent, EdgeTxIcon icon);
PageHeader(Window* parent, const char* iconFile);

void setTitle(std::string txt) { title->setText(std::move(txt)); }
StaticText* setTitle2(std::string txt);
Expand Down
11 changes: 11 additions & 0 deletions radio/src/gui/colorlcd/libui/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,17 @@ void Window::addBackButton()
},
window_create);
}

void Window::addCustomButton(coord_t x, coord_t y, std::function<void()> action)
{
new ButtonBase(
this, {x, y, EdgeTxStyles::MENU_HEADER_HEIGHT, EdgeTxStyles::MENU_HEADER_HEIGHT},
[=]() -> uint8_t {
action();
return 0;
},
window_create);
}
#endif

void NavWindow::onEvent(event_t event)
Expand Down
1 change: 1 addition & 0 deletions radio/src/gui/colorlcd/libui/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class Window

#if defined(HARDWARE_TOUCH)
void addBackButton();
void addCustomButton(coord_t x, coord_t y, std::function<void()> action);
#endif

inline lv_obj_t *getLvObj() { return lvobj; }
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/radio/radio_theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ class ThemeEditPage : public Page
#endif

// save and cancel
rect_t r = {LCD_W - (ColorEditPage::BUTTON_WIDTH + 5), PAD_MEDIUM, ColorEditPage::BUTTON_WIDTH, 0};
rect_t r = {LCD_W - (ColorEditPage::BUTTON_WIDTH + 5) - EdgeTxStyles::MENU_HEADER_HEIGHT, PAD_MEDIUM, ColorEditPage::BUTTON_WIDTH, 0};
new TextButton(window, r, STR_DETAILS, [=]() {
new ThemeDetailsDialog(_theme, [=](ThemeFile t) {
_theme.setAuthor(t.getAuthor());
Expand Down
11 changes: 8 additions & 3 deletions radio/src/gui/colorlcd/setup_menus/pagegroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ class PageGroupHeader : public Window

etx_solid_bg(lvobj, COLOR_THEME_SECONDARY1_INDEX);

new HeaderIcon(this, icon, [=]() { menu->openMenu(); });
new HeaderIcon(this, icon);

titleLabel = lv_label_create(lvobj);
etx_txt_color(titleLabel, COLOR_THEME_PRIMARY2_INDEX);
lv_obj_set_pos(titleLabel, PageGroup::MENU_TITLE_TOP + PAD_LARGE, PAD_MEDIUM * 2);
lv_obj_set_size(titleLabel, LCD_W - PageGroup::MENU_TITLE_TOP * 2 - PAD_LARGE * 2, PageGroup::MENU_TITLE_TOP - PAD_MEDIUM * 2);
setTitle("");

new HeaderBackIcon(this, [=]() { menu->onCancel(); });
new HeaderBackIcon(this);
}

void setTitle(const char* title) { if (titleLabel) lv_label_set_text(titleLabel, title); }
Expand Down Expand Up @@ -190,7 +190,12 @@ PageGroup::PageGroup(EdgeTxIcon icon, PageDef* pages) :
lv_obj_add_event_cb(lvobj, on_draw_end, LV_EVENT_DRAW_POST_END, nullptr);
#endif

for (int i = 0; pages[i].icon < EDGETX_ICONS_COUNT; i += 1) {
#if defined(HARDWARE_TOUCH)
addCustomButton(0, 0, [=]() { openMenu(); });
addCustomButton(LCD_W - EdgeTxStyles::MENU_HEADER_HEIGHT, 0, [=]() { onCancel(); });
#endif

for (int i = 0; pages[i].icon < EDGETX_ICONS_COUNT; i += 1) {
if (!pages[i].enabled || pages[i].enabled())
addTab(pages[i].createPage(pages[i]));
}
Expand Down
5 changes: 5 additions & 0 deletions radio/src/gui/colorlcd/setup_menus/quick_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,8 @@ void QuickMenu::onEvent(event_t event)
Window::onEvent(event);
}
}

void QuickMenu::onClicked()
{
closeMenu();
}
2 changes: 2 additions & 0 deletions radio/src/gui/colorlcd/setup_menus/quick_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,6 @@ class QuickMenu : public Window
SubMenu curPage;

void buildMainMenu();

void onClicked() override;
};
8 changes: 6 additions & 2 deletions radio/src/lua/lua_lvgl_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1699,10 +1699,14 @@ class WidgetPage : public NavWindow, public LuaEventHandler
NavWindow(parent, {0, 0, LCD_W, LCD_H}), backAction(std::move(backAction))
{
if (iconFile.empty())
header = new PageHeader(this, ICON_EDGETX, [=]() { onCancel(); });
header = new PageHeader(this, ICON_EDGETX);
else
header = new PageHeader(this, iconFile.c_str(), [=]() { onCancel(); });
header = new PageHeader(this, iconFile.c_str());

#if defined(HARDWARE_TOUCH)
addCustomButton(0, 0, [=]() { onCancel(); });
#endif

body = new Window(
this, {0, EdgeTxStyles::MENU_HEADER_HEIGHT, LCD_W, LCD_H - EdgeTxStyles::MENU_HEADER_HEIGHT});
body->setWindowFlag(NO_FOCUS);
Expand Down

0 comments on commit 8f6aa0b

Please sign in to comment.