Skip to content

Commit f658ed8

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`](DioxusLabs#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 d52ab8f commit f658ed8

File tree

693 files changed

+4274
-4251
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

+4274
-4251
lines changed

README.md

+3-3
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

+26
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/benches/flexbox.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn build_yoga_deep_hierarchy(node_count: u32, branching_factor: u32) -> (yg::Yog
9797
/// A deep tree that matches the shape and styling that yoga use on their benchmarks
9898
fn build_taffy_huge_nested_hierarchy(node_count: u32, branching_factor: u32) -> (Taffy, NodeId) {
9999
let style = Style {
100-
size: Size { width: Dimension::Points(10.0), height: Dimension::Points(10.0) },
100+
size: Size { width: Dimension::Length(10.0), height: Dimension::Length(10.0) },
101101
flex_grow: 1.0,
102102
..Default::default()
103103
};
@@ -115,7 +115,7 @@ fn build_taffy_huge_nested_hierarchy(node_count: u32, branching_factor: u32) ->
115115
/// A deep tree that matches the shape and styling that yoga use on their benchmarks
116116
fn build_yoga_huge_nested_hierarchy(node_count: u32, branching_factor: u32) -> (yg::YogaTree, yg::NodeId) {
117117
let style = Style {
118-
size: Size { width: Dimension::Points(10.0), height: Dimension::Points(10.0) },
118+
size: Size { width: Dimension::Length(10.0), height: Dimension::Length(10.0) },
119119
flex_grow: 1.0,
120120
..Default::default()
121121
};

benches/benches/grid.rs

+5-5
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/src/random_style.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl Randomizeable for Dimension {
2626
if switch < 0.2 {
2727
Dimension::Auto
2828
} else if switch < 0.8 {
29-
Dimension::Points(rng.gen_range(0.0..500.0))
29+
Dimension::Length(rng.gen_range(0.0..500.0))
3030
} else {
3131
Dimension::Percent(rng.gen_range(0.0..1.0))
3232
}

benches/src/yoga_helpers.rs

+1-1
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

+1-1
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

+1-1
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

+2-2
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

+4-4
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

+2-2
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

scripts/gentest/src/main.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,9 @@ fn generate_length_percentage(dimen: &serde_json::Map<String, Value>) -> TokenSt
643643

644644
match unit {
645645
Value::String(ref unit) => match unit.as_ref() {
646-
"points" => {
646+
"px" => {
647647
let value = value();
648-
quote!(taffy::style::LengthPercentage::Points(#value))
648+
quote!(taffy::style::LengthPercentage::Length(#value))
649649
}
650650
"percent" => {
651651
let value = value();
@@ -664,9 +664,9 @@ fn generate_length_percentage_auto(dimen: &serde_json::Map<String, Value>) -> To
664664
match unit {
665665
Value::String(ref unit) => match unit.as_ref() {
666666
"auto" => quote!(taffy::style::LengthPercentageAuto::Auto),
667-
"points" => {
667+
"px" => {
668668
let value = value();
669-
quote!(taffy::style::LengthPercentageAuto::Points(#value))
669+
quote!(taffy::style::LengthPercentageAuto::Length(#value))
670670
}
671671
"percent" => {
672672
let value = value();
@@ -685,9 +685,9 @@ fn generate_dimension(dimen: &serde_json::Map<String, Value>) -> TokenStream {
685685
match unit {
686686
Value::String(ref unit) => match unit.as_ref() {
687687
"auto" => quote!(taffy::style::Dimension::Auto),
688-
"points" => {
688+
"px" => {
689689
let value = value();
690-
quote!(taffy::style::Dimension::Points(#value))
690+
quote!(taffy::style::Dimension::Length(#value))
691691
}
692692
"percent" => {
693693
let value = value();
@@ -817,10 +817,10 @@ fn generate_scalar_definition(track_definition: &serde_json::Map<String, Value>)
817817
"auto" => quote!(auto()),
818818
"min-content" => quote!(min_content()),
819819
"max-content" => quote!(max_content()),
820-
"points" | "percent" | "fraction" => {
820+
"px" | "percent" | "fraction" => {
821821
let value = value();
822822
match unit() {
823-
"points" => quote!(points(#value)),
823+
"px" => quote!(length(#value)),
824824
"percent" => quote!(percent(#value)),
825825
"fraction" => quote!(fr(#value)),
826826
_ => unreachable!(),

scripts/gentest/test_helper.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class TrackSizingParser {
3636
// console.debug(this.index, char);
3737

3838
// Skip whitespace
39-
if (char === ' ') { this.index++; continue;}
39+
if (char === ' ') { this.index++; continue; }
4040

4141
if (TrackSizingParser.INITIAL_CHAR_REGEX.test(char)) {
4242
const token = this._parseItem();
@@ -51,7 +51,7 @@ class TrackSizingParser {
5151
}
5252
}
5353

54-
throw new Error (`Invalid start of token ${char}`);
54+
throw new Error(`Invalid start of token ${char}`);
5555
}
5656
}
5757

@@ -98,9 +98,9 @@ function parseRepetition(input) {
9898
}
9999

100100
function parseDimension(input, options = { allowFrUnits: false }) {
101-
if (options.allowFrUnits && input.endsWith('fr')) return { unit: 'fraction', value: parseFloat(input.replace('fr','')) };
102-
if (input.endsWith('px')) return { unit: 'points', value: parseFloat(input.replace('px','')) };
103-
if (input.endsWith('%')) return { unit: 'percent', value: parseFloat(input.replace('%','')) / 100 };
101+
if (options.allowFrUnits && input.endsWith('fr')) return { unit: 'fraction', value: parseFloat(input.replace('fr', '')) };
102+
if (input.endsWith('px')) return { unit: 'px', value: parseFloat(input.replace('px', '')) };
103+
if (input.endsWith('%')) return { unit: 'percent', value: parseFloat(input.replace('%', '')) / 100 };
104104
if (input === 'auto') return { unit: 'auto' };
105105
if (input === 'min-content') return { unit: 'min-content' };
106106
if (input === 'max-content') return { unit: 'max-content' };
@@ -136,15 +136,15 @@ function parseEdges(edges) {
136136
const right = parseDimension(edges.right);
137137
const top = parseDimension(edges.top);
138138
const bottom = parseDimension(edges.bottom);
139-
139+
140140
if (!left && !right && !top && !bottom) return undefined;
141141
return { left, right, top, bottom };
142142
}
143143

144144
function parseSize(size) {
145145
const width = parseDimension(size.width);
146146
const height = parseDimension(size.height);
147-
147+
148148
if (!width && !height) return undefined;
149149
return { width, height };
150150
}
@@ -155,7 +155,7 @@ function parseGaps(style) {
155155
return { row: gaps[0], column: gaps[1] ?? gaps[0] };
156156
}
157157
if (style.rowGap || style.columnGap) {
158-
return { row: parseDimension(style.rowGap), column: parseDimension(style.columnGap) }
158+
return { row: parseDimension(style.rowGap), column: parseDimension(style.columnGap) };
159159
}
160160
return undefined;
161161
}
@@ -174,9 +174,9 @@ function parseGridAutoFlow(input) {
174174
}
175175

176176
function parseGridPosition(input) {
177-
if (input === 'auto') return { kind: 'auto' }
178-
if (/^span +\d+$/.test(input)) return { kind: 'span', value: parseInt(input.replace(/[^\d]/g, ''), 10)}
179-
if (/^-?\d+$/.test(input)) return { kind: 'line', value: parseInt(input, 10)}
177+
if (input === 'auto') return { kind: 'auto' };
178+
if (/^span +\d+$/.test(input)) return { kind: 'span', value: parseInt(input.replace(/[^\d]/g, ''), 10) };
179+
if (/^-?\d+$/.test(input)) return { kind: 'line', value: parseInt(input, 10) };
180180
return undefined;
181181
}
182182

@@ -226,9 +226,9 @@ function describeElement(e) {
226226

227227
gap: parseGaps(e.style),
228228

229-
size: parseSize({width: e.style.width, height: e.style.height}),
230-
minSize: parseSize({width: e.style.minWidth, height: e.style.minHeight}),
231-
maxSize: parseSize({width: e.style.maxWidth, height: e.style.maxHeight}),
229+
size: parseSize({ width: e.style.width, height: e.style.height }),
230+
minSize: parseSize({ width: e.style.minWidth, height: e.style.minHeight }),
231+
maxSize: parseSize({ width: e.style.maxWidth, height: e.style.maxHeight }),
232232
aspectRatio: parseRatio(e.style.aspectRatio),
233233

234234
margin: parseEdges({
@@ -295,7 +295,7 @@ function describeElement(e) {
295295
useRounding: e.getAttribute("data-test-rounding") !== "false",
296296

297297
children: Array.from(e.children).map(c => describeElement(c)),
298-
}
298+
};
299299
}
300300

301301
// Useful when developing this script. Logs the parsed style to the console when any test fixture is opened in a browser.
@@ -305,4 +305,4 @@ window.onload = function () {
305305
} catch (e) {
306306
console.error(e);
307307
}
308-
}
308+
};

0 commit comments

Comments
 (0)