69 lines
1.8 KiB
C++
69 lines
1.8 KiB
C++
//
|
|
// Created by robtor on 09.12.22.
|
|
//
|
|
|
|
#include "Menu.h"
|
|
|
|
namespace floatpump::menu {
|
|
void Menu::addEntry(const Menu_Entry &entry) {
|
|
m_entries.push_back(entry);
|
|
}
|
|
|
|
void Menu::addSubmenu(Menu *submenu) {
|
|
//Always set this menu as parent of created submenus within this menu
|
|
submenu->m_parent = this;
|
|
m_submenus.push_back(submenu);
|
|
}
|
|
|
|
std::string Menu::printLine() const {
|
|
return m_name;
|
|
}
|
|
|
|
std::vector<std::string> Menu::getDisplayList() {
|
|
std::vector<std::string> list;
|
|
|
|
list.reserve(m_submenus.size() + m_entries.size());
|
|
|
|
//Append al Submenus
|
|
for (auto &m_submenu: m_submenus) {
|
|
list.push_back(m_submenu->printLine());
|
|
}
|
|
|
|
//Append all Entries
|
|
for (auto &m_entry: m_entries) {
|
|
list.push_back(m_entry.printLine());
|
|
}
|
|
|
|
//Append Go-Back-Entry if we are within a submenu
|
|
if (m_parent != nullptr) {
|
|
list.emplace_back("<- Go Back");
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
unsigned int Menu::getAllEntriesNum() const {
|
|
//Add 1 to this if we have a parent menu -> makes Go-Back-Entry selectable
|
|
return (m_entries.size() + m_submenus.size()) + ((m_parent != nullptr) ? 1 : 0);
|
|
}
|
|
|
|
Menu *Menu::getSubmenu(int index) {
|
|
if (index >= 0 && index < m_submenus.size()) {
|
|
return m_submenus[index];
|
|
} else {
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
Menu_Entry *Menu::getEntry(int index) {
|
|
if (index >= m_submenus.size() && index < m_entries.size() + m_submenus.size()) {
|
|
return &m_entries[index - m_submenus.size()];
|
|
} else {
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
Menu *Menu::getParent() {
|
|
return m_parent;
|
|
}
|
|
} |