EN
RU
Portals
0.7.0 · dev
0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Toggle main menu visibility
Loading...
Searching...
No Matches
managed_origin.hpp
1
// Copyright (c) 2026 ttldtor.
2
// SPDX-License-Identifier: BSL-1.0
3
#pragma once
4
5
#include <portals/widget.hpp>
6
#include <thread>
7
8
namespace
portals::detail {
10
// Metadata alone may outlive the scene. It owns no widget, tree or Property.
11
struct
ManagedOrigin {
12
WidgetTree *tree{};
13
Node<Widget> node;
14
std::weak_ptr<const void> lifetime;
15
const
std::thread::id owner = std::this_thread::get_id();
16
bool
retired{};
17
bool
closed{};
18
19
std::expected<void, TreeError> check() {
20
if
(owner != std::this_thread::get_id()) {
21
return
std::unexpected(TreeError::WRONG_THREAD);
22
}
23
24
if
(lifetime.expired() || closed) {
25
return
std::unexpected(TreeError::CLOSED);
26
}
27
28
if
(retired) {
29
return
std::unexpected(TreeError::STALE_NODE);
30
}
31
32
auto
live
= tree->withScope(node, [](
const
UiScope &) {
33
});
34
35
if
(!live && (
live
.error() == TreeError::STALE_NODE ||
live
.error() == TreeError::CLOSED)) {
36
retired =
true
;
37
}
38
39
return
live
;
40
}
41
};
42
44
}
// namespace portals::detail
portals::style::ct::live
auto live(ManagedScene &scene, const S &description)
Definition
style_static.hpp:1703
include
portals
detail
managed_origin.hpp