6#include <portals/layout.hpp>
12namespace portals::detail {
20inline std::expected<SizePolicy, TreeError> effectiveSizePolicy(SizePolicy policy, std::int32_t styleMinWidth,
21 const StyleSizing *sizing) {
22 const auto valid = [](AxisSize axis) {
23 return axis.minimum >= 0 && axis.maximum >= axis.minimum && axis.preferred >=
INTRINSIC_EXTENT && axis.weight > 0 &&
28 if (styleMinWidth < 0 || !valid(policy.width) || !valid(policy.height)) {
32 policy.width.minimum = std::max(policy.width.minimum, styleMinWidth);
34 const auto intersect = [](AxisSize &axis,
const std::optional<StyleAxisSize> &request,
35 std::optional<std::int32_t> minimum, std::optional<std::int32_t> maximum) {
36 if ((minimum && *minimum < 0) || (maximum && *maximum < 0)) {
41 axis.minimum = std::max(axis.minimum, *minimum);
45 axis.maximum = std::min(axis.maximum, *maximum);
49 if (request->weight == 0 || request->extent < 0) {
56 switch (request->mode) {
58 axis.minimum = std::max(axis.minimum, request->extent);
59 axis.maximum = std::min(axis.maximum, request->extent);
60 axis.preferred = request->extent;
75 axis.weight = request->weight;
83 return axis.maximum >= axis.minimum;
86 if (sizing && (!intersect(policy.width, sizing->width, {}, sizing->maxWidth) ||
87 !intersect(policy.height, sizing->height, sizing->minHeight, sizing->maxHeight))) {
91 if (policy.width.maximum < policy.width.minimum) {
103inline std::expected<SizePolicy, TreeError> effectiveSizePolicy(
const Widget &widget, std::int32_t styleMinWidth,
104 const StyleSizing *sizing =
nullptr) {
105 const auto *item =
dynamic_cast<const LayoutItem *
>(&widget);
107 return effectiveSizePolicy(item ? item->sizePolicy() : SizePolicy{}, styleMinWidth, sizing);
113inline std::expected<SizePolicy, TreeError> effectiveSizePolicy(
const Widget &widget) {
114 const auto &style = widget.computedStyle();
116 return effectiveSizePolicy(widget, style ? style->minWidth : 0, style ? style->sizing() :
nullptr);
147 return tree.arrangeImpl(node, local, viewport, edge.
surfaceClip, &edge);
158 std::span<const RegionalInputOwnerProposal> owners);
An owning, invariant-preserving half-open cell rectangle.
Definition geometry.hpp:81
Owning immutable identities and local sizes from one completed layout pass. Copies share immutable va...
Definition layout_snapshot.hpp:43
Copyable typed observer; never owns or exposes an unchecked widget pointer.
Definition widget.hpp:92
Public Portals API.
Definition action.hpp:8
@ AUTOMATIC
Use the ordinary preferred/intrinsic allocation.
Definition style_types.hpp:140
@ CONTENT
Prefer intrinsic content without consuming spare cells.
Definition style_types.hpp:143
@ FIXED
Intersect an exact cell extent with all hard bounds.
Definition style_types.hpp:141
@ FLEX
Share spare cells using the positive weight.
Definition style_types.hpp:142
@ AUTOMATIC
Use the preferred/intrinsic extent; shrink towards minimum when space is scarce.
Definition layout.hpp:13
@ CONTENT
Prefer intrinsic size, shrink towards minimum, and never grow to consume spare cells.
Definition layout.hpp:16
@ FIXED
Keep the bounded preferred/intrinsic extent even when it overflows the available space.
Definition layout.hpp:14
@ FLEX
Share spare main-axis cells by weight; allow shrinking towards minimum.
Definition layout.hpp:15
constexpr std::int32_t INTRINSIC_EXTENT
Sentinel requesting the widget's intrinsic measurement.
Definition layout.hpp:20
@ INVALID_ARGUMENT
An option, enum value or operation argument is invalid.
Definition widget_types.hpp:27
Owning identity, independent of addresses; zero is never a live identity.
Definition widget_types.hpp:15
Owning arranged edge before intersection with any ancestor's clip.
Definition widget.hpp:150
CellRect surfaceClip
Owner clip in surface coordinates, before intersection.
Definition widget.hpp:153
Internal checked bridge for owning layout edges and regional input. Public arrange retains its ordina...
Definition layout_traversal.hpp:137
static std::expected< bool, TreeError > adoptRegionalInput(WidgetTree &tree, const LayoutSnapshot &snapshot, std::span< const RegionalInputOwnerProposal > owners)
Validate and allocate the whole batch before publishing any gate.
static std::expected< void, TreeError > arrange(WidgetTree &tree, Node< Widget > node, CellRect local, CellRect viewport, const ParentLayoutEdge &edge)
Definition layout_traversal.hpp:145