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());
82 constexpr
char const*
name()
const
89 !
IsObservedLike<std::decay_t<U>> && !std::invocable<U, Nui::val> && !std::invocable<U> &&
100 template <
typename U>
102 Attribute operator=(U const& shared)
const
106 if (
auto shared = weak.lock(); shared)
107 element.setProperty(
name, shared->value());
109 [
name =
name(), weak = std::weak_ptr{shared}](std::weak_ptr<Dom::ChildlessElement>&& element) {
110 auto shared = weak.lock();
115 [
name, element, obsWeak = std::weak_ptr{shared}](
auto eventId) {
116 auto obsShared = obsWeak.lock();
121 if (
auto shared = element.lock(); shared)
123 shared->setProperty(
name, obsShared->value());
126 obsShared->detachEvent(eventId);
129 [element, obsWeak = std::weak_ptr{shared}]() {
130 return !element.expired() && !obsWeak.expired();
133 shared->attachEvent(eventId);
137 if (
auto shared = weak.lock(); shared)
138 shared->detachEvent(
id);
143 template <
typename U>
145 Attribute operator=(U&&
val)
const
147 auto shared =
val.lock();
154 template <
typename U>
156 Attribute operator=(U&
val)
const
159 [
name =
name(), &
val](Dom::ChildlessElement& element) {
160 element.setProperty(
name,
val.value());
162 [
name =
name(), &
val](std::weak_ptr<Dom::ChildlessElement>&& element) {
172 template <
typename RendererType,
typename... ObservedValues>
174 operator=(ObservedValueCombinatorWithPropertyGenerator<RendererType, ObservedValues...>
const& combinator)
const
177 [
name =
name(), combinator](Dom::ChildlessElement& element) {
178 element.setProperty(
name, combinator.value());
180 [
name =
name(), combinator](std::weak_ptr<Dom::ChildlessElement>&& element) {
184 combinator.detachEvent(
id);
189 template <
typename RendererType,
typename... ObservedValues>
191 operator=(ObservedValueCombinatorWithGenerator<RendererType, ObservedValues...>
const& combinator)
const
194 [
name =
name(), combinator](Dom::ChildlessElement& element) {
195 element.setProperty(
name, combinator.value());
197 [
name =
name(), combinator](std::weak_ptr<Dom::ChildlessElement>&& element) {
201 combinator.detachEvent(
id);
209 [
name =
name(), func = std::move(func)](Dom::ChildlessElement& element) {
218 Attribute
operator=(std::function<
void()> func)
const
221 [
name =
name(), func = std::move(func)](Dom::ChildlessElement& element) {
250 constexpr
char const*
name()
const
255 template <
typename U>
257 !
IsObservedLike<std::decay_t<U>> && !std::invocable<U, Nui::val> && !std::invocable<U> &&
263 element.setAttribute(
name,
val);
268 template <
typename U>
270 Attribute operator=(U const& shared)
const
274 if (
auto shared = weak.lock(); shared)
275 element.setAttribute(
name, shared->value());
277 [
name =
name(), weak = std::weak_ptr{shared}](std::weak_ptr<Dom::ChildlessElement>&& element) {
278 auto shared = weak.lock();
283 [
name, element, obsWeak = std::weak_ptr{shared}](
auto eventId) {
284 auto obsShared = obsWeak.lock();
289 if (
auto shared = element.lock(); shared)
291 shared->setAttribute(
name, obsShared->value());
294 obsShared->detachEvent(eventId);
297 [element, obsWeak = std::weak_ptr{shared}]() {
298 return !element.expired() && !obsWeak.expired();
301 shared->attachEvent(eventId);
305 if (
auto shared = weak.lock(); shared)
306 shared->detachEvent(
id);
311 template <
typename U>
313 Attribute operator=(U&&
val)
const
315 auto shared =
val.lock();
322 template <
typename U>
324 Attribute operator=(U&
val)
const
327 [
name =
name(), &
val](Dom::ChildlessElement& element) {
328 element.setAttribute(
name,
val.value());
330 [
name =
name(), &
val](std::weak_ptr<Dom::ChildlessElement>&& element) {
340 template <
typename U>
342 Attribute operator=(
Nui::Detail::Property<U> const& prop)
const
345 [
name =
name(), p = prop.prop](Dom::ChildlessElement& element) {
346 element.setProperty(
name, p->value());
348 [
name =
name(), p = prop.prop](std::weak_ptr<Dom::ChildlessElement>&& element) {
358 template <
typename U>
360 Attribute operator=(
Nui::Detail::Property<U> const& prop)
const
362 auto shared = prop.prop.lock();
367 [
name =
name(), weak = std::weak_ptr{shared}](Dom::ChildlessElement& element) {
368 if (
auto shared = weak.lock(); shared)
369 element.setProperty(
name, shared->value());
371 [
name =
name(), weak = std::weak_ptr{shared}](std::weak_ptr<Dom::ChildlessElement>&& element) {
372 auto shared = weak.lock();
377 [
name, element, obsWeak = std::weak_ptr{shared}](
auto eventId) {
378 auto obsShared = obsWeak.lock();
383 if (
auto shared = element.lock(); shared)
385 shared->setProperty(
name, obsShared->value());
388 obsShared->detachEvent(eventId);
391 [element, obsWeak = std::weak_ptr{shared}]() {
392 return !element.expired() && !obsWeak.expired();
395 shared->attachEvent(eventId);
399 if (
auto shared = weak.lock(); shared)
400 shared->detachEvent(
id);
405 template <
typename U>
409 return Attribute{[
name =
name(), p = std::move(prop.
prop)](Dom::ChildlessElement& element) {
410 element.setProperty(
name, p);
414 template <
typename RendererType,
typename... ObservedValues>
416 operator=(ObservedValueCombinatorWithPropertyGenerator<RendererType, ObservedValues...>
const& combinator)
const
419 [
name =
name(), combinator](Dom::ChildlessElement& element) {
420 element.setProperty(
name, combinator.value());
422 [
name =
name(), combinator](std::weak_ptr<Dom::ChildlessElement>&& element) {
426 combinator.detachEvent(
id);
431 template <
typename RendererType,
typename... ObservedValues>
433 operator=(ObservedValueCombinatorWithGenerator<RendererType, ObservedValues...>
const& combinator)
const
436 [
name =
name(), combinator](Dom::ChildlessElement& element) {
437 element.setAttribute(
name, combinator.value());
439 [
name =
name(), combinator](std::weak_ptr<Dom::ChildlessElement>&& element) {
443 combinator.detachEvent(
id);
451 [
name =
name(), func = std::move(func)](Dom::ChildlessElement& element) {
460 Attribute
operator=(std::function<
void()> func)
const
463 [
name =
name(), func = std::move(func)](Dom::ChildlessElement& element) {
475 [
name =
name(), func = std::move(func.prop)](Dom::ChildlessElement& element) {
487 [
name =
name(), func = std::move(func.prop)](Dom::ChildlessElement& element) {
516 constexpr
char const*
name()
const
538 func(std::move(
val));
549 inline namespace Literals
567 template <
typename T>
572 template <
typename... Args>
575 auto attr =
factory.operator=(std::forward<Args>(args)...);
582 template <
typename T>
584 std::is_same_v<T, AttributeFactory> || std::is_same_v<T, PropertyFactory> || std::is_same_v<T, EventFactory>)
591 #define MAKE_HTML_VALUE_ATTRIBUTE_RENAME(NAME, HTML_NAME) \
592 namespace Nui::Attributes \
594 static constexpr auto NAME = AttributeFactory{HTML_NAME}; \
597 #define MAKE_HTML_VALUE_ATTRIBUTE(NAME) MAKE_HTML_VALUE_ATTRIBUTE_RENAME(NAME, #NAME)
599 #define MAKE_HTML_EVENT_ATTRIBUTE_RENAME(NAME, HTML_ACTUAL) \
600 namespace Nui::Attributes \
604 static constexpr auto Attr##NAME = fixToLower(HTML_ACTUAL); \
606 static constexpr auto NAME = AttributeFactory{Names::Attr##NAME}; \
609 #define MAKE_HTML_EVENT_ATTRIBUTE(NAME) MAKE_HTML_EVENT_ATTRIBUTE_RENAME(NAME, #NAME)
Definition: attribute.hpp:15
Definition: attribute_factory.hpp:235
constexpr AttributeFactory(AttributeFactory const &other)
Definition: attribute_factory.hpp:241
constexpr char const * name() const
Definition: attribute_factory.hpp:250
constexpr AttributeFactory(char const *name)
Definition: attribute_factory.hpp:237
AttributeFactory & operator=(AttributeFactory &&)=delete
AttributeFactory & operator=(AttributeFactory const &)=delete
requires(!IsObservedLike< std::decay_t< U >> &&!std::invocable< U, Nui::val > &&!std::invocable< U > &&!Nui::Detail::IsProperty< std::decay_t< U >>) Attribute operator
constexpr AttributeFactory(AttributeFactory &&other)
Definition: attribute_factory.hpp:244
Definition: attribute_factory.hpp:501
Attribute operator=(std::function< void(Nui::val)> func) const
Definition: attribute_factory.hpp:533
EventFactory & operator=(EventFactory &&)=delete
constexpr char const * name() const
Definition: attribute_factory.hpp:516
constexpr EventFactory(EventFactory const &other)
Definition: attribute_factory.hpp:507
Attribute operator=(std::function< void()> func) const
Definition: attribute_factory.hpp:521
constexpr EventFactory(char const *name)
Definition: attribute_factory.hpp:503
constexpr EventFactory(EventFactory &&other)
Definition: attribute_factory.hpp:510
EventFactory & operator=(EventFactory const &)=delete
Definition: attribute_factory.hpp:67
PropertyFactory & operator=(PropertyFactory const &)=delete
constexpr PropertyFactory(PropertyFactory const &other)
Definition: attribute_factory.hpp:73
constexpr PropertyFactory(PropertyFactory &&other)
Definition: attribute_factory.hpp:76
constexpr PropertyFactory(char const *name)
Definition: attribute_factory.hpp:69
constexpr char const * name() const
Definition: attribute_factory.hpp:82
requires(!IsObservedLike< std::decay_t< U >> &&!std::invocable< U, Nui::val > &&!std::invocable< U > &&!Nui::Detail::IsProperty< std::decay_t< U >>) Attribute operator
PropertyFactory & operator=(PropertyFactory &&)=delete
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
void executeActiveEventsImmediately()
Definition: event_context.hpp:64
constexpr static auto invalidEventId
Definition: event_context.hpp:41
EventIdType registerEvent(Event event)
Definition: event_context.hpp:52
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
requires(std::is_same_v< T, AttributeFactory >||std::is_same_v< T, PropertyFactory >||std::is_same_v< T, EventFactory >) Detail
Definition: attribute_factory.hpp:583
concept IsProperty
Definition: property.hpp:42
Definition: file_dialog.hpp:6
concept IsSharedObserved
Definition: observed_value.hpp:1453
concept IsObserved
Definition: observed_value.hpp:1451
thread_local EventContext globalEventContext
Definition: event_context.cpp:5
Attribute && operator!(Attribute &&attribute)
Definition: attribute.hpp:84
RendererType
Definition: materialize.hpp:43
emscripten::val val
Definition: val.hpp:5
concept IsWeakObserved
Definition: observed_value.hpp:1455
concept IsObservedLike
Definition: observed_value.hpp:1457
Definition: attribute_factory.hpp:569
T factory
Definition: attribute_factory.hpp:570
Attribute operator=(Args &&... args) const
Definition: attribute_factory.hpp:573
Definition: observed_value.hpp:1463
Definition: property.hpp:13
T prop
Definition: property.hpp:14