From 645bc868d0402996e1da21d40d4e127eea0c6d32 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Mon, 14 Sep 2020 18:12:47 +0200 Subject: [PATCH] [Table] Factorize the onSelect call --- radio/src/thirdparty/libopenui/src/table.cpp | 22 ++++---------------- radio/src/thirdparty/libopenui/src/table.h | 9 ++++++-- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/radio/src/thirdparty/libopenui/src/table.cpp b/radio/src/thirdparty/libopenui/src/table.cpp index e188dd901..3067b485b 100644 --- a/radio/src/thirdparty/libopenui/src/table.cpp +++ b/radio/src/thirdparty/libopenui/src/table.cpp @@ -77,26 +77,12 @@ void Table::Body::onEvent(event_t event) } } if (event == EVT_ROTARY_RIGHT) { - if (lines.empty()) - return; - - int newSelection = (selection + 1) % lines.size(); - select(newSelection, true); - auto onSelect = lines[selection].onSelect; - if (onSelect) { - onSelect(); - } + if (!lines.empty()) + select((selection + 1) % lines.size(), true); } else if (event == EVT_ROTARY_LEFT) { - if (lines.empty()) - return; - - int newSelection = selection <= 0 ? lines.size() - 1 : selection - 1; - select(newSelection, true); - auto onSelect = lines[selection].onSelect; - if (onSelect) { - onSelect(); - } + if (!lines.empty()) + select(selection <= 0 ? lines.size() - 1 : selection - 1, true); } else if (event == EVT_KEY_BREAK(KEY_EXIT) && selection >= 0) { select(-1, true); diff --git a/radio/src/thirdparty/libopenui/src/table.h b/radio/src/thirdparty/libopenui/src/table.h index 5658e7eb8..1be678ac9 100644 --- a/radio/src/thirdparty/libopenui/src/table.h +++ b/radio/src/thirdparty/libopenui/src/table.h @@ -115,6 +115,12 @@ class Table: public FormField { scrollTo(rect); } invalidate(); + if (index >= 0) { + auto onSelect = lines[index].onSelect; + if (onSelect) { + onSelect(); + } + } } void paint(BitmapBuffer * dc) override; @@ -177,8 +183,7 @@ class Table: public FormField { void setFocus(uint8_t flag) override { if (body.selection < 0) { - body.selection = 0; - body.invalidate(); + select(0); } body.setFocus(flag); }