5#include <portals/style_pss.hpp>
6#include <portals/ui_scene_resource.hpp>
10namespace portals::ui {
14 std::optional<std::string>
name{};
16 std::optional<StyleLayerOptions>
layers{};
24 std::filesystem::path
path;
30inline FileSource file(
const std::filesystem::path &path) {
56 std::source_location origin = std::source_location::current())
65 std::source_location origin = std::source_location::current())
74 template <std::
size_t N>
76 std::source_location origin = std::source_location::current())
77 :
StyleStage(
bytes(std::string_view(input, N && input[N - 1] ==
'\0' ? N - 1 : N), options, origin)) {
85 template <
class Po
inter>
86 requires(std::same_as<std::remove_cvref_t<Pointer>,
const char *> ||
87 std::same_as<std::remove_cvref_t<Pointer>,
char *>)
89 std::source_location origin = std::source_location::current())
98 std::source_location origin = std::source_location::current())
99 :
StyleStage(document(input, options, origin)) {
107 std::source_location origin = std::source_location::current())
119 template <std::
size_t R, std::
size_t C, std::
size_t D, std::
size_t B>
121 std::source_location origin = std::source_location::current())
122 :
StyleStage(compact(input, options, origin)) {
159 return owner.
style(stage, stage.origin_);
167 Scene owner(std::move(input));
169 owner.
style(stage, stage.origin_);
177 template <std::
size_t R, std::
size_t C, std::
size_t D, std::
size_t B>
179 std::source_location origin) {
182 return converted ? document(*converted, options, origin) :
failure(converted.error(), options, origin);
187 friend struct detail::NamedAccess;
193 StyleStage scoped(std::shared_ptr<detail::RefTarget> target)
const;
197 StyleStage(std::shared_ptr<const Impl> payload, std::source_location origin)
198 : payload_(std::move(payload)), origin_(origin) {
201 std::expected<StyleLayerHandle, ManagedError> apply(ManagedScene &scene,
const StyleLayerHandle *existing)
const;
203 std::shared_ptr<detail::RefTarget> target_;
204 std::shared_ptr<const Impl> payload_;
205 std::source_location origin_;
209 return stage.scoped(std::move(
target));
218 std::source_location origin = std::source_location::current()) {
228template <std::
size_t N>
229StyleStage style(
const char (&bytes)[N],
const StyleOptions &options = StyleOptions{},
230 std::source_location origin = std::source_location::current()) {
231 return style(std::string_view(bytes, N && bytes[N - 1] ==
'\0' ? N - 1 : N), options, origin);
239inline StyleStage style(
const PssDocument &document,
const StyleOptions &options = {},
240 std::source_location origin = std::source_location::current()) {
249inline StyleStage style(
const FileSource &source,
const StyleOptions &options = {},
250 std::source_location origin = std::source_location::current()) {
263template <std::
size_t R, std::
size_t C, std::
size_t D, std::
size_t B>
264StyleStage style(
const style::ct::CompactSheet<R, C, D, B> &description,
const StyleOptions &options = {},
265 std::source_location origin = std::source_location::current()) {
269 : StyleStage::failure(document.error(), options, origin);
280StyleStage style(
const Ref<T> &reference, std::string_view bytes,
const StyleOptions &options = {},
281 std::source_location origin = std::source_location::current()) {
291inline StyleStage style(
const DynamicRef &reference, std::string_view bytes,
const StyleOptions &options = {},
292 std::source_location origin = std::source_location::current()) {
304template <
class T, std::
size_t N>
306StyleStage style(
const T &reference,
const char (&bytes)[N],
const StyleOptions &options = {},
307 std::source_location origin = std::source_location::current()) {
308 return style(reference, std::string_view(bytes, N && bytes[N - 1] ==
'\0' ? N - 1 : N), options, origin);
316inline StyleStage styleFile(
const std::filesystem::path &path,
const StyleOptions &options = {},
317 std::source_location origin = std::source_location::current()) {
318 return style(file(path), options, origin);
330StyleStage styleFile(
const T &reference,
const std::filesystem::path &path,
const StyleOptions &options = {},
331 std::source_location origin = std::source_location::current()) {
340inline Scene &style(Scene &owner,
const StyleStage &stage,
341 std::source_location origin = std::source_location::current()) {
342 return owner.style(stage, origin);
346template <
class Source>
347 requires std::constructible_from<StyleStage, Source &&, const StyleOptions &, std::source_location>
349 const StyleStage stage(std::forward<Source>(source), options, origin);
351 return style(stage, origin);
355template <
class Source>
356 requires std::constructible_from<StyleStage, Source &&, const StyleOptions &, std::source_location>
358 static_cast<Scene &
>(*this).style(std::forward<Source>(source), options, origin);
360 return std::move(*
this);
370template <
class Source>
371 requires std::constructible_from<StyleStage, Source &&, const StyleOptions &, std::source_location>
373 std::source_location origin = std::source_location::current()) {
374 return owner.
style(std::forward<Source>(source), options, origin);
378template <
class S>
struct LiveDescriptor;
386 std::shared_ptr<RefTarget>
events = std::make_shared<RefTarget>();
393 std::expected<bool, ManagedError>
attach(
ManagedScene &scene,
const std::shared_ptr<SceneAnchor> &anchor)
override {
394 if (
descriptor->owner != std::this_thread::get_id()) {
399 const auto previousAnchor =
descriptor->anchor.lock();
400 const auto previous =
descriptor->binding.lock();
402 if (!previousAnchor || !previous) {
406 if (previousAnchor != anchor) {
410 auto checked = previous->controller.apply();
412 return checked ? std::expected<bool, ManagedError>{
false} : std::unexpected(checked.error());
418 return std::unexpected(attached.error());
425 events->node = scene.root();
441 const std::thread::id
owner = std::this_thread::get_id();
449 std::expected<std::shared_ptr<LiveBinding>,
ManagedError>
450 create(
const std::shared_ptr<SceneAnchor> &receiving)
override {
451 if (
owner != std::this_thread::get_id()) {
456 const auto previous =
anchor.lock();
457 const auto existing =
binding.lock();
459 if (!previous || !existing) {
463 if (previous != receiving) {
467 return std::static_pointer_cast<LiveBinding>(existing);
470 return std::static_pointer_cast<LiveBinding>(std::make_shared<
LiveController<S>>(this->shared_from_this()));
493 template <style::ct::detail::Literal Name>
494 auto get(std::source_location origin = std::source_location::current())
const {
495 using Result =
decltype(std::declval<style::ct::LiveTheme<S>>().template
get<Name>());
496 auto binding = lock();
499 return Result(std::unexpected(binding.error()));
502 auto result = (*binding)->controller.template
get<Name>();
505 detail::reportEventError((*binding)->events, result.error(), origin);
517 template <style::ct::detail::Literal Name,
class T>
518 std::expected<bool, ManagedError>
set(T value, std::source_location origin = std::source_location::current())
const {
526 template <
class... C> std::expected<bool, ManagedError>
apply(C... changes)
const {
527 return applyAt(std::source_location::current(), changes...);
534 : descriptor_(std::move(descriptor)), owner_(owner) {
537 std::expected<std::shared_ptr<detail::LiveController<S>>,
ManagedError> lock()
const {
538 if (owner_ != std::thread::id{} && owner_ != std::this_thread::get_id()) {
539 return std::unexpected(ManagedError{ManagedPhase::STYLE, {}, TreeError::WRONG_THREAD, {}, {}});
542 const auto descriptor = descriptor_.lock();
543 const auto binding = descriptor ? descriptor->binding.lock() :
nullptr;
545 if (!binding || !descriptor->bound || descriptor->anchor.expired()) {
546 return std::unexpected(ManagedError{ManagedPhase::STYLE, {}, TreeError::CLOSED, {}, {}});
549 auto admitted = detail::eventScene(binding->events);
551 return admitted ? std::expected<std::shared_ptr<detail::LiveController<S>>, ManagedError>{binding}
552 : std::unexpected(admitted.error());
555 template <
class... C> std::expected<bool, ManagedError> applyAt(std::source_location origin, C... changes)
const {
556 auto binding = lock();
559 return std::unexpected(binding.error());
562 auto result = (*binding)->controller.apply(changes...);
565 detail::reportEventError((*binding)->events, result.error(), origin);
571 std::weak_ptr<detail::LiveDescriptor<S>> descriptor_;
572 std::thread::id owner_{};
594 : descriptor_(std::make_shared<detail::LiveDescriptor<S>>(description)), origin_(origin) {
599 return {descriptor_, descriptor_->owner};
606 template <style::ct::detail::Literal Name>
607 auto get(std::source_location origin = std::source_location::current())
const {
617 template <style::ct::detail::Literal Name,
class T>
618 std::expected<bool, ManagedError>
set(T value, std::source_location origin = std::source_location::current())
const {
626 template <
class... C> std::expected<bool, ManagedError>
apply(C... changes)
const {
627 return ref().apply(changes...);
637 stage.install(owner);
647 Scene owner(std::move(input));
649 stage.install(owner);
655 void install(
Scene &owner)
const {
659 std::shared_ptr<detail::LiveDescriptor<S>> descriptor_;
660 std::source_location origin_;
669 requires style::ct::detail::IsSheet<S>::value
670LiveThemeStage<S> liveTheme(
const S &description, std::source_location origin = std::source_location::current()) {
Additive lifecycle owner over one existing Application subtree. UI affine and nonmovable....
Definition managed.hpp:530
Immutable owning scalar stylesheet; its public type contains only numeric capacities.
Definition pss_compact.hpp:220
Copyable UI-affine observer with owned rules and current scalar parameter values. Copies share values...
Definition style_static.hpp:1510
static std::expected< LiveTheme, ManagedError > attach(ManagedScene &scene, const S &description)
Definition style_static.hpp:1533
Weak typed live parameter observation, never owning a controller or UI owner.
Definition ui_style.hpp:484
std::expected< bool, ManagedError > set(T value, std::source_location origin=std::source_location::current()) const
Definition ui_style.hpp:518
std::expected< bool, ManagedError > apply(C... changes) const
Definition ui_style.hpp:526
auto get(std::source_location origin=std::source_location::current()) const
Definition ui_style.hpp:494
LiveThemeRef()=default
Construct an empty observer; operations return CLOSED.
Copyable owning static description with one single-scene live binding identity.
Definition ui_style.hpp:580
LiveThemeRef< S > ref() const
Definition ui_style.hpp:598
std::expected< bool, ManagedError > apply(C... changes) const
Definition ui_style.hpp:626
std::expected< bool, ManagedError > set(T value, std::source_location origin=std::source_location::current()) const
Definition ui_style.hpp:618
auto get(std::source_location origin=std::source_location::current()) const
Definition ui_style.hpp:607
LiveThemeStage & operator=(const LiveThemeStage &other) noexcept=default
friend Scene & operator|(Scene &owner, const LiveThemeStage &stage)
Definition ui_style.hpp:634
LiveThemeStage(const LiveThemeStage &other) noexcept=default
friend Scene operator|(Scene &&input, const LiveThemeStage &stage)
Definition ui_style.hpp:646
LiveThemeStage(const S &description, std::source_location origin)
Definition ui_style.hpp:593
Single-use lazy owner of one Application and ManagedScene; no second runtime. Construct and operate o...
Definition ui_scene.hpp:253
Scene & style(const StyleStage &stage, std::source_location origin=std::source_location::current()) &
Scene(Scene &&other) noexcept
Transfer a UI-affine owner between operations, including between session steps. Wrong-thread moves an...
Copyable immutable owning style payload with one shared stage identity. Independent unnamed stages co...
Definition ui_style.hpp:39
static StyleStage failure(PssError failure, const StyleOptions &options, std::source_location origin)
StyleStage & operator=(const StyleStage &other) noexcept=default
StyleStage(const std::string &input, const StyleOptions &options={}, std::source_location origin=std::source_location::current())
Definition ui_style.hpp:64
static StyleStage document(const PssDocument &document, const StyleOptions &options, std::source_location origin)
StyleStage(const FileSource &input, const StyleOptions &options={}, std::source_location origin=std::source_location::current())
Definition ui_style.hpp:106
friend Scene operator|(Scene &&input, const StyleStage &stage)
Definition ui_style.hpp:166
StyleStage(const PssDocument &input, const StyleOptions &options={}, std::source_location origin=std::source_location::current())
Definition ui_style.hpp:97
static StyleStage source(const FileSource &source, const StyleOptions &options, std::source_location origin)
StyleStage(Pointer &&input, const StyleOptions &options={}, std::source_location origin=std::source_location::current())
Definition ui_style.hpp:88
StyleStage(const char(&input)[N], const StyleOptions &options={}, std::source_location origin=std::source_location::current())
Definition ui_style.hpp:75
StyleStage(std::string_view input, const StyleOptions &options={}, std::source_location origin=std::source_location::current())
Definition ui_style.hpp:55
StyleStage(const StyleStage &other) noexcept=default
friend Scene & operator|(Scene &owner, const StyleStage &stage)
Definition ui_style.hpp:158
StyleStage(const portals::style::ct::CompactSheet< R, C, D, B > &input, const StyleOptions &options={}, std::source_location origin=std::source_location::current())
Definition ui_style.hpp:120
static StyleStage bytes(std::string_view bytes, const StyleOptions &options, std::source_location origin)
std::expected< PssDocument, PssError > materializeDocument(const CompactSheet< R, C, D, B > &description)
Definition style_pss.hpp:400
auto change(T value)
Definition style_static.hpp:1496
auto reference(ui::Ref< T > value)
Definition ui_static.hpp:572
@ STYLE
Register or apply styles, including a theme change.
Definition managed_diagnostics.hpp:52
StyleTier
Independent cascade priority, before selector specificity.
Definition style.hpp:251
@ APPLICATION
Application overrides, above THEME.
Definition style.hpp:254
TreeError
Checked tree failures; rejected operations never start the requested callback.
Definition widget_types.hpp:26
@ CLOSED
The owning tree or source is closed.
Definition widget_types.hpp:31
@ WRONG_THREAD
Operation requires the tree's UI thread.
Definition widget_types.hpp:28
@ INVALID_ARGUMENT
An option, enum value or operation argument is invalid.
Definition widget_types.hpp:27
Original error plus independent runner/restoration and cleanup failures.
Definition managed_diagnostics.hpp:62
Owning parsed declarations and provenance; input bytes need not survive the call. Metadata is not aut...
Definition pss_data.hpp:259
Allocation-free error owning its bounded subject; message always has static lifetime.
Definition pss_data.hpp:203
static std::weak_ptr< const void > lifetime(ManagedScene &scene)
Definition style_static.hpp:705
Owning explicit file source; no watcher, includes or implicit path detection.
Definition ui_style.hpp:20
std::filesystem::path path
Owned native path; Windows Unicode is retained without narrow conversion.
Definition ui_style.hpp:24
~FileSource()=default
Suppress implicit noexcept path moves; checked MSVC path copies can allocate.
Style source admission and existing layer policy.
Definition ui_style.hpp:12
std::string sourceName
Owning UTF-8 source label; empty preserves a document's identity.
Definition ui_style.hpp:15
StyleTier tier
APPLICATION by default; USER must be explicit.
Definition ui_style.hpp:13
std::optional< StyleLayerOptions > layers
Omitted adopts existing limits or atomic first-enable defaults.
Definition ui_style.hpp:16
std::optional< std::string > name
Explicit tier/name upsert, or independent owning stage identity.
Definition ui_style.hpp:14
Erased facade-owned binding; concrete bindings reuse the existing LiveTheme controller.
Definition ui_scene.hpp:220
Scene-owned actual existing controller with weak publication only.
Definition ui_style.hpp:383
style::ct::LiveTheme< S > controller
Existing theme controller and authority lease.
Definition ui_style.hpp:385
LiveController(std::shared_ptr< LiveDescriptor< S > > value)
Definition ui_style.hpp:389
std::shared_ptr< RefTarget > events
Preallocated weak collector observation.
Definition ui_style.hpp:386
std::expected< bool, ManagedError > attach(ManagedScene &scene, const std::shared_ptr< SceneAnchor > &anchor) override
Definition ui_style.hpp:393
std::shared_ptr< LiveDescriptor< S > > descriptor
Owns the descriptor, never an additional UI owner.
Definition ui_style.hpp:384
Shared owning descriptor identity, retaining only weak UI binding observations.
Definition ui_style.hpp:439
std::weak_ptr< SceneAnchor > anchor
Original single receiving facade identity.
Definition ui_style.hpp:443
bool bound
Permanent first-success marker; cleanup never permits rebinding.
Definition ui_style.hpp:444
std::weak_ptr< LiveController< S > > binding
Published only after successful attachment.
Definition ui_style.hpp:442
const S description
Immutable owning static sheet, independent of caller storage.
Definition ui_style.hpp:440
std::expected< std::shared_ptr< LiveBinding >, ManagedError > create(const std::shared_ptr< SceneAnchor > &receiving) override
Definition ui_style.hpp:450
LiveDescriptor(const S &value)
Definition ui_style.hpp:474
const std::thread::id owner
Immutable descriptor affinity.
Definition ui_style.hpp:441
Erased owning live descriptor factory invoked only within facade admission. Concrete descriptor ident...
Definition ui_scene.hpp:234
static std::shared_ptr< RefTarget > target(const DynamicRef &reference)
Definition ui_ref.hpp:2704
static StyleStage scopeStyle(const StyleStage &stage, std::shared_ptr< RefTarget > target)
Definition ui_style.hpp:208
static void live(Scene &owner, std::shared_ptr< LiveFactory > factory, std::source_location origin)
Definition ui_scene.hpp:1307