[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 (event == EVT_ROTARY_RIGHT) {
|
||||||
if (lines.empty())
|
if (!lines.empty())
|
||||||
return;
|
select((selection + 1) % lines.size(), true);
|
||||||
|
|
||||||
int newSelection = (selection + 1) % lines.size();
|
|
||||||
select(newSelection, true);
|
|
||||||
auto onSelect = lines[selection].onSelect;
|
|
||||||
if (onSelect) {
|
|
||||||
onSelect();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (event == EVT_ROTARY_LEFT) {
|
else if (event == EVT_ROTARY_LEFT) {
|
||||||
if (lines.empty())
|
if (!lines.empty())
|
||||||
return;
|
select(selection <= 0 ? lines.size() - 1 : selection - 1, true);
|
||||||
|
|
||||||
int newSelection = selection <= 0 ? lines.size() - 1 : selection - 1;
|
|
||||||
select(newSelection, true);
|
|
||||||
auto onSelect = lines[selection].onSelect;
|
|
||||||
if (onSelect) {
|
|
||||||
onSelect();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (event == EVT_KEY_BREAK(KEY_EXIT) && selection >= 0) {
|
else if (event == EVT_KEY_BREAK(KEY_EXIT) && selection >= 0) {
|
||||||
select(-1, true);
|
select(-1, true);
|
||||||
|
|||||||
+7
-2
@@ -115,6 +115,12 @@ class Table: public FormField {
|
|||||||
scrollTo(rect);
|
scrollTo(rect);
|
||||||
}
|
}
|
||||||
invalidate();
|
invalidate();
|
||||||
|
if (index >= 0) {
|
||||||
|
auto onSelect = lines[index].onSelect;
|
||||||
|
if (onSelect) {
|
||||||
|
onSelect();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void paint(BitmapBuffer * dc) override;
|
void paint(BitmapBuffer * dc) override;
|
||||||
@@ -177,8 +183,7 @@ class Table: public FormField {
|
|||||||
void setFocus(uint8_t flag) override
|
void setFocus(uint8_t flag) override
|
||||||
{
|
{
|
||||||
if (body.selection < 0) {
|
if (body.selection < 0) {
|
||||||
body.selection = 0;
|
select(0);
|
||||||
body.invalidate();
|
|
||||||
}
|
}
|
||||||
body.setFocus(flag);
|
body.setFocus(flag);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user