Skip to content

Commit 551881c

Browse files
committed
Create style traits
1 parent d4374b9 commit 551881c

File tree

4 files changed

+400
-8
lines changed

4 files changed

+400
-8
lines changed

src/style/flex.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,76 @@
11
//! Style types for Flexbox layout
2+
use super::{AlignContent, AlignItems, AlignSelf, CoreStyle, Dimension, LengthPercentage, Style};
3+
use crate::geometry::Size;
4+
5+
/// The set of styles required for a Flexbox container
6+
pub trait FlexboxContainerStyle: CoreStyle {
7+
/// Which direction does the main axis flow in?
8+
#[inline(always)]
9+
fn flex_direction(&self) -> FlexDirection {
10+
Style::DEFAULT.flex_direction
11+
}
12+
/// Should elements wrap, or stay in a single line?
13+
#[inline(always)]
14+
fn flex_wrap(&self) -> FlexWrap {
15+
Style::DEFAULT.flex_wrap
16+
}
17+
18+
/// How large should the gaps between items in a grid or flex container be?
19+
#[inline(always)]
20+
fn gap(&self) -> Size<LengthPercentage> {
21+
Style::DEFAULT.gap
22+
}
23+
24+
// Alignment properties
25+
26+
/// How should content contained within this item be aligned in the cross/block axis
27+
#[inline(always)]
28+
fn align_content(&self) -> Option<AlignContent> {
29+
Style::DEFAULT.align_content
30+
}
31+
/// How this node's children aligned in the cross/block axis?
32+
#[inline(always)]
33+
fn align_items(&self) -> Option<AlignItems> {
34+
Style::DEFAULT.align_items
35+
}
36+
/// How this node's children should be aligned in the inline axis
37+
#[inline(always)]
38+
fn justify_items(&self) -> Option<AlignItems> {
39+
Style::DEFAULT.justify_items
40+
}
41+
}
42+
43+
/// The set of styles required for a Flexbox item (child of a Flexbox container)
44+
pub trait FlexboxItemStyle: CoreStyle {
45+
/// Sets the initial main axis size of the item
46+
#[inline(always)]
47+
fn flex_basis(&self) -> Dimension {
48+
Style::DEFAULT.flex_basis
49+
}
50+
/// The relative rate at which this item grows when it is expanding to fill space
51+
#[inline(always)]
52+
fn flex_grow(&self) -> f32 {
53+
Style::DEFAULT.flex_grow
54+
}
55+
/// The relative rate at which this item shrinks when it is contracting to fit into space
56+
#[inline(always)]
57+
fn flex_shrink(&self) -> f32 {
58+
Style::DEFAULT.flex_shrink
59+
}
60+
61+
/// How this node should be aligned in the cross/block axis
62+
/// Falls back to the parents [`AlignItems`] if not set
63+
#[inline(always)]
64+
fn align_self(&self) -> Option<AlignSelf> {
65+
Style::DEFAULT.align_self
66+
}
67+
/// How this node should be aligned in the inline axis
68+
/// Falls back to the parents [`super::JustifyItems`] if not set
69+
#[inline(always)]
70+
fn justify_self(&self) -> Option<AlignSelf> {
71+
Style::DEFAULT.justify_self
72+
}
73+
}
274

375
/// Controls whether flex items are forced onto one line or can wrap onto multiple lines.
476
///

src/style/grid.rs

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,97 @@
11
//! Style types for CSS Grid layout
2-
use super::{AlignContent, LengthPercentage, Style};
2+
use super::{AlignContent, AlignItems, AlignSelf, CoreStyle, JustifyContent, LengthPercentage, Style};
33
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};
65
use crate::style_helpers::*;
76
use crate::util::sys::GridTrackVec;
87
use core::cmp::{max, min};
98
use core::convert::Infallible;
109

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+
1195
/// Controls whether grid items are placed row-wise or column-wise. And whether the sparse or dense packing algorithm is used.
1296
///
1397
/// 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

Comments
 (0)