diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-06-08 08:04:48 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-06-08 08:04:48 +0200 |
commit | 63edd105d758a39b856f9099b339de30895df8ac (patch) | |
tree | 8c5d0bc4c3aa63e29391291cc7f1e8dca1f5da7c /editor | |
parent | a0b3c0b64b44536bb073677eac57bdc737dd4e9b (diff) |
inspect: simplify getting object unique id for imgui
Diffstat (limited to 'editor')
-rw-r--r-- | editor/app.hpp | 2 | ||||
-rw-r--r-- | editor/imgui.cpp | 4 | ||||
-rw-r--r-- | editor/inspect-draw.cpp | 15 |
3 files changed, 10 insertions, 11 deletions
diff --git a/editor/app.hpp b/editor/app.hpp index 4476fb91..aecd495b 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -138,7 +138,7 @@ private: void draw_editor_pane(float main_menu_height); void draw_inspector(); - static void entity_inspector_name(char* buf, size_t len, object_id id); + static void entity_inspector_name(char(&buf)[10], object_id id); static void entity_friendly_name(char* buf, size_t len, const object& obj); bool check_inspector_exists(const popup_target& p); void set_cursor_from_imgui(); diff --git a/editor/imgui.cpp b/editor/imgui.cpp index 916257b2..2923c3ea 100644 --- a/editor/imgui.cpp +++ b/editor/imgui.cpp @@ -372,8 +372,8 @@ void app::do_popup_menu() if (!exists) add_inspector(std::exchange(_popup_target, {})); { - char buf2[32], buf3[128], buf[sizeof buf2 + sizeof buf3 - 1]; - entity_inspector_name(buf2, sizeof buf2, e.id); + char buf2[10], buf3[128], buf[sizeof buf2 + sizeof buf3 - 1]; + entity_inspector_name(buf2, e.id); entity_friendly_name(buf3, sizeof buf3, e); std::snprintf(buf, sizeof buf, "%s###%s", buf3, buf2); ImGui::SetWindowFocus(buf); diff --git a/editor/inspect-draw.cpp b/editor/inspect-draw.cpp index 9752f018..d5474b8b 100644 --- a/editor/inspect-draw.cpp +++ b/editor/inspect-draw.cpp @@ -1,4 +1,5 @@ #include "app.hpp" +#include "compat/array-size.hpp" #include "compat/format.hpp" #include "inspect.hpp" #include "floormat/main.hpp" @@ -32,9 +33,9 @@ void app::draw_inspector() } auto& e = *eʹ; - char buf2[32], buf3[128], buf[sizeof buf2 + sizeof buf3 - 1]; + char buf2[10], buf3[128], buf[sizeof buf2 + sizeof buf3 - 1]; ImGui::SetNextWindowSize({375*dpi[0], 0}); - entity_inspector_name(buf2, sizeof buf2, e.id); + entity_inspector_name(buf2, e.id); entity_friendly_name(buf3, sizeof buf3, e); std::snprintf(buf, sizeof buf, "%s###%s", buf3, buf2); @@ -49,13 +50,11 @@ void app::draw_inspector() } } -void app::entity_inspector_name(char* buf, size_t len, object_id id) +void app::entity_inspector_name(char(&buf)[10], object_id id) { - constexpr auto min_len = sizeof "inspector-" + 8; - fm_assert(len >= min_len); - auto result = fmt::format_to_n(buf, len, "inspector-{:08x}"_cf, id); - fm_assert(result.size < len); - buf[result.size] = '\0'; + auto result = fmt::format_to_n(buf, array_size(buf), "@{:08x}"_cf, id); + fm_assert(result.size == 9); + buf[array_size(buf)-1] = '\0'; } void app::entity_friendly_name(char* buf, size_t len, const object& obj) |