Choice and Menu fixes

This commit is contained in:
Bertrand Songis
2019-10-29 10:22:37 +01:00
parent 6341d0d530
commit d156bf8171
3 changed files with 14 additions and 17 deletions
+3 -4
View File
@@ -44,8 +44,6 @@ void Choice::onEvent(event_t event)
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
if (event == EVT_KEY_BREAK(KEY_ENTER)) {
editMode = true;
invalidate();
openMenu();
}
else {
@@ -88,6 +86,9 @@ void Choice::openMenu()
editMode = false;
setFocus();
});
setEditMode(true);
invalidate();
}
#if defined(HARDWARE_TOUCH)
@@ -95,8 +96,6 @@ bool Choice::onTouchEnd(coord_t, coord_t)
{
onKeyPress();
openMenu();
setEditMode(true);
setFocus();
return true;
}
#endif
+10 -10
View File
@@ -29,7 +29,7 @@ void MenuWindow::select(int index)
{
selectedIndex = index;
if (innerHeight > height()) {
setScrollPositionY(lineHeight * index - 3 * lineHeight);
setScrollPositionY(MENUS_LINE_HEIGHT * index - 3 * MENUS_LINE_HEIGHT);
}
invalidate();
}
@@ -63,7 +63,7 @@ void MenuWindow::onEvent(event_t event)
#if defined(HARDWARE_TOUCH)
bool MenuWindow::onTouchEnd(coord_t x, coord_t y)
{
int index = y / lineHeight;
int index = y / MENUS_LINE_HEIGHT;
lines[index].onPress();
return false; // = close the menu (inverted so that click outside the menu closes it)
}
@@ -73,18 +73,18 @@ void MenuWindow::paint(BitmapBuffer * dc)
{
int width = (innerHeight > height() ? 195 : 200);
dc->clear(MENU_BGCOLOR);
for (unsigned i = 0; i < lines.size(); i++) {
for (auto i = 0; i < lines.size(); i++) {
auto & line = lines[i];
LcdFlags flags = (selectedIndex == (int) i ? HIGHLIGHT_COLOR : MENU_COLOR);
if (line.drawLine) {
line.drawLine(dc, 0, i * lineHeight /*+ (lineHeight - 20) / 2*/, flags);
line.drawLine(dc, 0, i * MENUS_LINE_HEIGHT /*+ (lineHeight - 20) / 2*/, flags);
}
else {
const char *text = line.text.data();
dc->drawText(10, i * lineHeight + (lineHeight - 20) / 2, text[0] == '\0' ? "---" : text, flags);
const char * text = line.text.data();
dc->drawText(10, i * MENUS_LINE_HEIGHT + (MENUS_LINE_HEIGHT - 20) / 2, text[0] == '\0' ? "---" : text, flags);
}
if (i > 0) {
dc->drawSolidHorizontalLine(0, i * lineHeight - 1, width, DISABLE_COLOR);
dc->drawSolidHorizontalLine(0, i * MENUS_LINE_HEIGHT - 1, width, DISABLE_COLOR);
}
}
}
@@ -93,12 +93,12 @@ void Menu::updatePosition()
{
if (!toolbar) {
// there is no navigation bar at the left, we may center the window on screen
int count = min<int>(MenuWindow::maxLines, menuWindow.lines.size());
coord_t h = count * MenuWindow::lineHeight - 1;
int count = min<int>(MENUS_MAX_LINES, menuWindow.lines.size());
coord_t h = count * MENUS_LINE_HEIGHT - 1;
menuWindow.setTop((LCD_H - h) / 2 + 20);
menuWindow.setHeight(h);
}
menuWindow.setInnerHeight(menuWindow.lines.size() * MenuWindow::lineHeight - 1);
menuWindow.setInnerHeight(menuWindow.lines.size() * MENUS_LINE_HEIGHT - 1);
}
void Menu::addLine(const std::string & text, std::function<void()> onPress)
+1 -3
View File
@@ -109,8 +109,6 @@ class MenuWindow: public Window {
int selectedIndex = 0;
#endif
std::function<void()> onCancel;
static constexpr uint8_t maxLines = 7; // TODO NV14 was 8
static constexpr uint8_t lineHeight = 30; // TODO NV14 was 40
};
class Menu : public Window {
@@ -186,7 +184,7 @@ class Menu : public Window {
#endif
protected:
Window * previousFocus;
Window * previousFocus = nullptr;
MenuWindow menuWindow;
Window * toolbar = nullptr;
void updatePosition();