Skip to main content

GridItem

Struct GridItem 

Source
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: NodeId

The id of the node that this item represents

§source_order: u16

The 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: bool

Is it a compressible replaced element? https://drafts.csswg.org/css-sizing-3/#min-content-zero

§is_replaced: bool

Whether the item is a replaced element. Such items are not stretched by normal alignment.

§overflow: Point<Overflow>

The item’s overflow style

§box_sizing: BoxSizing

The 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: AlignSelf

The item’s align_self property, or the parent’s align_items property if it is None

§justify_self: AlignSelf

The 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: f32

Shim 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 stored in a grid’s AbstractAxisTracks)

§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 stored in a grid’s AbstractAxisTracks)

§crosses_flexible_row: bool

Whether the item crosses a flexible row

§crosses_flexible_column: bool

Whether the item crosses a flexible column

§crosses_intrinsic_row: bool

Whether the item crosses a intrinsic row

§crosses_intrinsic_column: bool

Whether 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: f32

Final y position, excluding any relative offset (which does not affect the container’s baseline). Used to compute baseline alignment for the container.

§height: f32

Final height. Used to compute baseline alignment for the container.

§oof_candidates: OofCandidates

Out-of-flow candidates bubbled out of this item’s subtree (anchors relative to the container’s border box)

Implementations§

Source§

impl GridItem

Source

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.

Source

pub fn has_auto_block_margin(&self) -> bool

Whether the item has an auto margin in the block axis

Source

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.

Source

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

Source

pub fn placement(&self, axis: AbstractAxis) -> Line<OriginZeroLine>

This item’s placement in the specified axis in OriginZero coordinates

Source

pub fn placement_indexes(&self, axis: AbstractAxis) -> Line<u16>

This item’s placement in the specified axis as GridTrackVec indices

Source

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.

Source

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

Source

pub fn span(&self, axis: AbstractAxis) -> u16

Returns the number of tracks that this item spans in the specified axis

Source

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

Source

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

Source

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.

Source

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

Source

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.

Source

fn is_stretch_aligned(&self, alignment: AlignSelf) -> bool

Whether the given self-alignment stretches the item: stretch, or normal unless the item is replaced

Source

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

Source

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

Source

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

Source

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.

Source

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

Source

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

Source

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

Source

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.

Source

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(…))

Source

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

Source

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

Source

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

Trait Implementations§

Source§

impl Debug for GridItem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.