menu: removed separator
This commit is contained in:
committed by
Raphael Coeffic
parent
5ace4d010e
commit
4a77acf6af
+3
-27
@@ -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);
|
lines.emplace_back(std::move(onPress), std::move(isChecked), nullptr);
|
||||||
|
|
||||||
auto idx = lines.size() - 1;
|
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,
|
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)
|
void MenuBody::selectNext(MENU_DIRECTION direction)
|
||||||
{
|
{
|
||||||
// look for the next non separator line
|
// look for the next non separator line
|
||||||
int index = selectedIndex + direction;
|
int index = selectedIndex + direction;
|
||||||
index = rangeCheck(index);
|
setIndex(rangeCheck(index));
|
||||||
while (lines[index].isSeparator) {
|
|
||||||
index += direction;
|
|
||||||
index = rangeCheck(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
setIndex(index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -247,7 +229,7 @@ void MenuBody::onEvent(event_t event)
|
|||||||
if (!lines.empty()) {
|
if (!lines.empty()) {
|
||||||
onKeyPress();
|
onKeyPress();
|
||||||
if (selectedIndex < 0) {
|
if (selectedIndex < 0) {
|
||||||
select(0);
|
setIndex(0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Menu * menu = getParentMenu();
|
Menu * menu = getParentMenu();
|
||||||
@@ -348,12 +330,6 @@ void Menu::addLine(const uint8_t *icon_mask, const std::string &text,
|
|||||||
updatePosition();
|
updatePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::addSeparator()
|
|
||||||
{
|
|
||||||
content->body.addSeparator();
|
|
||||||
updatePosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::removeLines()
|
void Menu::removeLines()
|
||||||
{
|
{
|
||||||
content->body.removeLines();
|
content->body.removeLines();
|
||||||
|
|||||||
+3
-16
@@ -57,14 +57,12 @@ class MenuBody: public Window
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuLine(bool isSeparator) : isSeparator(true) {}
|
|
||||||
MenuLine(MenuLine &) = delete;
|
MenuLine(MenuLine &) = delete;
|
||||||
MenuLine(MenuLine &&) = default;
|
MenuLine(MenuLine &&) = default;
|
||||||
|
|
||||||
lv_obj_t* getIcon() { return icon.get(); }
|
lv_obj_t* getIcon() { return icon.get(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool isSeparator = false;
|
|
||||||
std::function<void()> onPress;
|
std::function<void()> onPress;
|
||||||
std::function<bool()> isChecked;
|
std::function<bool()> isChecked;
|
||||||
std::unique_ptr<lv_obj_t, lvobj_delete> icon;
|
std::unique_ptr<lv_obj_t, lvobj_delete> icon;
|
||||||
@@ -80,16 +78,11 @@ class MenuBody: public Window
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void select(int index);
|
void setIndex(int index);
|
||||||
|
|
||||||
int selection() const
|
int selection() const
|
||||||
{
|
{
|
||||||
int index = selectedIndex;
|
return selectedIndex;
|
||||||
for (int i = 0; i < selectedIndex; i++)
|
|
||||||
if (lines[i].isSeparator)
|
|
||||||
index--;
|
|
||||||
|
|
||||||
return index;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int count() const
|
int count() const
|
||||||
@@ -108,11 +101,6 @@ class MenuBody: public Window
|
|||||||
std::function<void()> onPress,
|
std::function<void()> onPress,
|
||||||
std::function<bool()> isChecked);
|
std::function<bool()> isChecked);
|
||||||
|
|
||||||
void addSeparator()
|
|
||||||
{
|
|
||||||
lines.emplace_back(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeLines();
|
void removeLines();
|
||||||
|
|
||||||
void setCancelHandler(std::function<void()> handler)
|
void setCancelHandler(std::function<void()> handler)
|
||||||
@@ -130,7 +118,6 @@ class MenuBody: public Window
|
|||||||
|
|
||||||
void selectNext(MENU_DIRECTION direction);
|
void selectNext(MENU_DIRECTION direction);
|
||||||
int rangeCheck(int);
|
int rangeCheck(int);
|
||||||
void setIndex(int index);
|
|
||||||
|
|
||||||
std::vector<MenuLine> lines;
|
std::vector<MenuLine> lines;
|
||||||
int selectedIndex = 0;
|
int selectedIndex = 0;
|
||||||
@@ -217,7 +204,7 @@ class Menu: public ModalWindow
|
|||||||
|
|
||||||
void select(int index)
|
void select(int index)
|
||||||
{
|
{
|
||||||
content->body.select(index);
|
content->body.setIndex(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HARDWARE_KEYS)
|
#if defined(HARDWARE_KEYS)
|
||||||
|
|||||||
Reference in New Issue
Block a user