Made some changes to the menus, still needs to be fixed
This commit is contained in:
@ -149,7 +149,7 @@ LedstripMenu::LedstripMenu()
|
||||
constructMenuItem<makeComponent<MenuItem, espgui::StaticText<TEXT_STVO_ENABLEFRONTLIGHT>, BobbyCheckbox, EnableLedstripStVOFrontlight>>();
|
||||
|
||||
constructMenuItem<makeComponent<MenuItem, espgui::StaticText<TEXT_LEDANIMATION>, BobbyCheckbox, EnableLedAnimationAccessor>>();
|
||||
constructMenuItem<makeComponent<MenuItem, espgui::StaticText<TEXT_SELECTANIMATION>, espgui::SwitchScreenAction<TypeSafeChangeMenu<LedstripAnimation, LedstripMenu, configs.ledstrip.animationType>>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, espgui::StaticText<TEXT_SELECTANIMATION>, espgui::SwitchScreenAction<TypeSafeChangeMenu<LedstripAnimation, LedstripMenu, decltype([&](LedstripAnimation enum_value, const auto &string_value)->void {})>>>>(); // this needs to be fixed
|
||||
|
||||
constructMenuItem<makeComponent<MenuItem, espgui::StaticText<TEXT_BRAKELIGHTS>, BobbyCheckbox, EnableBrakeLightsAccessor>>();
|
||||
|
||||
|
@ -10,59 +10,80 @@
|
||||
#include "actions/dummyaction.h"
|
||||
#include "actions/switchscreenaction.h"
|
||||
#include "displays/bobbymenudisplay.h"
|
||||
#include "bobbyerrorhandler.h"
|
||||
|
||||
namespace typesafeenumchangemenu {
|
||||
constexpr char TEXT_BACK[] = "Back";
|
||||
} // namespace typesafeenumchangemenu
|
||||
|
||||
template<typename TEnum, espconfig::ConfigWrapper<TEnum> config>
|
||||
class TypesafeEnumCurrentValueMenuItemText :
|
||||
public espgui::TextInterface
|
||||
template<typename TEnum>
|
||||
class TypesafeEnumCurrentValueMenuItem :
|
||||
public espgui::MenuItem
|
||||
{
|
||||
public:
|
||||
TypesafeEnumCurrentValueMenuItem(ConfigWrapper<TEnum> &config) : m_config{config} {}
|
||||
std::string text() const override
|
||||
{
|
||||
return toString(config.value);
|
||||
return toString(m_config.value);
|
||||
}
|
||||
void triggered() override {}
|
||||
|
||||
int color() const override
|
||||
{
|
||||
return TFT_DARKGREY;
|
||||
}
|
||||
private:
|
||||
const ConfigWrapper<TEnum> &m_config;
|
||||
};
|
||||
|
||||
template<typename TEnum, espconfig::ConfigWrapper<TEnum> config>
|
||||
template<typename TEnum>
|
||||
class TypesafeEnumSetterMenuItem :
|
||||
public espgui::MenuItem
|
||||
{
|
||||
public:
|
||||
TypesafeEnumSetterMenuItem(TEnum value, ConfigWrapper<TEnum> &config) : m_value{value}, m_config{config} {}
|
||||
|
||||
std::string text() const override
|
||||
{
|
||||
return toString(config.value);
|
||||
return toString(m_value);
|
||||
}
|
||||
|
||||
void triggered() override
|
||||
{
|
||||
|
||||
if (auto result = configs.write_config(m_config, m_value); !result)
|
||||
BobbyErrorHandler{}.errorOccured(std::move(result).error());
|
||||
}
|
||||
private:
|
||||
const TEnum m_value;
|
||||
const ConfigWrapper<TEnum> &m_config;
|
||||
};
|
||||
|
||||
template<typename TEnum, typename TMenu, espconfig::ConfigWrapper<TEnum> config>
|
||||
template<typename TEnum, typename TMenu, typename TIterator>
|
||||
class TypeSafeChangeMenu :
|
||||
public BobbyMenuDisplay
|
||||
{
|
||||
TypeSafeChangeMenu()
|
||||
public:
|
||||
TypeSafeChangeMenu(ConfigWrapper<TEnum> &config, TIterator iterator) : m_config{config}
|
||||
{
|
||||
using namespace espgui;
|
||||
using namespace typesafeenumchangemenu;
|
||||
constructMenuItem<makeComponent<MenuItem, TypesafeEnumCurrentValueMenuItemText<TEnum, config>, DisabledColor, DummyAction>>();
|
||||
constructMenuItem<TypesafeEnumCurrentValueMenuItem<TEnum>>(m_config);
|
||||
constructMenuItem<makeComponent<MenuItem, EmptyText, DummyAction>>();
|
||||
iterate([&](TEnum enum_value, const auto &string_value){ // this line needs to be fixed, help required
|
||||
constructMenuItem<TypesafeEnumSetterMenuItem<TEnum, config>>(enum_value);
|
||||
iterator([&](TEnum enum_value, const auto &string_value){
|
||||
constructMenuItem<TypesafeEnumSetterMenuItem<TEnum>>(enum_value, m_config);
|
||||
});
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<TMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
||||
}
|
||||
\
|
||||
|
||||
std::string text() const override
|
||||
{
|
||||
return fmt::format("Select {}", config.nvsName());
|
||||
return fmt::format("Select {}", m_config.nvsName());
|
||||
}
|
||||
\
|
||||
|
||||
void back() override
|
||||
{
|
||||
espgui::switchScreen<TMenu>();
|
||||
}
|
||||
private:
|
||||
const ConfigWrapper<TEnum> &m_config;
|
||||
};
|
||||
|
Reference in New Issue
Block a user