From d832896c9ab65c28526135441acf55644a442edc Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 23 Feb 2023 14:02:10 +0100 Subject: a --- editor/inspect.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'editor') diff --git a/editor/inspect.cpp b/editor/inspect.cpp index 41986a19..52d3bc12 100644 --- a/editor/inspect.cpp +++ b/editor/inspect.cpp @@ -15,6 +15,8 @@ namespace floormat { namespace { +using entities::erased_constraints::is_magnum_vector; + String label_left(StringView label) { float width = ImGui::CalcItemWidth(), x = ImGui::GetCursorPosX(); @@ -25,13 +27,6 @@ String label_left(StringView label) return ""_s.join(StringIterable({ "##"_s, label })); } -template struct is_magnum_vector_ final : std::false_type {}; -template struct is_magnum_vector_> : std::true_type {}; -template struct is_magnum_vector_> : std::true_type {}; -template struct is_magnum_vector_> : std::true_type {}; -template struct is_magnum_vector_> : std::true_type {}; -template constexpr bool is_magnum_vector = is_magnum_vector_::value; - template struct IGDT_; template<> struct IGDT_ : std::integral_constant {}; template<> struct IGDT_ : std::integral_constant {}; @@ -45,6 +40,10 @@ 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; } +constexpr bool eqv(float a, float b) { return std::fabs(a - b) < 1e-8f; } +template constexpr bool eqv(const Math::Vector& a, const Math::Vector& b) { return a == b; } + template void do_inspect_field(void* datum, const erased_accessor& accessor, field_repr repr) { fm_assert(accessor.check_field_name()); @@ -99,7 +98,7 @@ template void do_inspect_field(void* datum, const erased_accessor& a ImGui::NewLine(); - if (ret && !should_disable && value != orig) + if (ret && !should_disable && !eqv(value, orig)) if (accessor.is_enabled(datum) >= field_status::enabled && accessor.can_write()) accessor.write_fun(datum, accessor.writer, &value); } @@ -111,21 +110,21 @@ template void do_inspect_field(void* datum, const erased_accessor& a do_inspect_field(datum, accessor, (repr)); \ } -#define MAKE_SPEC_REPR(type, repr) \ +#define MAKE_SPEC2(type, repr) \ template<> void inspect_field>(void* datum, const erased_accessor& accessor) { \ do_inspect_field(datum, accessor, (repr)); \ } -#define MAKE_SPEC_REPRS(type) \ - MAKE_SPEC_REPR(type, field_repr::input) \ - MAKE_SPEC_REPR(type, field_repr::slider) \ - MAKE_SPEC_REPR(type, field_repr::drag) \ +#define MAKE_SPEC_REPRS(type) \ + MAKE_SPEC2(type, field_repr::input) \ + MAKE_SPEC2(type, field_repr::slider) \ + MAKE_SPEC2(type, field_repr::drag) \ MAKE_SPEC(type, field_repr::input) -#define MAKE_SPEC_REPRS2(type) \ - MAKE_SPEC_REPRS(Math::Vector2) \ - MAKE_SPEC_REPRS(Math::Vector3) \ - MAKE_SPEC_REPRS(Math::Vector4) \ +#define MAKE_SPEC_REPRS2(type) \ + MAKE_SPEC_REPRS(Math::Vector2) \ + MAKE_SPEC_REPRS(Math::Vector3) \ + MAKE_SPEC_REPRS(Math::Vector4) \ MAKE_SPEC_REPRS(type) MAKE_SPEC_REPRS2(std::uint8_t) @@ -134,5 +133,6 @@ MAKE_SPEC_REPRS2(std::uint16_t) MAKE_SPEC_REPRS2(std::int16_t) MAKE_SPEC_REPRS2(std::uint32_t) MAKE_SPEC_REPRS2(std::int32_t) +MAKE_SPEC_REPRS2(float) } // namespace floormat -- cgit v1.2.3