pub struct GridElem {
pub columns: Settable<Self, 0u8>,
pub rows: Settable<Self, 1u8>,
pub column_gutter: Settable<Self, 3u8>,
pub row_gutter: Settable<Self, 4u8>,
pub inset: Settable<Self, 5u8>,
pub align: Settable<Self, 6u8>,
pub fill: Settable<Self, 7u8>,
pub stroke: Settable<Self, 8u8>,
pub children: Vec<GridChild>,
pub grid: Option<Arc<CellGrid>>,
}Expand description
Arranges content in a grid.
The grid element allows you to arrange content in a grid. You can define the number of rows and columns, as well as the size of the gutters between them. There are multiple sizing modes for columns and rows that can be used to create complex layouts.
While the grid and table elements work very similarly, they are intended for
different use cases and carry different semantics. The grid element is
intended for presentational and layout purposes, while the [table] element
is intended for, in broad terms, presenting multiple related data points.
Set and show rules on one of these elements do not affect the other. Refer
to the Accessibility Section to learn how grids and
tables are presented to users of Assistive Technology (AT) like screen
readers.
§Sizing the tracks { #track-size }
A grid’s sizing is determined by the track sizes specified in the arguments.
There are multiple sizing parameters: columns,
rows and gutter.
Because each of the sizing parameters accepts the same values, we will
explain them just once, here. Each sizing argument accepts an array of
individual track sizes. A track size is either:
-
{auto}: The track will be sized to fit its contents. It will be at most as large as the remaining space. If there is more than one{auto}track width, and together they claim more than the available space, the{auto}tracks will fairly distribute the available space among themselves. -
A fixed or relative length (e.g.
{10pt}or{20% - 1cm}): The track will be exactly of this size. -
A fractional length (e.g.
{1fr}): Once all other tracks have been sized, the remaining space will be divided among the fractional tracks according to their fractions. For example, if there are two fractional tracks, each with a fraction of{1fr}, they will each take up half of the remaining space.
To specify a single track, the array can be omitted in favor of a single
value. To specify multiple {auto} tracks, enter the number of tracks
instead of an array. For example, columns: {3} is equivalent to
columns: {(auto, auto, auto)}.
§Examples
The example below demonstrates the different track sizing options. It also
shows how you can use [grid.cell] to make an individual cell span two grid
tracks.
// We use `rect` to emphasize the
// area of cells.
#set rect(
inset: 8pt,
fill: rgb("e4e5ea"),
width: 100%,
)
#grid(
columns: (60pt, 1fr, 2fr),
rows: (auto, 60pt),
gutter: 3pt,
rect[Fixed width, auto height],
rect[1/3 of the remains],
rect[2/3 of the remains],
rect(height: 100%)[Fixed height],
grid.cell(
colspan: 2,
image("tiger.jpg", width: 100%),
),
)You can also spread an array of strings or content into a grid to populate its cells.
#grid(
columns: 5,
gutter: 5pt,
..range(25).map(str)
)§Styling the grid { #styling }
The grid and table elements work similarly. For a hands-on explanation, refer to the Table Guide; for a quick overview, continue reading.
The grid’s appearance can be customized through different parameters. These are the most important ones:
alignto change how cells are alignedinsetto optionally add internal padding to cellsfillto give cells a backgroundstroketo optionally enable grid lines with a certain stroke
To meet different needs, there are various ways to set them.
If you need to override the above options for individual cells, you can use
the [grid.cell] element. Likewise, you can override individual grid lines
with the [grid.hline] and [grid.vline] elements.
To configure an overall style for a grid, you may instead specify the option in any of the following fashions:
- As a single value that applies to all cells.
- As an array of values corresponding to each column. The array will be cycled if there are more columns than the array has items.
- As a function in the form of
(x, y) => value. It receives the cell’s column and row indices (both starting from zero) and should return the value to apply to that cell.
#grid(
columns: 5,
// By a single value
align: center,
// By a single but more complicated value
inset: (x: 2pt, y: 3pt),
// By an array of values (cycling)
fill: (rgb("#239dad50"), none),
// By a function that returns a value
stroke: (x, y) => if calc.rem(x + y, 3) == 0 { 0.5pt },
..range(5 * 3).map(n => numbering("A", n + 1))
)On top of that, you may apply styling rules to [grid] and
[grid.cell]. Especially, the x and y
fields of grid.cell can be used in a where selector,
making it possible to style cells at specific columns or rows, or individual
positions.
§Stroke styling precedence
As explained above, there are three ways to set the stroke of a grid cell:
through {grid.cell}’s stroke field, by using
{grid.hline} and {grid.vline}, or by
setting the {grid}’s stroke field. When multiple of
these settings are present and conflict, the hline and vline settings
take the highest precedence, followed by the cell settings, and finally
the grid settings.
Furthermore, strokes of a repeated grid header or footer will take precedence over regular cell strokes.
§Accessibility
Grids do not carry any special semantics. Assistive Technology (AT) does not
offer the ability to navigate two-dimensionally by cell in grids. If you
want to present tabular data, use the [table] element instead.
AT will read the grid cells in their semantic order. Usually, this is the
order in which you passed them to the grid. However, if you manually
positioned them using grid.cell’s x and y arguments,
cells will be read row by row, from left to right (in left-to-right
documents). A cell will be read when its position is first reached.
Fields§
§columns: Settable<Self, 0u8>§rows: Settable<Self, 1u8>§column_gutter: Settable<Self, 3u8>§row_gutter: Settable<Self, 4u8>§inset: Settable<Self, 5u8>§align: Settable<Self, 6u8>§fill: Settable<Self, 7u8>§stroke: Settable<Self, 8u8>§children: Vec<GridChild>§grid: Option<Arc<CellGrid>>Implementations§
Source§impl GridElem
impl GridElem
Sourcepub fn with_columns(self, columns: TrackSizings) -> Self
pub fn with_columns(self, columns: TrackSizings) -> Self
Builder-style setter for the columns field.
Sourcepub fn with_rows(self, rows: TrackSizings) -> Self
pub fn with_rows(self, rows: TrackSizings) -> Self
Builder-style setter for the rows field.
Sourcepub fn with_column_gutter(self, column_gutter: TrackSizings) -> Self
pub fn with_column_gutter(self, column_gutter: TrackSizings) -> Self
Builder-style setter for the column-gutter field.
Sourcepub fn with_row_gutter(self, row_gutter: TrackSizings) -> Self
pub fn with_row_gutter(self, row_gutter: TrackSizings) -> Self
Builder-style setter for the row-gutter field.
Sourcepub fn with_inset(self, inset: Celled<Sides<Option<Rel<Length>>>>) -> Self
pub fn with_inset(self, inset: Celled<Sides<Option<Rel<Length>>>>) -> Self
Builder-style setter for the inset field.
Sourcepub fn with_align(self, align: Celled<Smart<Alignment>>) -> Self
pub fn with_align(self, align: Celled<Smart<Alignment>>) -> Self
Builder-style setter for the align field.
Sourcepub fn with_fill(self, fill: Celled<Option<Paint>>) -> Self
pub fn with_fill(self, fill: Celled<Option<Paint>>) -> Self
Builder-style setter for the fill field.
Source§impl GridElem
impl GridElem
pub const columns: Field<Self, 0u8>
pub const rows: Field<Self, 1u8>
pub const column_gutter: Field<Self, 3u8>
pub const row_gutter: Field<Self, 4u8>
pub const inset: Field<Self, 5u8>
pub const align: Field<Self, 6u8>
pub const fill: Field<Self, 7u8>
pub const stroke: Field<Self, 8u8>
pub const children: Field<Self, 9u8>
pub const grid: Field<Self, 10u8>
Trait Implementations§
Source§impl ExternalField<2> for GridElem
impl ExternalField<2> for GridElem
const FIELD: ExternalFieldData<Self, 2u8>
type Type = TrackSizings
Source§impl NativeElement for GridElem
impl NativeElement for GridElem
Source§impl NativeScope for GridElem
impl NativeScope for GridElem
Source§fn constructor() -> Option<&'static NativeFuncData>
fn constructor() -> Option<&'static NativeFuncData>
Source§impl RequiredField<9> for GridElem
impl RequiredField<9> for GridElem
Source§impl SettableField<0> for GridElem
impl SettableField<0> for GridElem
const FIELD: SettableFieldData<Self, 0u8>
type Type = TrackSizings
Source§impl SettableField<1> for GridElem
impl SettableField<1> for GridElem
const FIELD: SettableFieldData<Self, 1u8>
type Type = TrackSizings
Source§impl SettableField<3> for GridElem
impl SettableField<3> for GridElem
const FIELD: SettableFieldData<Self, 3u8>
type Type = TrackSizings
Source§impl SettableField<4> for GridElem
impl SettableField<4> for GridElem
const FIELD: SettableFieldData<Self, 4u8>
type Type = TrackSizings
Source§impl SettableField<5> for GridElem
impl SettableField<5> for GridElem
Source§impl SettableField<6> for GridElem
impl SettableField<6> for GridElem
Source§impl SettableField<7> for GridElem
impl SettableField<7> for GridElem
Source§impl SettableField<8> for GridElem
impl SettableField<8> for GridElem
Source§impl SynthesizedField<10> for GridElem
impl SynthesizedField<10> for GridElem
impl RefableProperty<0> for GridElem
impl RefableProperty<1> for GridElem
impl RefableProperty<3> for GridElem
impl RefableProperty<4> for GridElem
impl RefableProperty<6> for GridElem
impl RefableProperty<7> for GridElem
Auto Trait Implementations§
impl Freeze for GridElem
impl !RefUnwindSafe for GridElem
impl Send for GridElem
impl Sync for GridElem
impl Unpin for GridElem
impl !UnwindSafe for GridElem
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoResult for Twhere
T: IntoValue,
impl<T> IntoResult for Twhere
T: IntoValue,
Source§fn into_result(self, _: Span) -> Result<Value, EcoVec<SourceDiagnostic>>
fn into_result(self, _: Span) -> Result<Value, EcoVec<SourceDiagnostic>>
Source§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> IntoValue for Twhere
T: NativeElement,
impl<T> IntoValue for Twhere
T: NativeElement,
Source§fn into_value(self) -> Value
fn into_value(self) -> Value
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<T, const I: u8> SettableProperty<I> for Twhere
T: SettableField<I>,
impl<T, const I: u8> SettableProperty<I> for Twhere
T: SettableField<I>,
const FIELD: SettablePropertyData<T, I> = const FIELD: SettablePropertyData<Self, I> = <Self as SettableField::<I>>::FIELD.property;
type Type = <T as SettableField<I>>::Type
const FOLD: Option<FoldFn<Self::Type>> = _
Source§fn default_ref() -> &'static Self::Type
fn default_ref() -> &'static Self::Type
Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more