pub(in compute::grid) struct GridItem {Show 33 fields
pub node: NodeId,
pub source_order: u16,
pub row: Line<OriginZeroLine>,
pub column: Line<OriginZeroLine>,
pub is_compressible_replaced: bool,
pub is_replaced: bool,
pub overflow: Point<Overflow>,
pub box_sizing: BoxSizing,
pub size: Size<Dimension>,
pub min_size: Size<LengthPercentageAuto>,
pub max_size: Size<LengthPercentageAuto>,
pub aspect_ratio: Option<f32>,
pub padding: Rect<LengthPercentage>,
pub border: Rect<LengthPercentage>,
pub margin: Rect<LengthPercentageAuto>,
pub align_self: AlignSelf,
pub justify_self: AlignSelf,
pub baseline: Option<f32>,
pub baseline_shim: f32,
pub row_indexes: Line<u16>,
pub column_indexes: Line<u16>,
pub crosses_flexible_row: bool,
pub crosses_flexible_column: bool,
pub crosses_intrinsic_row: bool,
pub crosses_intrinsic_column: bool,
pub grid_area_size_cache: Option<Size<Option<f32>>>,
pub known_dimensions_cache: Option<KnownDimensionsCacheEntry>,
pub min_content_contribution_cache: Size<Option<f32>>,
pub minimum_contribution_cache: Size<Option<f32>>,
pub max_content_contribution_cache: Size<Option<f32>>,
pub y_position: f32,
pub height: f32,
pub oof_candidates: OofCandidates,
}Expand description
Represents a single grid item
Fields§
§node: NodeIdThe id of the node that this item represents
source_order: u16The index of the item in the children array
row: Line<OriginZeroLine>The item’s definite row-start and row-end, as resolved by the placement algorithm (in origin-zero coordinates). Set by the placement algorithm.
column: Line<OriginZeroLine>The items definite column-start and column-end, as resolved by the placement algorithm (in origin-zero coordinates). Set by the placement algorithm.
is_compressible_replaced: boolIs it a compressible replaced element? https://drafts.csswg.org/css-sizing-3/#min-content-zero
is_replaced: boolWhether the item is a replaced element. Such items are not stretched by normal alignment.
overflow: Point<Overflow>The item’s overflow style
box_sizing: BoxSizingThe item’s box_sizing style
size: Size<Dimension>The item’s size style
min_size: Size<LengthPercentageAuto>The item’s min_size style
max_size: Size<LengthPercentageAuto>The item’s max_size style
aspect_ratio: Option<f32>The item’s aspect_ratio style
padding: Rect<LengthPercentage>The item’s padding style
border: Rect<LengthPercentage>The item’s border style
margin: Rect<LengthPercentageAuto>The item’s margin style
align_self: AlignSelfThe item’s align_self property, or the parent’s align_items property if it is None
justify_self: AlignSelfThe item’s justify_self property, or the parent’s justify_items property if it is None
baseline: Option<f32>The item’s first baseline (horizontal), measured from the top of its border box. Set from the item’s intrinsic layout when resolving baseline alignment during track sizing, then from its final layout.
baseline_shim: f32Shim for baseline alignment that acts like an extra top margin TODO: Support last baseline and vertical text baselines
row_indexes: Line<u16>The item’s definite row-start and row-end (same as row field, except in a different coordinate system)
(as indexes into the Vec
column_indexes: Line<u16>The items definite column-start and column-end (same as column field, except in a different coordinate system)
(as indexes into the Vec
crosses_flexible_row: boolWhether the item crosses a flexible row
crosses_flexible_column: boolWhether the item crosses a flexible column
crosses_intrinsic_row: boolWhether the item crosses a intrinsic row
crosses_intrinsic_column: boolWhether the item crosses a intrinsic column
grid_area_size_cache: Option<Size<Option<f32>>>Cache for the known_dimensions input to intrinsic sizing computation
known_dimensions_cache: Option<KnownDimensionsCacheEntry>Cache for the known_dimensions passed to the child when computing its intrinsic contributions, stored along with
the grid area size it was computed for. Must be cleared whenever baseline_shim changes.
min_content_contribution_cache: Size<Option<f32>>Cache for the min-content size
minimum_contribution_cache: Size<Option<f32>>Cache for the minimum contribution
max_content_contribution_cache: Size<Option<f32>>Cache for the max-content size
y_position: f32Final y position, excluding any relative offset (which does not affect the container’s baseline). Used to compute baseline alignment for the container.
height: f32Final height. Used to compute baseline alignment for the container.
oof_candidates: OofCandidatesOut-of-flow candidates bubbled out of this item’s subtree (anchors relative to the container’s border box)
Implementations§
Source§impl GridItem
impl GridItem
Sourcepub fn new_with_style_and_order<S: GridItemStyle>(
node: NodeId,
style: S,
parent_align_items: AlignItems,
parent_justify_items: AlignItems,
source_order: u16,
) -> Self
pub fn new_with_style_and_order<S: GridItemStyle>( node: NodeId, style: S, parent_align_items: AlignItems, parent_justify_items: AlignItems, source_order: u16, ) -> Self
Create a new item from its style. Its placement (row/column) is filled in by the placement algorithm.
Sourcepub fn has_auto_block_margin(&self) -> bool
pub fn has_auto_block_margin(&self) -> bool
Whether the item has an auto margin in the block axis
Sourcepub fn has_cyclic_block_size_dependency(&self) -> bool
pub fn has_cyclic_block_size_dependency(&self) -> bool
Whether the item’s block size depends on the size of its row(s), creating a cyclic dependency with baseline alignment (which affects row sizing). Per https://www.w3.org/TR/css-grid-1/#row-align such items do not participate in baseline alignment and are aligned using their fallback alignment instead.
Sourcepub fn participates_in_baseline_alignment(&self) -> bool
pub fn participates_in_baseline_alignment(&self) -> bool
Returns true if the item participates in baseline alignment: it has align-self: baseline
and neither of its block-axis margins are auto.
See https://www.w3.org/TR/css-align-3/#baseline-align-self
Sourcepub fn placement(&self, axis: AbstractAxis) -> Line<OriginZeroLine>
pub fn placement(&self, axis: AbstractAxis) -> Line<OriginZeroLine>
This item’s placement in the specified axis in OriginZero coordinates
Sourcepub fn placement_indexes(&self, axis: AbstractAxis) -> Line<u16>
pub fn placement_indexes(&self, axis: AbstractAxis) -> Line<u16>
This item’s placement in the specified axis as GridTrackVec indices
Sourcepub fn track_range_excluding_lines(&self, axis: AbstractAxis) -> Range<usize> ⓘ
pub fn track_range_excluding_lines(&self, axis: AbstractAxis) -> Range<usize> ⓘ
Returns a range which can be used as an index into the GridTrackVec in the specified axis which will produce a sub-slice of covering all the tracks and lines that this item spans excluding the lines that bound it.
Sourcepub fn spans_track_matching(
&self,
axis: AbstractAxis,
axis_tracks: &[GridTrack],
predicate: impl Fn(&GridTrack) -> bool,
) -> bool
pub fn spans_track_matching( &self, axis: AbstractAxis, axis_tracks: &[GridTrack], predicate: impl Fn(&GridTrack) -> bool, ) -> bool
Whether any track spanned by this item in the specified axis satisfies predicate
Sourcepub fn span(&self, axis: AbstractAxis) -> u16
pub fn span(&self, axis: AbstractAxis) -> u16
Returns the number of tracks that this item spans in the specified axis
Sourcepub fn crosses_flexible_track(&self, axis: AbstractAxis) -> bool
pub fn crosses_flexible_track(&self, axis: AbstractAxis) -> bool
Returns the pre-computed value indicating whether the grid item crosses a flexible track in the specified axis
Sourcepub fn crosses_intrinsic_track(&self, axis: AbstractAxis) -> bool
pub fn crosses_intrinsic_track(&self, axis: AbstractAxis) -> bool
Returns the pre-computed value indicating whether the grid item crosses an intrinsic track in the specified axis
Sourcepub fn spanned_track_limit(
&mut self,
axis: AbstractAxis,
axis_tracks: &[GridTrack],
axis_parent_size: Option<f32>,
resolve_calc_value: &dyn Fn(*const (), f32) -> f32,
) -> Option<f32>
pub fn spanned_track_limit( &mut self, axis: AbstractAxis, axis_tracks: &[GridTrack], axis_parent_size: Option<f32>, resolve_calc_value: &dyn Fn(*const (), f32) -> f32, ) -> Option<f32>
For an item spanning multiple tracks, the upper limit used to calculate its limited min-/max-content contribution is the sum of the fixed max track sizing functions of any tracks it spans, and is applied if it only spans such tracks.
Sourcepub fn spanned_fixed_track_limit(
&mut self,
axis: AbstractAxis,
axis_tracks: &[GridTrack],
axis_parent_size: Option<f32>,
resolve_calc_value: &dyn Fn(*const (), f32) -> f32,
) -> Option<f32>
pub fn spanned_fixed_track_limit( &mut self, axis: AbstractAxis, axis_tracks: &[GridTrack], axis_parent_size: Option<f32>, resolve_calc_value: &dyn Fn(*const (), f32) -> f32, ) -> Option<f32>
Similar to the spanned_track_limit, but excludes FitContent arguments from the limit. Used to clamp the automatic minimum contributions of an item
Sourcefn known_dimensions_cached(
&mut self,
tree: &mut impl LayoutPartialTree,
grid_area_size: Size<Option<f32>>,
) -> Size<Option<f32>>
fn known_dimensions_cached( &mut self, tree: &mut impl LayoutPartialTree, grid_area_size: Size<Option<f32>>, ) -> Size<Option<f32>>
Retrieve the known_dimensions for the given grid area size from the cache or compute them. The min-content and max-content contributions of an item are both computed from the same known_dimensions.
Sourcefn is_stretch_aligned(&self, alignment: AlignSelf) -> bool
fn is_stretch_aligned(&self, alignment: AlignSelf) -> bool
Whether the given self-alignment stretches the item: stretch, or normal unless the item is replaced
Sourcefn known_dimensions(
&self,
tree: &mut impl LayoutPartialTree,
grid_area_size: Size<Option<f32>>,
) -> Size<Option<f32>>
fn known_dimensions( &self, tree: &mut impl LayoutPartialTree, grid_area_size: Size<Option<f32>>, ) -> Size<Option<f32>>
Compute the known_dimensions to be passed to the child sizing functions The key thing that is being done here is applying stretch alignment, which is necessary to allow percentage sizes further down the tree to resolve properly in some cases
Sourcepub fn grid_area_size(
&self,
axis: AbstractAxis,
axis_tracks: &[GridTrack],
other_axis_tracks: &[GridTrack],
available_space: Size<Option<f32>>,
get_track_size_estimate: impl Fn(&GridTrack, Option<f32>) -> Option<f32>,
resolve_calc_value: &impl Fn(*const (), f32) -> f32,
) -> Size<Option<f32>>
pub fn grid_area_size( &self, axis: AbstractAxis, axis_tracks: &[GridTrack], other_axis_tracks: &[GridTrack], available_space: Size<Option<f32>>, get_track_size_estimate: impl Fn(&GridTrack, Option<f32>) -> Option<f32>, resolve_calc_value: &impl Fn(*const (), f32) -> f32, ) -> Size<Option<f32>>
Returns the grid area’s size in the specified axis when every spanned track has a definite fixed size.
During intrinsic sizing, percentages on grid items resolve against the size of the grid area, not the grid container. If the spanned tracks in an axis are not all definite yet, the grid area is still indefinite in that axis and percentage-dependent values must stay unresolved here.
Spec: https://www.w3.org/TR/css-grid-1/#grid-item-sizing https://www.w3.org/TR/css-grid-1/#algo-overview
Compute the available_space to be passed to the child sizing functions These are estimates based on either the max track sizing function or the provisional base size in the opposite axis to the one currently being sized. https://www.w3.org/TR/css-grid-1/#algo-overview
Sourcepub fn grid_area_size_cached(
&mut self,
axis: AbstractAxis,
axis_tracks: &[GridTrack],
other_axis_tracks: &[GridTrack],
available_space: Size<Option<f32>>,
get_track_size_estimate: impl Fn(&GridTrack, Option<f32>) -> Option<f32>,
resolve_calc_value: &impl Fn(*const (), f32) -> f32,
) -> Size<Option<f32>>
pub fn grid_area_size_cached( &mut self, axis: AbstractAxis, axis_tracks: &[GridTrack], other_axis_tracks: &[GridTrack], available_space: Size<Option<f32>>, get_track_size_estimate: impl Fn(&GridTrack, Option<f32>) -> Option<f32>, resolve_calc_value: &impl Fn(*const (), f32) -> f32, ) -> Size<Option<f32>>
Retrieve the available_space from the cache or compute them using the passed parameters
Sourcepub fn margins_axis_sums_with_baseline_shims(
&self,
inner_node_width: Option<f32>,
tree: &impl LayoutPartialTree,
) -> Size<f32>
pub fn margins_axis_sums_with_baseline_shims( &self, inner_node_width: Option<f32>, tree: &impl LayoutPartialTree, ) -> Size<f32>
Compute the item’s resolved margins for size contributions. Horizontal percentage margins always resolve to zero if the container size is indefinite as otherwise this would introduce a cyclic dependency.
Sourcepub fn min_content_contribution(
&mut self,
axis: AbstractAxis,
tree: &mut impl LayoutPartialTree,
grid_area_size: Size<Option<f32>>,
available_space: Size<Option<f32>>,
) -> f32
pub fn min_content_contribution( &mut self, axis: AbstractAxis, tree: &mut impl LayoutPartialTree, grid_area_size: Size<Option<f32>>, available_space: Size<Option<f32>>, ) -> f32
Compute the item’s min content contribution from the provided parameters
Sourcepub fn min_content_contribution_cached(
&mut self,
axis: AbstractAxis,
tree: &mut impl LayoutPartialTree,
grid_area_size: Size<Option<f32>>,
available_space: Size<Option<f32>>,
) -> f32
pub fn min_content_contribution_cached( &mut self, axis: AbstractAxis, tree: &mut impl LayoutPartialTree, grid_area_size: Size<Option<f32>>, available_space: Size<Option<f32>>, ) -> f32
Retrieve the item’s min content contribution from the cache or compute it using the provided parameters
Sourcepub fn max_content_contribution(
&mut self,
axis: AbstractAxis,
tree: &mut impl LayoutPartialTree,
grid_area_size: Size<Option<f32>>,
available_space: Size<Option<f32>>,
) -> f32
pub fn max_content_contribution( &mut self, axis: AbstractAxis, tree: &mut impl LayoutPartialTree, grid_area_size: Size<Option<f32>>, available_space: Size<Option<f32>>, ) -> f32
Compute the item’s max content contribution from the provided parameters
Sourcefn available_space_minus_margins(
&self,
grid_area_size: Size<Option<f32>>,
available_space: Size<Option<f32>>,
tree: &impl LayoutPartialTree,
) -> Size<Option<f32>>
fn available_space_minus_margins( &self, grid_area_size: Size<Option<f32>>, available_space: Size<Option<f32>>, tree: &impl LayoutPartialTree, ) -> Size<Option<f32>>
Subtract the item’s margins (and baseline shim) from the definite axes of the space available
to the item’s margin box, giving the available space that is passed to the item.
As when the item is laid out into its final position, margins resolve against the width
of the grid area and auto margins are treated as zero.
Sourcefn keyword_adjusted_available_space(
&self,
grid_area_size: Size<Option<f32>>,
available_space: Size<AvailableSpace>,
tree: &impl LayoutPartialTree,
) -> Size<AvailableSpace>
fn keyword_adjusted_available_space( &self, grid_area_size: Size<Option<f32>>, available_space: Size<AvailableSpace>, tree: &impl LayoutPartialTree, ) -> Size<AvailableSpace>
Override the available space in each axis whose size style is a sizing keyword that measures the item under a specific available space constraint (min-content, max-content, fit-content, fit-content(…))
Sourcepub fn max_content_contribution_cached(
&mut self,
axis: AbstractAxis,
tree: &mut impl LayoutPartialTree,
grid_area_size: Size<Option<f32>>,
available_space: Size<Option<f32>>,
) -> f32
pub fn max_content_contribution_cached( &mut self, axis: AbstractAxis, tree: &mut impl LayoutPartialTree, grid_area_size: Size<Option<f32>>, available_space: Size<Option<f32>>, ) -> f32
Retrieve the item’s max content contribution from the cache or compute it using the provided parameters
Sourcepub fn minimum_contribution(
&mut self,
tree: &mut impl LayoutPartialTree,
axis: AbstractAxis,
axis_tracks: &[GridTrack],
grid_area_size: Size<Option<f32>>,
inner_node_size: Size<Option<f32>>,
) -> f32
pub fn minimum_contribution( &mut self, tree: &mut impl LayoutPartialTree, axis: AbstractAxis, axis_tracks: &[GridTrack], grid_area_size: Size<Option<f32>>, inner_node_size: Size<Option<f32>>, ) -> f32
The minimum contribution of an item is the smallest outer size it can have. Specifically:
- If the item’s computed preferred size behaves as auto or depends on the size of its containing block in the relevant axis: Its minimum contribution is the outer size that would result from assuming the item’s used minimum size as its preferred size;
- Else the item’s minimum contribution is its min-content contribution.
Because the minimum contribution often depends on the size of the item’s content, it is considered a type of intrinsic size contribution. See: https://www.w3.org/TR/css-grid-1/#min-size-auto
Sourcepub fn minimum_contribution_cached(
&mut self,
tree: &mut impl LayoutPartialTree,
axis: AbstractAxis,
axis_tracks: &[GridTrack],
grid_area_size: Size<Option<f32>>,
inner_node_size: Size<Option<f32>>,
) -> f32
pub fn minimum_contribution_cached( &mut self, tree: &mut impl LayoutPartialTree, axis: AbstractAxis, axis_tracks: &[GridTrack], grid_area_size: Size<Option<f32>>, inner_node_size: Size<Option<f32>>, ) -> f32
Retrieve the item’s minimum contribution from the cache or compute it using the provided parameters