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