Nui
nui
include
nui
frontend
elements
comment.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <
nui/frontend/elements/impl/html_element_incl.hpp
>
4
#include <
nui/frontend/event_system/observed_value.hpp
>
5
#include <
nui/frontend/event_system/event_context.hpp
>
6
7
#include <string_view>
8
9
namespace
Nui::Elements
10
{
11
struct
comment
:
HtmlElement
12
{
13
comment
(
comment
const
&) =
default
;
14
comment
(
comment
&&) =
default
;
15
comment
(std::string_view content)
16
:
HtmlElement
{
""
, &
CommentElementBridge
,
Attribute
{content, {}, {}}}
17
{}
18
comment
(
Nui::Observed<std::string>
& obs)
19
:
HtmlElement
{
20
""
,
21
&
CommentElementBridge
,
22
Attribute
{
23
obs.value(),
24
[&obs](std::weak_ptr<Dom::ChildlessElement>&& element) {
25
const
auto
eventId =
globalEventContext
.
registerEvent
(
Event
{
26
[element, &obs](
auto
eventId) {
27
if
(
auto
shared = element.lock(); shared)
28
{
29
shared->setNodeValue(obs.
value
());
30
return
true
;
31
}
32
obs.
detachEvent
(eventId);
33
return
false
;
34
},
35
[element]() {
36
return
!element.expired();
37
}});
38
obs.
attachEvent
(eventId);
39
return
eventId;
40
},
41
[&obs](
EventContext::EventIdType
const
& id) {
42
obs.detachEvent(
id
);
43
},
44
},
45
}
46
{}
47
};
48
}
Nui::Attribute
Definition:
attribute.hpp:15
Nui::EventContext::EventIdType
EventRegistry::EventIdType EventIdType
Definition:
event_context.hpp:40
Nui::EventContext::registerEvent
EventIdType registerEvent(Event event)
Definition:
event_context.hpp:52
Nui::Event
Definition:
event.hpp:40
Nui::HtmlElement
Definition:
html_element.hpp:60
Nui::ModifiableObserved::value
ContainedT const & value() const
Definition:
observed_value.hpp:313
Nui::ObservedBase::attachEvent
void attachEvent(EventContext::EventIdType eventId) const
Definition:
observed_value.hpp:62
Nui::ObservedBase::detachEvent
void detachEvent(EventContext::EventIdType eventId) const
Definition:
observed_value.hpp:70
Nui::Observed< std::string >
event_context.hpp
observed_value.hpp
html_element_incl.hpp
Nui::Elements
Definition:
comment.hpp:10
Nui::globalEventContext
thread_local EventContext globalEventContext
Definition:
event_context.cpp:5
Nui::CommentElementBridge
constexpr auto CommentElementBridge
Definition:
html_element_bridges.hpp:34
Nui::Elements::comment
Definition:
comment.hpp:12
Nui::Elements::comment::comment
comment(Nui::Observed< std::string > &obs)
Definition:
comment.hpp:18
Nui::Elements::comment::comment
comment(comment &&)=default
Nui::Elements::comment::comment
comment(comment const &)=default
Nui::Elements::comment::comment
comment(std::string_view content)
Definition:
comment.hpp:15
Generated by
1.9.1