some additional menu fixes

This commit is contained in:
kkoenig1@optonline.com
2022-06-11 15:13:11 +02:00
committed by Raphael Coeffic
parent 3dd0a72ed8
commit e53c334aed
2 changed files with 1 additions and 118 deletions
-107
View File
@@ -182,87 +182,6 @@ void MenuBody::onEvent(event_t event)
}
#endif
#if defined(HARDWARE_TOUCH)
bool MenuBody::onTouchEnd(coord_t /*x*/, coord_t y)
{
Menu * menu = getParentMenu();
int index = 0;
// dynamically find the selected element based on variable line heights
coord_t yAccumulator = 0;
for (int i = 0; i < (signed)lines.size(); i++) {
if (y >= yAccumulator && y <= yAccumulator + lines[i].lineHeight()) {
index = i;
break;
}
yAccumulator += lines[i].lineHeight();
}
// dont allow selecting separators
if (lines[index].isSeparator)
return false;
if (index < (int)lines.size()) {
onKeyPress();
if (menu->multiple) {
if (selectedIndex == index)
lines[index].onPress();
else
setIndex(index);
menu->invalidate();
}
else {
setIndex(index);
menu->deleteLater();
lines[index].onPress();
}
}
return true;
}
#endif
void MenuBody::paint(BitmapBuffer * dc)
{
// dc->clear(COLOR_THEME_PRIMARY2);
// int y = 0;
// for (int i = 0; i < (signed)lines.size(); i++) {
// auto& line = lines[i];
// LcdFlags flags = COLOR_THEME_PRIMARY3 | MENU_FONT;
// // draw selection if appropriate
// if (selectedIndex == i && ! line.isSeparator) {
// flags = COLOR_THEME_PRIMARY2 | MENU_FONT;
// if (COLOR_THEME_FOCUS != COLOR_THEME_PRIMARY2) {
// dc->drawSolidFilledRect(0, y, width(),
// MENUS_LINE_HEIGHT, COLOR_THEME_FOCUS);
// }
// }
// if (line.isSeparator) {
// dc->drawHorizontalLine(5, y + MENUS_SEPARATOR_HEIGHT / 2, width() - 10, 255, COLOR_THEME_SECONDARY1);
// } else if (line.drawLine) {
// line.drawLine(dc, 0, y, COLOR_THEME_PRIMARY3);
// } else {
// const char* text = line.text.data();
// dc->drawText(10,
// y + (MENUS_LINE_HEIGHT - getFontHeight(MENU_FONT)) / 2,
// text[0] == '\0' ? "---" : text, flags);
// }
// Menu* menu = getParentMenu();
// if (menu->multiple && line.isChecked) {
// theme->drawCheckBox(dc, line.isChecked(), width() - 35,
// y + (MENUS_LINE_HEIGHT - 20) / 2,
// 0);
// }
// y += line.lineHeight();
// }
}
MenuWindowContent::MenuWindowContent(Menu* parent) :
ModalWindowContent(parent, {(LCD_W - MENUS_WIDTH) / 2,
(LCD_H - MENUS_WIDTH) / 2, MENUS_WIDTH, 0}),
@@ -272,21 +191,6 @@ MenuWindowContent::MenuWindowContent(Menu* parent) :
lv_obj_set_style_bg_opa(lvobj, LV_OPA_100, LV_PART_MAIN);
}
void MenuWindowContent::paint(BitmapBuffer * dc)
{
// // the background
// dc->clear(COLOR_THEME_SECONDARY1);
// // the title
// if (!title.empty()) {
// dc->drawText(MENUS_WIDTH / 2,
// (POPUP_HEADER_HEIGHT - getFontHeight(MENU_HEADER_FONT)) / 2,
// title.c_str(), CENTERED | MENU_HEADER_FONT | COLOR_THEME_PRIMARY2);
// dc->drawSolidHorizontalLine(0, POPUP_HEADER_HEIGHT - 1, MENUS_WIDTH,
// COLOR_THEME_SECONDARY2);
// }
}
Menu::Menu(Window * parent, bool multiple):
ModalWindow(parent, true),
content(createMenuWindow(this)),
@@ -360,14 +264,3 @@ void Menu::onEvent(event_t event)
}
#endif
void Menu::paint(BitmapBuffer * dc)
{
ModalWindow::paint(dc);
rect_t r(content->getRect());
if (toolbar) {
r.x = toolbar->left();
r.w += toolbar->width();
}
dc->drawSolidRect(r.x - 1, r.y - 1, r.w + 2, r.h + 2, 1, COLOR_THEME_SECONDARY1);
}
+1 -11
View File
@@ -71,7 +71,7 @@ class MenuBody: public Window
protected:
friend void menuBodyEventCallback(lv_event_t *e);
bool isSeparator = false;
coord_t height = MENUS_LINE_HEIGHT;
coord_t height = MENUS_LINE_HEIGHT + 10;
std::string text;
std::function<void(BitmapBuffer * dc, coord_t x, coord_t y, LcdFlags flags)> drawLine;
std::function<void()> onPress;
@@ -109,10 +109,6 @@ class MenuBody: public Window
void onEvent(event_t event) override;
#endif
#if defined(HARDWARE_TOUCH)
bool onTouchEnd(coord_t x, coord_t y) override;
#endif
void addLine(const std::string & text, std::function<void()> onPress, std::function<bool()> isChecked);
void addCustomLine(std::function<void(BitmapBuffer * /*dc*/, coord_t /*x*/, coord_t /*y*/, LcdFlags /*flags*/)> drawLine, std::function<void()> onPress, std::function<bool()> isChecked)
@@ -133,8 +129,6 @@ class MenuBody: public Window
onCancel = std::move(handler);
}
void paint(BitmapBuffer * dc) override;
protected:
friend void menuBodyEventCallback(lv_event_t *);
void selectNext(MENU_DIRECTION direction);
@@ -171,8 +165,6 @@ class MenuWindowContent: public ModalWindowContent
}
#endif
void paint(BitmapBuffer * dc) override;
protected:
MenuBody body;
};
@@ -251,8 +243,6 @@ class Menu: public ModalWindow
}
}
void paint(BitmapBuffer * dc) override;
protected:
friend void menuBodyEventCallback(lv_event_t *);
MenuWindowContent * content;