Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
layout_snapshot.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5#include <portals/scroll_controls.hpp>
6#include <portals/widget.hpp>
7
8#include <memory>
9#include <optional>
10#include <vector>
11
12namespace portals {
13namespace detail {
14enum class ScrollSnapshotAdmission;
15struct ScrollSnapshotAccess;
16struct ScrollSnapshotTestAccess;
17} // namespace detail
23
32 bool visible{};
33 std::optional<ScrollAreaLayoutSnapshot> scrollArea;
34 std::optional<ParentLayoutEdge> parentLayoutEdge;
35 std::optional<std::uint64_t> geometryEpoch;
36};
37
43class LayoutSnapshot {
44public:
54 [[nodiscard]] static std::expected<LayoutSnapshot, TreeError> capture(WidgetTree &tree, Node<Widget> node);
63 [[nodiscard]] static std::expected<LayoutSnapshot, TreeError> capture(WidgetTree &tree, Node<Widget> node,
64 LayoutSnapshotProfile profile);
72 [[nodiscard]] std::expected<CellSize, TreeError> viewport(Node<Widget> node) const noexcept;
77 [[nodiscard]] std::expected<LayoutGeometrySnapshot, TreeError> geometry(Node<Widget> node) const noexcept;
81 [[nodiscard]] std::expected<std::uint64_t, TreeError> geometryRevision() const noexcept;
82
83private:
84 friend struct detail::LayoutTraversalAccess;
85 friend struct detail::ScrollSnapshotAccess;
86 friend struct detail::ScrollSnapshotTestAccess;
87 std::expected<detail::ScrollSnapshotAdmission, TreeError> admitScrollSnapshot(WidgetTree &tree) const;
88
89 struct Record {
90 NodeId id;
91 CellSize size;
92 };
93
94 struct GeometryRecord {
95 NodeId id;
97 };
98
99 LayoutSnapshot(std::uint64_t session, std::shared_ptr<const std::vector<Record>> records);
100 LayoutSnapshot(std::uint64_t session, std::shared_ptr<const std::vector<Record>> records,
101 std::shared_ptr<const std::vector<GeometryRecord>> geometry, std::uint64_t revision,
102 std::uint64_t inputGeneration);
103 std::uint64_t session_;
104 std::shared_ptr<const std::vector<Record>> records_;
105 std::shared_ptr<const std::vector<GeometryRecord>> geometry_;
106 std::uint64_t geometryRevision_{};
107 std::uint64_t inputGeneration_{};
108};
109} // namespace portals
An owning, invariant-preserving half-open cell rectangle.
Definition geometry.hpp:81
static std::expected< LayoutSnapshot, TreeError > capture(WidgetTree &tree, Node< Widget > node)
Copy every live node in a subtree, including effectively hidden descendants. Call on the tree's UI th...
static std::expected< LayoutSnapshot, TreeError > capture(WidgetTree &tree, Node< Widget > node, LayoutSnapshotProfile profile)
Opt into geometry capture without changing the original overload's allocation path.
std::expected< std::uint64_t, TreeError > geometryRevision() const noexcept
std::expected< LayoutGeometrySnapshot, TreeError > geometry(Node< Widget > node) const noexcept
std::expected< CellSize, TreeError > viewport(Node< Widget > node) const noexcept
Read a captured local extent without consulting the current tree.
Copyable typed observer; never owns or exposes an unchecked widget pointer.
Definition widget.hpp:92
Exclusive parent/child ownership on Scheduler's UI thread. Scheduler must outlive this object....
Definition widget.hpp:179
Public Portals API.
Definition action.hpp:8
LayoutSnapshotProfile
Explicit capture cost profile; dimension-only scenes keep their original path.
Definition layout_snapshot.hpp:19
@ GEOMETRY
Copy geometry, visibility and pure descendant clips for scroll preparation.
Definition layout_snapshot.hpp:21
@ DIMENSIONS
Original size records, without optional geometry storage.
Definition layout_snapshot.hpp:20
TreeError
Checked tree failures; rejected operations never start the requested callback.
Definition widget_types.hpp:26
An owning available extent in terminal columns/rows.
Definition geometry.hpp:44
Owning geometry independent of later live invalidation or widget destruction. descendantClip precedes...
Definition layout_snapshot.hpp:28
bool visible
Effective visibility; visible zero differs from hidden.
Definition layout_snapshot.hpp:32
std::optional< ScrollAreaLayoutSnapshot > scrollArea
Copied derived values for an initialized area.
Definition layout_snapshot.hpp:33
Node< Widget > parent
Captured full parent identity, without ownership.
Definition layout_snapshot.hpp:29
std::optional< std::uint64_t > geometryEpoch
Nonreused stamp of this child's arrangement.
Definition layout_snapshot.hpp:35
CellRect descendantClip
Pure childClip translated to surface coordinates.
Definition layout_snapshot.hpp:31
NodeGeometry geometry
Full local/surface bounds and cumulative paint clip.
Definition layout_snapshot.hpp:30
std::optional< ParentLayoutEdge > parentLayoutEdge
Specialized edge, before ancestor intersection.
Definition layout_snapshot.hpp:34
Owning arranged geometry; invalid geometry must never be used for hit-testing.
Definition widget_types.hpp:48
Owning identity, independent of addresses; zero is never a live identity.
Definition widget_types.hpp:15