5#ifndef MALENA_COMPONENT_H
6#define MALENA_COMPONENT_H
33 template<
typename... Ts>
36 static constexpr int value = (has_Image<Ts>::value + ... + 0);
42 template<
typename... Ts>
45 static constexpr int value = (has_Font<Ts>::value + ... + 0);
51 template<
typename... Ts>
54 static constexpr int value = (has_Sound<Ts>::value + ... + 0);
60 template<
typename T,
typename =
void>
61 struct has_Text : std::false_type {};
63 struct has_Text<T, std::void_t<typename T::Text>> : std::true_type {};
65 template<
typename... Ts>
68 static constexpr int value = (has_Text<Ts>::value + ... + 0);
75 template<
typename T,
typename =
void>
76 struct extract_manifest_or_void {
using type = void; };
79 struct extract_manifest_or_void<T, std::void_t<typename T::manifest_type>>
80 {
using type =
typename T::manifest_type; };
89 template<
typename... Traits>
90 struct HasCoreTraits : std::disjunction<
91 std::is_same<Traits, Subscribable>...,
92 std::is_same<Traits, Flaggable>...,
93 std::is_same<Traits, Positionable>...
106 template<
typename ComponentManifest = void,
typename... Traits>
110 public GatherFlags <ComponentManifest, Draggable, Traits...>::type,
111 public GatherStates<ComponentManifest, Draggable, Traits...>::type
114 !HasCoreTraits<Traits...>::value,
115 "[Malena] Subscribable, Flaggable, and Positionable are already "
116 "included via Core — do not pass them as traits."
125 Core* self =
static_cast<Core*
>(
this);
128 [](
const std::optional<sf::Event>&){},
true, self);
130 [](
const std::optional<sf::Event>&){},
true, self);
174 template<
typename ComponentManifest,
typename... Traits>
182 using _AllManifests = std::tuple<
184 typename extract_manifest_or_void<Traits>::type...
191 typename extract_manifest_or_void<Traits>::type...
193 "[Malena] Images alias is ambiguous — two or more manifests in "
194 "this component's inheritance chain both declare an Images enum. "
195 "Use MyManifest::Images::VALUE syntax to qualify explicitly."
202 typename extract_manifest_or_void<Traits>::type...
204 "[Malena] Fonts alias is ambiguous — two or more manifests in "
205 "this component's inheritance chain both declare a Fonts enum. "
206 "Use MyManifest::Fonts::VALUE syntax to qualify explicitly."
213 typename extract_manifest_or_void<Traits>::type...
215 "[Malena] Sounds alias is ambiguous — two or more manifests in "
216 "this component's inheritance chain both declare a Sounds enum. "
217 "Use MyManifest::Sounds::VALUE syntax to qualify explicitly."
224 typename extract_manifest_or_void<Traits>::type...
226 "[Malena] Text alias is ambiguous — two or more manifests in "
227 "this component's inheritance chain both declare a Text enum. "
228 "Use MyManifest::Text::VALUE syntax to qualify explicitly."
252 template<
typename... Traits>
253 struct ComponentBase<void, Traits...> :
public sf::Drawable,
254 public ComponentCore<void, Traits...>
294 template<
typename First = void,
typename... Rest>
296 std::is_base_of_v<Manifest, First>,
297 ComponentBase<First, Rest...>,
298 ComponentBase<void, First, Rest...>
322 template<
typename M,
typename... Traits>
Primary base class for all user-facing Malena components.
void drawChildren(sf::RenderTarget &target, sf::RenderStates states) const
Receiver trait that adds mouse-drag behavior to any Component.
static void subscribe(EnumType eventEnum, EventReceiver *component, Core *core=nullptr)
Register a component for an enum-keyed event.
Enum-keyed boolean flag store.
void toggleFlag(State state)
void disableFlag(State state)
void setFlag(State state, bool status)
bool checkFlag(State state) const
void enableFlag(State state)
Trait that adds mouse-hover and mouse-leave callbacks to any Core object.
Component< M, Traits... > ComponentWith
Alias for Component<M, Traits...>.
@ CLICK
Mouse button released over component.
@ HOVER
Mouse entered component bounds.
@ DRAG
Component is being dragged.
Flag
System-level boolean flags available on every ml::Core object.
Intermediate drawable layer — with manifest.
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
ml::ManifestResources< ComponentManifest > Resources
Collects all Flag enums from a component manifest and its traits.
Collects all State enums from a component manifest and its traits.
Unified manifest resource and config accessor.