From c2da6e265b059cc21fd1aa9f1e975f99a940d6a3 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 26 May 2023 06:35:28 +0200 Subject: editor/inspect: add widget for color types --- editor/inspect-types.cpp | 8 ++++---- editor/inspect.cpp | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp index 421194bc..9465b4af 100644 --- a/editor/inspect-types.cpp +++ b/editor/inspect-types.cpp @@ -205,10 +205,10 @@ struct entity_accessors { using E = Entity; auto tuple0 = entity_accessors::accessors(); auto tuple = std::tuple{ - E::type::field{"color"_s, - [](const light& x) { return Vector3ub(x.color); }, - [](light& x, Vector3ub value) { x.color = Color3ub{value}; }, - constantly(constraints::range{{0, 0, 0}, {255, 255, 255}}), + E::type::field{"color"_s, + [](const light& x) { return x.color; }, + [](light& x, Color3ub value) { x.color = value; }, + constantly(constraints::range{{0, 0, 0}, {255, 255, 255}}), }, E::type::field{"falloff"_s, [](const light& x) { return x.falloff; }, diff --git a/editor/inspect.cpp b/editor/inspect.cpp index 0b707882..bfd2e3dc 100644 --- a/editor/inspect.cpp +++ b/editor/inspect.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include namespace floormat::entities { @@ -96,6 +97,18 @@ bool do_inspect_field(void* datum, const erased_accessor& accessor, field_repr r } else if constexpr(std::is_same_v) ret = ImGui::Checkbox(label, &value); + else if constexpr (std::is_same_v) + { + auto vec = Vector3(value) * (1.f/255); + ret = ImGui::ColorEdit3(label, vec.data()); + value = Color3ub(vec * 255); + } + else if constexpr (std::is_same_v) + { + auto vec = Vector4(value) * (1.f/255); + ret = ImGui::ColorEdit4(label, vec.data()); + value = Color4ub(vec * 255); + } else if constexpr (!Math::IsVector()) { auto [min, max] = accessor.get_range(datum).convert(); @@ -214,5 +227,7 @@ MAKE_SPEC_REPRS2(float) MAKE_SPEC(bool, field_repr::input) MAKE_SPEC(String, field_repr::input) MAKE_SPEC(StringView, field_repr::input) +MAKE_SPEC(Color3ub, field_repr::input) +MAKE_SPEC(Color4ub, field_repr::input) } // namespace floormat::entities -- cgit v1.2.3