From acf323ebd958219a586d79aed1c4d6672bb98d52 Mon Sep 17 00:00:00 2001 From: OVOAOVO <2410651402@qq.com> Date: Sat, 20 Jan 2024 16:28:39 +0800 Subject: [PATCH 1/4] Template color picker 3/4 --- Engine/Source/Runtime/ImGui/ImGuiUtils.hpp | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp b/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp index a73f2110..07c9e27b 100644 --- a/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp +++ b/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp @@ -263,7 +263,8 @@ static bool ImGuiTransformProperty(const char* pName, cd::Transform& value) return dirty; } -static void ColorPickerProperty(const char* Name, cd::Vec3f& veccolor) +template +static void ColorPickerProperty(const char* Name, T& veccolor) { static std::map showMap; if (!showMap.count(Name)) @@ -282,7 +283,19 @@ static void ColorPickerProperty(const char* Name, cd::Vec3f& veccolor) ImGui::PushItemWidth(-1); ImGui::SameLine(); ImGui::NextColumn(); - ImGui::DragFloat3("", veccolor.begin(), 0, 0.0f, 1.0f); + if constexpr (std::is_same()) + { + ImGui::DragFloat3("", veccolor.begin(), 0, 0.0f, 1.0f); + } + else if (std::is_same()) + { + ImGui::DragFloat4("", veccolor.begin(), 0, 0.0f, 1.0f); + } + else + { + static_assert("Unsupported color data type for ImGuiColorPickerProperty."); + } + ImGui::PopItemWidth(); if (showMap[Name]) { @@ -294,7 +307,14 @@ static void ColorPickerProperty(const char* Name, cd::Vec3f& veccolor) ImGui::SetNextWindowPos(windowPos, ImGuiCond_Always); ImGui::Begin(Name, &showMap[Name], ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize); - ImGui::ColorPicker3("Color Picker", veccolor.begin()); + if constexpr (std::is_same()) + { + ImGui::ColorPicker3("Color Picker", veccolor.begin()); + } + else if constexpr (std::is_same()) + { + ImGui::ColorPicker4("Color Picker", veccolor.begin()); + } ImGui::End(); } ImGui::Separator(); From 314f6d07d6b329357a1ec41ecc72b1e05a958997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B5=A9=E5=A4=A9?= <88096545+OVOAOVO@users.noreply.github.com> Date: Sun, 21 Jan 2024 14:07:13 +0800 Subject: [PATCH 2/4] Update Engine/Source/Runtime/ImGui/ImGuiUtils.hpp Co-authored-by: Jiajun <75730859+T-rvw@users.noreply.github.com> --- Engine/Source/Runtime/ImGui/ImGuiUtils.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp b/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp index 07c9e27b..251ca497 100644 --- a/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp +++ b/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp @@ -287,7 +287,7 @@ static void ColorPickerProperty(const char* Name, T& veccolor) { ImGui::DragFloat3("", veccolor.begin(), 0, 0.0f, 1.0f); } - else if (std::is_same()) + else if constexpr (std::is_same()) { ImGui::DragFloat4("", veccolor.begin(), 0, 0.0f, 1.0f); } From 1ed271c4811c76443843e6f5ac0342af5cbaddce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B5=A9=E5=A4=A9?= <88096545+OVOAOVO@users.noreply.github.com> Date: Sun, 21 Jan 2024 14:07:26 +0800 Subject: [PATCH 3/4] Update Engine/Source/Runtime/ImGui/ImGuiUtils.hpp Co-authored-by: Jiajun <75730859+T-rvw@users.noreply.github.com> --- Engine/Source/Runtime/ImGui/ImGuiUtils.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp b/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp index 251ca497..36b1acd4 100644 --- a/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp +++ b/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp @@ -264,7 +264,7 @@ static bool ImGuiTransformProperty(const char* pName, cd::Transform& value) } template -static void ColorPickerProperty(const char* Name, T& veccolor) +static void ColorPickerProperty(const char* Name, T& color) { static std::map showMap; if (!showMap.count(Name)) From a3bbc74a5b9e03d0057f81c9d26f282861d9c6b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B5=A9=E5=A4=A9?= <88096545+OVOAOVO@users.noreply.github.com> Date: Sun, 21 Jan 2024 06:28:40 +0000 Subject: [PATCH 4/4] color and pName fixed --- Engine/Source/Runtime/ImGui/ImGuiUtils.hpp | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp b/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp index 36b1acd4..d5c589fd 100644 --- a/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp +++ b/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp @@ -264,20 +264,20 @@ static bool ImGuiTransformProperty(const char* pName, cd::Transform& value) } template -static void ColorPickerProperty(const char* Name, T& color) +static void ColorPickerProperty(const char* pName, T& color) { static std::map showMap; - if (!showMap.count(Name)) + if (!showMap.count(pName)) { - showMap[Name] = false; + showMap[pName] = false; } - ImGui::TextUnformatted(Name); + ImGui::TextUnformatted(pName); ImGui::SameLine(); ImGui::NextColumn(); - ImGui::PushID(Name); + ImGui::PushID(pName); if (ImGui::Button("...")) { - showMap[Name] = true; + showMap[pName] = true; } ImGui::PopID(); ImGui::PushItemWidth(-1); @@ -285,11 +285,11 @@ static void ColorPickerProperty(const char* Name, T& color) ImGui::NextColumn(); if constexpr (std::is_same()) { - ImGui::DragFloat3("", veccolor.begin(), 0, 0.0f, 1.0f); + ImGui::DragFloat3("", color.begin(), 0, 0.0f, 1.0f); } else if constexpr (std::is_same()) { - ImGui::DragFloat4("", veccolor.begin(), 0, 0.0f, 1.0f); + ImGui::DragFloat4("", color.begin(), 0, 0.0f, 1.0f); } else { @@ -297,7 +297,7 @@ static void ColorPickerProperty(const char* Name, T& color) } ImGui::PopItemWidth(); - if (showMap[Name]) + if (showMap[pName]) { ImGuiIO& io = ImGui::GetIO(); ImVec2 mainWindowSize = io.DisplaySize; @@ -306,14 +306,14 @@ static void ColorPickerProperty(const char* Name, T& color) ImVec2 windowPos(mainWindowSize.x - offsetX, mainWindowSize.y - offsetY); ImGui::SetNextWindowPos(windowPos, ImGuiCond_Always); - ImGui::Begin(Name, &showMap[Name], ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize); + ImGui::Begin(pName, &showMap[pName], ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize); if constexpr (std::is_same()) { - ImGui::ColorPicker3("Color Picker", veccolor.begin()); + ImGui::ColorPicker3("Color Picker", color.begin()); } else if constexpr (std::is_same()) { - ImGui::ColorPicker4("Color Picker", veccolor.begin()); + ImGui::ColorPicker4("Color Picker", color.begin()); } ImGui::End(); }