mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-01 21:17:44 -05:00
feat: Added a theme manager view to make it easier to make new themes
This commit is contained in:
@@ -134,6 +134,7 @@ namespace hex {
|
||||
EVENT_DEF(RequestChangeTheme, std::string);
|
||||
EVENT_DEF(RequestOpenPopup, std::string);
|
||||
EVENT_DEF(RequestCreateProvider, std::string, bool, hex::prv::Provider **);
|
||||
EVENT_DEF(RequestInitThemeHandlers);
|
||||
|
||||
EVENT_DEF(RequestShowInfoPopup, std::string);
|
||||
EVENT_DEF(RequestShowErrorPopup, std::string);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <hex/helpers/fs.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
#include <imgui.h>
|
||||
@@ -14,24 +15,54 @@ namespace hex::api {
|
||||
public:
|
||||
constexpr static auto NativeTheme = "Native";
|
||||
|
||||
using ColorMap = std::map<std::string, u32>;
|
||||
|
||||
struct Style {
|
||||
std::variant<ImVec2*, float*> value;
|
||||
float min;
|
||||
float max;
|
||||
};
|
||||
using StyleMap = std::map<std::string, Style>;
|
||||
|
||||
static void changeTheme(std::string name);
|
||||
|
||||
static void addTheme(const std::string &content);
|
||||
static void addThemeHandler(const std::string &name, const std::function<void(std::string, std::string)> &handler);
|
||||
static void addStyleHandler(const std::string &name, const std::function<void(std::string, std::string)> &handler);
|
||||
static void addThemeHandler(const std::string &name, const ColorMap &colorMap, const std::function<ImColor(u32)> &getFunction, const std::function<void(u32, ImColor)> &setFunction);
|
||||
static void addStyleHandler(const std::string &name, const StyleMap &styleMap);
|
||||
|
||||
static std::vector<std::string> getThemeNames();
|
||||
static const std::string &getThemeImagePostfix();
|
||||
|
||||
static std::optional<ImColor> parseColorString(const std::string &colorString);
|
||||
|
||||
static nlohmann::json exportCurrentTheme(const std::string &name);
|
||||
|
||||
static void reset();
|
||||
|
||||
|
||||
public:
|
||||
struct ThemeHandler {
|
||||
ColorMap colorMap;
|
||||
std::function<ImColor(u32)> getFunction;
|
||||
std::function<void(u32, ImColor)> setFunction;
|
||||
};
|
||||
|
||||
struct StyleHandler {
|
||||
StyleMap styleMap;
|
||||
};
|
||||
|
||||
static std::map<std::string, ThemeHandler>& getThemeHandlers() { return s_themeHandlers; }
|
||||
static std::map<std::string, StyleHandler>& getStyleHandlers() { return s_styleHandlers; }
|
||||
|
||||
private:
|
||||
ThemeManager() = default;
|
||||
|
||||
|
||||
static std::map<std::string, nlohmann::json> s_themes;
|
||||
static std::map<std::string, std::function<void(std::string, std::string)>> s_themeHandlers, s_styleHandlers;
|
||||
static std::map<std::string, ThemeHandler> s_themeHandlers;
|
||||
static std::map<std::string, StyleHandler> s_styleHandlers;
|
||||
static std::string s_imagePostfix;
|
||||
static std::string s_currTheme;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user