Skip to content

Commit 6cefb6e

Browse files
committed
Rename Points/points to Length/length in many APIs
⚠️ This is a fairly disruptive breaking changes, although the fix for users is mostly search-and-replace. The old name for this one-dimensional length: * Suggests PostScript points, but is documented as an abstract unit: “Users of Taffy may define what they correspond to in their application (pixels, logical pixels, mm, etc) as they see fit.” * Is spelled similar to the two-dimensional `Point` though its meaning is unrelated. * In CSS syntax, `1px = 0.75pt` but the former is much more commonly used. When [parsing CSS into a `Style`](#440) we’ll probably want the default mapping to be `1px` => 1f32 abstract unit, so naming the abstract unit "points" would be confusing.
1 parent fda1f88 commit 6cefb6e

File tree

693 files changed

+4272
-4249
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

693 files changed

+4272
-4249
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ let mut taffy = Taffy::new();
2828
let header_node = taffy
2929
.new_leaf(
3030
Style {
31-
size: Size { width: points(800.0), height: points(100.0) },
31+
size: Size { width: length(800.0), height: length(100.0) },
3232
..Default::default()
3333
},
3434
).unwrap();
3535

3636
let body_node = taffy
3737
.new_leaf(
3838
Style {
39-
size: Size { width: points(800.0), height: auto() },
39+
size: Size { width: length(800.0), height: auto() },
4040
flex_grow: 1.0,
4141
..Default::default()
4242
},
@@ -46,7 +46,7 @@ let root_node = taffy
4646
.new_with_children(
4747
Style {
4848
flex_direction: FlexDirection::Column,
49-
size: Size { width: points(800.0), height: points(600.0) },
49+
size: Size { width: length(800.0), height: length(600.0) },
5050
..Default::default()
5151
},
5252
&[header_node, body_node],

RELEASES.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,32 @@
22

33
## Unreleased
44

5+
### Breaking
6+
7+
Many APIs have been renamed to replace `points` or `Points` with `length` or `Length`.
8+
This new name better describes one-dimentional measure of space in some unspecified unit
9+
which is often unrelated to the PostScript point or the CSS `pt` unit.
10+
11+
This also removes a misleading similarity with the 2D `Point`,
12+
whose components can have any unit and are not even necessarily absolute lengths.
13+
14+
Example usage change:
15+
16+
```diff
17+
use taffy::prelude::*;
18+
19+
// …
20+
21+
let header_node = taffy
22+
.new_leaf(
23+
Style {
24+
- size: Size { width: points(800.0), height: points(100.0) },
25+
+ size: Size { width: length(800.0), height: length(100.0) },
26+
..Default::default()
27+
},
28+
).unwrap();
29+
```
30+
531
### Removed
632

733
- `layout_flexbox()` has been removed from the prelude. Use `FlexboxAlgorithm::perform_layout()` instead.

benches/flexbox.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn build_yoga_deep_hierarchy(node_count: u32, branching_factor: u32) -> (yg::Yog
100100
/// A deep tree that matches the shape and styling that yoga use on their benchmarks
101101
fn build_taffy_huge_nested_hierarchy(node_count: u32, branching_factor: u32) -> (Taffy, NodeId) {
102102
let style = Style {
103-
size: Size { width: Dimension::Points(10.0), height: Dimension::Points(10.0) },
103+
size: Size { width: Dimension::Length(10.0), height: Dimension::Length(10.0) },
104104
flex_grow: 1.0,
105105
..Default::default()
106106
};
@@ -118,7 +118,7 @@ fn build_taffy_huge_nested_hierarchy(node_count: u32, branching_factor: u32) ->
118118
/// A deep tree that matches the shape and styling that yoga use on their benchmarks
119119
fn build_yoga_huge_nested_hierarchy(node_count: u32, branching_factor: u32) -> (yg::YogaTree, yg::NodeId) {
120120
let style = Style {
121-
size: Size { width: Dimension::Points(10.0), height: Dimension::Points(10.0) },
121+
size: Size { width: Dimension::Length(10.0), height: Dimension::Length(10.0) },
122122
flex_grow: 1.0,
123123
..Default::default()
124124
};

benches/grid.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use taffy::style::Style;
88

99
/// Build a random leaf node
1010
fn build_random_leaf(taffy: &mut Taffy, _rng: &mut ChaCha8Rng) -> NodeId {
11-
taffy.new_with_children(Style { size: points(20.0), ..Default::default() }, &[]).unwrap()
11+
taffy.new_with_children(Style { size: length(20.0), ..Default::default() }, &[]).unwrap()
1212
}
1313

1414
fn random_grid_track<R: Rng>(rng: &mut R) -> TrackSizingFunction {
@@ -22,9 +22,9 @@ fn random_grid_track<R: Rng>(rng: &mut R) -> TrackSizingFunction {
2222
} else if switch < 0.5 {
2323
fr(1.0)
2424
} else if switch < 0.6 {
25-
minmax(points(0.0), fr(1.0))
25+
minmax(length(0.0), fr(1.0))
2626
} else if switch < 0.8 {
27-
points(40.0)
27+
length(40.0)
2828
} else {
2929
percent(0.3)
3030
}
@@ -110,7 +110,7 @@ fn taffy_benchmarks(c: &mut Criterion) {
110110
|b, &track_count| {
111111
b.iter_batched(
112112
|| build_grid_flat_hierarchy(track_count, track_count),
113-
|(mut taffy, root)| taffy.compute_layout(root, points(12000.0)).unwrap(),
113+
|(mut taffy, root)| taffy.compute_layout(root, length(12000.0)).unwrap(),
114114
criterion::BatchSize::SmallInput,
115115
)
116116
},
@@ -128,7 +128,7 @@ fn taffy_benchmarks(c: &mut Criterion) {
128128
|b, &(levels, tracks)| {
129129
b.iter_batched(
130130
|| build_taffy_deep_grid_hierarchy(levels, tracks),
131-
|(mut taffy, root)| taffy.compute_layout(root, points(12000.0)).unwrap(),
131+
|(mut taffy, root)| taffy.compute_layout(root, length(12000.0)).unwrap(),
132132
criterion::BatchSize::SmallInput,
133133
)
134134
},

benches/helpers/yoga_helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn new_with_children(
4141
fn into_yg_units(dim: impl Into<tf::Dimension>) -> yg::StyleUnit {
4242
match dim.into() {
4343
tf::Dimension::Auto => yg::StyleUnit::Auto,
44-
tf::Dimension::Points(val) => yg::StyleUnit::Point(yg::OrderedFloat(val)),
44+
tf::Dimension::Length(val) => yg::StyleUnit::Point(yg::OrderedFloat(val)),
4545
tf::Dimension::Percent(val) => yg::StyleUnit::Percent(yg::OrderedFloat(val)),
4646
}
4747
}

docs/morphorm-style-properties.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub enum PositionType {
2525

2626
```rust
2727
pub enum Units {
28-
Pixels(f32), // = Dimension::Points
28+
Pixels(f32), // = Dimension::Length
2929
Percentage(f32), // = Dimension::Percent
3030
Auto, // = Dimension::Auto
3131
Stretch(f32), // No equivalent in Taffy!

examples/basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main() -> Result<(), taffy::TaffyError> {
1010

1111
let node = taffy.new_with_children(
1212
Style {
13-
size: Size { width: Dimension::Points(100.0), height: Dimension::Points(100.0) },
13+
size: Size { width: Dimension::Length(100.0), height: Dimension::Length(100.0) },
1414
justify_content: Some(JustifyContent::Center),
1515
..Default::default()
1616
},

examples/flexbox_gap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ use taffy::prelude::*;
66
fn main() -> Result<(), taffy::TaffyError> {
77
let mut taffy = Taffy::new();
88

9-
let child_style = Style { size: Size { width: points(20.0), height: points(20.0) }, ..Default::default() };
9+
let child_style = Style { size: Size { width: length(20.0), height: length(20.0) }, ..Default::default() };
1010
let child0 = taffy.new_leaf(child_style.clone())?;
1111
let child1 = taffy.new_leaf(child_style.clone())?;
1212
let child2 = taffy.new_leaf(child_style.clone())?;
1313

1414
let root = taffy.new_with_children(
15-
Style { gap: Size { width: points(10.0), height: zero() }, ..Default::default() },
15+
Style { gap: Size { width: length(10.0), height: zero() }, ..Default::default() },
1616
&[child0, child1, child2],
1717
)?;
1818

examples/grid_holy_grail.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ fn main() -> Result<(), taffy::TaffyError> {
2424
// Setup the grid
2525
let root_style = Style {
2626
display: Display::Grid,
27-
size: Size { width: points(800.0), height: points(600.0) },
28-
grid_template_columns: vec![points(250.0), fr(1.0), points(250.0)],
29-
grid_template_rows: vec![points(150.0), fr(1.0), points(150.0)],
27+
size: Size { width: length(800.0), height: length(600.0) },
28+
grid_template_columns: vec![length(250.0), fr(1.0), length(250.0)],
29+
grid_template_rows: vec![length(150.0), fr(1.0), length(150.0)],
3030
..default()
3131
};
3232

@@ -41,7 +41,7 @@ fn main() -> Result<(), taffy::TaffyError> {
4141
let root = taffy.new_with_children(root_style, &[header, left_sidebar, content_area, right_sidebar, footer])?;
4242

4343
// Compute layout and print result
44-
taffy.compute_layout(root, Size { width: points(800.0), height: points(600.0) })?;
44+
taffy.compute_layout(root, Size { width: length(800.0), height: length(600.0) })?;
4545
taffy::util::print_tree(&taffy, root);
4646

4747
Ok(())

examples/nested.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn main() -> Result<(), taffy::TaffyError> {
55

66
// left
77
let child_t1 = taffy.new_leaf(Style {
8-
size: Size { width: Dimension::Points(5.0), height: Dimension::Points(5.0) },
8+
size: Size { width: Dimension::Length(5.0), height: Dimension::Length(5.0) },
99
..Default::default()
1010
})?;
1111

@@ -20,7 +20,7 @@ fn main() -> Result<(), taffy::TaffyError> {
2020

2121
// right
2222
let child_t2 = taffy.new_leaf(Style {
23-
size: Size { width: Dimension::Points(5.0), height: Dimension::Points(5.0) },
23+
size: Size { width: Dimension::Length(5.0), height: Dimension::Length(5.0) },
2424
..Default::default()
2525
})?;
2626

0 commit comments

Comments
 (0)