17 template <
typename ElementT,
typename T>
19 std::weak_ptr<ElementT> element,
21 std::function<
bool(std::shared_ptr<ElementT>
const&)> onLock)
24 [element, obs, onLock = std::move(onLock)](
auto eventId) {
25 if (
auto shared = element.lock(); shared)
27 return onLock(shared);
29 obs.detachEvent(eventId);
33 return !element.expired();
35 obs.attachEvent(eventId);
39 template <
typename ElementT,
typename T>
45 std::function<
bool(std::shared_ptr<ElementT>
const&)>{
46 [name, obs](std::shared_ptr<ElementT>
const& shared) {
47 shared->setAttribute(name, obs.value());
52 template <
typename ElementT,
typename T>
58 std::function<
bool(std::shared_ptr<ElementT>
const&)>{
59 [name, obs](std::shared_ptr<ElementT>
const& shared) {
60 shared->setProperty(name, obs.value());
79 constexpr char const*
name()
const
105 if (
auto shared = weak.lock(); shared)
106 element.setProperty(
name, shared->value());
108 [
name =
name(), weak = std::weak_ptr{shared}](std::weak_ptr<Dom::ChildlessElement>
const& element) {
109 auto shared = weak.lock();
114 [
name, element, obsWeak = std::weak_ptr{shared}](
auto eventId) {
115 auto obsShared = obsWeak.lock();
120 if (
auto shared = element.lock(); shared)
122 shared->setProperty(
name, obsShared->value());
125 obsShared->detachEvent(eventId);
128 [element, obsWeak = std::weak_ptr{shared}]() {
129 return !element.expired() && !obsWeak.expired();
132 shared->attachEvent(eventId);
136 if (
auto shared = weak.lock(); shared)
137 shared->detachEvent(
id);
142 template <
typename U>
147 auto shared =
val.lock();
154 template <
typename U>
161 element.setProperty(
name,
val.value());
163 [
name =
name(), &
val](std::weak_ptr<Dom::ChildlessElement>&& element) {
173 template <
typename RendererType,
typename... ObservedValues>
180 element.setProperty(
name, combinator.
value());
182 [
name =
name(), combinator](std::weak_ptr<Dom::ChildlessElement>&& element) {
191 template <
typename RendererType,
typename... ObservedValues>
198 element.setProperty(
name, combinator.
value());
200 [
name =
name(), combinator](std::weak_ptr<Dom::ChildlessElement>&& element) {
215 func(std::move(
val));
252 constexpr char const*
name()
const
257 template <
typename U>
266 element.setAttribute(
name,
val);
271 template <
typename U>
278 if (
auto shared = weak.lock(); shared)
279 element.setAttribute(
name, shared->value());
281 [
name =
name(), weak = std::weak_ptr{shared}](std::weak_ptr<Dom::ChildlessElement>
const& element) {
282 auto shared = weak.lock();
287 [
name, element, obsWeak = std::weak_ptr{shared}](
auto eventId) {
288 auto obsShared = obsWeak.lock();
293 if (
auto shared = element.lock(); shared)
295 shared->setAttribute(
name, obsShared->value());
298 obsShared->detachEvent(eventId);
301 [element, obsWeak = std::weak_ptr{shared}]() {
302 return !element.expired() && !obsWeak.expired();
305 shared->attachEvent(eventId);
309 if (
auto shared = weak.lock(); shared)
310 shared->detachEvent(
id);
315 template <
typename U>
320 auto shared =
val.lock();
327 template <
typename U>
334 element.setAttribute(
name,
val.value());
336 [
name =
name(), &
val](std::weak_ptr<Dom::ChildlessElement>&& element) {
346 template <
typename U>
353 element.setProperty(
name, p->value());
355 [
name =
name(), p = prop.
prop](std::weak_ptr<Dom::ChildlessElement>&& element) {
365 template <
typename U>
370 auto shared = prop.
prop.lock();
376 if (
auto shared = weak.lock(); shared)
377 element.setProperty(
name, shared->value());
379 [
name =
name(), weak = std::weak_ptr{shared}](std::weak_ptr<Dom::ChildlessElement>
const& element) {
380 auto shared = weak.lock();
385 [
name, element, obsWeak = std::weak_ptr{shared}](
auto eventId) {
386 auto obsShared = obsWeak.lock();
391 if (
auto shared = element.lock(); shared)
393 shared->setProperty(
name, obsShared->value());
396 obsShared->detachEvent(eventId);
399 [element, obsWeak = std::weak_ptr{shared}]() {
400 return !element.expired() && !obsWeak.expired();
403 shared->attachEvent(eventId);
407 if (
auto shared = weak.lock(); shared)
408 shared->detachEvent(
id);
413 template <
typename U>
419 element.setProperty(
name, p);
423 template <
typename RendererType,
typename... ObservedValues>
430 element.setProperty(
name, combinator.
value());
432 [
name =
name(), combinator](std::weak_ptr<Dom::ChildlessElement>&& element) {
441 template <
typename RendererType,
typename... ObservedValues>
448 element.setAttribute(
name, combinator.
value());
450 [
name =
name(), combinator](std::weak_ptr<Dom::ChildlessElement>&& element) {
465 func(std::move(
val));
491 func(std::move(
val));
528 constexpr char const*
name()
const
538 element.addEventListener(
name, [func](
Nui::val const&) {
552 func(std::move(
val));
563 inline namespace Literals
569 constexpr PropertyFactory operator""_prop(
char const* name, std::size_t)
573 constexpr EventFactory operator""_event(
char const* name, std::size_t)
581 template <
typename T>
586 template <
typename... Args>
588 Attribute operator=(Args&&... args)
const
590 auto attr = factory.operator=(std::forward<Args>(args)...);
597 template <
typename T>
599 std::is_same_v<T, AttributeFactory> || std::is_same_v<T, PropertyFactory> || std::is_same_v<T, EventFactory>)
607#define MAKE_HTML_VALUE_ATTRIBUTE_RENAME(NAME, HTML_NAME) \
608 namespace Nui::Attributes \
610 static constexpr auto NAME = AttributeFactory{HTML_NAME}; \
613#define MAKE_HTML_VALUE_ATTRIBUTE(NAME) MAKE_HTML_VALUE_ATTRIBUTE_RENAME(NAME, #NAME)
615#define MAKE_HTML_EVENT_ATTRIBUTE_RENAME(NAME, HTML_ACTUAL) \
616 namespace Nui::Attributes \
620 static constexpr auto Attr##NAME = fixToLower(HTML_ACTUAL); \
622 static constexpr auto NAME = AttributeFactory{Names::Attr##NAME}; \
626#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:240
~AttributeFactory()=default
AttributeFactory & operator=(AttributeFactory &&)=delete
constexpr AttributeFactory(AttributeFactory &&other)=default
constexpr AttributeFactory(char const *name)
Definition attribute_factory.hpp:242
Attribute operator=(ObservedValueCombinatorWithPropertyGenerator< RendererType, ObservedValues... > const &combinator) const
Definition attribute_factory.hpp:426
AttributeFactory & operator=(AttributeFactory const &)=delete
Attribute operator=(std::function< void()> func) const
Definition attribute_factory.hpp:473
Attribute operator=(std::function< void(Nui::val)> func) const
Definition attribute_factory.hpp:460
Attribute operator=(ObservedValueCombinatorWithGenerator< RendererType, ObservedValues... > const &combinator) const
Definition attribute_factory.hpp:444
Attribute operator=(Nui::Detail::Property< std::function< void(Nui::val)> > func) const
Definition attribute_factory.hpp:486
constexpr AttributeFactory(AttributeFactory const &other)=default
constexpr char const * name() const
Definition attribute_factory.hpp:252
Attribute operator=(Nui::Detail::Property< std::function< void()> > func) const
Definition attribute_factory.hpp:499
Definition attribute_factory.hpp:516
constexpr EventFactory(EventFactory const &other)=default
EventFactory & operator=(EventFactory &&)=delete
Attribute operator=(std::function< void(Nui::val)> func) const
Definition attribute_factory.hpp:547
constexpr EventFactory(EventFactory &&other)=default
Attribute operator=(std::function< void()> func) const
Definition attribute_factory.hpp:534
constexpr char const * name() const
Definition attribute_factory.hpp:528
constexpr EventFactory(char const *name)
Definition attribute_factory.hpp:518
EventFactory & operator=(EventFactory const &)=delete
Definition attribute_factory.hpp:67
~PropertyFactory()=default
constexpr PropertyFactory(char const *name)
Definition attribute_factory.hpp:69
Attribute operator=(ObservedValueCombinatorWithGenerator< RendererType, ObservedValues... > const &combinator) const
Definition attribute_factory.hpp:194
PropertyFactory & operator=(PropertyFactory &&)=delete
Attribute operator=(std::function< void()> func) const
Definition attribute_factory.hpp:223
Attribute operator=(std::function< void(Nui::val)> func) const
Definition attribute_factory.hpp:210
PropertyFactory & operator=(PropertyFactory const &)=delete
Attribute operator=(ObservedValueCombinatorWithPropertyGenerator< RendererType, ObservedValues... > const &combinator) const
Definition attribute_factory.hpp:176
constexpr PropertyFactory(PropertyFactory &&other) noexcept=default
constexpr char const * name() const
Definition attribute_factory.hpp:79
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:122
Definition observed_value_combinator.hpp:143
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:18
EventContext::EventIdType defaultPropertyEvent(std::weak_ptr< ElementT > element, T const &obs, char const *name)
Definition attribute_factory.hpp:53
EventContext::EventIdType defaultAttributeEvent(std::weak_ptr< ElementT > element, T const &obs, char const *name)
Definition attribute_factory.hpp:40
Definition attribute_factory.hpp:14
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 observed_value.hpp:1546
Definition property.hpp:13
T prop
Definition property.hpp:14