2022-12-29 19:26:00 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
|
|
|
#include <hex/helpers/fs.hpp>
|
|
|
|
|
|
|
|
#include <string>
|
2023-02-16 18:06:40 +01:00
|
|
|
#include <variant>
|
2022-12-29 19:26:00 +01:00
|
|
|
|
|
|
|
#include <nlohmann/json_fwd.hpp>
|
|
|
|
#include <imgui.h>
|
|
|
|
|
2023-03-23 20:35:16 +01:00
|
|
|
namespace hex {
|
2022-12-29 19:26:00 +01:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief The Theme Manager takes care of loading and applying themes
|
|
|
|
*/
|
2022-12-29 19:26:00 +01:00
|
|
|
class ThemeManager {
|
|
|
|
public:
|
|
|
|
constexpr static auto NativeTheme = "Native";
|
|
|
|
|
2023-02-16 18:06:40 +01:00
|
|
|
using ColorMap = std::map<std::string, u32>;
|
|
|
|
|
|
|
|
struct Style {
|
|
|
|
std::variant<ImVec2*, float*> value;
|
|
|
|
float min;
|
|
|
|
float max;
|
2023-03-18 10:52:50 +01:00
|
|
|
bool needsScaling;
|
2023-02-16 18:06:40 +01:00
|
|
|
};
|
|
|
|
using StyleMap = std::map<std::string, Style>;
|
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Changes the current theme to the one with the given name
|
|
|
|
* @param name Name of the theme to change to
|
|
|
|
*/
|
2022-12-29 19:26:00 +01:00
|
|
|
static void changeTheme(std::string name);
|
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
/**
|
|
|
|
* @brief Adds a theme from json data
|
|
|
|
* @param content JSON data of the theme
|
|
|
|
*/
|
2022-12-29 19:26:00 +01:00
|
|
|
static void addTheme(const std::string &content);
|
2023-03-21 15:33:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Adds a theme handler to handle color values loaded from a theme file
|
|
|
|
* @param name Name of the handler
|
|
|
|
* @param colorMap Map of color names to their respective constants
|
|
|
|
* @param getFunction Function to get the color value of a constant
|
|
|
|
* @param setFunction Function to set the color value of a constant
|
|
|
|
*/
|
2023-02-16 18:06:40 +01:00
|
|
|
static void addThemeHandler(const std::string &name, const ColorMap &colorMap, const std::function<ImColor(u32)> &getFunction, const std::function<void(u32, ImColor)> &setFunction);
|
2023-03-21 15:33:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Adds a style handler to handle style values loaded from a theme file
|
|
|
|
* @param name Name of the handler
|
|
|
|
* @param styleMap Map of style names to their respective constants
|
|
|
|
*/
|
2023-02-16 18:06:40 +01:00
|
|
|
static void addStyleHandler(const std::string &name, const StyleMap &styleMap);
|
2022-12-29 19:26:00 +01:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
|
2022-12-29 19:26:00 +01:00
|
|
|
static std::vector<std::string> getThemeNames();
|
2023-07-04 08:42:33 +02:00
|
|
|
static const std::string &getImageTheme();
|
2022-12-29 19:26:00 +01:00
|
|
|
|
|
|
|
static std::optional<ImColor> parseColorString(const std::string &colorString);
|
2023-01-05 09:29:16 +01:00
|
|
|
|
2023-02-16 18:06:40 +01:00
|
|
|
static nlohmann::json exportCurrentTheme(const std::string &name);
|
|
|
|
|
2023-01-05 09:29:16 +01:00
|
|
|
static void reset();
|
2023-02-16 18:06:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
struct ThemeHandler {
|
|
|
|
ColorMap colorMap;
|
|
|
|
std::function<ImColor(u32)> getFunction;
|
|
|
|
std::function<void(u32, ImColor)> setFunction;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StyleHandler {
|
|
|
|
StyleMap styleMap;
|
|
|
|
};
|
|
|
|
|
2023-07-26 13:50:51 +02:00
|
|
|
static std::map<std::string, ThemeHandler>& getThemeHandlers();
|
|
|
|
static std::map<std::string, StyleHandler>& getStyleHandlers();
|
2023-02-16 18:06:40 +01:00
|
|
|
|
2022-12-29 19:26:00 +01:00
|
|
|
private:
|
|
|
|
ThemeManager() = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|