[Table] Factorize the onSelect call

This commit is contained in:
Bertrand Songis
2020-09-14 18:12:47 +02:00
parent e0d3f2bb56
commit 645bc868d0
2 changed files with 11 additions and 20 deletions
+4 -18
View File
@@ -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);
+7 -2
View File
@@ -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);
}