Skip to content

Commit

Permalink
chore: serialize ImVec to array instead of object (#641)
Browse files Browse the repository at this point in the history
because:
1. it's less cloggy
2. it follows the same format as d3d vecs
3. serializations should be placed in Util
  • Loading branch information
Pentalimbed authored Oct 14, 2024
1 parent cd265e4 commit 41a3356
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
12 changes: 0 additions & 12 deletions src/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@
#include "Streamline.h"
#include "Upscaling.h"

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
ImVec2,
x,
y)

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
ImVec4,
x,
y,
z,
w)

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
Menu::ThemeSettings,
FontScale,
Expand Down
22 changes: 22 additions & 0 deletions src/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,4 +466,26 @@ namespace nlohmann
std::array<float, 4> temp = j;
v = { temp[0], temp[1], temp[2], temp[3] };
}

void to_json(json& j, const ImVec2& v)
{
j = json{ v.x, v.y };
}

void from_json(const json& j, ImVec2& v)
{
std::array<float, 2> temp = j;
v = { temp[0], temp[1] };
}

void to_json(json& j, const ImVec4& v)
{
j = json{ v.x, v.y, v.z, v.w };
}

void from_json(const json& j, ImVec4& v)
{
std::array<float, 4> temp = j;
v = { temp[0], temp[1], temp[2], temp[3] };
}
}
5 changes: 5 additions & 0 deletions src/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,9 @@ namespace nlohmann
void from_json(const json& j, float3& v);
void to_json(json& j, const float4& v);
void from_json(const json& j, float4& v);

void to_json(json& j, const ImVec2& v);
void from_json(const json& j, ImVec2& v);
void to_json(json& j, const ImVec4& v);
void from_json(const json& j, ImVec4& v);
};

0 comments on commit 41a3356

Please sign in to comment.