Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: serialize ImVec to array instead of object #641

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
};
Loading