Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
ui_construction.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5#include <portals/ui_description.hpp>
6
7namespace portals::ui {
8
16template <class T, class... Args> Description<T> custom(Args &&...args) {
17 using OwnedArguments = std::tuple<decltype(detail::own(std::forward<Args>(args)))...>;
18 constexpr bool HAS_TEXT_ARGUMENT = (std::convertible_to<Args, std::string_view> || ...);
19
20 // Construct strings directly in stationary tuple storage. Moving a string or tuple<string>
21 // can allocate a checked MSVC proxy despite noexcept; a string_view constructor stays fallible.
22 // Explicit element types also preserve tuple/pair constructor arguments without CTAD flattening.
23 auto owned = [&] {
24 if constexpr (HAS_TEXT_ARGUMENT && detail::CHECKED_STRING_MOVES) {
25 return std::make_unique<OwnedArguments>(detail::constructionArgument(std::forward<Args>(args))...);
26 } else {
27 return OwnedArguments(detail::own(std::forward<Args>(args))...);
28 }
29 }();
30
31 return Description<T>([owned = std::move(owned)](ManagedScene &scene, Node<Widget> parent) mutable {
32 auto &arguments = [&]() -> auto & {
33 if constexpr (HAS_TEXT_ARGUMENT && detail::CHECKED_STRING_MOVES) {
34 return *owned;
35 } else {
36 return owned;
37 }
38 }();
39
40 return std::apply(
41 [&](auto &...values) {
42 return scene.emplace<T>(parent, std::move(values)...);
43 },
44 arguments);
45 });
46}
47
54template <class T, class... Args> Description<T> custom(Ref<T> reference, Args &&...args) {
55 return custom<T>(std::forward<Args>(args)...).reference(std::move(reference));
56}
57
58} // namespace portals::ui
Additive lifecycle owner over one existing Application subtree. UI affine and nonmovable....
Definition managed.hpp:530
Copyable typed observer; never owns or exposes an unchecked widget pointer.
Definition widget.hpp:92
Single-use owning construction recipe; no mounted widget ownership.
Definition ui_description.hpp:48
Description()=default
Construct an empty recipe; mounting it returns INVALID_ARGUMENT.
Description && reference(NodeRef< T > reference) &&
Definition ui_description.hpp:1251
friend Description< U > custom(Args &&...args)
Capture constructor arguments without requiring inheritance from a DSL widget.
Definition ui_construction.hpp:16
Typed Widget observation; explicit composite specializations reuse their existing weak facades.
Definition ui_ref.hpp:761