20 template <
typename SlotId>
25 : delocalizedElement_{[&renderer]() -> decltype(delocalizedElement_) {
29 element->replaceElement(renderer);
37 , slotId_{std::make_unique<Nui::Observed<SlotId>>()}
46 return delocalizedElement_;
51 delocalizedElement_->replaceElement(renderer);
55 return delocalizedElement_ !=
nullptr;
69 return slotId_->value();
72 template <
typename SlotIdB>
76 std::vector<Attribute> wrapperAttributes,
80 std::shared_ptr<Dom::Element> delocalizedElement_;
82 std::unique_ptr<Nui::Observed<SlotId>> slotId_;
85 template <
typename SlotId>
89 std::vector<Attribute> wrapperAttributes = {},
92 using namespace Elements;
93 using namespace Attributes;
95 auto element = delocalizedElement.delocalizedElement_;
97 return Elements::div{std::move(wrapperAttributes)}(
98 observe(*delocalizedElement.slotId_),
99 [element, slot, &observedId = *delocalizedElement.slotId_, alternative]()
mutable {
100 return [element, slot, &observedId, alternative](
101 Dom::Element& wrapper, Renderer
const& gen) -> std::shared_ptr<Dom::Element> {
102 if (element && slot == observedId.value())
104 wrapper.val().call<
void>(
"appendChild", element->val());
105 return nil()(wrapper, gen);
110 return alternative(wrapper, gen);
112 return nil()(wrapper, gen);
121 std::vector<Attribute> wrapperAttributes = {},
124 return delocalizedSlot<std::string>(
125 std::string{slot}, delocalizedElement, std::move(wrapperAttributes), std::move(alternative));
A delocalized element can switch positions in several slots.
Definition: delocalized.hpp:22
Delocalized(Nui::ElementRenderer renderer={})
Definition: delocalized.hpp:24
Delocalized & operator=(Delocalized const &)=delete
Delocalized(Delocalized const &)=delete
SlotId slot() const
Definition: delocalized.hpp:67
Delocalized(Delocalized &&)=default
void slot(SlotId slot)
Definition: delocalized.hpp:63
std::shared_ptr< Dom::Element > element()
Definition: delocalized.hpp:44
friend ElementRenderer delocalizedSlot(SlotIdB slot, Delocalized< SlotIdB > &delocalizedElement, std::vector< Attribute > wrapperAttributes, Nui::ElementRenderer alternative)
void element(Nui::ElementRenderer renderer)
Definition: delocalized.hpp:48
bool hasElement() const
Definition: delocalized.hpp:53
void initializeIfEmpty(Nui::ElementRenderer renderer)
Definition: delocalized.hpp:57
Delocalized & operator=(Delocalized &&)=default
static std::shared_ptr< Element > makeElement(HtmlElement const &element)
Definition: element.hpp:87
Definition: html_element.hpp:60
struct Nui::Attributes::style_ style
Definition: file_dialog.hpp:6
static auto nil()
Definition: nil.hpp:7
constexpr auto RegularHtmlElementBridge
Definition: html_element_bridges.hpp:8
std::function< std::shared_ptr< Dom::Element >(Dom::Element &, Renderer const &)> ElementRenderer
Definition: element_renderer.hpp:11
ElementRenderer delocalizedSlot(SlotId slot, Delocalized< SlotId > &delocalizedElement, std::vector< Attribute > wrapperAttributes={}, ElementRenderer alternative=Elements::div{Attributes::style="display: none"}())
Definition: delocalized.hpp:86