Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
ui_key_info.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5#include <portals/ui_ref.hpp>
6#include <portals/key_binding.hpp>
7
8namespace portals::ui {
10class KeyInfo {
11public:
13 explicit KeyInfo(TextValue label, TextResolver resolver = {}) : value_(std::move(label)) {
14 value_.resolver = std::move(resolver);
15 }
16
19 value_.description = std::move(text);
20 return std::move(*this);
21 }
22
25 value_.publication_ = std::move(reference.slot_);
26 return std::move(*this);
27 }
28
30 template <class T>
31 requires std::derived_from<T, Widget>
33 owner_ = reference.target();
34 return std::move(*this);
35 }
36
38 template <class T>
39 requires std::derived_from<T, Widget>
41 scope_ = reference.target();
42 return std::move(*this);
43 }
44
46 KeyInfo &&enabled(bool value) && {
47 value_.enabled = value;
48 return std::move(*this);
49 }
50
52 KeyInfo &&visible(bool value) && {
53 value_.visible = value;
54 return std::move(*this);
55 }
56
57private:
58 friend class Scene;
59
60 std::expected<portals::KeyInfo, ManagedError> resolve(ManagedScene &scene) {
61 for (const auto &target : {owner_, scope_}) {
62 if (!target) {
63 continue;
64 }
65 auto owner = detail::eventScene(target);
66 if (!owner) {
67 return std::unexpected(owner.error());
68 }
69 if (*owner != &scene) {
70 return std::unexpected(
71 ManagedError{ManagedPhase::BIND, target->node.id(), TreeError::INVALID_ARGUMENT, {}, {}});
72 }
73 }
74 if (owner_) {
75 value_.owner = owner_->node;
76 }
77 if (scope_) {
78 value_.scope = scope_->node;
79 }
80 return std::move(value_);
81 }
82
83 portals::KeyInfo value_;
84 std::shared_ptr<detail::RefTarget> owner_, scope_;
85};
86
88inline KeyInfo keyInfo(std::string_view label) {
89 return KeyInfo(TextValue(label));
90}
91
93inline KeyInfo keyInfo(TextValue label, TextResolver resolver = {}) {
94 return KeyInfo(std::move(label), std::move(resolver));
95}
96
97
98} // namespace portals::ui
Additive lifecycle owner over one existing Application subtree. UI affine and nonmovable....
Definition managed.hpp:530
Owning literal bytes or a resource key, measured only at resolution.
Definition text_value.hpp:42
constexpr TextValue(const TextValue &other)=default
Copy expression bytes and kind into independent storage.
Deferred observing slot, published only by a complete successful registration. Construction may alloc...
Definition key_binding.hpp:198
Consuming metadata for one canonical annotated registration; refs resolve after complete mount.
Definition ui_key_info.hpp:10
KeyInfo && description(TextValue text) &&
Definition ui_key_info.hpp:18
KeyInfo && scope(const Ref< T > &reference) &&
Definition ui_key_info.hpp:40
KeyInfo && reference(KeyBindingRef reference) &&
Definition ui_key_info.hpp:24
KeyInfo && owner(const Ref< T > &reference) &&
Definition ui_key_info.hpp:32
KeyInfo(TextValue label, TextResolver resolver={})
Definition ui_key_info.hpp:13
KeyInfo && enabled(bool value) &&
Definition ui_key_info.hpp:46
KeyInfo && visible(bool value) &&
Definition ui_key_info.hpp:52
Typed Widget observation; explicit composite specializations reuse their existing weak facades.
Definition ui_ref.hpp:761
Single-use lazy owner of one Application and ManagedScene; no second runtime. Construct and operate o...
Definition ui_scene.hpp:253
@ BIND
Register a managed callback, binding or presentation adapter.
Definition managed_diagnostics.hpp:51
@ INVALID_ARGUMENT
An option, enum value or operation argument is invalid.
Definition widget_types.hpp:27
KeyTextResolver resolver
Not retained after successful normalization.
Definition key_binding.hpp:67