Skip to content

Commit

Permalink
Rename FlexboxLayout back to Style (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns authored Nov 23, 2022
1 parent 9e53f03 commit 49893a7
Show file tree
Hide file tree
Showing 564 changed files with 2,069 additions and 2,211 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ let mut taffy = Taffy::new();

// Create a tree of nodes using `taffy.new_leaf` and `taffy.new_with_children`.
// These functions both return a node id which can be used to refer to that node
// The FlexboxLayout struct is used to specify styling information
// The Style struct is used to specify styling information
let header_node = taffy
.new_leaf(
FlexboxLayout {
Style {
size: Size { width: Dimension::Points(800.0), height: Dimension::Points(100.0) },
..Default::default()
},
).unwrap();

let body_node = taffy
.new_leaf(
FlexboxLayout {
Style {
size: Size { width: Dimension::Points(800.0), height: Dimension::Undefined },
flex_grow: 1.0,
..Default::default()
Expand All @@ -44,7 +44,7 @@ let body_node = taffy

let root_node = taffy
.new_with_children(
FlexboxLayout {
Style {
flex_direction: FlexDirection::Column,
size: Size { width: Dimension::Points(800.0), height: Dimension::Points(600.0) },
..Default::default()
Expand Down
19 changes: 9 additions & 10 deletions benches/big_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use rand::prelude::*;
use rand_chacha::ChaCha8Rng;
use taffy::prelude::*;
use taffy::randomizable::Randomizeable;
use taffy::style::FlexboxLayout;
use taffy::style::Style;

/// Build a random leaf node
fn build_random_leaf(taffy: &mut Taffy, rng: &mut ChaCha8Rng) -> Node {
taffy.new_with_children(FlexboxLayout::random(rng), &[]).unwrap()
taffy.new_with_children(Style::random(rng), &[]).unwrap()
}

/// A tree with many children that have shallow depth
Expand All @@ -20,13 +20,13 @@ fn build_flat_hierarchy(taffy: &mut Taffy, total_node_count: u32) -> Node {
while node_count < total_node_count {
let sub_children_count = rng.gen_range(1..=4);
let sub_children: Vec<Node> = (0..sub_children_count).map(|_| build_random_leaf(taffy, &mut rng)).collect();
let node = taffy.new_with_children(FlexboxLayout::random(&mut rng), &sub_children).unwrap();
let node = taffy.new_with_children(Style::random(&mut rng), &sub_children).unwrap();

children.push(node);
node_count += 1 + sub_children_count;
}

taffy.new_with_children(FlexboxLayout { ..Default::default() }, children.as_slice()).unwrap()
taffy.new_with_children(Style { ..Default::default() }, children.as_slice()).unwrap()
}

/// A helper function to recursively construct a deep tree
Expand Down Expand Up @@ -58,18 +58,17 @@ fn build_deep_hierarchy(taffy: &mut Taffy, node_count: u32, branching_factor: u3
let mut rng = ChaCha8Rng::seed_from_u64(12345);
let mut build_leaf_node = |taffy: &mut Taffy| build_random_leaf(taffy, &mut rng);
let mut rng = ChaCha8Rng::seed_from_u64(12345);
let mut build_flex_node = |taffy: &mut Taffy, children: Vec<Node>| {
taffy.new_with_children(FlexboxLayout::random(&mut rng), &children).unwrap()
};
let mut build_flex_node =
|taffy: &mut Taffy, children: Vec<Node>| taffy.new_with_children(Style::random(&mut rng), &children).unwrap();

let tree = build_deep_tree(taffy, node_count, branching_factor, &mut build_leaf_node, &mut build_flex_node);

taffy.new_with_children(FlexboxLayout { ..Default::default() }, &tree).unwrap()
taffy.new_with_children(Style { ..Default::default() }, &tree).unwrap()
}

/// A deep tree that matches the shape and styling that yoga use on their benchmarks
fn build_yoga_deep_hierarchy(taffy: &mut Taffy, node_count: u32, branching_factor: u32) -> Node {
let style = FlexboxLayout {
let style = Style {
size: Size { width: Dimension::Points(10.0), height: Dimension::Points(10.0) },
flex_grow: 1.0,
..Default::default()
Expand All @@ -79,7 +78,7 @@ fn build_yoga_deep_hierarchy(taffy: &mut Taffy, node_count: u32, branching_facto
|taffy: &mut Taffy, children: Vec<Node>| taffy.new_with_children(style.clone(), &children).unwrap();

let tree = build_deep_tree(taffy, node_count, branching_factor, &mut build_leaf_node, &mut build_flex_node);
let root = taffy.new_with_children(FlexboxLayout::DEFAULT, &tree).unwrap();
let root = taffy.new_with_children(Style::DEFAULT, &tree).unwrap();

root
}
Expand Down
36 changes: 15 additions & 21 deletions benches/complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use criterion::{criterion_group, criterion_main, Criterion};

fn build_deep_hierarchy(taffy: &mut taffy::node::Taffy) -> taffy::node::Node {
let node111 = taffy
.new_leaf(taffy::style::FlexboxLayout {
.new_leaf(taffy::style::Style {
size: taffy::geometry::Size {
width: taffy::style::Dimension::Points(10.0),
height: taffy::style::Dimension::Points(10.0),
Expand All @@ -11,7 +11,7 @@ fn build_deep_hierarchy(taffy: &mut taffy::node::Taffy) -> taffy::node::Node {
})
.unwrap();
let node112 = taffy
.new_leaf(taffy::style::FlexboxLayout {
.new_leaf(taffy::style::Style {
size: taffy::geometry::Size {
width: taffy::style::Dimension::Points(10.0),
height: taffy::style::Dimension::Points(10.0),
Expand All @@ -21,7 +21,7 @@ fn build_deep_hierarchy(taffy: &mut taffy::node::Taffy) -> taffy::node::Node {
.unwrap();

let node121 = taffy
.new_leaf(taffy::style::FlexboxLayout {
.new_leaf(taffy::style::Style {
size: taffy::geometry::Size {
width: taffy::style::Dimension::Points(10.0),
height: taffy::style::Dimension::Points(10.0),
Expand All @@ -30,7 +30,7 @@ fn build_deep_hierarchy(taffy: &mut taffy::node::Taffy) -> taffy::node::Node {
})
.unwrap();
let node122 = taffy
.new_leaf(taffy::style::FlexboxLayout {
.new_leaf(taffy::style::Style {
size: taffy::geometry::Size {
width: taffy::style::Dimension::Points(10.0),
height: taffy::style::Dimension::Points(10.0),
Expand All @@ -39,15 +39,12 @@ fn build_deep_hierarchy(taffy: &mut taffy::node::Taffy) -> taffy::node::Node {
})
.unwrap();

let node11 =
taffy.new_with_children(taffy::style::FlexboxLayout { ..Default::default() }, &[node111, node112]).unwrap();
let node12 =
taffy.new_with_children(taffy::style::FlexboxLayout { ..Default::default() }, &[node121, node122]).unwrap();
let node1 =
taffy.new_with_children(taffy::style::FlexboxLayout { ..Default::default() }, &[node11, node12]).unwrap();
let node11 = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node111, node112]).unwrap();
let node12 = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node121, node122]).unwrap();
let node1 = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node11, node12]).unwrap();

let node211 = taffy
.new_leaf(taffy::style::FlexboxLayout {
.new_leaf(taffy::style::Style {
size: taffy::geometry::Size {
width: taffy::style::Dimension::Points(10.0),
height: taffy::style::Dimension::Points(10.0),
Expand All @@ -56,7 +53,7 @@ fn build_deep_hierarchy(taffy: &mut taffy::node::Taffy) -> taffy::node::Node {
})
.unwrap();
let node212 = taffy
.new_leaf(taffy::style::FlexboxLayout {
.new_leaf(taffy::style::Style {
size: taffy::geometry::Size {
width: taffy::style::Dimension::Points(10.0),
height: taffy::style::Dimension::Points(10.0),
Expand All @@ -66,7 +63,7 @@ fn build_deep_hierarchy(taffy: &mut taffy::node::Taffy) -> taffy::node::Node {
.unwrap();

let node221 = taffy
.new_leaf(taffy::style::FlexboxLayout {
.new_leaf(taffy::style::Style {
size: taffy::geometry::Size {
width: taffy::style::Dimension::Points(10.0),
height: taffy::style::Dimension::Points(10.0),
Expand All @@ -75,7 +72,7 @@ fn build_deep_hierarchy(taffy: &mut taffy::node::Taffy) -> taffy::node::Node {
})
.unwrap();
let node222 = taffy
.new_leaf(taffy::style::FlexboxLayout {
.new_leaf(taffy::style::Style {
size: taffy::geometry::Size {
width: taffy::style::Dimension::Points(10.0),
height: taffy::style::Dimension::Points(10.0),
Expand All @@ -84,15 +81,12 @@ fn build_deep_hierarchy(taffy: &mut taffy::node::Taffy) -> taffy::node::Node {
})
.unwrap();

let node21 =
taffy.new_with_children(taffy::style::FlexboxLayout { ..Default::default() }, &[node211, node212]).unwrap();
let node22 =
taffy.new_with_children(taffy::style::FlexboxLayout { ..Default::default() }, &[node221, node222]).unwrap();
let node21 = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node211, node212]).unwrap();
let node22 = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node221, node222]).unwrap();

let node2 =
taffy.new_with_children(taffy::style::FlexboxLayout { ..Default::default() }, &[node21, node22]).unwrap();
let node2 = taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node21, node22]).unwrap();

taffy.new_with_children(taffy::style::FlexboxLayout { ..Default::default() }, &[node1, node2]).unwrap()
taffy.new_with_children(taffy::style::Style { ..Default::default() }, &[node1, node2]).unwrap()
}

fn taffy_benchmarks(c: &mut Criterion) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions benches/generated/absolute_layout_align_items_center.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions benches/generated/absolute_layout_child_order.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 49893a7

Please sign in to comment.