Skip to content

Commit 0bccf6c

Browse files
Weibyenicoburns
andauthored
Moving flexbox behind a feature flag (#414)
* Moving flexbox behind a feature flag * More stuff behind feature flag * Enabling flexbox by default * Fixing double definition of default * Update workflow * Adding default const to Display when no features are enabled * Comment out more stuff from the prelude * Ensure only one default * Putting stuff behind feature flags * formatting * adding std to feature testing * Uncomment temp commented code * Fix missing comma * Update Ci job keys * Cleanup and documentatnion * Gating alignement properties behind flexbox or grid * Rename job key back to original value * Gate justify_items and justify_self behind the grid feature * Reinstate alloc job name * Fix github actions job name --------- Co-authored-by: Nico Burns <[email protected]>
1 parent 83b9ac1 commit 0bccf6c

File tree

8 files changed

+147
-25
lines changed

8 files changed

+147
-25
lines changed

.github/workflows/ci.yml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
name: Continuous integration
1010

1111
jobs:
12+
# None
1213
test-features-none:
1314
name: "Test Suite [Features: None]"
1415
runs-on: ubuntu-latest
@@ -19,6 +20,7 @@ jobs:
1920
- run: cargo build --no-default-features
2021
- run: cargo test --no-default-features
2122

23+
# Default
2224
test-features-default:
2325
name: "Test Suite [Features: Default]"
2426
runs-on: ubuntu-latest
@@ -37,17 +39,46 @@ jobs:
3739
- run: cargo build --features serde
3840
- run: cargo test --features serde
3941

40-
test-features-alloc:
41-
name: "Test Suite [Features: alloc]"
42+
test-features-no-grid-nor-flexbox:
43+
name: "Test Suite [Features: std (no grid or flexbox)]"
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v3
47+
- uses: dtolnay/rust-toolchain@stable
48+
- run: cargo build --no-default-features --features std
49+
- run: cargo test --no-default-features --features std
50+
51+
# Flexbox
52+
test-features-flexbox:
53+
name: "Test Suite [Features: flexbox + std]"
54+
runs-on: ubuntu-latest
55+
steps:
56+
- uses: actions/checkout@v3
57+
- uses: dtolnay/rust-toolchain@stable
58+
- run: cargo build --no-default-features --features flexbox,std
59+
- run: cargo test --no-default-features --features flexbox,std
60+
61+
# Grid
62+
test-features-grid:
63+
name: "Test Suite [Features: grid + std]"
64+
runs-on: ubuntu-latest
65+
steps:
66+
- uses: actions/checkout@v3
67+
- uses: dtolnay/rust-toolchain@stable
68+
- run: cargo build --no-default-features --features grid,std
69+
- run: cargo test --no-default-features --features grid,std
70+
71+
test-features-grid-with-alloc:
72+
name: "Test Suite [Features: grid + alloc]"
4273
runs-on: ubuntu-latest
4374
steps:
4475
- uses: actions/checkout@v3
4576
- uses: dtolnay/rust-toolchain@stable
4677
- run: cargo build --no-default-features --features alloc,grid
4778
- run: cargo test --no-default-features --features alloc,grid
4879

49-
test-features-alloc-no-grid:
50-
name: "Test Suite [Features: alloc (no grid)]"
80+
test-features-alloc:
81+
name: "Test Suite [Features: alloc]"
5182
runs-on: ubuntu-latest
5283
steps:
5384
- uses: actions/checkout@v3

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ slotmap = "1.0.6"
2222
grid = { version = "0.9.0", optional = true }
2323

2424
[features]
25-
default = ["std", "grid"]
25+
default = ["std", "flexbox", "grid" ]
26+
flexbox = []
2627
grid = ["alloc", "dep:grid"]
2728
alloc = []
2829
std = ["num-traits/std"]

RELEASES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Release Notes
22

3+
## Unreleased
4+
5+
### Changes
6+
7+
- The Flexbox algorithm has now been moved behind the `flexbox` feature. The `flexbox` feature is enabled by default.
8+
- The `justify_self` property has been moved behind the `grid` feature.
9+
310
## 0.3.11
411

512
### Fixes

src/compute/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
//! The layout algorithms themselves
22
33
pub(crate) mod common;
4-
pub(crate) mod flexbox;
54
pub(crate) mod leaf;
65

6+
#[cfg(feature = "flexbox")]
7+
pub(crate) mod flexbox;
8+
79
#[cfg(feature = "grid")]
810
pub(crate) mod grid;
911

@@ -16,7 +18,9 @@ use crate::style::{AvailableSpace, Display};
1618
use crate::sys::round;
1719
use crate::tree::LayoutTree;
1820

21+
#[cfg(feature = "flexbox")]
1922
use self::flexbox::FlexboxAlgorithm;
23+
2024
#[cfg(feature = "grid")]
2125
use self::grid::CssGridAlgorithm;
2226
use self::leaf::LeafAlgorithm;
@@ -189,6 +193,7 @@ fn compute_node_layout(
189193
run_mode,
190194
sizing_mode,
191195
),
196+
#[cfg(feature = "flexbox")]
192197
(Display::Flex, true) => perform_computations::<FlexboxAlgorithm>(
193198
tree,
194199
node,

src/debug.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ fn print_node(tree: &impl LayoutTree, node: Node, has_sibling: bool, lines_strin
2121
let display = match (num_children, style.display) {
2222
(_, style::Display::None) => "NONE",
2323
(0, _) => "LEAF",
24+
#[cfg(feature = "flexbox")]
2425
(_, style::Display::Flex) => "FLEX",
2526
#[cfg(feature = "grid")]
2627
(_, style::Display::Grid) => "GRID",

src/geometry.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
//! Geometric primitives useful for layout
22
3-
use crate::style::{Dimension, FlexDirection};
3+
use crate::style::Dimension;
44
use crate::sys::f32_max;
55
use core::ops::Add;
66

7+
#[cfg(feature = "flexbox")]
8+
use crate::style::FlexDirection;
9+
710
#[cfg(feature = "grid")]
811
use crate::axis::AbstractAxis;
912

@@ -61,6 +64,7 @@ impl<T> Rect<T> {
6164
/// When applied to the left and right sides, the width is used
6265
/// as the second parameter of `f`.
6366
/// When applied to the top or bottom sides, the height is used instead.
67+
#[cfg(feature = "flexbox")]
6468
pub(crate) fn zip_size<R, F, U>(self, size: Size<U>, f: F) -> Rect<R>
6569
where
6670
F: Fn(T, U) -> R,
@@ -134,6 +138,7 @@ where
134138
///
135139
/// If the [`FlexDirection`] is [`FlexDirection::Row`] or [`FlexDirection::RowReverse`], this is [`Rect::horizontal`].
136140
/// Otherwise, this is [`Rect::vertical`].
141+
#[cfg(feature = "flexbox")]
137142
pub(crate) fn main_axis_sum(&self, direction: FlexDirection) -> U {
138143
if direction.is_row() {
139144
self.horizontal_axis_sum()
@@ -146,6 +151,7 @@ where
146151
///
147152
/// If the [`FlexDirection`] is [`FlexDirection::Row`] or [`FlexDirection::RowReverse`], this is [`Rect::vertical`].
148153
/// Otherwise, this is [`Rect::horizontal`].
154+
#[cfg(feature = "flexbox")]
149155
pub(crate) fn cross_axis_sum(&self, direction: FlexDirection) -> U {
150156
if direction.is_row() {
151157
self.vertical_axis_sum()
@@ -160,6 +166,7 @@ where
160166
T: Copy + Clone,
161167
{
162168
/// The `start` or `top` value of the [`Rect`], from the perspective of the main layout axis
169+
#[cfg(feature = "flexbox")]
163170
pub(crate) fn main_start(&self, direction: FlexDirection) -> T {
164171
if direction.is_row() {
165172
self.left
@@ -169,6 +176,7 @@ where
169176
}
170177

171178
/// The `end` or `bottom` value of the [`Rect`], from the perspective of the main layout axis
179+
#[cfg(feature = "flexbox")]
172180
pub(crate) fn main_end(&self, direction: FlexDirection) -> T {
173181
if direction.is_row() {
174182
self.right
@@ -178,6 +186,7 @@ where
178186
}
179187

180188
/// The `start` or `top` value of the [`Rect`], from the perspective of the cross layout axis
189+
#[cfg(feature = "flexbox")]
181190
pub(crate) fn cross_start(&self, direction: FlexDirection) -> T {
182191
if direction.is_row() {
183192
self.top
@@ -187,6 +196,7 @@ where
187196
}
188197

189198
/// The `end` or `bottom` value of the [`Rect`], from the perspective of the main layout axis
199+
#[cfg(feature = "flexbox")]
190200
pub(crate) fn cross_end(&self, direction: FlexDirection) -> T {
191201
if direction.is_row() {
192202
self.bottom
@@ -301,6 +311,7 @@ impl<T> Size<T> {
301311
/// Sets the extent of the main layout axis
302312
///
303313
/// Whether this is the width or height depends on the `direction` provided
314+
#[cfg(feature = "flexbox")]
304315
pub(crate) fn set_main(&mut self, direction: FlexDirection, value: T) {
305316
if direction.is_row() {
306317
self.width = value
@@ -312,6 +323,7 @@ impl<T> Size<T> {
312323
/// Sets the extent of the cross layout axis
313324
///
314325
/// Whether this is the width or height depends on the `direction` provided
326+
#[cfg(feature = "flexbox")]
315327
pub(crate) fn set_cross(&mut self, direction: FlexDirection, value: T) {
316328
if direction.is_row() {
317329
self.height = value
@@ -324,6 +336,7 @@ impl<T> Size<T> {
324336
///
325337
/// Whether this is the width or height depends on the `direction` provided
326338
#[allow(dead_code)]
339+
#[cfg(feature = "flexbox")]
327340
pub(crate) fn with_main(self, direction: FlexDirection, value: T) -> Self {
328341
let mut new = self;
329342
if direction.is_row() {
@@ -337,6 +350,7 @@ impl<T> Size<T> {
337350
/// Creates a new value of type Self with the cross axis set to value provided
338351
///
339352
/// Whether this is the width or height depends on the `direction` provided
353+
#[cfg(feature = "flexbox")]
340354
pub(crate) fn with_cross(self, direction: FlexDirection, value: T) -> Self {
341355
let mut new = self;
342356
if direction.is_row() {
@@ -350,6 +364,7 @@ impl<T> Size<T> {
350364
/// Gets the extent of the main layout axis
351365
///
352366
/// Whether this is the width or height depends on the `direction` provided
367+
#[cfg(feature = "flexbox")]
353368
pub(crate) fn main(self, direction: FlexDirection) -> T {
354369
if direction.is_row() {
355370
self.width
@@ -361,6 +376,7 @@ impl<T> Size<T> {
361376
/// Gets the extent of the cross layout axis
362377
///
363378
/// Whether this is the width or height depends on the `direction` provided
379+
#[cfg(feature = "flexbox")]
364380
pub(crate) fn cross(self, direction: FlexDirection) -> T {
365381
if direction.is_row() {
366382
self.height

src/prelude.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
//! Commonly used types
22
3-
use crate::compute::LayoutAlgorithm;
4-
use crate::layout::{SizeAndBaselines, SizingMode};
3+
#[cfg(feature = "flexbox")]
4+
use crate::{
5+
compute::LayoutAlgorithm,
6+
layout::{SizeAndBaselines, SizingMode},
7+
};
58

69
/// Apply the flexbox algorithm and recursively layout the specified node
10+
#[cfg(feature = "flexbox")]
711
#[inline(always)]
812
pub fn layout_flexbox(
913
tree: &mut impl LayoutTree,
@@ -28,8 +32,8 @@ pub use crate::{
2832
layout::Layout,
2933
node::{Node, Taffy},
3034
style::{
31-
AlignContent, AlignItems, AlignSelf, AvailableSpace, Dimension, Display, FlexDirection, FlexWrap,
32-
JustifyContent, JustifyItems, JustifySelf, LengthPercentage, LengthPercentageAuto, Position, Style,
35+
AlignContent, AlignItems, AlignSelf, AvailableSpace, Dimension, Display, JustifyContent, JustifyItems,
36+
JustifySelf, LengthPercentage, LengthPercentageAuto, Position, Style,
3337
},
3438
style_helpers::{
3539
auto, fit_content, max_content, min_content, percent, points, zero, FromFlex, FromPercent, FromPoints,
@@ -38,6 +42,9 @@ pub use crate::{
3842
tree::LayoutTree,
3943
};
4044

45+
#[cfg(feature = "flexbox")]
46+
pub use crate::style::{FlexDirection, FlexWrap};
47+
4148
#[cfg(feature = "grid")]
4249
pub use crate::style::{
4350
GridAutoFlow, GridPlacement, GridTrackRepetition, MaxTrackSizingFunction, MinTrackSizingFunction,

0 commit comments

Comments
 (0)