From 3f3e6ff1fb40c4166c5d4e54f74ab475a919536a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Mon, 9 Dec 2024 15:05:21 -0500 Subject: [PATCH] concepts: play with a visual range concept separate from the mapping range --- examples/Advanced/Utilities/Gain.hpp | 9 ++++++++- include/avnd/concepts/range.hpp | 4 ++++ include/avnd/introspection/range.hpp | 26 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/examples/Advanced/Utilities/Gain.hpp b/examples/Advanced/Utilities/Gain.hpp index 84bd2be4..19287c23 100644 --- a/examples/Advanced/Utilities/Gain.hpp +++ b/examples/Advanced/Utilities/Gain.hpp @@ -22,7 +22,14 @@ class Gain struct inputs { - halp::smooth_knob<"Gain", halp::range{0., 5., 0.}> gain; + struct : halp::smooth_knob<"Gain", halp::range{0., 1., 0.}> + { + struct visual_range + { + double min = 0.; + double max = 5.; + }; + } gain; }; double operator()(double input, const inputs& in) { return input * in.gain; } }; diff --git a/include/avnd/concepts/range.hpp b/include/avnd/concepts/range.hpp index 05bf9b73..2c22f223 100644 --- a/include/avnd/concepts/range.hpp +++ b/include/avnd/concepts/range.hpp @@ -11,4 +11,8 @@ namespace avnd template concept has_range = requires { C::range(); } || requires { sizeof(C::range); } || requires { sizeof(typename C::range); }; +template +concept has_visual_range = requires { C::visual_range(); } || requires { + sizeof(C::visual_range); +} || requires { sizeof(typename C::visual_range); }; } diff --git a/include/avnd/introspection/range.hpp b/include/avnd/introspection/range.hpp index cc8f513a..f8af180d 100644 --- a/include/avnd/introspection/range.hpp +++ b/include/avnd/introspection/range.hpp @@ -26,4 +26,30 @@ consteval auto get_range(const T&) { return get_range(); } + +template +consteval auto get_visual_range() +{ + if constexpr(requires { sizeof(typename T::visual_range); }) + return typename T::visual_range{}; + else if constexpr(requires { T::visual_range(); }) + return T::visual_range(); + else if constexpr(requires { sizeof(decltype(T::visual_range)); }) + return T::visual_range; + else + return get_range(); +} + +template + requires(!avnd::has_visual_range) +consteval auto get_visual_range() +{ + return get_range(); +} + +template +consteval auto get_visual_range(const T&) +{ + return get_visual_range(); +} }