Nui
Loading...
Searching...
No Matches
materialize.hpp
Go to the documentation of this file.
2
3#include <type_traits>
4#include <cstddef>
5
6namespace Nui
7{
8 class HtmlElement;
9
10 namespace Materializers
11 {
13 inline auto appendMaterialize(auto& parent, auto const& htmlElement)
14 {
15 return parent.appendElement(htmlElement);
16 }
19 inline auto fragmentMaterialize(auto& parent, auto const& htmlElement)
20 {
21 auto elem = parent.makeElement(htmlElement);
22 parent.val().template call<Nui::val>("appendChild", elem->val());
23 return elem;
24 }
26 inline auto insertMaterialize(std::size_t where, auto& parent, auto const& htmlElement)
27 {
28 return parent.insert(where, htmlElement);
29 }
31 inline auto replaceMaterialize(auto& element, auto const& htmlElement)
32 {
33 return element.replaceElement(htmlElement);
34 }
36 inline auto emplaceMaterialize(auto& element, auto const& htmlElement)
37 {
38 return element.emplaceElement(htmlElement);
39 }
41 inline auto inplaceMaterialize(auto& element, auto const&)
42 {
43 return element.template shared_from_base<std::decay_t<decltype(element)>>();
44 }
45 }
46
47 enum class RendererType
48 {
49 Append,
51 Insert,
52 Replace,
53 Inplace,
55 };
56 struct Renderer
57 {
59 std::size_t metadata{0};
60 };
61 auto renderElement(Renderer const& gen, auto& element, auto const& htmlElement)
62 {
63 switch (gen.type)
64 {
66 return Materializers::appendMaterialize(element, htmlElement);
68 return Materializers::fragmentMaterialize(element, htmlElement);
70 return Materializers::insertMaterialize(gen.metadata, element, htmlElement);
72 return Materializers::replaceMaterialize(element, htmlElement);
74 return Materializers::inplaceMaterialize(element, htmlElement);
76 return Materializers::emplaceMaterialize(element, htmlElement);
77 }
78 };
79}
auto appendMaterialize(auto &parent, auto const &htmlElement)
Creates new actual element and makes it a child of the given parent.
Definition materialize.hpp:13
auto emplaceMaterialize(auto &element, auto const &htmlElement)
Replaces the given element with the new one.
Definition materialize.hpp:36
auto inplaceMaterialize(auto &element, auto const &)
Used for elements that dont have a direct parent.
Definition materialize.hpp:41
auto replaceMaterialize(auto &element, auto const &htmlElement)
Replaces the given element with the new one.
Definition materialize.hpp:31
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:26
auto fragmentMaterialize(auto &parent, auto const &htmlElement)
Similar to appendMaterialize, but the new element is not added to the children list.
Definition materialize.hpp:19
Definition file_dialog.hpp:6
auto renderElement(Renderer const &gen, auto &element, auto const &htmlElement)
Definition materialize.hpp:61
@ Insert
Definition range_event_context.hpp:19
RendererType
Definition materialize.hpp:48
Definition materialize.hpp:57
std::size_t metadata
Definition materialize.hpp:59
RendererType type
Definition materialize.hpp:58