From 89017a853a12b0161879e5ff1063b92d11e022b0 Mon Sep 17 00:00:00 2001 From: NoSloppy <53964195+NoSloppy@users.noreply.github.com> Date: Fri, 15 Aug 2025 22:12:49 -0400 Subject: [PATCH 01/19] add error msgs --- styles/layers.h | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/styles/layers.h b/styles/layers.h index dcf434ac9..41847aead 100644 --- a/styles/layers.h +++ b/styles/layers.h @@ -4,6 +4,15 @@ #include "alpha.h" #include "../functions/int.h" #include "colors.h" +#include +#include + +// Identify “solid” colors by the return type of getColor() +namespace layers_detail { + template struct IsOpaqueColor : std::false_type {}; + template<> struct IsOpaqueColor : std::true_type {}; + template<> struct IsOpaqueColor : std::true_type {}; +} // Usage: Layers // BASE: COLOR or LAYER @@ -73,12 +82,35 @@ class Compose { } }; - template struct LayerSelector {}; template struct LayerSelector { typedef BASE type; }; template struct LayerSelector>, L1> { typedef L1 type; }; -template struct LayerSelector { typedef Compose type; }; -template struct LayerSelector { + +// If base is exactly AlphaL<*, Int<0>> and there are 3+ args, drop it early +template +struct LayerSelector>, L1, L2, REST...> { + typedef typename LayerSelector::type type; +}; + +// Solid+solid check +template +struct LayerSelector { + using BaseColorT = decltype(std::declval().getColor(0)); + using LayerColorT = decltype(std::declval().getColor(0)); + static_assert(!(layers_detail::IsOpaqueColor::value && + layers_detail::IsOpaqueColor::value), + "Layers<> error: *** CANNOT STACK TWO SOLID COLORS. ***"); + typedef Compose type; +}; + +// Recursive +template +struct LayerSelector { + using BaseColorT = decltype(std::declval().getColor(0)); + using LayerColorT = decltype(std::declval().getColor(0)); + static_assert(!(layers_detail::IsOpaqueColor::value && + layers_detail::IsOpaqueColor::value), + "Layers<> error: *** CANNOT STACK TWO SOLID COLORS. ***"); typedef typename LayerSelector, REST...>::type type; }; From 00d33c515674c6c745bdcfcaf87b3a7dd6f5a1e6 Mon Sep 17 00:00:00 2001 From: NoSloppy <53964195+NoSloppy@users.noreply.github.com> Date: Fri, 15 Aug 2025 22:13:39 -0400 Subject: [PATCH 02/19] add error msgs --- styles/style_ptr.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/styles/style_ptr.h b/styles/style_ptr.h index 0c85ad8ea..4cd2196da 100644 --- a/styles/style_ptr.h +++ b/styles/style_ptr.h @@ -3,6 +3,17 @@ #include "blade_style.h" +template class Compose; // forward-declare Layers node + +namespace style_base_check_detail { + template struct TopBase { using type = T; }; + template struct TopBase> : TopBase {}; + + template struct IsOpaqueColor : std::false_type {}; + template<> struct IsOpaqueColor : std::true_type {}; + template<> struct IsOpaqueColor : std::true_type {}; +} + // Usage: StylePtr // BLADE: COLOR // return value: suitable for preset array @@ -133,6 +144,10 @@ class ChargingStyle : public Style { // Get a pointer to class. template StyleAllocator StylePtr() { + using _TopBaseT = typename style_base_check_detail::TopBase