From e1c198823bb60c22081efb1c79e335e77b341bf6 Mon Sep 17 00:00:00 2001 From: iWas-Coder Date: Mon, 7 Oct 2024 18:06:33 +0200 Subject: [PATCH] [WIP] fix: show correct sprite name/path in editor --- src/Renderer/SpriteRendererComponent.cc | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Renderer/SpriteRendererComponent.cc b/src/Renderer/SpriteRendererComponent.cc index 042482d..81ddc45 100644 --- a/src/Renderer/SpriteRendererComponent.cc +++ b/src/Renderer/SpriteRendererComponent.cc @@ -49,16 +49,15 @@ namespace volt::renderer { } void SpriteRendererComponent::Draw(void) { - static bool is_first_time { true }; + static size_t sprite_path_len {0}; static std::array sprite_path { "default" }; static ImVec4 sprite_color {1, 1, 1, 1}; - if (is_first_time) { - size_t len { std::min(sprite.name().size(), sprite_path.size() - 1) }; - std::copy_n(sprite.name().begin(), len, sprite_path.begin()); - sprite_path[len] = 0; - is_first_time = false; - } if (ImGui::CollapsingHeader(SpriteRendererComponent::cmp_name)) { + if (sprite.name() != sprite_path.data()) { + sprite_path_len = std::min(sprite.name().size(), sprite_path.size() - 1); + std::copy_n(sprite.name().begin(), sprite_path_len, sprite_path.begin()); + sprite_path[sprite_path_len] = 0; + } ImGui::InputText("Sprite", sprite_path.data(), sprite_path.size()); try { sprite.Reset(std::string(sprite_path.data())); } catch (const std::runtime_error &) {