Nui
property.hpp
Go to the documentation of this file.
3 
4 #include <concepts>
5 #include <functional>
6 
7 namespace Nui
8 {
9  namespace Detail
10  {
11  template <typename T>
12  struct Property
13  {
14  T prop;
15  };
16 
17  template <typename T>
18  struct Property<Observed<T>>
19  {
20  Observed<T> const* prop;
21  };
22 
23  template <typename T>
24  struct Property<std::weak_ptr<Observed<T>>>
25  {
26  std::weak_ptr<Observed<T>> prop;
27  };
28 
29  template <typename T>
31  {
32  static constexpr bool value = false;
33  };
34 
35  template <typename T>
37  {
38  static constexpr bool value = true;
39  };
40 
41  template <typename T>
43  }
44 
45  template <typename U>
46  requires(IsObserved<std::decay_t<U>>)
47  Detail::Property<std::decay_t<U>> property(U& val)
48  {
50  }
51 
52  template <typename U>
53  requires(IsWeakObserved<std::decay_t<U>>)
54  Detail::Property<std::decay_t<U>> property(U&& val)
55  {
56  return Detail::Property<std::decay_t<U>>{.prop = std::forward<U>(val)};
57  }
58 
59  template <typename U>
60  requires(IsSharedObserved<std::decay_t<U>>)
61  Detail::Property<typename std::decay_t<U>::weak_type> property(U const& val)
62  {
64  }
65 
66  template <typename U>
67  requires(std::invocable<U, Nui::val>)
68  Detail::Property<std::function<void(Nui::val)>> property(U val)
69  {
70  return Detail::Property<std::function<void(Nui::val)>>{.prop = std::move(val)};
71  }
72 
73  template <typename U>
74  requires(std::invocable<U>)
75  Detail::Property<std::function<void()>> property(U val)
76  {
77  return Detail::Property<std::function<void()>>{.prop = std::move(val)};
78  }
79 
80  template <typename U>
81  requires(!IsObservedLike<std::decay_t<U>> && !std::invocable<U> && !std::invocable<U, Nui::val>)
83  {
84  return Detail::Property<std::decay_t<U>>{.prop = std::move(val)};
85  }
86 
87  template <typename RendererType, typename... ObservedValues>
88  ObservedValueCombinatorWithPropertyGenerator<RendererType, ObservedValues...>
90  {
91  return ObservedValueCombinatorWithPropertyGenerator<RendererType, ObservedValues...>{std::move(combinator)};
92  }
93 }
Definition: observed_value_combinator.hpp:144
Definition: observed_value.hpp:1202
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
requires(IsObservedLike< ObservedValues > &&...) ObservedValueCombinator< std
Definition: observed_value_combinator.hpp:191
ObservedValueCombinatorWithPropertyGenerator< RendererType, ObservedValues... > property(ObservedValueCombinatorWithGenerator< RendererType, ObservedValues... > combinator)
Definition: property.hpp:89
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: property.hpp:31
static constexpr bool value
Definition: property.hpp:32
Observed< T > const * prop
Definition: property.hpp:20
std::weak_ptr< Observed< T > > prop
Definition: property.hpp:26
Definition: property.hpp:13
T prop
Definition: property.hpp:14