Skip to content

Commit

Permalink
Added semantic colours support
Browse files Browse the repository at this point in the history
  • Loading branch information
Madman10K committed May 23, 2024
1 parent c640c94 commit 8683496
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
28 changes: 26 additions & 2 deletions UTheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ YAML::Emitter& operator<<(YAML::Emitter& out, const ImVec2& vect) noexcept
#define OUTPUT_YAML_STYLE_VAR(x) out << YAML::Key << #x << YAML::Value << style.x;
#define RENDER_STYLE_VAR_EDIT(x) renderStyleVar(#x, style.x)

int UImGui::Theme::load(const char* file) noexcept
#define LOAD_YAML_SEMANTIC_COLOUR(x, y) if (out[#y]) (x)->y = out[#y].as<ImVec4>()
#define OUTPUT_YAML_SEMANTIC_COLOUR(x, y) out << YAML::Key << #y << YAML::Value << x->y;

int UImGui::Theme::load(const char* file, SemanticColorData* semanticColorData) noexcept
{
YAML::Node out;
try
Expand Down Expand Up @@ -120,10 +123,21 @@ int UImGui::Theme::load(const char* file) noexcept
#ifdef IMGUI_HAS_DOCK
LOAD_YAML_STYLE_VAR(DockingSeparatorSize);
#endif

if (semanticColorData != nullptr)
{
LOAD_YAML_SEMANTIC_COLOUR(semanticColorData, DestructiveColor);
LOAD_YAML_SEMANTIC_COLOUR(semanticColorData, DestructiveColorActive);
LOAD_YAML_SEMANTIC_COLOUR(semanticColorData, SuccessColor);
LOAD_YAML_SEMANTIC_COLOUR(semanticColorData, SuccessColorActive);
LOAD_YAML_SEMANTIC_COLOUR(semanticColorData, WarningColor);
LOAD_YAML_SEMANTIC_COLOUR(semanticColorData, WarningColorActive);
}

return 0;
}

void UImGui::Theme::save(const char* file) noexcept
void UImGui::Theme::save(const char* file, SemanticColorData* semanticColorData) noexcept
{
auto& style = ImGui::GetStyle();

Expand Down Expand Up @@ -165,6 +179,16 @@ void UImGui::Theme::save(const char* file) noexcept
#ifdef IMGUI_HAS_DOCK
OUTPUT_YAML_STYLE_VAR(DockingSeparatorSize);
#endif
if (semanticColorData != nullptr)
{
OUTPUT_YAML_SEMANTIC_COLOUR(semanticColorData, DestructiveColor);
OUTPUT_YAML_SEMANTIC_COLOUR(semanticColorData, DestructiveColorActive);
OUTPUT_YAML_SEMANTIC_COLOUR(semanticColorData, SuccessColor);
OUTPUT_YAML_SEMANTIC_COLOUR(semanticColorData, SuccessColorActive);
OUTPUT_YAML_SEMANTIC_COLOUR(semanticColorData, WarningColor);
OUTPUT_YAML_SEMANTIC_COLOUR(semanticColorData, WarningColorActive);
}

out << YAML::EndMap;

std::ofstream o(file);
Expand Down
23 changes: 20 additions & 3 deletions UTheme.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,26 @@

namespace UImGui
{
class Theme
struct IMGUI_API SemanticColorData
{
ImVec4 DestructiveColor;
ImVec4 DestructiveColorActive;
ImVec4 SuccessColor;
ImVec4 SuccessColorActive;
ImVec4 WarningColor;
ImVec4 WarningColorActive;
};

class IMGUI_API Theme
{
public:
/**
* @brief Loads a theme from file location
* @param file - The location of the theme file
* @return Result state. 0 on success, -1 on bad file
*/
static int load(const char* file) noexcept;
static void save(const char* file) noexcept;
static int load(const char* file, SemanticColorData* semanticColorData = nullptr) noexcept;
static void save(const char* file, SemanticColorData* semanticColorData = nullptr) noexcept;

static void showThemeEditor(void* bOpen) noexcept;
static void showThemeEditorInline() noexcept;
Expand Down Expand Up @@ -81,6 +91,13 @@ namespace UImGui
"NavWindowingHighlight",
"NavWindowingDimBg",
"ModalWindowDimBg",

"DestructiveColor",
"DestructiveColorActive",
"SuccessColor",
"SuccessColorActive",
"WarningColor",
"WarningColorActive"
};
};
}

0 comments on commit 8683496

Please sign in to comment.