summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--editor/inspect-draw.cpp2
-rw-r--r--editor/inspect-types.cpp14
-rw-r--r--editor/inspect.cpp26
-rw-r--r--editor/inspect.hpp11
4 files changed, 33 insertions, 20 deletions
diff --git a/editor/inspect-draw.cpp b/editor/inspect-draw.cpp
index 1f1ccec3..d3c95e58 100644
--- a/editor/inspect-draw.cpp
+++ b/editor/inspect-draw.cpp
@@ -45,7 +45,7 @@ void app::draw_inspector()
snformat(buf, "inspector-{:08x}"_cf, e.id);
auto b1 = push_id(buf);
- ImGui::SetNextWindowSize({300*dpi[0], 0});
+ ImGui::SetNextWindowSize({375*dpi[0], 0});
auto name = loader.strip_prefix(e.atlas->name());
if (z == 0)
snformat(buf, "{} ({}x{} -> {}x{})"_cf, name, ch.x, ch.y, (int)pos.x, (int)pos.y);
diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp
index 6bf87f49..421194bc 100644
--- a/editor/inspect-types.cpp
+++ b/editor/inspect-types.cpp
@@ -9,6 +9,7 @@
#include "src/character.hpp"
#include "src/light.hpp"
#include <Corrade/Containers/ArrayViewStl.h>
+#include <imgui.h>
namespace floormat::entities {
@@ -150,12 +151,19 @@ struct enum_values<rotation, U>
template<typename T>
static bool inspect_type(T& x)
{
+ size_t width = 0;
+ visit_tuple([&](const auto& field) {
+ const auto& name = field.name;
+ auto width_ = (size_t)ImGui::CalcTextSize(name.cbegin(), name.cend()).x;
+ width = std::max(width, width_);
+ }, entity_metadata<T>::accessors);
+
bool ret = false;
visit_tuple([&](const auto& field) {
using type = typename std::decay_t<decltype(field)>::FieldType;
- using enum_type = enum_values<type, T>;
- const auto& list = enum_type::get(x);
- ret |= inspect_field<type>(&x, field.erased(), list);
+ using enum_type = enum_values<type, T>;
+ const auto& list = enum_type::get(x);
+ ret |= inspect_field<type>(&x, field.erased(), list, width);
}, entity_metadata<T>::accessors);
return ret;
}
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_<int64_t> : std::integral_constant<int, ImGuiDataType_S64
template<> struct IGDT_<float> : std::integral_constant<int, ImGuiDataType_Float> {};
template<typename T> constexpr auto IGDT = IGDT_<T>::value;
-using namespace imgui;
-using namespace entities;
-
template<typename T> requires std::is_integral_v<T> 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<typename T>
bool do_inspect_field(void* datum, const erased_accessor& accessor, field_repr repr,
- const ArrayView<const std::pair<StringView, size_t>>& list)
+ const ArrayView<const std::pair<StringView, size_t>>& list,
+ size_t label_width)
{
if (list.isEmpty())
fm_assert(accessor.check_field_type<T>());
@@ -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<type>(void* datum, const erased_accessor& accessor, \
- const ArrayView<const std::pair<StringView, size_t>>& list) \
+ const ArrayView<const std::pair<StringView, size_t>>& list, \
+ size_t label_width) \
{ \
- return do_inspect_field<type>(datum, accessor, (repr), list); \
+ return do_inspect_field<type>(datum, accessor, (repr), list, label_width); \
}
#define MAKE_SPEC2(type, repr) \
template<> \
bool inspect_field<field_repr_<type, field_repr, repr>>(void* datum, const erased_accessor& accessor, \
- const ArrayView<const std::pair<StringView, size_t>>& list) \
+ const ArrayView<const std::pair<StringView, size_t>>& list, \
+ size_t label_width) \
{ \
- return do_inspect_field<type>(datum, accessor, (repr), list); \
+ return do_inspect_field<type>(datum, accessor, (repr), list, label_width); \
}
#define MAKE_SPEC_REPRS(type) \
diff --git a/editor/inspect.hpp b/editor/inspect.hpp
index f7769fae..de572666 100644
--- a/editor/inspect.hpp
+++ b/editor/inspect.hpp
@@ -26,16 +26,19 @@ template<typename T> using field_repr_slider = field_repr_<T, field_repr, field_
template<typename T> using field_repr_drag = field_repr_<T, field_repr, field_repr::drag>;
template<typename T> using field_repr_cbx = field_repr_<T, field_repr, field_repr::cbx>;
-template<typename T> bool inspect_field(void* datum, const entities::erased_accessor& accessor,
- const ArrayView<const std::pair<StringView, size_t>>& list);
bool inspect_entity_subtype(entity& x);
+template<typename T> bool inspect_field(void* datum, const entities::erased_accessor& accessor,
+ const ArrayView<const std::pair<StringView, size_t>>& list,
+ size_t label_width);
+
template<typename T>
requires std::is_enum_v<T>
bool inspect_field(void* datum, const entities::erased_accessor& accessor,
- const ArrayView<const std::pair<StringView, size_t>>& list)
+ const ArrayView<const std::pair<StringView, size_t>>& list,
+ size_t label_width)
{
- return inspect_field<field_repr_cbx<std::underlying_type_t<T>>>(datum, accessor, list);
+ return inspect_field<field_repr_cbx<std::underlying_type_t<T>>>(datum, accessor, list, label_width);
}
} // namespace floormat::entities