13#include <traits/functions.hpp>
23 template <
typename ElementT,
typename T>
25 std::weak_ptr<ElementT> element,
27 std::function<
bool(std::shared_ptr<ElementT>
const&)> onLock)
31 [element, obs, onLock = std::move(onLock)](
auto eventId) {
32 if (
auto shared = element.lock(); shared)
34 return onLock(shared);
36 obs.detachEvent(eventId);
40 return !element.expired();
42 obs.attachEvent(eventId);
46 template <
typename ElementT,
typename T>
52 std::function<
bool(std::shared_ptr<ElementT>
const&)>{
53 [name, obs](std::shared_ptr<ElementT>
const& shared) {
54 shared->setAttribute(name, obs.value());
59 template <
typename ElementT,
typename T>
65 std::function<
bool(std::shared_ptr<ElementT>
const&)>{
66 [name, obs](std::shared_ptr<ElementT>
const& shared) {
67 shared->setProperty(name, obs.value());
72 template <
typename FunctionT>
75 static constexpr bool value =
false;
78 template <
typename FunctionT>
79 requires Traits::IsCallableOfArity<FunctionT, 1>
83 std::is_constructible_v<typename Traits::FunctionTraits<FunctionT>::template Argument<0>,
Nui::val>;
86 template <
typename FunctionCallableByExplicitConstructionOfVal>
88 IsCallableByExplicitConstructionOfValImpl<std::decay_t<FunctionCallableByExplicitConstructionOfVal>>::value;
104 constexpr char const*
name()
const
109 template <
typename U>
118 element.setProperty(
name,
val);
123 template <
typename U>
130 if (
auto shared = weak.lock(); shared)
131 element.setProperty(
name, shared->value());
133 [
name =
name(), weak = std::weak_ptr{shared}](std::weak_ptr<Dom::ChildlessElement>
const& element) {
134 auto shared = weak.lock();
140 [
name, element, obsWeak = std::weak_ptr{shared}](
auto eventId) {
141 auto obsShared = obsWeak.lock();
146 if (
auto shared = element.lock(); shared)
148 shared->setProperty(
name, obsShared->value());
151 obsShared->detachEvent(eventId);
154 [element, obsWeak = std::weak_ptr{shared}]() {
155 return !element.expired() && !obsWeak.expired();
158 shared->attachEvent(eventId);
162 if (
auto shared = weak.lock(); shared)
163 shared->detachEvent(
id);
168 template <
typename U>
173 auto shared =
val.lock();
180 template <
typename U>
187 element.setProperty(
name,
val.value());
189 [
name =
name(), &
val](std::weak_ptr<Dom::ChildlessElement>&& element) {
199 template <
typename RendererType,
typename... ObservedValues>
206 element.setProperty(
name, combinator.
value());
208 [
name =
name(), combinator](std::weak_ptr<Dom::ChildlessElement>&& element) {
217 template <
typename RendererType,
typename... ObservedValues>
224 element.setProperty(
name, combinator.
value());
226 [
name =
name(), combinator](std::weak_ptr<Dom::ChildlessElement>&& element) {
241 func(std::move(
val));
261 template <
typename FunctionT>
270 std::decay_t<
typename Traits::FunctionTraits<FunctionT>::template Argument<0>>{
295 constexpr char const*
name()
const
300 template <
typename U>
310 element.setAttribute(
name,
val);
315 template <
typename U>
322 if (
auto shared = weak.lock(); shared)
323 element.setAttribute(
name, shared->value());
325 [
name =
name(), weak = std::weak_ptr{shared}](std::weak_ptr<Dom::ChildlessElement>
const& element) {
326 auto shared = weak.lock();
332 [
name, element, obsWeak = std::weak_ptr{shared}](
auto eventId) {
333 auto obsShared = obsWeak.lock();
338 if (
auto shared = element.lock(); shared)
340 shared->setAttribute(
name, obsShared->value());
343 obsShared->detachEvent(eventId);
346 [element, obsWeak = std::weak_ptr{shared}]() {
347 return !element.expired() && !obsWeak.expired();
350 shared->attachEvent(eventId);
354 if (
auto shared = weak.lock(); shared)
355 shared->detachEvent(
id);
360 template <
typename U>
365 auto shared =
val.lock();
372 template <
typename U>
379 element.setAttribute(
name,
val.value());
381 [
name =
name(), &
val](std::weak_ptr<Dom::ChildlessElement>&& element) {
391 template <
typename U>
398 element.setProperty(
name, p->value());
400 [
name =
name(), p = prop.
prop](std::weak_ptr<Dom::ChildlessElement>&& element) {
410 template <
typename U>
415 auto shared = prop.
prop.lock();
421 if (
auto shared = weak.lock(); shared)
422 element.setProperty(
name, shared->value());
424 [
name =
name(), weak = std::weak_ptr{shared}](std::weak_ptr<Dom::ChildlessElement>
const& element) {
425 auto shared = weak.lock();
431 [
name, element, obsWeak = std::weak_ptr{shared}](
auto eventId) {
432 auto obsShared = obsWeak.lock();
437 if (
auto shared = element.lock(); shared)
439 shared->setProperty(
name, obsShared->value());
442 obsShared->detachEvent(eventId);
445 [element, obsWeak = std::weak_ptr{shared}]() {
446 return !element.expired() && !obsWeak.expired();
449 shared->attachEvent(eventId);
453 if (
auto shared = weak.lock(); shared)
454 shared->detachEvent(
id);
459 template <
typename U>
467 element.setProperty(
name, p);
471 template <
typename RendererType,
typename... ObservedValues>
478 element.setProperty(
name, combinator.
value());
480 [
name =
name(), combinator](std::weak_ptr<Dom::ChildlessElement>&& element) {
489 template <
typename RendererType,
typename... ObservedValues>
496 element.setAttribute(
name, combinator.
value());
498 [
name =
name(), combinator](std::weak_ptr<Dom::ChildlessElement>&& element) {
513 func(std::move(
val));
533 template <
typename FunctionT>
542 std::decay_t<
typename Traits::FunctionTraits<FunctionT>::template Argument<0>>{
556 func(std::move(
val));
576 template <
typename FunctionT>
585 std::decay_t<
typename Traits::FunctionTraits<FunctionT>::template Argument<0>>{
610 constexpr char const*
name()
const
620 element.addEventListener(
name, [func](
Nui::val const&) {
634 func(std::move(
val));
641 template <
typename FunctionT>
650 std::decay_t<
typename Traits::FunctionTraits<FunctionT>::template Argument<0>>{
662 inline namespace Literals
668 constexpr PropertyFactory operator""_prop(
char const* name, std::size_t)
672 constexpr EventFactory operator""_event(
char const* name, std::size_t)
680 template <
typename T>
685 template <
typename... Args>
687 Attribute operator=(Args&&... args)
const
689 auto attr = factory.operator=(std::forward<Args>(args)...);
696 template <
typename T>
698 std::is_same_v<T, AttributeFactory> || std::is_same_v<T, PropertyFactory> || std::is_same_v<T, EventFactory>)
706#define MAKE_HTML_VALUE_ATTRIBUTE_RENAME(NAME, HTML_NAME) \
707 namespace Nui::Attributes \
709 static constexpr auto NAME = AttributeFactory{HTML_NAME}; \
712#define MAKE_HTML_VALUE_ATTRIBUTE(NAME) MAKE_HTML_VALUE_ATTRIBUTE_RENAME(NAME, #NAME)
714#define MAKE_HTML_EVENT_ATTRIBUTE_RENAME(NAME, HTML_ACTUAL) \
715 namespace Nui::Attributes \
719 static constexpr auto Attr##NAME = fixToLower(HTML_ACTUAL); \
721 static constexpr auto NAME = AttributeFactory{Names::Attr##NAME}; \
725#define MAKE_HTML_EVENT_ATTRIBUTE(NAME) MAKE_HTML_EVENT_ATTRIBUTE_RENAME(NAME, #NAME)
Definition attribute.hpp:15
bool defer() const
Definition attribute.cpp:41
Definition attribute_factory.hpp:283
Attribute operator=(Nui::Detail::Property< FunctionT > func) const
Definition attribute_factory.hpp:579
~AttributeFactory()=default
AttributeFactory & operator=(AttributeFactory &&)=delete
constexpr AttributeFactory(AttributeFactory &&other)=default
constexpr AttributeFactory(char const *name)
Definition attribute_factory.hpp:285
Attribute operator=(ObservedValueCombinatorWithPropertyGenerator< RendererType, ObservedValues... > const &combinator) const
Definition attribute_factory.hpp:474
AttributeFactory & operator=(AttributeFactory const &)=delete
Attribute operator=(std::function< void()> func) const
Definition attribute_factory.hpp:521
Attribute operator=(std::function< void(Nui::val)> func) const
Definition attribute_factory.hpp:508
Attribute operator=(ObservedValueCombinatorWithGenerator< RendererType, ObservedValues... > const &combinator) const
Definition attribute_factory.hpp:492
Attribute operator=(Nui::Detail::Property< std::function< void(Nui::val)> > func) const
Definition attribute_factory.hpp:551
constexpr AttributeFactory(AttributeFactory const &other)=default
constexpr char const * name() const
Definition attribute_factory.hpp:295
Attribute operator=(Nui::Detail::Property< std::function< void()> > func) const
Definition attribute_factory.hpp:564
Attribute operator=(FunctionT func) const
Definition attribute_factory.hpp:536
Definition attribute_factory.hpp:598
constexpr EventFactory(EventFactory const &other)=default
EventFactory & operator=(EventFactory &&)=delete
Attribute operator=(std::function< void(Nui::val)> func) const
Definition attribute_factory.hpp:629
constexpr EventFactory(EventFactory &&other)=default
Attribute operator=(std::function< void()> func) const
Definition attribute_factory.hpp:616
constexpr char const * name() const
Definition attribute_factory.hpp:610
constexpr EventFactory(char const *name)
Definition attribute_factory.hpp:600
Attribute operator=(FunctionT func) const
Definition attribute_factory.hpp:644
EventFactory & operator=(EventFactory const &)=delete
Definition attribute_factory.hpp:92
~PropertyFactory()=default
constexpr PropertyFactory(char const *name)
Definition attribute_factory.hpp:94
Attribute operator=(ObservedValueCombinatorWithGenerator< RendererType, ObservedValues... > const &combinator) const
Definition attribute_factory.hpp:220
PropertyFactory & operator=(PropertyFactory &&)=delete
Attribute operator=(std::function< void()> func) const
Definition attribute_factory.hpp:249
Attribute operator=(FunctionT func) const
Definition attribute_factory.hpp:264
Attribute operator=(std::function< void(Nui::val)> func) const
Definition attribute_factory.hpp:236
PropertyFactory & operator=(PropertyFactory const &)=delete
Attribute operator=(ObservedValueCombinatorWithPropertyGenerator< RendererType, ObservedValues... > const &combinator) const
Definition attribute_factory.hpp:202
constexpr PropertyFactory(PropertyFactory &&other) noexcept=default
constexpr char const * name() const
Definition attribute_factory.hpp:104
constexpr PropertyFactory(PropertyFactory const &other)=default
The basic element cannot have children and does not hold explicit ownership of them.
Definition childless_element.hpp:19
EventRegistry::EventIdType EventIdType
Definition event_context.hpp:40
static constexpr auto invalidEventId
Definition event_context.hpp:41
void executeActiveEventsImmediately()
Definition event_context.hpp:64
EventIdType registerEvent(Event event)
Definition event_context.hpp:52
constexpr void detachEvent(auto eventId) const
Definition observed_value_combinator.hpp:56
Definition observed_value_combinator.hpp:108
constexpr auto value() const
Definition observed_value_combinator.hpp:124
Definition observed_value_combinator.hpp:145
Definition attribute_factory.hpp:87
Definition property.hpp:42
Definition observed_value.hpp:1540
Definition observed_value.hpp:1534
Definition observed_value.hpp:1536
Definition observed_value.hpp:1538
EventContext::EventIdType changeEventHandler(std::weak_ptr< ElementT > element, T const &obs, std::function< bool(std::shared_ptr< ElementT > const &)> onLock)
Definition attribute_factory.hpp:24
EventContext::EventIdType defaultPropertyEvent(std::weak_ptr< ElementT > element, T const &obs, char const *name)
Definition attribute_factory.hpp:60
EventContext::EventIdType defaultAttributeEvent(std::weak_ptr< ElementT > element, T const &obs, char const *name)
Definition attribute_factory.hpp:47
Definition attribute_factory.hpp:20
static constexpr auto extractJsonMember(nlohmann::json const &json) -> decltype(auto)
Definition rpc_hub.hpp:29
thread_local EventContext globalEventContext
Definition event_context.cpp:5
RendererType
Definition materialize.hpp:48
emscripten::val val
Definition val.hpp:5
Definition attribute_factory.hpp:74
static constexpr bool value
Definition attribute_factory.hpp:75
Definition observed_value.hpp:1546
Definition property.hpp:13
T prop
Definition property.hpp:14