menu: removed separator

This commit is contained in:
Raphael Coeffic
2022-06-11 15:13:11 +02:00
committed by Raphael Coeffic
parent 5ace4d010e
commit 4a77acf6af
2 changed files with 6 additions and 43 deletions
+3 -27
View File
@@ -106,7 +106,7 @@ void MenuBody::addLine(const std::string &text, std::function<void()> onPress,
lines.emplace_back(std::move(onPress), std::move(isChecked), nullptr);
auto idx = lines.size() - 1;
lv_table_set_cell_value_fmt(lvobj, idx, 0, text.c_str());
lv_table_set_cell_value(lvobj, idx, 0, text.c_str());
}
void MenuBody::addLine(const uint8_t *icon_mask, const std::string &text,
@@ -200,29 +200,11 @@ void MenuBody::setIndex(int index)
}
}
void MenuBody::select(int index)
{
// adjust the selection based on separators
for (int i = 0; i <= index; i++) {
if (lines[i].isSeparator)
index++;
index = rangeCheck(index);
}
setIndex(index);
}
void MenuBody::selectNext(MENU_DIRECTION direction)
{
// look for the next non separator line
int index = selectedIndex + direction;
index = rangeCheck(index);
while (lines[index].isSeparator) {
index += direction;
index = rangeCheck(index);
}
setIndex(index);
setIndex(rangeCheck(index));
}
@@ -247,7 +229,7 @@ void MenuBody::onEvent(event_t event)
if (!lines.empty()) {
onKeyPress();
if (selectedIndex < 0) {
select(0);
setIndex(0);
}
else {
Menu * menu = getParentMenu();
@@ -348,12 +330,6 @@ void Menu::addLine(const uint8_t *icon_mask, const std::string &text,
updatePosition();
}
void Menu::addSeparator()
{
content->body.addSeparator();
updatePosition();
}
void Menu::removeLines()
{
content->body.removeLines();
+3 -16
View File
@@ -57,14 +57,12 @@ class MenuBody: public Window
{
}
MenuLine(bool isSeparator) : isSeparator(true) {}
MenuLine(MenuLine &) = delete;
MenuLine(MenuLine &&) = default;
lv_obj_t* getIcon() { return icon.get(); }
protected:
bool isSeparator = false;
std::function<void()> onPress;
std::function<bool()> isChecked;
std::unique_ptr<lv_obj_t, lvobj_delete> icon;
@@ -80,16 +78,11 @@ class MenuBody: public Window
}
#endif
void select(int index);
void setIndex(int index);
int selection() const
{
int index = selectedIndex;
for (int i = 0; i < selectedIndex; i++)
if (lines[i].isSeparator)
index--;
return index;
return selectedIndex;
}
int count() const
@@ -108,11 +101,6 @@ class MenuBody: public Window
std::function<void()> onPress,
std::function<bool()> isChecked);
void addSeparator()
{
lines.emplace_back(true);
}
void removeLines();
void setCancelHandler(std::function<void()> handler)
@@ -130,7 +118,6 @@ class MenuBody: public Window
void selectNext(MENU_DIRECTION direction);
int rangeCheck(int);
void setIndex(int index);
std::vector<MenuLine> lines;
int selectedIndex = 0;
@@ -217,7 +204,7 @@ class Menu: public ModalWindow
void select(int index)
{
content->body.select(index);
content->body.setIndex(index);
}
#if defined(HARDWARE_KEYS)