这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
10385a3
Add content_size field to Layout struct
nicoburns Apr 25, 2023
460bb98
Add scroll_width and scroll_height methods to Layout struct
nicoburns Apr 25, 2023
a653c11
Add content_size field to LayoutOutput struct
nicoburns Apr 25, 2023
d549065
Implement content size computation for flexbox
nicoburns Apr 25, 2023
39cc7af
Implement content size computation for CSS Grid
nicoburns Apr 25, 2023
2aee6f7
Add Overflow::Clip style
nicoburns May 18, 2023
93d7449
Add tests for scroll width/height
nicoburns Apr 25, 2023
f8690f9
Use naive dimensions for scroll size tests
nicoburns Oct 28, 2023
727c136
Round content size
nicoburns Oct 28, 2023
d6198ea
Print content size in print_tree function
nicoburns Oct 28, 2023
6ccc9bf
Trim text content of text nodes in generated tests
nicoburns Oct 28, 2023
11030eb
Remove caching run_mode exception for leaf layout
nicoburns Oct 28, 2023
e5300da
Leaf layout: always compute content size when run mode is PerformLayout
nicoburns Oct 28, 2023
3a7c615
Set content_size of root node
nicoburns Oct 28, 2023
d6d377e
Flexbox: compute correct content size
nicoburns Oct 28, 2023
2916a3d
Grid: compute correct content size
nicoburns Oct 28, 2023
30904ce
Block: compute correct content size
nicoburns Oct 28, 2023
99218f8
Remove unsupported non-breaking spaces from leaf tests
nicoburns Oct 28, 2023
2a39531
Document feature flags
nicoburns Oct 29, 2023
d8cad60
Add content_size feature flag
nicoburns Oct 29, 2023
75b34e5
Feature flag Flexbox content_size implementation
nicoburns Oct 29, 2023
2878d51
Feature flag Grid content_size implementation
nicoburns Oct 29, 2023
0fbc816
Feature flag content_size assertions in gentests
nicoburns Oct 29, 2023
70c578a
Add benchmark feature flag for content size
nicoburns Oct 29, 2023
b68c275
Simplify f32_min and f32_max implementations
nicoburns Oct 29, 2023
55e99ae
Enable content_size feature by default
nicoburns Oct 29, 2023
a7ff95b
Fixup: format fixtures
nicoburns Oct 29, 2023
57723e7
Fix clippy lints
nicoburns Oct 29, 2023
dc1c44a
Introduce Size::has_non_zero_area method
nicoburns Oct 29, 2023
e95a1ee
Remove commented code from test_helper script
nicoburns Oct 29, 2023
18dea5e
Refactor main/cross -> x/y conversion
nicoburns Oct 30, 2023
347652e
Fully feature flag content size computation
nicoburns Nov 15, 2023
79ccf8b
Disable content_size feature by default
nicoburns Nov 15, 2023
d71bf43
Fix Taffy.layout method when rounding is disabled
nicoburns Nov 15, 2023
23c000e
Use absolute difference when comparing unrounded values in gentests
nicoburns Nov 15, 2023
20532a8
Output scrollbar size in layout
nicoburns Nov 15, 2023
a08755e
Fix content_size feature flag in print tree function
nicoburns Nov 16, 2023
28aff64
Update scroll_width/scroll_height methods to take into account space …
nicoburns Nov 16, 2023
b260448
Specialise cache for perform_layout and run_mode steps
nicoburns Nov 21, 2023
73d69df
Fix typo: it's -> its
nicoburns Nov 21, 2023
9db77e8
Add padding and border fields to Layout struct
nicoburns Nov 21, 2023
6be8996
Use border in scroll width/height calculation
nicoburns Nov 21, 2023
77c9958
Make content_size a default feature
nicoburns Nov 21, 2023
b406533
Document content size code
nicoburns Nov 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ jobs:
- run: cargo build --features serde
- run: cargo test --features serde

test-features-default-except-content-size:
name: "Test Suite [Features: Default except content_size]"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo build --no-default-features --features std,taffy_tree,grid,flexbox,block_layout
- run: cargo test --no-default-features --features std,taffy_tree,grid,flexbox,block_layout

test-features-no-grid-nor-flexbox:
name: "Test Suite [Features: std (no grid or flexbox)]"
runs-on: ubuntu-latest
Expand Down
30 changes: 26 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,39 @@ serde = { version = "1.0", optional = true, features = ["serde_derive"] }
slotmap = { version = "1.0.6", optional = true }
grid = { version = "0.11.0", default-features = false, optional = true }

### FEATURES #################################################################

[features]
default = ["std", "flexbox", "grid", "block_layout", "taffy_tree"]
default = ["std", "taffy_tree", "flexbox", "grid", "block_layout", "content_size"]

### Algorithms

# Enables the Block layout algorithm
block_layout = []
# Enables the Flexbox layout algorithm
flexbox = []
# Enables the CSS Grid layout algorithm
grid = ["alloc", "dep:grid"]
alloc = []
std = ["num-traits/std", "grid?/std"]
# Causes all algorithms to compute and output a content size for each node
content_size = []

### Taffy Tree

# Enable the built-in Taffy node tree
taffy_tree = ["dep:slotmap"]

### Other

# Add serde derives to Style structs
serde = ["dep:serde"]
# Allow Taffy to depend on the standard library
std = ["num-traits/std", "grid?/std"]
# Allow Taffy to depend on the alloc library
alloc = []
# Internal featyre for debugging
debug = ["std"]
# Internal feature for profiling
profile = ["std"]
taffy_tree = ["dep:slotmap"]

[dev-dependencies]
serde_json = "1.0.93"
Expand Down
1 change: 1 addition & 0 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ slotmap = { version = "1.0.6", optional = true }
yoga = ["dep:yoga", "dep:slotmap", "dep:ordered-float"]
yoga-super-deep = ["yoga"]
taffy03 = ["dep:taffy_03"]
content_size = ["taffy/content_size"]
small = []
large = []

Expand Down
30 changes: 23 additions & 7 deletions scripts/gentest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,15 @@ fn generate_assertions(ident: &str, node: &Value, use_rounding: bool) -> TokenSt
let layout = if use_rounding { &node["smartRoundedLayout"] } else { &node["unroundedLayout"] };

let read_f32 = |s: &str| layout[s].as_f64().unwrap() as f32;
let read_naive_f32 = |s: &str| node["naivelyRoundedLayout"][s].as_f64().unwrap() as f32;
let width = read_f32("width");
let height = read_f32("height");
let x = read_f32("x");
let y = read_f32("y");

let scroll_width = (read_f32("scrollWidth") - read_naive_f32("clientWidth")).max(0.0);
let scroll_height = (read_f32("scrollHeight") - read_naive_f32("clientHeight")).max(0.0);

let children = {
let mut c = Vec::new();
if let Value::Array(ref value) = node["children"] {
Expand All @@ -253,21 +257,31 @@ fn generate_assertions(ident: &str, node: &Value, use_rounding: bool) -> TokenSt

if use_rounding {
quote!(
let Layout { size, location, .. } = taffy.layout(#ident).unwrap();
#[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
let layout @ Layout { size, location, .. } = taffy.layout(#ident).unwrap();
assert_eq!(size.width, #width, "width of node {:?}. Expected {}. Actual {}", #ident, #width, size.width);
assert_eq!(size.height, #height, "height of node {:?}. Expected {}. Actual {}", #ident, #height, size.height);
assert_eq!(location.x, #x, "x of node {:?}. Expected {}. Actual {}", #ident, #x, location.x);
assert_eq!(location.y, #y, "y of node {:?}. Expected {}. Actual {}", #ident, #y, location.y);
#[cfg(feature = "content_size")]
assert_eq!(layout.scroll_width(), #scroll_width, "scroll_width of node {:?}. Expected {}. Actual {}", #ident, #scroll_width, layout.scroll_width());
#[cfg(feature = "content_size")]
assert_eq!(layout.scroll_height(), #scroll_height, "scroll_height of node {:?}. Expected {}. Actual {}", #ident, #scroll_height, layout.scroll_height());

#children
)
} else {
quote!(
let Layout { size, location, .. } = taffy.layout(#ident).unwrap();
assert!(size.width - #width < 0.1, "width of node {:?}. Expected {}. Actual {}", #ident, #width, size.width);
assert!(size.height - #height < 0.1, "height of node {:?}. Expected {}. Actual {}", #ident, #height, size.height);
assert!(location.x - #x < 0.1, "x of node {:?}. Expected {}. Actual {}", #ident, #x, location.x);
assert!(location.y - #y < 0.1, "y of node {:?}. Expected {}. Actual {}", #ident, #y, location.y);
#[cfg_attr(not(feature = "content_size"), allow(unused_variables))]
let layout @ Layout { size, location, .. } = taffy.layout(#ident).unwrap();
assert!((size.width - #width).abs() < 0.1, "width of node {:?}. Expected {}. Actual {}", #ident, #width, size.width);
assert!((size.height - #height).abs() < 0.1, "height of node {:?}. Expected {}. Actual {}", #ident, #height, size.height);
assert!((location.x - #x).abs() < 0.1, "x of node {:?}. Expected {}. Actual {}", #ident, #x, location.x);
assert!((location.y - #y).abs() < 0.1, "y of node {:?}. Expected {}. Actual {}", #ident, #y, location.y);
#[cfg(feature = "content_size")]
assert!((layout.scroll_width() - #scroll_width).abs() < 0.1, "scroll_width of node {:?}. Expected {}. Actual {}", #ident, #scroll_width, layout.scroll_width());
#[cfg(feature = "content_size")]
assert!((layout.scroll_height() - #scroll_height).abs() < 0.1, "scroll_height of node {:?}. Expected {}. Actual {}", #ident, #scroll_height, layout.scroll_height());

#children
)
Expand Down Expand Up @@ -867,6 +881,8 @@ fn generate_scalar_definition(track_definition: &serde_json::Map<String, Value>)
}

fn generate_node_context(text_content: &str, writing_mode: Option<&str>, aspect_ratio: Option<f32>) -> TokenStream {
let trimmed_text_content = text_content.trim();

let writing_mode_token = match writing_mode {
Some("vertical-rl" | "vertical-lr") => quote!(crate::WritingMode::Vertical),
_ => quote!(crate::WritingMode::Horizontal),
Expand All @@ -879,7 +895,7 @@ fn generate_node_context(text_content: &str, writing_mode: Option<&str>, aspect_

quote!(
crate::TextMeasure {
text_content: #text_content,
text_content: #trimmed_text_content,
writing_mode: #writing_mode_token,
_aspect_ratio: #aspect_ratio_token,
}
Expand Down
12 changes: 12 additions & 0 deletions scripts/gentest/test_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ function describeElement(e) {
height: boundingRect.height,
x: boundingRect.x - parentBoundingRect.x,
y: boundingRect.y - parentBoundingRect.y,
scrollWidth: e.scrollWidth,
scrollHeight: e.scrollHeight,
clientWidth: e.clientWidth,
clientHeight: e.clientHeight,
},

// The naively rounded layout of the node. This is equivalent to calling Math.round() on
Expand All @@ -293,6 +297,10 @@ function describeElement(e) {
height: e.offsetHeight,
x: e.offsetLeft + e.parentNode.clientLeft,
y: e.offsetTop + e.parentNode.clientTop,
scrollWidth: e.scrollWidth,
scrollHeight: e.scrollHeight,
clientWidth: e.clientWidth,
clientHeight: e.clientHeight,
},

// The naive rounding can result in 1px gaps in the layout, so Taffy uses a smarter algorithm to avoid this.
Expand All @@ -303,6 +311,10 @@ function describeElement(e) {
height: Math.round(boundingRect.bottom) - Math.round(boundingRect.top),
x: Math.round(boundingRect.x - parentBoundingRect.x),
y: Math.round(boundingRect.y - parentBoundingRect.y),
scrollWidth: e.scrollWidth,
scrollHeight: e.scrollHeight,
clientWidth: e.clientWidth,
clientHeight: e.clientHeight,
},

// Whether the test should enable rounding
Expand Down
Loading