Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement CSS Block layout (Display::Block) #474

Merged
merged 85 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
621bcdd
Add `Block` variant to `Display` enum + stub block layout implementation
nicoburns May 1, 2023
43d4ef9
Implement super-naive version of the block algorithm
nicoburns May 1, 2023
df49417
Add display:block support to the test generator
nicoburns May 1, 2023
5a53f8f
Fixup duplicate Display default
nicoburns May 1, 2023
d6b1c88
Fixup: yoga helpers
nicoburns May 1, 2023
733d043
Implement intrinsic sizing for block layout
nicoburns May 1, 2023
e4b6e7c
Add basic test for block layout intrinsic sizing
nicoburns May 1, 2023
c53fd20
Remove unused imports
nicoburns May 1, 2023
cd777c3
Implment block layout inline-axis stretch fitting
nicoburns May 1, 2023
37d8d24
Implement block container padding and border
nicoburns May 1, 2023
ee58f0a
Add tests for block container padding and border
nicoburns May 1, 2023
2a4e5fb
Implement block item inset
nicoburns May 1, 2023
1580192
Add test for block item inset
nicoburns May 1, 2023
2d9728b
Add Sub impl to Size<T> where T: Sub
nicoburns May 4, 2023
33d4744
Block algo: implement percentage padding, border, and inset
nicoburns May 4, 2023
5b01528
Block: Add tests for percentage padding, margin, and inset
nicoburns May 4, 2023
da5351e
Add tests for scrollbars taking up space in block layout
nicoburns May 4, 2023
5340741
Add `Add` impl for Point<T> where T: Add
nicoburns May 5, 2023
6df3707
Block: initial implementation of absolute positioning
nicoburns May 5, 2023
59bad7c
Block: clamp intrinsic sizes by min/max sizes
nicoburns May 5, 2023
423b231
Add single position:absolute test for block layout
nicoburns May 5, 2023
c2d100b
Add early return for case where height is known but width isn't
nicoburns May 5, 2023
f085df6
Remove unnecessary unwrap_or
nicoburns May 5, 2023
48ad736
Support block margins in the x/inline axis
nicoburns May 6, 2023
3c512ff
Add tests for negative inline-axis block margins
nicoburns May 6, 2023
ec02224
Block: implement support for auto margins for relatively positioned i…
nicoburns May 6, 2023
2393075
Support vertical block margins in non-collapsing and sibling-collapsi…
nicoburns May 6, 2023
e12dc50
Fix clippy lints
nicoburns May 6, 2023
733bc83
Add CollapsibleMarginSet type + thread it through the layout tree cal…
nicoburns May 6, 2023
15be4c3
Add can_collapse through to SizeBaselinesAndMargins struct
nicoburns May 6, 2023
314071b
Fix feature flagging
nicoburns May 6, 2023
3e7c285
Rework sibling margin collapse in terms of CollapsibleMarginSet
nicoburns May 6, 2023
ed5f09d
Convert collapsible margin parameters to booleans
nicoburns May 6, 2023
d349cf7
Implement collapsing first-child and last-child margins with their pa…
nicoburns May 6, 2023
b412fc5
Add tests for first- and last-child margins collapsing with their par…
nicoburns May 6, 2023
4a8f9a4
Fix doc warnings
nicoburns May 6, 2023
7b42f9b
Add tests for mix of +/- margins with first-child collapse (+disabled…
nicoburns May 6, 2023
f4e4163
Add simple granchild collapsing test
nicoburns May 6, 2023
4485e0e
Make collapse_with_margin and collapse_with_set take self rather than…
nicoburns May 6, 2023
b74fe59
Preserve separate positive/negative components of margin sets when re…
nicoburns May 6, 2023
d422c60
Enable test_fixtures/block_margin_y_fixed_size_first_granchild_collap…
nicoburns May 6, 2023
e18dde1
Only propagate child margins to parent if current node's margins can …
nicoburns May 6, 2023
8b23454
Enable block_margin_y_fixed_size_last_child_collapse_positive_and_neg…
nicoburns May 6, 2023
2fd0809
Remove height from non-leaf nodes for parent-child margin collapsing …
nicoburns May 6, 2023
84c8abe
Block: Implement hidden layout
nicoburns May 7, 2023
9d98d2f
Block: Compute first baseline for baseline alignment
nicoburns May 7, 2023
3b7b540
Add tests for hidden layout of block children
nicoburns May 7, 2023
1838365
Block absolute positioning fixes
nicoburns May 7, 2023
6432e7d
Add tests for absolute positioning
nicoburns May 7, 2023
1de5815
Add tests for block auto margins
nicoburns May 7, 2023
0ee8326
Block absolute auto margin fixes
nicoburns May 7, 2023
3db00d1
Tests for block absolute auto margins
nicoburns May 7, 2023
a73a37a
Fix block absolute auto margins
nicoburns May 7, 2023
7a1a130
Add basic support for collapsing margins through block nodes
nicoburns May 8, 2023
bd03ea6
Add test for margins collapsing through a block node
nicoburns May 8, 2023
2e41651
Fix compilation with block_layout feature disabled
nicoburns May 9, 2023
249c5bf
Fix clippy lints
nicoburns May 9, 2023
107661d
Add some basic block layout - flexbox integration tests
nicoburns May 10, 2023
18b8f04
Remove useless variable
nicoburns May 10, 2023
17b606b
Remove dbg!() statements
nicoburns May 10, 2023
1bc037a
Remove unused fields from BlockItem struct
nicoburns May 10, 2023
f939292
Remove print statement
nicoburns May 11, 2023
c582986
Apply suggestions from code review
nicoburns May 11, 2023
8311333
Update block module documentation
nicoburns May 11, 2023
23d4403
Clamp block auto width by min/max width
nicoburns May 15, 2023
2a92507
Don't clamp content size of block nodes by their max height
nicoburns May 15, 2023
a7de646
Add block aspect_ratio tests
nicoburns May 15, 2023
ba72e69
Remove baseline alignment support from block layout algorithm
nicoburns May 15, 2023
300ded3
Add tests for block algorithm baseline computation
nicoburns May 15, 2023
8d95cad
Add block layout to changelog
nicoburns May 15, 2023
e2de11b
Add block layout to the README
nicoburns May 15, 2023
83094e8
Improve comment on order field
nicoburns May 15, 2023
cb664aa
Add extra block margin collapsing through tests
nicoburns May 15, 2023
6b74908
Prevent margins collapsing through nodes with overflow-x set to a scroll
nicoburns May 15, 2023
42584a8
Don't allow margins to collapse through line boxes
nicoburns May 15, 2023
77e82c4
Add tests for margin collapsing through a node being blocked
nicoburns May 15, 2023
14a4879
Overflow-x blocking margin collapse fixup
nicoburns May 15, 2023
f56c025
Add tests for margin collapsing with children being blocked
nicoburns May 15, 2023
5c688ac
Floor size of block containers by padding_border sum
nicoburns May 17, 2023
077c46f
Add tests for flooring size of block containers by padding_border sum
nicoburns May 17, 2023
93eb2f6
Rename margin tests
nicoburns May 18, 2023
70b7d4b
Add some percentage vertical margin tests
nicoburns May 18, 2023
1585664
Add tests for margin collapsing being blocked by flexbox and grid nodes
nicoburns May 18, 2023
4e5ffd4
Add block <-> grid integration tests
nicoburns May 18, 2023
93e5d14
Add complex margin collapse tests
nicoburns May 18, 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
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ slotmap = { version = "1.0.6", optional = true }
grid = { version = "0.10.0", default-features = false, optional = true }

[features]
default = ["std", "flexbox", "grid", "taffy_tree"]
default = ["std", "flexbox", "grid", "block_layout", "taffy_tree"]
block_layout = []
flexbox = []
grid = ["alloc", "dep:grid"]
alloc = []
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Taffy is a flexible, high-performance, cross-platform UI layout library written in [Rust](https://www.rust-lang.org).

It currently implements the **Flexbox** and **CSS Grid** layout algorithms. Support for other paradigms is planned. For more information on this and other future development plans see the [roadmap issue](https://github.com/DioxusLabs/taffy/issues/345).
It currently implements the CSS **Block**, **Flexbox** and **CSS Grid** layout algorithms. Support for other paradigms is planned. For more information on this and other future development plans see the [roadmap issue](https://github.com/DioxusLabs/taffy/issues/345).

This crate is a collaborative, cross-team project, and is designed to be used as a dependency for other UI and GUI libraries.
Right now, it powers:
Expand Down
4 changes: 4 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Example usage change:
).unwrap();
```

### Added

- Support for [CSS Block layout](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flow_Layout/Block_and_Inline_Layout_in_Normal_Flow#elements_participating_in_a_block_formatting_context) has been added. This can be used via the new `Display::Block` variant of the `Display` enum. Note that inline, inline-block and float have *not* been implemented. The use case supported is block container nodes which contain block-level children.

### Removed

- `layout_flexbox()` has been removed from the prelude. Use `FlexboxAlgorithm::perform_layout()` instead.
Expand Down
5 changes: 3 additions & 2 deletions benches/src/yoga_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ fn content_into_justify(align: Option<tf::JustifyContent>) -> yg::Justify {
pub fn apply_taffy_style(node: &mut yg::Node, style: &tf::Style) {
// display
node.set_display(match style.display {
tf::Display::Flex => yg::Display::Flex,
tf::Display::Grid => panic!("Yoga does not support CSS Grid"),
tf::Display::None => yg::Display::None,
tf::Display::Flex => yg::Display::Flex,
tf::Display::Grid => panic!("Yoga does not support CSS Grid layout"),
tf::Display::Block => panic!("Yoga does not support CSS Block layout"),
});

// position
Expand Down
1 change: 1 addition & 0 deletions scripts/gentest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ fn generate_node(ident: &str, node: &Value) -> TokenStream {
let display = match style["display"] {
Value::String(ref value) => match value.as_ref() {
"none" => quote!(display: taffy::style::Display::None,),
"block" => quote!(display: taffy::style::Display::Block,),
"grid" => quote!(display: taffy::style::Display::Grid,),
_ => quote!(display: taffy::style::Display::Flex,),
},
Expand Down
Loading