#pragma once #include #include #include #include #include #include namespace hex { /** * @brief The Theme Manager takes care of loading and applying themes */ class ThemeManager { public: constexpr static auto NativeTheme = "Native"; using ColorMap = std::map; struct Style { std::variant value; float min; float max; bool needsScaling; }; using StyleMap = std::map; /** * @brief Changes the current theme to the one with the given name * @param name Name of the theme to change to */ static void changeTheme(std::string name); /** * @brief Adds a theme from json data * @param content JSON data of the theme */ static void addTheme(const std::string &content); /** * @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 */ static void addThemeHandler(const std::string &name, const ColorMap &colorMap, const std::function &getFunction, const std::function &setFunction); /** * @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 */ static void addStyleHandler(const std::string &name, const StyleMap &styleMap); static std::vector getThemeNames(); static const std::string &getImageTheme(); static std::optional parseColorString(const std::string &colorString); static nlohmann::json exportCurrentTheme(const std::string &name); static void reset(); public: struct ThemeHandler { ColorMap colorMap; std::function getFunction; std::function setFunction; }; struct StyleHandler { StyleMap styleMap; }; static std::map& getThemeHandlers() { return s_themeHandlers; } static std::map& getStyleHandlers() { return s_styleHandlers; } private: ThemeManager() = default; static std::map s_themes; static std::map s_themeHandlers; static std::map s_styleHandlers; static std::string s_imageTheme; static std::string s_currTheme; }; }