Nui
materialize.hpp
Go to the documentation of this file.
1 namespace Nui
2 {
3  class HtmlElement;
4 
5  namespace Materializers
6  {
8  inline auto appendMaterialize(auto& parent, auto const& htmlElement)
9  {
10  return parent.appendElement(htmlElement);
11  }
14  inline auto fragmentMaterialize(auto& parent, auto const& htmlElement)
15  {
16  auto elem = parent.makeElement(htmlElement);
17  parent.val().template call<Nui::val>("appendChild", elem->val());
18  return elem;
19  }
21  inline auto insertMaterialize(std::size_t where, auto& parent, auto const& htmlElement)
22  {
23  return parent.insert(where, htmlElement);
24  }
26  inline auto replaceMaterialize(auto& element, auto const& htmlElement)
27  {
28  return element.replaceElement(htmlElement);
29  }
31  inline auto emplaceMaterialize(auto& element, auto const& htmlElement)
32  {
33  return element.emplaceElement(htmlElement);
34  }
36  inline auto inplaceMaterialize(auto& element, auto const&)
37  {
38  return element.template shared_from_base<std::decay_t<decltype(element)>>();
39  }
40  }
41 
42  enum class RendererType
43  {
44  Append,
45  Fragment,
46  Insert,
47  Replace,
48  Inplace,
49  Emplace
50  };
51  struct Renderer
52  {
54  std::size_t metadata{0};
55  };
56  auto renderElement(Renderer const& gen, auto& element, auto const& htmlElement)
57  {
58  switch (gen.type)
59  {
61  return Materializers::appendMaterialize(element, htmlElement);
63  return Materializers::fragmentMaterialize(element, htmlElement);
65  return Materializers::insertMaterialize(gen.metadata, element, htmlElement);
67  return Materializers::replaceMaterialize(element, htmlElement);
69  return Materializers::inplaceMaterialize(element, htmlElement);
71  return Materializers::emplaceMaterialize(element, htmlElement);
72  }
73  };
74 }
auto appendMaterialize(auto &parent, auto const &htmlElement)
Creates new actual element and makes it a child of the given parent.
Definition: materialize.hpp:8
auto emplaceMaterialize(auto &element, auto const &htmlElement)
Replaces the given element with the new one.
Definition: materialize.hpp:31
auto inplaceMaterialize(auto &element, auto const &)
Used for elements that dont have a direct parent.
Definition: materialize.hpp:36
auto replaceMaterialize(auto &element, auto const &htmlElement)
Replaces the given element with the new one.
Definition: materialize.hpp:26
auto insertMaterialize(std::size_t where, auto &parent, auto const &htmlElement)
Inserts new element at the given position of the given parent.
Definition: materialize.hpp:21
auto fragmentMaterialize(auto &parent, auto const &htmlElement)
Similar to appendMaterialize, but the new element is not added to the children list.
Definition: materialize.hpp:14
Definition: file_dialog.hpp:6
auto renderElement(Renderer const &gen, auto &element, auto const &htmlElement)
Definition: materialize.hpp:56
RendererType
Definition: materialize.hpp:43
Definition: materialize.hpp:52
std::size_t metadata
Definition: materialize.hpp:54
RendererType type
Definition: materialize.hpp:53