From ae934efb136307908d8e2dbf82da0c4c7da64621 Mon Sep 17 00:00:00 2001 From: Panos Karabelas Date: Fri, 1 Dec 2023 14:28:16 +0000 Subject: [PATCH] [Editor] Fixed erratic behaviour of material multiplier sliders when selecting different entities in the world --- editor/ImGui/ImGuiExtension.h | 4 +++- editor/Widgets/Properties.cpp | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/editor/ImGui/ImGuiExtension.h b/editor/ImGui/ImGuiExtension.h index bd557bc0f..6692abcb8 100644 --- a/editor/ImGui/ImGuiExtension.h +++ b/editor/ImGui/ImGuiExtension.h @@ -343,7 +343,7 @@ namespace ImGuiSp static bool needs_to_wrap = false; ImGuiIO& imgui_io = ImGui::GetIO(); - // Wrap + // wrap if (ImGui::IsMouseDragging(ImGuiMouseButton_Left)) { ImVec2 position_cursor = imgui_io.MousePos; @@ -376,7 +376,9 @@ namespace ImGuiSp } } + ImGui::PushID(static_cast(ImGui::GetCursorPosX() + ImGui::GetCursorPosY())); ImGui::DragFloat(label, v, v_speed, v_min, v_max, format, flags); + ImGui::PopID(); } static bool combo_box(const char* label, const std::vector& options, uint32_t* selection_index) diff --git a/editor/Widgets/Properties.cpp b/editor/Widgets/Properties.cpp index d44ffbf77..2b57138f5 100644 --- a/editor/Widgets/Properties.cpp +++ b/editor/Widgets/Properties.cpp @@ -674,7 +674,7 @@ void Properties::ShowMaterial(Material* material) const if (material->GetProperty(MaterialProperty::CanBeEdited) == 1.0f) { - // Texture slots + // texture slots { const auto show_property = [this, &material](const char* name, const char* tooltip, const MaterialTexture mat_tex, const MaterialProperty mat_property) { @@ -697,7 +697,7 @@ void Properties::ShowMaterial(Material* material) const } } - // Texture + // texture if (show_texture) { auto setter = [&material, &mat_tex](const shared_ptr& texture) { material->SetTexture(mat_tex, texture); }; @@ -723,7 +723,7 @@ void Properties::ShowMaterial(Material* material) const } } - // Modifier + // modifier/multiplier if (show_modifier) { if (mat_property == MaterialProperty::ColorTint) @@ -732,7 +732,6 @@ void Properties::ShowMaterial(Material* material) const } else { - ImGui::PushID(static_cast(ImGui::GetCursorPosX() + ImGui::GetCursorPosY())); float value = material->GetProperty(mat_property); if (mat_property != MaterialProperty::MultiplierMetalness) @@ -751,12 +750,13 @@ void Properties::ShowMaterial(Material* material) const else { bool is_metallic = value != 0.0f; + ImGui::PushID(static_cast(ImGui::GetCursorPosX() + ImGui::GetCursorPosY())); ImGui::Checkbox("##metalness", &is_metallic); + ImGui::PopID(); value = is_metallic ? 1.0f : 0.0f; } material->SetProperty(mat_property, value); - ImGui::PopID(); } } };