|
1 | 1 | //! Style types for CSS Grid layout
|
2 |
| -use super::{AlignContent, LengthPercentage, Style}; |
| 2 | +use super::{AlignContent, AlignItems, AlignSelf, CoreStyle, JustifyContent, LengthPercentage, Style}; |
3 | 3 | use crate::compute::grid::{GridCoordinate, GridLine, OriginZeroLine};
|
4 |
| -use crate::geometry::{AbsoluteAxis, AbstractAxis}; |
5 |
| -use crate::geometry::{Line, MinMax}; |
| 4 | +use crate::geometry::{AbsoluteAxis, AbstractAxis, Line, MinMax, Size}; |
6 | 5 | use crate::style_helpers::*;
|
7 | 6 | use crate::util::sys::GridTrackVec;
|
8 | 7 | use core::cmp::{max, min};
|
9 | 8 | use core::convert::Infallible;
|
10 | 9 |
|
| 10 | +/// The set of styles required for a CSS Grid container |
| 11 | +pub trait GridContainerStyle: CoreStyle { |
| 12 | + /// Defines the track sizing functions (heights) of the grid rows |
| 13 | + #[inline(always)] |
| 14 | + fn grid_template_rows(&self) -> &[TrackSizingFunction] { |
| 15 | + &[] |
| 16 | + } |
| 17 | + /// Defines the track sizing functions (widths) of the grid columns |
| 18 | + #[inline(always)] |
| 19 | + fn grid_template_columns(&self) -> &[TrackSizingFunction] { |
| 20 | + &[] |
| 21 | + } |
| 22 | + /// Defines the size of implicitly created rows |
| 23 | + #[inline(always)] |
| 24 | + fn grid_auto_rows(&self) -> &[NonRepeatedTrackSizingFunction] { |
| 25 | + &[] |
| 26 | + } |
| 27 | + /// Defined the size of implicitly created columns |
| 28 | + #[inline(always)] |
| 29 | + fn grid_auto_columns(&self) -> &[NonRepeatedTrackSizingFunction] { |
| 30 | + &[] |
| 31 | + } |
| 32 | + /// Controls how items get placed into the grid for auto-placed items |
| 33 | + #[inline(always)] |
| 34 | + fn grid_auto_flow(&self) -> GridAutoFlow { |
| 35 | + Style::DEFAULT.grid_auto_flow |
| 36 | + } |
| 37 | + |
| 38 | + /// How large should the gaps between items in a grid or flex container be? |
| 39 | + #[inline(always)] |
| 40 | + fn gap(&self) -> Size<LengthPercentage> { |
| 41 | + Style::DEFAULT.gap |
| 42 | + } |
| 43 | + |
| 44 | + // Alignment properties |
| 45 | + |
| 46 | + /// How should content contained within this item be aligned in the cross/block axis |
| 47 | + #[inline(always)] |
| 48 | + fn align_content(&self) -> Option<AlignContent> { |
| 49 | + Style::DEFAULT.align_content |
| 50 | + } |
| 51 | + /// How should contained within this item be aligned in the main/inline axis |
| 52 | + #[inline(always)] |
| 53 | + fn justify_content(&self) -> Option<JustifyContent> { |
| 54 | + Style::DEFAULT.justify_content |
| 55 | + } |
| 56 | + /// How this node's children aligned in the cross/block axis? |
| 57 | + #[inline(always)] |
| 58 | + fn align_items(&self) -> Option<AlignItems> { |
| 59 | + Style::DEFAULT.align_items |
| 60 | + } |
| 61 | + /// How this node's children should be aligned in the inline axis |
| 62 | + #[inline(always)] |
| 63 | + fn justify_items(&self) -> Option<AlignItems> { |
| 64 | + Style::DEFAULT.justify_items |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +/// The set of styles required for a CSS Grid item (child of a CSS Grid container) |
| 69 | +pub trait GridItemStyle: CoreStyle { |
| 70 | + /// Defines which row in the grid the item should start and end at |
| 71 | + #[inline(always)] |
| 72 | + fn grid_row(&self) -> Line<GridPlacement> { |
| 73 | + Style::DEFAULT.grid_row |
| 74 | + } |
| 75 | + /// Defines which column in the grid the item should start and end at |
| 76 | + #[inline(always)] |
| 77 | + fn grid_column(&self) -> Line<GridPlacement> { |
| 78 | + Style::DEFAULT.grid_column |
| 79 | + } |
| 80 | + |
| 81 | + /// How this node should be aligned in the cross/block axis |
| 82 | + /// Falls back to the parents [`AlignItems`] if not set |
| 83 | + #[inline(always)] |
| 84 | + fn align_self(&self) -> Option<AlignSelf> { |
| 85 | + Style::DEFAULT.align_self |
| 86 | + } |
| 87 | + /// How this node should be aligned in the inline axis |
| 88 | + /// Falls back to the parents [`super::JustifyItems`] if not set |
| 89 | + #[inline(always)] |
| 90 | + fn justify_self(&self) -> Option<AlignSelf> { |
| 91 | + Style::DEFAULT.justify_self |
| 92 | + } |
| 93 | +} |
| 94 | + |
11 | 95 | /// Controls whether grid items are placed row-wise or column-wise. And whether the sparse or dense packing algorithm is used.
|
12 | 96 | ///
|
13 | 97 | /// The "dense" packing algorithm attempts to fill in holes earlier in the grid, if smaller items come up later. This may cause items to appear out-of-order, when doing so would fill in holes left by larger items.
|
|
0 commit comments