From 3562ee6ef75d3ff436d9fb38f8a4ea83329162ec Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 25 May 2023 11:49:03 +0200 Subject: editor/inspect: adjust label width dynamically --- editor/inspect.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'editor/inspect.cpp') diff --git a/editor/inspect.cpp b/editor/inspect.cpp index 7f69b56f..e6448e4e 100644 --- a/editor/inspect.cpp +++ b/editor/inspect.cpp @@ -16,13 +16,13 @@ namespace floormat::entities { namespace { -const char* label_left(StringView label, char* buf, size_t len) +const char* label_left(StringView label, char* buf, size_t len, float width) { std::snprintf(buf, len, "##%s", label.data()); - float width = ImGui::CalcItemWidth(), x = ImGui::GetCursorPosX(); + float x = ImGui::GetCursorPosX(); ImGui::Text("%s", label.data()); ImGui::SameLine(); - ImGui::SetCursorPosX(x + width*.5f + ImGui::GetStyle().ItemInnerSpacing.x); + ImGui::SetCursorPosX(x + width + ImGui::GetStyle().ItemInnerSpacing.x); ImGui::SetNextItemWidth(-1); return buf; } @@ -39,9 +39,6 @@ template<> struct IGDT_ : std::integral_constant struct IGDT_ : std::integral_constant {}; template constexpr auto IGDT = IGDT_::value; -using namespace imgui; -using namespace entities; - template requires std::is_integral_v constexpr bool eqv(T a, T b) { return a == b; } inline bool eqv(float a, float b) { return std::fabs(a - b) < 1e-8f; } inline bool eqv(const String& a, const String& b) { return a == b; } @@ -59,9 +56,12 @@ int corrade_string_resize_callback(ImGuiInputTextCallbackData* data) return 0; } +using namespace imgui; + template bool do_inspect_field(void* datum, const erased_accessor& accessor, field_repr repr, - const ArrayView>& list) + const ArrayView>& list, + size_t label_width) { if (list.isEmpty()) fm_assert(accessor.check_field_type()); @@ -80,7 +80,7 @@ bool do_inspect_field(void* datum, const erased_accessor& accessor, field_repr r should_disable = should_disable || !accessor.can_write(); [[maybe_unused]] auto disabler = begin_disabled(should_disable); bool ret = false; - const char* const label = label_left(accessor.field_name, buf, sizeof buf); + const char* const label = label_left(accessor.field_name, buf, sizeof buf, (float)label_width); T value{}; accessor.read_fun(datum, accessor.reader, &value); auto orig = value; @@ -173,17 +173,19 @@ bool do_inspect_field(void* datum, const erased_accessor& accessor, field_repr r #define MAKE_SPEC(type, repr) \ template<> \ bool inspect_field(void* datum, const erased_accessor& accessor, \ - const ArrayView>& list) \ + const ArrayView>& list, \ + size_t label_width) \ { \ - return do_inspect_field(datum, accessor, (repr), list); \ + return do_inspect_field(datum, accessor, (repr), list, label_width); \ } #define MAKE_SPEC2(type, repr) \ template<> \ bool inspect_field>(void* datum, const erased_accessor& accessor, \ - const ArrayView>& list) \ + const ArrayView>& list, \ + size_t label_width) \ { \ - return do_inspect_field(datum, accessor, (repr), list); \ + return do_inspect_field(datum, accessor, (repr), list, label_width); \ } #define MAKE_SPEC_REPRS(type) \ -- cgit v1.2.3