Compute_grid.Grid_itemSourceGrid item representation for CSS Grid layout algorithm.
This module defines the grid item type used during track sizing and placement. Each item represents a single child node positioned within the grid, with cached intrinsic size contributions.
row_indexes and column_indexes are initialized during placement and remain valid throughout layout.min_content_contribution_cache, etc.) are valid only for a single track-sizing run.available_space_cache must match the current known_dimensions input or be None.baseline_shim acts as additional top margin for baseline alignment.Grid items track placement in two coordinate systems:
row and column fields, with lines numbered from the grid origin.row_indexes and column_indexes, indexing into GridTrack arrays.Intrinsic size caches are tied to available_space_cache. When the available space changes, all caches must be cleared by setting available_space_cache to None.
Origin-zero line coordinate type.
type t = {node : Tree.Node_id.t;source_order : int;row : origin_zero_line Geometry.line;column : origin_zero_line Geometry.line;is_compressible_replaced : bool;overflow : Style.overflow Geometry.point;box_sizing : Style.box_sizing;size : Style.dimension Geometry.size;min_size : Style.dimension Geometry.size;max_size : Style.dimension Geometry.size;aspect_ratio : float option;padding : Style.length_percentage Geometry.rect;border : Style.length_percentage Geometry.rect;margin : Style.length_percentage_auto Geometry.rect;align_self : Style.align_self;justify_self : Style.justify_self;mutable baseline : float option;mutable baseline_shim : float;mutable row_indexes : int Geometry.line;mutable column_indexes : int Geometry.line;mutable crosses_flexible_row : bool;mutable crosses_flexible_column : bool;mutable crosses_intrinsic_row : bool;mutable crosses_intrinsic_column : bool;mutable available_space_cache : float option Geometry.size option;mutable min_content_contribution_cache : float option Geometry.size;mutable minimum_contribution_cache : float option Geometry.size;mutable max_content_contribution_cache : float option Geometry.size;mutable y_position : float;mutable height : float;}Grid item representation.
val new_with_placement_style_and_order :
node:Tree.Node_id.t ->
col_span:origin_zero_line Geometry.line ->
row_span:origin_zero_line Geometry.line ->
style:Style.t ->
parent_align_items:Style.align_items ->
parent_justify_items:Style.justify_items ->
source_order:int ->
tnew_with_placement_style_and_order ~node ~col_span ~row_span ~style ~parent_align_items ~parent_justify_items ~source_order creates a grid item with concrete placement.
Initializes style properties from style and sets align_self/justify_self to parent values if not explicitly specified. All index and crossing fields are set to default values and must be initialized later.
placement t axis returns the item's placement in origin-zero coordinates for axis.
placement_indexes t axis returns the item's placement as GridTrack vector indices for axis.
track_range_excluding_lines t axis returns (start_idx, end_idx) covering all tracks the item spans in axis, excluding bounding lines.
Used to slice GridTrack arrays for iteration over spanned tracks.
span t axis returns the number of tracks the item spans in axis. Returns 0 if placement is invalid.
crosses_flexible_track t axis returns the pre-computed flag indicating whether the item crosses a flexible track in axis.
crosses_intrinsic_track t axis returns the pre-computed flag indicating whether the item crosses an intrinsic track in axis.
val spanned_track_limit :
t ->
Geometry.abstract_axis ->
Compute_grid__.Grid_track.t array ->
float option ->
(int -> float -> float) ->
float optionspanned_track_limit t axis axis_tracks axis_parent_size resolve_calc_value computes the upper limit for the item's min/max-content contribution.
Returns Some limit if the item spans only tracks with definite max track sizing functions, where limit is the sum of those maximums. Otherwise returns None.
This implements the limited min-/max-content contribution per CSS Grid specification.
val known_dimensions :
(module Tree.LAYOUT_PARTIAL_TREE with type t = 'tree) ->
t ->
'tree ->
float option Geometry.size ->
float option Geometry.size ->
float option Geometry.sizeknown_dimensions tree t inner_node_size grid_area_size computes the known_dimensions for child sizing.
Applies stretch alignment to resolve percentage sizes correctly. Algorithm:
justify_self = Stretch and margins are not auto.align_self = Stretch and margins are not auto.Returns the final known_dimensions to pass to child layout functions.
val spanned_fixed_track_limit :
t ->
Geometry.abstract_axis ->
Compute_grid__.Grid_track.t array ->
float option ->
(int -> float -> float) ->
float optionspanned_fixed_track_limit t axis axis_tracks axis_parent_size resolve_calc_value computes the limit for automatic minimum contributions.
Similar to spanned_track_limit but excludes fit-content arguments. Returns Some limit if all spanned tracks have definite max track sizing functions (excluding fit-content).
val min_content_contribution :
(module Tree.LAYOUT_PARTIAL_TREE with type t = 'tree) ->
t ->
Geometry.abstract_axis ->
'tree ->
float option Geometry.size ->
float option Geometry.size ->
floatmin_content_contribution tree t axis available_space inner_node_size computes the item's min-content contribution in axis.
Measures the child with min-content available space in axis.
val min_content_contribution_cached :
t ->
Geometry.abstract_axis ->
(module Tree.LAYOUT_PARTIAL_TREE with type t = 'tree) ->
'tree ->
float option Geometry.size ->
float option Geometry.size ->
floatmin_content_contribution_cached t axis tree available_space inner_node_size retrieves the cached min-content contribution or computes it.
Cache is invalidated when available_space_cache changes.
val max_content_contribution :
(module Tree.LAYOUT_PARTIAL_TREE with type t = 'tree) ->
t ->
Geometry.abstract_axis ->
'tree ->
float option Geometry.size ->
float option Geometry.size ->
floatmax_content_contribution tree t axis available_space inner_node_size computes the item's max-content contribution in axis.
Measures the child with max-content available space in axis.
val max_content_contribution_cached :
t ->
Geometry.abstract_axis ->
(module Tree.LAYOUT_PARTIAL_TREE with type t = 'tree) ->
'tree ->
float option Geometry.size ->
float option Geometry.size ->
floatmax_content_contribution_cached t axis tree available_space inner_node_size retrieves the cached max-content contribution or computes it.
Cache is invalidated when available_space_cache changes.
val available_space :
t ->
Geometry.abstract_axis ->
Compute_grid__.Grid_track.t array ->
float option ->
(Compute_grid__.Grid_track.t -> float option -> float option) ->
float option Geometry.sizeavailable_space t axis other_axis_tracks other_axis_available_space get_track_size_estimate computes the available space for sizing in axis.
Uses track size estimates from the opposite axis to determine cross-axis constraints. The result has the opposite axis dimension set and the sizing axis set to None.