Nui
reference.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
5 namespace Nui::Attributes
6 {
7  struct reference_
8  {
9  template <typename T>
10  requires std::invocable<T, std::weak_ptr<Dom::BasicElement>&&>
11  Attribute operator=(T&& func) const
12  {
13  return Attribute{[func = std::forward<T>(func)](Dom::ChildlessElement& element) {
14  func(element.weak_from_base<Dom::BasicElement>());
15  }};
16  }
17 
18  template <typename T>
19  requires std::invocable<T, Nui::val&&>
20  Attribute onMaterialize(T&& func) const
21  {
22  return operator=([func = std::forward<T>(func)](std::weak_ptr<Dom::BasicElement>&& element) {
23  func(element.lock()->val());
24  });
25  }
26 
27  Attribute operator=(std::weak_ptr<Dom::BasicElement>& ref) const
28  {
29  return operator=([&ref](std::weak_ptr<Dom::BasicElement>&& element) {
30  ref = std::move(element);
31  });
32  }
33 
35  {
36  return operator=([&ref](std::weak_ptr<Dom::BasicElement>&& element) {
37  ref = element.lock()->val();
38  });
39  }
40  } static constexpr reference;
41 }
Definition: attribute.hpp:15
Definition: basic_element.hpp:14
The basic element cannot have children and does not hold explicit ownership of them.
Definition: childless_element.hpp:19
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
struct Nui::Attributes::reference_ reference
emscripten::val val
Definition: val.hpp:5
Definition: reference.hpp:8
requires std::invocable< T, Nui::val && > Attribute onMaterialize(T &&func) const
Definition: reference.hpp:20
Attribute operator=(std::weak_ptr< Dom::BasicElement > &ref) const
Definition: reference.hpp:27
Attribute operator=(Nui::val &ref) const
Definition: reference.hpp:34
requires std::invocable< T, std::weak_ptr< Dom::BasicElement > && > Attribute operator=(T &&func) const
Definition: reference.hpp:11