[Table] Factorize the onSelect call
This commit is contained in:
+4
-18
@@ -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
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user