diff --git a/Engine/Source/Editor/UILayers/Inspector.cpp b/Engine/Source/Editor/UILayers/Inspector.cpp index 5602c2be..8594b27d 100644 --- a/Engine/Source/Editor/UILayers/Inspector.cpp +++ b/Engine/Source/Editor/UILayers/Inspector.cpp @@ -187,7 +187,7 @@ void UpdateComponentWidget(engine::SceneWorld* pScene { // TODO : generic cull mode. ImGuiUtils::ImGuiBoolProperty("TwoSided", pMaterialComponent->GetTwoSided()); - ImGuiUtils::ImGuiStringProperty("BlendMode", nameof::nameof_enum(pMaterialComponent->GetBlendMode()).data()); + ImGuiUtils::ImGuiEnumProperty("BlendMode", pMaterialComponent->GetBlendMode()); } ImGui::Separator(); @@ -559,25 +559,11 @@ void UpdateComponentWidget(engine::SceneWorld* pSceneWorld if (!skyTypes.empty()) { - static const char* crtItem = nameof::nameof_enum(engine::SkyType::SkyBox).data(); - if (ImGui::BeginCombo("##combo", crtItem)) + auto currentSkyType = pSkyComponent->GetSkyType(); + if (ImGuiUtils::ImGuiEnumProperty("SkyType", currentSkyType)) { - for (size_t index = 0; index < skyTypes.size(); ++index) - { - bool isSelected = (crtItem == skyTypes[index]); - if (ImGui::Selectable(skyTypes[index], isSelected)) - { - crtItem = skyTypes[index]; - pSkyComponent->SetSkyType(static_cast(index)); - } - if (isSelected) - { - ImGui::SetItemDefaultFocus(); - } - } - ImGui::EndCombo(); + pSkyComponent->SetSkyType(currentSkyType); } - } if (pSkyComponent->GetAtmophericScatteringEnable()) diff --git a/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp b/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp index 48734b9c..3b440c1b 100644 --- a/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp +++ b/Engine/Source/Runtime/ImGui/ImGuiUtils.hpp @@ -15,6 +15,44 @@ static bool ImGuiBoolProperty(const char* pName, bool& value) return ImGui::Checkbox(pName, &value); } +template +static bool ImGuiEnumProperty(const char* pName, EnumType& value) +{ + bool dirty = false; + + ImGui::Columns(2); + ImGui::TextUnformatted(pName); + ImGui::NextColumn(); + ImGui::PushItemWidth(-1); + + if (ImGui::BeginCombo("##combo", nameof::nameof_enum(value).data())) + { + auto enumCount = nameof::detail::count_v>; + for (uint32_t enumIndex = 0U; enumIndex < enumCount; ++enumIndex) + { + EnumType enumValue = static_cast(enumIndex); + bool isSelected = enumValue == value; + if (ImGui::Selectable(nameof::nameof_enum(enumValue).data(), isSelected)) + { + value = enumValue; + dirty = true; + } + + if (isSelected) + { + ImGui::SetItemDefaultFocus(); + } + } + ImGui::EndCombo(); + } + + ImGui::PopItemWidth(); + ImGui::NextColumn(); + ImGui::Columns(1); + + return dirty; +} + static bool ImGuiStringProperty(const char* pName, const char* pValue) { ImGui::Columns(2);