FIX: use raw pointer here
This commit is contained in:
parent
c247e0f40f
commit
1a926be1b7
@ -9,7 +9,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
|
||||||
|
|
||||||
namespace floatpump {
|
namespace floatpump {
|
||||||
namespace menu {
|
namespace menu {
|
||||||
@ -125,6 +124,10 @@ namespace floatpump {
|
|||||||
public:
|
public:
|
||||||
explicit Menu(const std::string &m_name) : m_name(m_name) {}
|
explicit Menu(const std::string &m_name) : m_name(m_name) {}
|
||||||
|
|
||||||
|
enum class Error {
|
||||||
|
invalid_index
|
||||||
|
};
|
||||||
|
|
||||||
template<typename T, typename... As>
|
template<typename T, typename... As>
|
||||||
auto addEntry(As &&...args) -> void {
|
auto addEntry(As &&...args) -> void {
|
||||||
m_entries.push_back(std::make_unique<T>(std::forward<As>(args)...));
|
m_entries.push_back(std::make_unique<T>(std::forward<As>(args)...));
|
||||||
@ -148,7 +151,7 @@ namespace floatpump {
|
|||||||
|
|
||||||
auto getSubmenu(int index) -> Menu *;
|
auto getSubmenu(int index) -> Menu *;
|
||||||
|
|
||||||
auto getEntry(int index) -> std::optional<std::reference_wrapper<IMenuEntry>>;
|
auto getEntry(int index) -> IMenuEntry* ;
|
||||||
|
|
||||||
auto getParent() -> Menu * {
|
auto getParent() -> Menu * {
|
||||||
return m_parent;
|
return m_parent;
|
||||||
|
@ -104,11 +104,11 @@ namespace floatpump::menu {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Menu::getEntry(int index) -> std::optional<std::reference_wrapper<IMenuEntry>> {
|
auto Menu::getEntry(int index) -> IMenuEntry* {
|
||||||
if (index >= m_submenus.size() && index < m_entries.size() + m_submenus.size()) {
|
if (index >= m_submenus.size() && index < m_entries.size() + m_submenus.size()) {
|
||||||
return *m_entries[index - m_submenus.size()];
|
return m_entries[index - m_submenus.size()].get();
|
||||||
} else {
|
} else {
|
||||||
return std::nullopt;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,8 +70,8 @@ namespace floatpump::menu {
|
|||||||
m_menu = m->getSubmenu(m_current_index);
|
m_menu = m->getSubmenu(m_current_index);
|
||||||
m_current_index = 0;
|
m_current_index = 0;
|
||||||
//Forward press action if entry is entry
|
//Forward press action if entry is entry
|
||||||
} else if (m->getEntry(m_current_index) != std::nullopt) {
|
} else if (m->getEntry(m_current_index) != nullptr) {
|
||||||
m->getEntry(m_current_index)->get().u_press();
|
m->getEntry(m_current_index)->u_press();
|
||||||
//If we are on the Go-Back-Entry and have a parent: replace menu with parent menu
|
//If we are on the Go-Back-Entry and have a parent: replace menu with parent menu
|
||||||
} else if (m_menu->getParent() != nullptr) {
|
} else if (m_menu->getParent() != nullptr) {
|
||||||
m_menu = m_menu->getParent();
|
m_menu = m_menu->getParent();
|
||||||
@ -81,10 +81,10 @@ namespace floatpump::menu {
|
|||||||
|
|
||||||
void Menu_Controller::increase(Menu *m) {
|
void Menu_Controller::increase(Menu *m) {
|
||||||
if (m_current_index < m->getAllEntriesNum()) {
|
if (m_current_index < m->getAllEntriesNum()) {
|
||||||
if (m->getEntry(m_current_index) != std::nullopt) {
|
if (m->getEntry(m_current_index) != nullptr) {
|
||||||
//Forward increase action to entry if we have an entered entry
|
//Forward increase action to entry if we have an entered entry
|
||||||
if (m->getEntry(m_current_index)->get().is_entered()) {
|
if (m->getEntry(m_current_index)->is_entered()) {
|
||||||
m->getEntry(m_current_index)->get().u_increase();
|
m->getEntry(m_current_index)->u_increase();
|
||||||
} else if (m_current_index < m->getAllEntriesNum() - 1) {
|
} else if (m_current_index < m->getAllEntriesNum() - 1) {
|
||||||
m_current_index++;
|
m_current_index++;
|
||||||
}
|
}
|
||||||
@ -98,10 +98,10 @@ namespace floatpump::menu {
|
|||||||
|
|
||||||
void Menu_Controller::decrease(Menu *m) {
|
void Menu_Controller::decrease(Menu *m) {
|
||||||
if (m_current_index > 0) {
|
if (m_current_index > 0) {
|
||||||
if (m->getEntry(m_current_index) != std::nullopt) {
|
if (m->getEntry(m_current_index) != nullptr) {
|
||||||
//Forward decrease action to entry if we have an entered entry
|
//Forward decrease action to entry if we have an entered entry
|
||||||
if (m->getEntry(m_current_index)->get().is_entered()) {
|
if (m->getEntry(m_current_index)->is_entered()) {
|
||||||
m->getEntry(m_current_index)->get().u_decrease();
|
m->getEntry(m_current_index)->u_decrease();
|
||||||
} else {
|
} else {
|
||||||
m_current_index--;
|
m_current_index--;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user