77 lines
1.7 KiB
C++
77 lines
1.7 KiB
C++
//
|
|
// Created by robtor on 09.12.22.
|
|
//
|
|
|
|
#ifndef FLOATPUMP_MENU_H
|
|
#define FLOATPUMP_MENU_H
|
|
|
|
#include <vector>
|
|
#include <typeinfo>
|
|
#include "Menu_Entry.h"
|
|
#include "LCD_I2C_Driver.h"
|
|
|
|
namespace floatpump {
|
|
namespace menu {
|
|
|
|
class Menu {
|
|
|
|
public:
|
|
Menu(LCD_I2C_Driver &driver) : m_driver(driver) {
|
|
}
|
|
|
|
void addEntry(Menu_Entry entry) {
|
|
m_entries.push_back(entry);
|
|
}
|
|
|
|
void addSubmenu(Menu *submenu) {
|
|
submenu->m_parent = this;
|
|
m_submenus.push_back(submenu);
|
|
}
|
|
|
|
|
|
bool isSubmenu(int index) {
|
|
if(index > 0 && index < m_submenus.size()) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool isEntry(int index) {
|
|
if(index >= m_submenus.size() && index < (m_entries.size() + m_submenus.size())) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
Menu_Entry *getEntry(int index) {
|
|
if(isEntry(index)) {
|
|
return &m_entries[index - m_submenus.size()];
|
|
} else {
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
Menu *getSubmenu(int index) {
|
|
if(isSubmenu(index)) {
|
|
return m_submenus[index];
|
|
} else {
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
|
|
LCD_I2C_Driver &m_driver;
|
|
std::vector<Menu_Entry> m_entries;
|
|
std::vector<Menu *> m_submenus;
|
|
Menu *m_parent = nullptr;
|
|
int m_current_index = 0;
|
|
|
|
private:
|
|
|
|
};
|
|
|
|
} // floatpump
|
|
} // menu
|
|
|
|
#endif //FLOATPUMP_MENU_H
|