Skip to content

Commit

Permalink
add imgui enum property util
Browse files Browse the repository at this point in the history
  • Loading branch information
T-rvw committed Sep 23, 2023
1 parent 9566c07 commit 00c520a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 18 deletions.
22 changes: 4 additions & 18 deletions Engine/Source/Editor/UILayers/Inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void UpdateComponentWidget<engine::MaterialComponent>(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();
Expand Down Expand Up @@ -559,25 +559,11 @@ void UpdateComponentWidget<engine::SkyComponent>(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<engine::SkyType>(index));
}
if (isSelected)
{
ImGui::SetItemDefaultFocus();
}
}
ImGui::EndCombo();
pSkyComponent->SetSkyType(currentSkyType);
}

}

if (pSkyComponent->GetAtmophericScatteringEnable())
Expand Down
38 changes: 38 additions & 0 deletions Engine/Source/Runtime/ImGui/ImGuiUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,44 @@ static bool ImGuiBoolProperty(const char* pName, bool& value)
return ImGui::Checkbox(pName, &value);
}

template<typename EnumType>
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<std::decay_t<EnumType>>;
for (uint32_t enumIndex = 0U; enumIndex < enumCount; ++enumIndex)
{
EnumType enumValue = static_cast<EnumType>(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);
Expand Down

0 comments on commit 00c520a

Please sign in to comment.