2024-04-21 14:17:50 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <imgui/imgui.h>
|
|
|
|
|
|
|
|
#include <entt/container/dense_map.hpp>
|
|
|
|
#include <entt/core/type_info.hpp>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
// default is resolving to its value
|
|
|
|
template<typename T>
|
|
|
|
std::string typeValueName(T V) {
|
|
|
|
return std::to_string(static_cast<std::underlying_type_t<T>>(V));
|
|
|
|
}
|
|
|
|
|
|
|
|
// stores theming values and colors not expressed by imgui directly
|
|
|
|
struct Theme {
|
|
|
|
using key_type = entt::id_type;
|
|
|
|
|
|
|
|
entt::dense_map<key_type, ImVec4> colors;
|
|
|
|
entt::dense_map<key_type, std::string> colors_name;
|
|
|
|
|
|
|
|
// TODO: spec out dependencies
|
|
|
|
|
|
|
|
// TODO: what for
|
|
|
|
entt::dense_map<key_type, float> single_values;
|
|
|
|
|
|
|
|
std::string name; // theme name
|
|
|
|
|
|
|
|
Theme(void);
|
|
|
|
|
|
|
|
// call when any color changed, so dependencies can be resolved
|
|
|
|
void update(void);
|
|
|
|
|
|
|
|
template<auto V>
|
|
|
|
void setColor(ImVec4 color) {
|
2024-04-21 20:39:03 +02:00
|
|
|
constexpr auto key = entt::type_hash<entt::tag<static_cast<entt::id_type>(V)>>::value();
|
2024-04-21 14:17:50 +02:00
|
|
|
colors[key] = color;
|
|
|
|
|
|
|
|
if (!colors_name.contains(key)) {
|
|
|
|
std::string key_name = static_cast<std::string>(
|
|
|
|
entt::type_name<decltype(V)>::value()
|
|
|
|
) + ":" + typeValueName(V);
|
|
|
|
colors_name[key] = key_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
template<auto V>
|
|
|
|
ImVec4 getColor(void) const {
|
2024-04-21 20:39:03 +02:00
|
|
|
constexpr auto key = entt::type_hash<entt::tag<static_cast<entt::id_type>(V)>>::value();
|
2024-04-21 14:17:50 +02:00
|
|
|
const auto it = colors.find(key);
|
|
|
|
if (it != colors.end()) {
|
|
|
|
return it->second;
|
|
|
|
} else {
|
|
|
|
return {}; // TODO: pink as default?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<auto V>
|
|
|
|
std::string_view getColorName(void) const {
|
2024-04-21 20:39:03 +02:00
|
|
|
constexpr auto key = entt::type_hash<entt::tag<static_cast<entt::id_type>(V)>>::value();
|
2024-04-21 14:17:50 +02:00
|
|
|
if (colors_name.contains(key)) {
|
|
|
|
return colors_name.at(key);
|
|
|
|
} else {
|
|
|
|
return "unk";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: actually serialize from config?
|
|
|
|
bool load(void);
|
|
|
|
bool store(void);
|
|
|
|
};
|
|
|
|
|
|
|
|
Theme getDefaultThemeDark(void);
|
|
|
|
Theme getDefaultThemeLight(void);
|
|
|
|
|