-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix clippy lints * Vertical border and padding percentage values are multiplied by available_space.width (#273) * fixed vertical padding + border calculation * changes: added fix to release notes, added new tests in "border_and_padding.rs" * fixed percentage border and padding heights being scaled by available_space.width * fmt, add fix to release notes * added test (cherry picked from commit 996e70d) * Revert "Resolve vertical percentage padding/border against node height" All percentage padding/border values resolve against the node's inline size (width in horizontal writing modes) as per the CSS spec. See: https://developer.mozilla.org/en-US/docs/Web/CSS/padding#values * Bump version to 0.2.2 Co-authored-by: ickshonpe <[email protected]>
- Loading branch information
Showing
8 changed files
with
133 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "taffy" | ||
version = "0.2.1" | ||
version = "0.2.2" | ||
authors = [ | ||
"Alice Cecile <[email protected]>", | ||
"Johnathan Kelley <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
use taffy::prelude::*; | ||
|
||
fn arr_to_rect<T: Copy>(items: [T; 4]) -> Rect<T> { | ||
Rect { left: items[0], right: items[1], top: items[2], bottom: items[3] } | ||
} | ||
|
||
#[test] | ||
fn border_on_a_single_axis_doesnt_increase_size() { | ||
for i in 0..4 { | ||
let mut taffy = Taffy::new(); | ||
let node = taffy | ||
.new_leaf(Style { | ||
border: { | ||
let mut lengths = [Dimension::Points(0.); 4]; | ||
lengths[i] = Dimension::Points(10.); | ||
arr_to_rect(lengths) | ||
}, | ||
..Default::default() | ||
}) | ||
.unwrap(); | ||
|
||
taffy | ||
.compute_layout( | ||
node, | ||
Size { height: AvailableSpace::Definite(100.0), width: AvailableSpace::Definite(100.0) }, | ||
) | ||
.ok(); | ||
|
||
let layout = taffy.layout(node).unwrap(); | ||
assert_eq!(layout.size.width * layout.size.height, 0.); | ||
} | ||
} | ||
|
||
#[test] | ||
fn padding_on_a_single_axis_doesnt_increase_size() { | ||
for i in 0..4 { | ||
let mut taffy = Taffy::new(); | ||
let node = taffy | ||
.new_leaf(Style { | ||
border: { | ||
let mut lengths = [Dimension::Points(0.); 4]; | ||
lengths[i] = Dimension::Points(10.); | ||
arr_to_rect(lengths) | ||
}, | ||
..Default::default() | ||
}) | ||
.unwrap(); | ||
|
||
taffy | ||
.compute_layout( | ||
node, | ||
Size { height: AvailableSpace::Definite(100.0), width: AvailableSpace::Definite(100.0) }, | ||
) | ||
.ok(); | ||
|
||
let layout = taffy.layout(node).unwrap(); | ||
assert_eq!(layout.size.width * layout.size.height, 0.); | ||
} | ||
} | ||
|
||
#[test] | ||
fn border_and_padding_on_a_single_axis_doesnt_increase_size() { | ||
for i in 0..4 { | ||
let mut taffy = Taffy::new(); | ||
let rect = { | ||
let mut lengths = [Dimension::Points(0.); 4]; | ||
lengths[i] = Dimension::Points(10.); | ||
arr_to_rect(lengths) | ||
}; | ||
let node = taffy.new_leaf(Style { border: rect, padding: rect, ..Default::default() }).unwrap(); | ||
|
||
taffy | ||
.compute_layout( | ||
node, | ||
Size { height: AvailableSpace::Definite(100.0), width: AvailableSpace::Definite(100.0) }, | ||
) | ||
.ok(); | ||
let layout = taffy.layout(node).unwrap(); | ||
assert_eq!(layout.size.width * layout.size.height, 0.); | ||
} | ||
} | ||
|
||
#[test] | ||
fn vertical_border_and_padding_percentage_values_use_available_space_correctly() { | ||
let mut taffy = Taffy::new(); | ||
|
||
let node = taffy | ||
.new_leaf(Style { | ||
padding: Rect { | ||
left: Dimension::Percent(1.0), | ||
top: Dimension::Percent(1.0), | ||
right: Dimension::Points(0.), | ||
bottom: Dimension::Points(0.), | ||
}, | ||
..Default::default() | ||
}) | ||
.unwrap(); | ||
|
||
taffy | ||
.compute_layout(node, Size { width: AvailableSpace::Definite(200.0), height: AvailableSpace::Definite(100.0) }) | ||
.ok(); | ||
|
||
let layout = taffy.layout(node).unwrap(); | ||
assert_eq!(layout.size.width, 200.0); | ||
assert_eq!(layout.size.height, 200.0); | ||
} |