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

add imgui enum property util #400

Merged
merged 2 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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>>;
T-rvw marked this conversation as resolved.
Show resolved Hide resolved
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