Loading...
Searching...
No Matches
Component.h
Go to the documentation of this file.
1#ifndef COMPONENT_H
2#define COMPONENT_H
3
4#include <Malena/Core/Core.h>
12#include <type_traits>
14
16
17namespace ml
18{
20 template<typename... Traits>
21 struct HasCoreTraits : std::disjunction<
22 std::is_same<Traits, Subscribable>...,
23 std::is_same<Traits, Flaggable>...,
24 std::is_same<Traits, Positionable>...
25 > {};
27
33 template<typename ComponentManifest = void, typename... Traits>
34 struct ComponentCore : public Core,
35 public Draggable,
36 public Traits...,
37 public GatherFlags <ComponentManifest, Draggable, Traits...>::type,
38 public GatherStates<ComponentManifest, Draggable, Traits...>::type
39 {
40 static_assert(
41 !HasCoreTraits<Traits...>::value,
42 "Subscribable, Flaggable, and Positionable are already included via Core."
43 );
44
46 {
48 this->onClick([](){});
49 this->onHover([](){});
50 }
51
52 // ── System flags (ml::Flag) ──────────────────────────────────────────
58
59 // ── Custom flags from manifest + traits ──────────────────────────────
60 using GatherFlags<ComponentManifest, Draggable, Traits...>::type::enableFlag;
61 using GatherFlags<ComponentManifest, Draggable, Traits...>::type::disableFlag;
62 using GatherFlags<ComponentManifest, Draggable, Traits...>::type::checkFlag;
63 using GatherFlags<ComponentManifest, Draggable, Traits...>::type::setFlag;
64 using GatherFlags<ComponentManifest, Draggable, Traits...>::type::toggleFlag;
65
66 // ── Custom states from manifest + traits ─────────────────────────────
67 using GatherStates<ComponentManifest, Draggable, Traits...>::type::setState;
68 using GatherStates<ComponentManifest, Draggable, Traits...>::type::getState;
69 using GatherStates<ComponentManifest, Draggable, Traits...>::type::isState;
70 using GatherStates<ComponentManifest, Draggable, Traits...>::type::onStateEnter;
71 using GatherStates<ComponentManifest, Draggable, Traits...>::type::onStateExit;
72 };
73
87 template<typename ComponentManifest, typename... Traits>
88 struct ComponentBase : public sf::Drawable,
89 public ComponentCore<ComponentManifest, Traits...>,
90 public ManifestResources<ComponentManifest>
91 {
93 };
94
96 template<typename... Traits>
97 struct ComponentBase<void, Traits...> : public sf::Drawable,
98 public ComponentCore<void, Traits...>
99 {
100 };
102
126 template<typename First = void, typename... Rest>
127 class Component : public std::conditional_t<
128 std::is_base_of_v<Manifest, First>,
129 ComponentBase<First, Rest...>,
130 ComponentBase<void, First, Rest...>
131 > {};
132
134 template<>
135 class Component<void> : public ComponentBase<void> {};
137
149 template<typename M, typename... Traits>
150 using ComponentWith = Component<M, Traits...>;
151
152} // namespace ml
153
154#endif // COMPONENT_H
void onClick(std::function< void()> callback)
Register a no-argument callback invoked when this component is clicked.
Primary base class for all user-facing Malena components.
Definition Component.h:131
Virtual base class for all Malena framework objects.
Definition Core.h:67
Receiver trait that adds mouse-drag behavior to any Component.
Definition Draggable.h:67
Draggable()=default
static void subscribe(EnumType eventEnum, EventReceiver *component)
Register a component for an enum-keyed event.
Enum-keyed boolean flag store.
Definition FlagManager.h:59
void toggleFlag(State state)
void disableFlag(State state)
void setFlag(State state, bool status)
bool checkFlag(State state) const
void enableFlag(State state)
void onHover(std::function< void()> callback)
Register a no-argument callback invoked when the mouse enters this component's bounds.
Component< M, Traits... > ComponentWith
Alias for Component<M, Traits...>.
Definition Component.h:150
@ DRAG
Component is being dragged.
Definition Event.h:42
Flag
System-level boolean flags available on every ml::Core object.
Definition Flag.h:60
Definition Component.h:18
Intermediate drawable layer — with manifest.
Definition Component.h:91
ml::ManifestResources< ComponentManifest > Resources
Definition Component.h:92
Internal non-drawable layer of the component hierarchy.
Definition Component.h:39
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.