From 18cdf7a68080e83564a9457cb32dec1b0ecd34ef Mon Sep 17 00:00:00 2001 From: Cole Poirier Date: Tue, 10 May 2022 10:19:42 -0700 Subject: [PATCH 01/15] depend on dioxus-maintained fork of stretch (stretch2) --- crates/bevy_ui/Cargo.toml | 6 +- crates/bevy_ui/src/flex/convert.rs | 124 ++++++++++++++--------------- crates/bevy_ui/src/flex/mod.rs | 72 +++++++++-------- 3 files changed, 103 insertions(+), 99 deletions(-) diff --git a/crates/bevy_ui/Cargo.toml b/crates/bevy_ui/Cargo.toml index 2997283d94d7a..81e954e28f572 100644 --- a/crates/bevy_ui/Cargo.toml +++ b/crates/bevy_ui/Cargo.toml @@ -18,7 +18,9 @@ bevy_hierarchy = { path = "../bevy_hierarchy", version = "0.8.0-dev" } bevy_input = { path = "../bevy_input", version = "0.8.0-dev" } bevy_log = { path = "../bevy_log", version = "0.8.0-dev" } bevy_math = { path = "../bevy_math", version = "0.8.0-dev" } -bevy_reflect = { path = "../bevy_reflect", version = "0.8.0-dev", features = ["bevy"] } +bevy_reflect = { path = "../bevy_reflect", version = "0.8.0-dev", features = [ + "bevy", +] } bevy_render = { path = "../bevy_render", version = "0.8.0-dev" } bevy_sprite = { path = "../bevy_sprite", version = "0.8.0-dev" } bevy_text = { path = "../bevy_text", version = "0.8.0-dev" } @@ -27,7 +29,7 @@ bevy_window = { path = "../bevy_window", version = "0.8.0-dev" } bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" } # other -stretch = "0.3.2" +stretch2 = "0.4.2" serde = { version = "1", features = ["derive"] } smallvec = { version = "1.6", features = ["union", "const_generics"] } bytemuck = { version = "1.5", features = ["derive"] } diff --git a/crates/bevy_ui/src/flex/convert.rs b/crates/bevy_ui/src/flex/convert.rs index 3c73b1f566714..e37d049fb02d6 100644 --- a/crates/bevy_ui/src/flex/convert.rs +++ b/crates/bevy_ui/src/flex/convert.rs @@ -6,8 +6,8 @@ use crate::{ pub fn from_rect( scale_factor: f64, rect: UiRect, -) -> stretch::geometry::Rect { - stretch::geometry::Rect { +) -> stretch2::geometry::Rect { + stretch2::geometry::Rect { start: from_val(scale_factor, rect.left), end: from_val(scale_factor, rect.right), // NOTE: top and bottom are intentionally flipped. stretch has a flipped y-axis @@ -16,8 +16,8 @@ pub fn from_rect( } } -pub fn from_f32_size(scale_factor: f64, size: Size) -> stretch::geometry::Size { - stretch::geometry::Size { +pub fn from_f32_size(scale_factor: f64, size: Size) -> stretch2::geometry::Size { + stretch2::geometry::Size { width: (scale_factor * size.width as f64) as f32, height: (scale_factor * size.height as f64) as f32, } @@ -26,16 +26,16 @@ pub fn from_f32_size(scale_factor: f64, size: Size) -> stretch::geometry::S pub fn from_val_size( scale_factor: f64, size: Size, -) -> stretch::geometry::Size { - stretch::geometry::Size { +) -> stretch2::geometry::Size { + stretch2::geometry::Size { width: from_val(scale_factor, size.width), height: from_val(scale_factor, size.height), } } -pub fn from_style(scale_factor: f64, value: &Style) -> stretch::style::Style { - stretch::style::Style { - overflow: stretch::style::Overflow::Visible, +pub fn from_style(scale_factor: f64, value: &Style) -> stretch2::style::Style { + stretch2::style::Style { + overflow: stretch2::style::Overflow::Visible, display: value.display.into(), position_type: value.position_type.into(), direction: value.direction.into(), @@ -56,117 +56,117 @@ pub fn from_style(scale_factor: f64, value: &Style) -> stretch::style::Style { min_size: from_val_size(scale_factor, value.min_size), max_size: from_val_size(scale_factor, value.max_size), aspect_ratio: match value.aspect_ratio { - Some(value) => stretch::number::Number::Defined(value), - None => stretch::number::Number::Undefined, + Some(value) => stretch2::number::Number::Defined(value), + None => stretch2::number::Number::Undefined, }, } } -pub fn from_val(scale_factor: f64, val: Val) -> stretch::style::Dimension { +pub fn from_val(scale_factor: f64, val: Val) -> stretch2::style::Dimension { match val { - Val::Auto => stretch::style::Dimension::Auto, - Val::Percent(value) => stretch::style::Dimension::Percent(value / 100.0), - Val::Px(value) => stretch::style::Dimension::Points((scale_factor * value as f64) as f32), - Val::Undefined => stretch::style::Dimension::Undefined, + Val::Auto => stretch2::style::Dimension::Auto, + Val::Percent(value) => stretch2::style::Dimension::Percent(value / 100.0), + Val::Px(value) => stretch2::style::Dimension::Points((scale_factor * value as f64) as f32), + Val::Undefined => stretch2::style::Dimension::Undefined, } } -impl From for stretch::style::AlignItems { +impl From for stretch2::style::AlignItems { fn from(value: AlignItems) -> Self { match value { - AlignItems::FlexStart => stretch::style::AlignItems::FlexStart, - AlignItems::FlexEnd => stretch::style::AlignItems::FlexEnd, - AlignItems::Center => stretch::style::AlignItems::Center, - AlignItems::Baseline => stretch::style::AlignItems::Baseline, - AlignItems::Stretch => stretch::style::AlignItems::Stretch, + AlignItems::FlexStart => stretch2::style::AlignItems::FlexStart, + AlignItems::FlexEnd => stretch2::style::AlignItems::FlexEnd, + AlignItems::Center => stretch2::style::AlignItems::Center, + AlignItems::Baseline => stretch2::style::AlignItems::Baseline, + AlignItems::Stretch => stretch2::style::AlignItems::Stretch, } } } -impl From for stretch::style::AlignSelf { +impl From for stretch2::style::AlignSelf { fn from(value: AlignSelf) -> Self { match value { - AlignSelf::Auto => stretch::style::AlignSelf::Auto, - AlignSelf::FlexStart => stretch::style::AlignSelf::FlexStart, - AlignSelf::FlexEnd => stretch::style::AlignSelf::FlexEnd, - AlignSelf::Center => stretch::style::AlignSelf::Center, - AlignSelf::Baseline => stretch::style::AlignSelf::Baseline, - AlignSelf::Stretch => stretch::style::AlignSelf::Stretch, + AlignSelf::Auto => stretch2::style::AlignSelf::Auto, + AlignSelf::FlexStart => stretch2::style::AlignSelf::FlexStart, + AlignSelf::FlexEnd => stretch2::style::AlignSelf::FlexEnd, + AlignSelf::Center => stretch2::style::AlignSelf::Center, + AlignSelf::Baseline => stretch2::style::AlignSelf::Baseline, + AlignSelf::Stretch => stretch2::style::AlignSelf::Stretch, } } } -impl From for stretch::style::AlignContent { +impl From for stretch2::style::AlignContent { fn from(value: AlignContent) -> Self { match value { - AlignContent::FlexStart => stretch::style::AlignContent::FlexStart, - AlignContent::FlexEnd => stretch::style::AlignContent::FlexEnd, - AlignContent::Center => stretch::style::AlignContent::Center, - AlignContent::Stretch => stretch::style::AlignContent::Stretch, - AlignContent::SpaceBetween => stretch::style::AlignContent::SpaceBetween, - AlignContent::SpaceAround => stretch::style::AlignContent::SpaceAround, + AlignContent::FlexStart => stretch2::style::AlignContent::FlexStart, + AlignContent::FlexEnd => stretch2::style::AlignContent::FlexEnd, + AlignContent::Center => stretch2::style::AlignContent::Center, + AlignContent::Stretch => stretch2::style::AlignContent::Stretch, + AlignContent::SpaceBetween => stretch2::style::AlignContent::SpaceBetween, + AlignContent::SpaceAround => stretch2::style::AlignContent::SpaceAround, } } } -impl From for stretch::style::Direction { +impl From for stretch2::style::Direction { fn from(value: Direction) -> Self { match value { - Direction::Inherit => stretch::style::Direction::Inherit, - Direction::LeftToRight => stretch::style::Direction::LTR, - Direction::RightToLeft => stretch::style::Direction::RTL, + Direction::Inherit => stretch2::style::Direction::Inherit, + Direction::LeftToRight => stretch2::style::Direction::LTR, + Direction::RightToLeft => stretch2::style::Direction::RTL, } } } -impl From for stretch::style::Display { +impl From for stretch2::style::Display { fn from(value: Display) -> Self { match value { - Display::Flex => stretch::style::Display::Flex, - Display::None => stretch::style::Display::None, + Display::Flex => stretch2::style::Display::Flex, + Display::None => stretch2::style::Display::None, } } } -impl From for stretch::style::FlexDirection { +impl From for stretch2::style::FlexDirection { fn from(value: FlexDirection) -> Self { match value { - FlexDirection::Row => stretch::style::FlexDirection::Row, - FlexDirection::Column => stretch::style::FlexDirection::Column, - FlexDirection::RowReverse => stretch::style::FlexDirection::RowReverse, - FlexDirection::ColumnReverse => stretch::style::FlexDirection::ColumnReverse, + FlexDirection::Row => stretch2::style::FlexDirection::Row, + FlexDirection::Column => stretch2::style::FlexDirection::Column, + FlexDirection::RowReverse => stretch2::style::FlexDirection::RowReverse, + FlexDirection::ColumnReverse => stretch2::style::FlexDirection::ColumnReverse, } } } -impl From for stretch::style::JustifyContent { +impl From for stretch2::style::JustifyContent { fn from(value: JustifyContent) -> Self { match value { - JustifyContent::FlexStart => stretch::style::JustifyContent::FlexStart, - JustifyContent::FlexEnd => stretch::style::JustifyContent::FlexEnd, - JustifyContent::Center => stretch::style::JustifyContent::Center, - JustifyContent::SpaceBetween => stretch::style::JustifyContent::SpaceBetween, - JustifyContent::SpaceAround => stretch::style::JustifyContent::SpaceAround, - JustifyContent::SpaceEvenly => stretch::style::JustifyContent::SpaceEvenly, + JustifyContent::FlexStart => stretch2::style::JustifyContent::FlexStart, + JustifyContent::FlexEnd => stretch2::style::JustifyContent::FlexEnd, + JustifyContent::Center => stretch2::style::JustifyContent::Center, + JustifyContent::SpaceBetween => stretch2::style::JustifyContent::SpaceBetween, + JustifyContent::SpaceAround => stretch2::style::JustifyContent::SpaceAround, + JustifyContent::SpaceEvenly => stretch2::style::JustifyContent::SpaceEvenly, } } } -impl From for stretch::style::PositionType { +impl From for stretch2::style::PositionType { fn from(value: PositionType) -> Self { match value { - PositionType::Relative => stretch::style::PositionType::Relative, - PositionType::Absolute => stretch::style::PositionType::Absolute, + PositionType::Relative => stretch2::style::PositionType::Relative, + PositionType::Absolute => stretch2::style::PositionType::Absolute, } } } -impl From for stretch::style::FlexWrap { +impl From for stretch2::style::FlexWrap { fn from(value: FlexWrap) -> Self { match value { - FlexWrap::NoWrap => stretch::style::FlexWrap::NoWrap, - FlexWrap::Wrap => stretch::style::FlexWrap::Wrap, - FlexWrap::WrapReverse => stretch::style::FlexWrap::WrapReverse, + FlexWrap::NoWrap => stretch2::style::FlexWrap::NoWrap, + FlexWrap::Wrap => stretch2::style::FlexWrap::Wrap, + FlexWrap::WrapReverse => stretch2::style::FlexWrap::WrapReverse, } } } diff --git a/crates/bevy_ui/src/flex/mod.rs b/crates/bevy_ui/src/flex/mod.rs index 8cb7fcd17a69b..55454d31c722b 100644 --- a/crates/bevy_ui/src/flex/mod.rs +++ b/crates/bevy_ui/src/flex/mod.rs @@ -14,11 +14,11 @@ use bevy_transform::components::Transform; use bevy_utils::HashMap; use bevy_window::{Window, WindowId, WindowScaleFactorChanged, Windows}; use std::fmt; -use stretch::{number::Number, Stretch}; +use stretch2::{number::Number, Stretch}; pub struct FlexSurface { - entity_to_stretch: HashMap, - window_nodes: HashMap, + entity_to_stretch: HashMap, + window_nodes: HashMap, stretch: Stretch, } @@ -30,8 +30,8 @@ unsafe impl Sync for FlexSurface {} fn _assert_send_sync_flex_surface_impl_safe() { fn _assert_send_sync() {} - _assert_send_sync::>(); - _assert_send_sync::>(); + _assert_send_sync::>(); + _assert_send_sync::>(); // FIXME https://github.com/vislyhq/stretch/issues/69 // _assert_send_sync::(); } @@ -62,7 +62,7 @@ impl FlexSurface { let stretch_style = convert::from_style(scale_factor, style); let stretch_node = self.entity_to_stretch.entry(entity).or_insert_with(|| { added = true; - stretch.new_node(stretch_style, Vec::new()).unwrap() + stretch.new_node(stretch_style, &Vec::new()).unwrap() }); if !added { @@ -81,25 +81,27 @@ impl FlexSurface { ) { let stretch = &mut self.stretch; let stretch_style = convert::from_style(scale_factor, style); - let measure = Box::new(move |constraints: stretch::geometry::Size| { - let mut size = convert::from_f32_size(scale_factor, calculated_size.size); - match (constraints.width, constraints.height) { - (Number::Undefined, Number::Undefined) => {} - (Number::Defined(width), Number::Undefined) => { - size.height = width * size.height / size.width; - size.width = width; + let measure = stretch2::node::MeasureFunc::Boxed(Box::new( + move |constraints: stretch2::geometry::Size| { + let mut size = convert::from_f32_size(scale_factor, calculated_size.size); + match (constraints.width, constraints.height) { + (Number::Undefined, Number::Undefined) => {} + (Number::Defined(width), Number::Undefined) => { + size.height = width * size.height / size.width; + size.width = width; + } + (Number::Undefined, Number::Defined(height)) => { + size.width = height * size.width / size.height; + size.height = height; + } + (Number::Defined(width), Number::Defined(height)) => { + size.width = width; + size.height = height; + } } - (Number::Undefined, Number::Defined(height)) => { - size.width = height * size.width / size.height; - size.height = height; - } - (Number::Defined(width), Number::Defined(height)) => { - size.width = width; - size.height = height; - } - } - Ok(size) - }); + size + }, + )); if let Some(stretch_node) = self.entity_to_stretch.get(&entity) { self.stretch @@ -129,7 +131,7 @@ without UI components as a child of an entity with UI components, results may be let stretch_node = self.entity_to_stretch.get(&entity).unwrap(); self.stretch - .set_children(*stretch_node, stretch_children) + .set_children(*stretch_node, &stretch_children) .unwrap(); } @@ -137,17 +139,17 @@ without UI components as a child of an entity with UI components, results may be let stretch = &mut self.stretch; let node = self.window_nodes.entry(window.id()).or_insert_with(|| { stretch - .new_node(stretch::style::Style::default(), Vec::new()) + .new_node(stretch2::style::Style::default(), &Vec::new()) .unwrap() }); stretch .set_style( *node, - stretch::style::Style { - size: stretch::geometry::Size { - width: stretch::style::Dimension::Points(window.physical_width() as f32), - height: stretch::style::Dimension::Points(window.physical_height() as f32), + stretch2::style::Style { + size: stretch2::geometry::Size { + width: stretch2::style::Dimension::Points(window.physical_width() as f32), + height: stretch2::style::Dimension::Points(window.physical_height() as f32), }, ..Default::default() }, @@ -163,21 +165,21 @@ without UI components as a child of an entity with UI components, results may be let stretch_node = self.window_nodes.get(&window_id).unwrap(); let child_nodes = children .map(|e| *self.entity_to_stretch.get(&e).unwrap()) - .collect::>(); + .collect::>(); self.stretch - .set_children(*stretch_node, child_nodes) + .set_children(*stretch_node, &child_nodes) .unwrap(); } pub fn compute_window_layouts(&mut self) { for window_node in self.window_nodes.values() { self.stretch - .compute_layout(*window_node, stretch::geometry::Size::undefined()) + .compute_layout(*window_node, stretch2::geometry::Size::undefined()) .unwrap(); } } - pub fn get_layout(&self, entity: Entity) -> Result<&stretch::result::Layout, FlexError> { + pub fn get_layout(&self, entity: Entity) -> Result<&stretch2::result::Layout, FlexError> { if let Some(stretch_node) = self.entity_to_stretch.get(&entity) { self.stretch .layout(*stretch_node) @@ -195,7 +197,7 @@ with UI components as a child of an entity without UI components, results may be #[derive(Debug)] pub enum FlexError { InvalidHierarchy, - StretchError(stretch::Error), + StretchError(stretch2::Error), } #[allow(clippy::too_many_arguments, clippy::type_complexity)] From 20dbdd266d17d3805f6ae002a00d25ecd71e7a60 Mon Sep 17 00:00:00 2001 From: Cole Poirier Date: Tue, 10 May 2022 15:34:14 -0700 Subject: [PATCH 02/15] depend on @mockersf's pr to stretch2 fixing relative positioning --- crates/bevy_ui/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/Cargo.toml b/crates/bevy_ui/Cargo.toml index 81e954e28f572..0d54decd55e4f 100644 --- a/crates/bevy_ui/Cargo.toml +++ b/crates/bevy_ui/Cargo.toml @@ -29,7 +29,7 @@ bevy_window = { path = "../bevy_window", version = "0.8.0-dev" } bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" } # other -stretch2 = "0.4.2" +stretch2 = { git = "https://github.com/mockersf/stretch/", branch = "remove_round_layout_changes" } serde = { version = "1", features = ["derive"] } smallvec = { version = "1.6", features = ["union", "const_generics"] } bytemuck = { version = "1.5", features = ["derive"] } From fea88fabe64d3988bf94d0251bb01afd79f476c0 Mon Sep 17 00:00:00 2001 From: Cole Poirier Date: Wed, 25 May 2022 14:21:03 -0700 Subject: [PATCH 03/15] update to stretch2 v0.4.3 --- crates/bevy_ui/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/Cargo.toml b/crates/bevy_ui/Cargo.toml index 0d54decd55e4f..2587ced6ba3ae 100644 --- a/crates/bevy_ui/Cargo.toml +++ b/crates/bevy_ui/Cargo.toml @@ -29,7 +29,7 @@ bevy_window = { path = "../bevy_window", version = "0.8.0-dev" } bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" } # other -stretch2 = { git = "https://github.com/mockersf/stretch/", branch = "remove_round_layout_changes" } +stretch2 = "0.4.3" serde = { version = "1", features = ["derive"] } smallvec = { version = "1.6", features = ["union", "const_generics"] } bytemuck = { version = "1.5", features = ["derive"] } From b8a9297c55827311f26f8fe8232e750876d626a2 Mon Sep 17 00:00:00 2001 From: Cole Poirier Date: Tue, 7 Jun 2022 13:13:46 -0700 Subject: [PATCH 04/15] depend on sprawl (what stretch2 was renames to) git main to see if this resolves CI check-bans failures --- crates/bevy_ui/Cargo.toml | 2 +- crates/bevy_ui/src/flex/convert.rs | 124 ++++++++++++++--------------- crates/bevy_ui/src/flex/mod.rs | 112 +++++++++++++------------- 3 files changed, 117 insertions(+), 121 deletions(-) diff --git a/crates/bevy_ui/Cargo.toml b/crates/bevy_ui/Cargo.toml index 2587ced6ba3ae..3725c0ce45bc0 100644 --- a/crates/bevy_ui/Cargo.toml +++ b/crates/bevy_ui/Cargo.toml @@ -29,7 +29,7 @@ bevy_window = { path = "../bevy_window", version = "0.8.0-dev" } bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" } # other -stretch2 = "0.4.3" +sprawl = { git = "https://github.com/DioxusLabs/sprawl.git" } serde = { version = "1", features = ["derive"] } smallvec = { version = "1.6", features = ["union", "const_generics"] } bytemuck = { version = "1.5", features = ["derive"] } diff --git a/crates/bevy_ui/src/flex/convert.rs b/crates/bevy_ui/src/flex/convert.rs index e37d049fb02d6..8ea399ad93c87 100644 --- a/crates/bevy_ui/src/flex/convert.rs +++ b/crates/bevy_ui/src/flex/convert.rs @@ -6,8 +6,8 @@ use crate::{ pub fn from_rect( scale_factor: f64, rect: UiRect, -) -> stretch2::geometry::Rect { - stretch2::geometry::Rect { +) -> sprawl::geometry::Rect { + sprawl::geometry::Rect { start: from_val(scale_factor, rect.left), end: from_val(scale_factor, rect.right), // NOTE: top and bottom are intentionally flipped. stretch has a flipped y-axis @@ -16,8 +16,8 @@ pub fn from_rect( } } -pub fn from_f32_size(scale_factor: f64, size: Size) -> stretch2::geometry::Size { - stretch2::geometry::Size { +pub fn from_f32_size(scale_factor: f64, size: Size) -> sprawl::geometry::Size { + sprawl::geometry::Size { width: (scale_factor * size.width as f64) as f32, height: (scale_factor * size.height as f64) as f32, } @@ -26,16 +26,16 @@ pub fn from_f32_size(scale_factor: f64, size: Size) -> stretch2::geometry:: pub fn from_val_size( scale_factor: f64, size: Size, -) -> stretch2::geometry::Size { - stretch2::geometry::Size { +) -> sprawl::geometry::Size { + sprawl::geometry::Size { width: from_val(scale_factor, size.width), height: from_val(scale_factor, size.height), } } -pub fn from_style(scale_factor: f64, value: &Style) -> stretch2::style::Style { - stretch2::style::Style { - overflow: stretch2::style::Overflow::Visible, +pub fn from_style(scale_factor: f64, value: &Style) -> sprawl::style::Style { + sprawl::style::Style { + overflow: sprawl::style::Overflow::Visible, display: value.display.into(), position_type: value.position_type.into(), direction: value.direction.into(), @@ -56,117 +56,117 @@ pub fn from_style(scale_factor: f64, value: &Style) -> stretch2::style::Style { min_size: from_val_size(scale_factor, value.min_size), max_size: from_val_size(scale_factor, value.max_size), aspect_ratio: match value.aspect_ratio { - Some(value) => stretch2::number::Number::Defined(value), - None => stretch2::number::Number::Undefined, + Some(value) => sprawl::number::Number::Defined(value), + None => sprawl::number::Number::Undefined, }, } } -pub fn from_val(scale_factor: f64, val: Val) -> stretch2::style::Dimension { +pub fn from_val(scale_factor: f64, val: Val) -> sprawl::style::Dimension { match val { - Val::Auto => stretch2::style::Dimension::Auto, - Val::Percent(value) => stretch2::style::Dimension::Percent(value / 100.0), - Val::Px(value) => stretch2::style::Dimension::Points((scale_factor * value as f64) as f32), - Val::Undefined => stretch2::style::Dimension::Undefined, + Val::Auto => sprawl::style::Dimension::Auto, + Val::Percent(value) => sprawl::style::Dimension::Percent(value / 100.0), + Val::Px(value) => sprawl::style::Dimension::Points((scale_factor * value as f64) as f32), + Val::Undefined => sprawl::style::Dimension::Undefined, } } -impl From for stretch2::style::AlignItems { +impl From for sprawl::style::AlignItems { fn from(value: AlignItems) -> Self { match value { - AlignItems::FlexStart => stretch2::style::AlignItems::FlexStart, - AlignItems::FlexEnd => stretch2::style::AlignItems::FlexEnd, - AlignItems::Center => stretch2::style::AlignItems::Center, - AlignItems::Baseline => stretch2::style::AlignItems::Baseline, - AlignItems::Stretch => stretch2::style::AlignItems::Stretch, + AlignItems::FlexStart => sprawl::style::AlignItems::FlexStart, + AlignItems::FlexEnd => sprawl::style::AlignItems::FlexEnd, + AlignItems::Center => sprawl::style::AlignItems::Center, + AlignItems::Baseline => sprawl::style::AlignItems::Baseline, + AlignItems::Stretch => sprawl::style::AlignItems::Stretch, } } } -impl From for stretch2::style::AlignSelf { +impl From for sprawl::style::AlignSelf { fn from(value: AlignSelf) -> Self { match value { - AlignSelf::Auto => stretch2::style::AlignSelf::Auto, - AlignSelf::FlexStart => stretch2::style::AlignSelf::FlexStart, - AlignSelf::FlexEnd => stretch2::style::AlignSelf::FlexEnd, - AlignSelf::Center => stretch2::style::AlignSelf::Center, - AlignSelf::Baseline => stretch2::style::AlignSelf::Baseline, - AlignSelf::Stretch => stretch2::style::AlignSelf::Stretch, + AlignSelf::Auto => sprawl::style::AlignSelf::Auto, + AlignSelf::FlexStart => sprawl::style::AlignSelf::FlexStart, + AlignSelf::FlexEnd => sprawl::style::AlignSelf::FlexEnd, + AlignSelf::Center => sprawl::style::AlignSelf::Center, + AlignSelf::Baseline => sprawl::style::AlignSelf::Baseline, + AlignSelf::Stretch => sprawl::style::AlignSelf::Stretch, } } } -impl From for stretch2::style::AlignContent { +impl From for sprawl::style::AlignContent { fn from(value: AlignContent) -> Self { match value { - AlignContent::FlexStart => stretch2::style::AlignContent::FlexStart, - AlignContent::FlexEnd => stretch2::style::AlignContent::FlexEnd, - AlignContent::Center => stretch2::style::AlignContent::Center, - AlignContent::Stretch => stretch2::style::AlignContent::Stretch, - AlignContent::SpaceBetween => stretch2::style::AlignContent::SpaceBetween, - AlignContent::SpaceAround => stretch2::style::AlignContent::SpaceAround, + AlignContent::FlexStart => sprawl::style::AlignContent::FlexStart, + AlignContent::FlexEnd => sprawl::style::AlignContent::FlexEnd, + AlignContent::Center => sprawl::style::AlignContent::Center, + AlignContent::Stretch => sprawl::style::AlignContent::Stretch, + AlignContent::SpaceBetween => sprawl::style::AlignContent::SpaceBetween, + AlignContent::SpaceAround => sprawl::style::AlignContent::SpaceAround, } } } -impl From for stretch2::style::Direction { +impl From for sprawl::style::Direction { fn from(value: Direction) -> Self { match value { - Direction::Inherit => stretch2::style::Direction::Inherit, - Direction::LeftToRight => stretch2::style::Direction::LTR, - Direction::RightToLeft => stretch2::style::Direction::RTL, + Direction::Inherit => sprawl::style::Direction::Inherit, + Direction::LeftToRight => sprawl::style::Direction::LTR, + Direction::RightToLeft => sprawl::style::Direction::RTL, } } } -impl From for stretch2::style::Display { +impl From for sprawl::style::Display { fn from(value: Display) -> Self { match value { - Display::Flex => stretch2::style::Display::Flex, - Display::None => stretch2::style::Display::None, + Display::Flex => sprawl::style::Display::Flex, + Display::None => sprawl::style::Display::None, } } } -impl From for stretch2::style::FlexDirection { +impl From for sprawl::style::FlexDirection { fn from(value: FlexDirection) -> Self { match value { - FlexDirection::Row => stretch2::style::FlexDirection::Row, - FlexDirection::Column => stretch2::style::FlexDirection::Column, - FlexDirection::RowReverse => stretch2::style::FlexDirection::RowReverse, - FlexDirection::ColumnReverse => stretch2::style::FlexDirection::ColumnReverse, + FlexDirection::Row => sprawl::style::FlexDirection::Row, + FlexDirection::Column => sprawl::style::FlexDirection::Column, + FlexDirection::RowReverse => sprawl::style::FlexDirection::RowReverse, + FlexDirection::ColumnReverse => sprawl::style::FlexDirection::ColumnReverse, } } } -impl From for stretch2::style::JustifyContent { +impl From for sprawl::style::JustifyContent { fn from(value: JustifyContent) -> Self { match value { - JustifyContent::FlexStart => stretch2::style::JustifyContent::FlexStart, - JustifyContent::FlexEnd => stretch2::style::JustifyContent::FlexEnd, - JustifyContent::Center => stretch2::style::JustifyContent::Center, - JustifyContent::SpaceBetween => stretch2::style::JustifyContent::SpaceBetween, - JustifyContent::SpaceAround => stretch2::style::JustifyContent::SpaceAround, - JustifyContent::SpaceEvenly => stretch2::style::JustifyContent::SpaceEvenly, + JustifyContent::FlexStart => sprawl::style::JustifyContent::FlexStart, + JustifyContent::FlexEnd => sprawl::style::JustifyContent::FlexEnd, + JustifyContent::Center => sprawl::style::JustifyContent::Center, + JustifyContent::SpaceBetween => sprawl::style::JustifyContent::SpaceBetween, + JustifyContent::SpaceAround => sprawl::style::JustifyContent::SpaceAround, + JustifyContent::SpaceEvenly => sprawl::style::JustifyContent::SpaceEvenly, } } } -impl From for stretch2::style::PositionType { +impl From for sprawl::style::PositionType { fn from(value: PositionType) -> Self { match value { - PositionType::Relative => stretch2::style::PositionType::Relative, - PositionType::Absolute => stretch2::style::PositionType::Absolute, + PositionType::Relative => sprawl::style::PositionType::Relative, + PositionType::Absolute => sprawl::style::PositionType::Absolute, } } } -impl From for stretch2::style::FlexWrap { +impl From for sprawl::style::FlexWrap { fn from(value: FlexWrap) -> Self { match value { - FlexWrap::NoWrap => stretch2::style::FlexWrap::NoWrap, - FlexWrap::Wrap => stretch2::style::FlexWrap::Wrap, - FlexWrap::WrapReverse => stretch2::style::FlexWrap::WrapReverse, + FlexWrap::NoWrap => sprawl::style::FlexWrap::NoWrap, + FlexWrap::Wrap => sprawl::style::FlexWrap::Wrap, + FlexWrap::WrapReverse => sprawl::style::FlexWrap::WrapReverse, } } } diff --git a/crates/bevy_ui/src/flex/mod.rs b/crates/bevy_ui/src/flex/mod.rs index 55454d31c722b..66c217cb05de6 100644 --- a/crates/bevy_ui/src/flex/mod.rs +++ b/crates/bevy_ui/src/flex/mod.rs @@ -13,16 +13,16 @@ use bevy_math::Vec2; use bevy_transform::components::Transform; use bevy_utils::HashMap; use bevy_window::{Window, WindowId, WindowScaleFactorChanged, Windows}; +use sprawl::{number::Number, Sprawl}; use std::fmt; -use stretch2::{number::Number, Stretch}; pub struct FlexSurface { - entity_to_stretch: HashMap, - window_nodes: HashMap, - stretch: Stretch, + entity_to_sprawl: HashMap, + window_nodes: HashMap, + sprawl: Sprawl, } -// SAFE: as long as MeasureFunc is Send + Sync. https://github.com/vislyhq/stretch/issues/69 +// SAFE: as long as MeasureFunc is Send + Sync. https://github.com/vislyhq/sprawl/issues/69 // TODO: remove allow on lint - https://github.com/bevyengine/bevy/issues/3666 #[allow(clippy::non_send_fields_in_send_ty)] unsafe impl Send for FlexSurface {} @@ -30,16 +30,16 @@ unsafe impl Sync for FlexSurface {} fn _assert_send_sync_flex_surface_impl_safe() { fn _assert_send_sync() {} - _assert_send_sync::>(); - _assert_send_sync::>(); - // FIXME https://github.com/vislyhq/stretch/issues/69 - // _assert_send_sync::(); + _assert_send_sync::>(); + _assert_send_sync::>(); + // FIXME https://github.com/vislyhq/sprawl/issues/69 + // _assert_send_sync::(); } impl fmt::Debug for FlexSurface { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("FlexSurface") - .field("entity_to_stretch", &self.entity_to_stretch) + .field("entity_to_sprawl", &self.entity_to_sprawl) .field("window_nodes", &self.window_nodes) .finish() } @@ -48,9 +48,9 @@ impl fmt::Debug for FlexSurface { impl Default for FlexSurface { fn default() -> Self { Self { - entity_to_stretch: Default::default(), + entity_to_sprawl: Default::default(), window_nodes: Default::default(), - stretch: Stretch::new(), + sprawl: Sprawl::new(), } } } @@ -58,17 +58,15 @@ impl Default for FlexSurface { impl FlexSurface { pub fn upsert_node(&mut self, entity: Entity, style: &Style, scale_factor: f64) { let mut added = false; - let stretch = &mut self.stretch; - let stretch_style = convert::from_style(scale_factor, style); - let stretch_node = self.entity_to_stretch.entry(entity).or_insert_with(|| { + let sprawl = &mut self.sprawl; + let sprawl_style = convert::from_style(scale_factor, style); + let sprawl_node = self.entity_to_sprawl.entry(entity).or_insert_with(|| { added = true; - stretch.new_node(stretch_style, &Vec::new()).unwrap() + sprawl.new_node(sprawl_style, &Vec::new()).unwrap() }); if !added { - self.stretch - .set_style(*stretch_node, stretch_style) - .unwrap(); + self.sprawl.set_style(*sprawl_node, sprawl_style).unwrap(); } } @@ -79,10 +77,10 @@ impl FlexSurface { calculated_size: CalculatedSize, scale_factor: f64, ) { - let stretch = &mut self.stretch; - let stretch_style = convert::from_style(scale_factor, style); - let measure = stretch2::node::MeasureFunc::Boxed(Box::new( - move |constraints: stretch2::geometry::Size| { + let sprawl = &mut self.sprawl; + let sprawl_style = convert::from_style(scale_factor, style); + let measure = sprawl::node::MeasureFunc::Boxed(Box::new( + move |constraints: sprawl::geometry::Size| { let mut size = convert::from_f32_size(scale_factor, calculated_size.size); match (constraints.width, constraints.height) { (Number::Undefined, Number::Undefined) => {} @@ -103,24 +101,22 @@ impl FlexSurface { }, )); - if let Some(stretch_node) = self.entity_to_stretch.get(&entity) { - self.stretch - .set_style(*stretch_node, stretch_style) - .unwrap(); - self.stretch - .set_measure(*stretch_node, Some(measure)) + if let Some(sprawl_node) = self.entity_to_sprawl.get(&entity) { + self.sprawl.set_style(*sprawl_node, sprawl_style).unwrap(); + self.sprawl + .set_measure(*sprawl_node, Some(measure)) .unwrap(); } else { - let stretch_node = stretch.new_leaf(stretch_style, measure).unwrap(); - self.entity_to_stretch.insert(entity, stretch_node); + let sprawl_node = sprawl.new_leaf(sprawl_style, measure).unwrap(); + self.entity_to_sprawl.insert(entity, sprawl_node); } } pub fn update_children(&mut self, entity: Entity, children: &Children) { - let mut stretch_children = Vec::with_capacity(children.len()); + let mut sprawl_children = Vec::with_capacity(children.len()); for child in children.iter() { - if let Some(stretch_node) = self.entity_to_stretch.get(child) { - stretch_children.push(*stretch_node); + if let Some(sprawl_node) = self.entity_to_sprawl.get(child) { + sprawl_children.push(*sprawl_node); } else { warn!( "Unstyled child in a UI entity hierarchy. You are using an entity \ @@ -129,27 +125,27 @@ without UI components as a child of an entity with UI components, results may be } } - let stretch_node = self.entity_to_stretch.get(&entity).unwrap(); - self.stretch - .set_children(*stretch_node, &stretch_children) + let sprawl_node = self.entity_to_sprawl.get(&entity).unwrap(); + self.sprawl + .set_children(*sprawl_node, &sprawl_children) .unwrap(); } pub fn update_window(&mut self, window: &Window) { - let stretch = &mut self.stretch; + let sprawl = &mut self.sprawl; let node = self.window_nodes.entry(window.id()).or_insert_with(|| { - stretch - .new_node(stretch2::style::Style::default(), &Vec::new()) + sprawl + .new_node(sprawl::style::Style::default(), &Vec::new()) .unwrap() }); - stretch + sprawl .set_style( *node, - stretch2::style::Style { - size: stretch2::geometry::Size { - width: stretch2::style::Dimension::Points(window.physical_width() as f32), - height: stretch2::style::Dimension::Points(window.physical_height() as f32), + sprawl::style::Style { + size: sprawl::geometry::Size { + width: sprawl::style::Dimension::Points(window.physical_width() as f32), + height: sprawl::style::Dimension::Points(window.physical_height() as f32), }, ..Default::default() }, @@ -162,28 +158,28 @@ without UI components as a child of an entity with UI components, results may be window_id: WindowId, children: impl Iterator, ) { - let stretch_node = self.window_nodes.get(&window_id).unwrap(); + let sprawl_node = self.window_nodes.get(&window_id).unwrap(); let child_nodes = children - .map(|e| *self.entity_to_stretch.get(&e).unwrap()) - .collect::>(); - self.stretch - .set_children(*stretch_node, &child_nodes) + .map(|e| *self.entity_to_sprawl.get(&e).unwrap()) + .collect::>(); + self.sprawl + .set_children(*sprawl_node, &child_nodes) .unwrap(); } pub fn compute_window_layouts(&mut self) { for window_node in self.window_nodes.values() { - self.stretch - .compute_layout(*window_node, stretch2::geometry::Size::undefined()) + self.sprawl + .compute_layout(*window_node, sprawl::geometry::Size::undefined()) .unwrap(); } } - pub fn get_layout(&self, entity: Entity) -> Result<&stretch2::result::Layout, FlexError> { - if let Some(stretch_node) = self.entity_to_stretch.get(&entity) { - self.stretch - .layout(*stretch_node) - .map_err(FlexError::StretchError) + pub fn get_layout(&self, entity: Entity) -> Result<&sprawl::result::Layout, FlexError> { + if let Some(sprawl_node) = self.entity_to_sprawl.get(&entity) { + self.sprawl + .layout(*sprawl_node) + .map_err(FlexError::SprawlError) } else { warn!( "Styled child in a non-UI entity hierarchy. You are using an entity \ @@ -197,7 +193,7 @@ with UI components as a child of an entity without UI components, results may be #[derive(Debug)] pub enum FlexError { InvalidHierarchy, - StretchError(stretch2::Error), + SprawlError(sprawl::Error), } #[allow(clippy::too_many_arguments, clippy::type_complexity)] From 24be2b7a85e1c7e91367c3a7adb15a366e5d2180 Mon Sep 17 00:00:00 2001 From: Cole Poirier Date: Wed, 8 Jun 2022 20:51:40 -0700 Subject: [PATCH 05/15] depend on sprawl git colepoirier to see if removing heapless from sprawl dependencies allows this to pass check-bans ci --- crates/bevy_ui/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/Cargo.toml b/crates/bevy_ui/Cargo.toml index 3725c0ce45bc0..5e4f9f141a52b 100644 --- a/crates/bevy_ui/Cargo.toml +++ b/crates/bevy_ui/Cargo.toml @@ -29,7 +29,7 @@ bevy_window = { path = "../bevy_window", version = "0.8.0-dev" } bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" } # other -sprawl = { git = "https://github.com/DioxusLabs/sprawl.git" } +sprawl = { git = "https://github.com/colepoirier/sprawl.git" } serde = { version = "1", features = ["derive"] } smallvec = { version = "1.6", features = ["union", "const_generics"] } bytemuck = { version = "1.5", features = ["derive"] } From b998d001b72a95ccf001246265c993e48108cb0d Mon Sep 17 00:00:00 2001 From: Cole Poirier Date: Wed, 8 Jun 2022 21:13:29 -0700 Subject: [PATCH 06/15] add version to sprawl git dependency --- crates/bevy_ui/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/Cargo.toml b/crates/bevy_ui/Cargo.toml index 5e4f9f141a52b..30c4982e7e870 100644 --- a/crates/bevy_ui/Cargo.toml +++ b/crates/bevy_ui/Cargo.toml @@ -29,7 +29,7 @@ bevy_window = { path = "../bevy_window", version = "0.8.0-dev" } bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" } # other -sprawl = { git = "https://github.com/colepoirier/sprawl.git" } +sprawl = { git = "https://github.com/colepoirier/sprawl.git", version = "0.1.0" } serde = { version = "1", features = ["derive"] } smallvec = { version = "1.6", features = ["union", "const_generics"] } bytemuck = { version = "1.5", features = ["derive"] } From de81161f4b4c3a6bb23efa7583d33ce6184603d6 Mon Sep 17 00:00:00 2001 From: Cole Poirier Date: Wed, 8 Jun 2022 21:13:49 -0700 Subject: [PATCH 07/15] sprawl::result was renamed to sprawl::layout --- crates/bevy_ui/src/flex/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/flex/mod.rs b/crates/bevy_ui/src/flex/mod.rs index 66c217cb05de6..1a72f7eaa5f6d 100644 --- a/crates/bevy_ui/src/flex/mod.rs +++ b/crates/bevy_ui/src/flex/mod.rs @@ -175,7 +175,7 @@ without UI components as a child of an entity with UI components, results may be } } - pub fn get_layout(&self, entity: Entity) -> Result<&sprawl::result::Layout, FlexError> { + pub fn get_layout(&self, entity: Entity) -> Result<&sprawl::layout::Layout, FlexError> { if let Some(sprawl_node) = self.entity_to_sprawl.get(&entity) { self.sprawl .layout(*sprawl_node) From 166cbfa1949e5489e4d0aaa060a606671c2a37fd Mon Sep 17 00:00:00 2001 From: Cole Poirier Date: Fri, 10 Jun 2022 11:46:05 -0700 Subject: [PATCH 08/15] sprawl renamed to taffy, some types removed --- crates/bevy_ui/Cargo.toml | 2 +- crates/bevy_ui/src/flex/convert.rs | 126 +++++++++++++---------------- crates/bevy_ui/src/flex/mod.rs | 38 ++++----- 3 files changed, 77 insertions(+), 89 deletions(-) diff --git a/crates/bevy_ui/Cargo.toml b/crates/bevy_ui/Cargo.toml index 30c4982e7e870..cc01517110b92 100644 --- a/crates/bevy_ui/Cargo.toml +++ b/crates/bevy_ui/Cargo.toml @@ -29,7 +29,7 @@ bevy_window = { path = "../bevy_window", version = "0.8.0-dev" } bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" } # other -sprawl = { git = "https://github.com/colepoirier/sprawl.git", version = "0.1.0" } +taffy = "0.1.0" serde = { version = "1", features = ["derive"] } smallvec = { version = "1.6", features = ["union", "const_generics"] } bytemuck = { version = "1.5", features = ["derive"] } diff --git a/crates/bevy_ui/src/flex/convert.rs b/crates/bevy_ui/src/flex/convert.rs index 8ea399ad93c87..d49f36afa79e5 100644 --- a/crates/bevy_ui/src/flex/convert.rs +++ b/crates/bevy_ui/src/flex/convert.rs @@ -6,8 +6,8 @@ use crate::{ pub fn from_rect( scale_factor: f64, rect: UiRect, -) -> sprawl::geometry::Rect { - sprawl::geometry::Rect { +) -> taffy::geometry::Rect { + taffy::geometry::Rect { start: from_val(scale_factor, rect.left), end: from_val(scale_factor, rect.right), // NOTE: top and bottom are intentionally flipped. stretch has a flipped y-axis @@ -16,8 +16,8 @@ pub fn from_rect( } } -pub fn from_f32_size(scale_factor: f64, size: Size) -> sprawl::geometry::Size { - sprawl::geometry::Size { +pub fn from_f32_size(scale_factor: f64, size: Size) -> taffy::geometry::Size { + taffy::geometry::Size { width: (scale_factor * size.width as f64) as f32, height: (scale_factor * size.height as f64) as f32, } @@ -26,19 +26,17 @@ pub fn from_f32_size(scale_factor: f64, size: Size) -> sprawl::geometry::Si pub fn from_val_size( scale_factor: f64, size: Size, -) -> sprawl::geometry::Size { - sprawl::geometry::Size { +) -> taffy::geometry::Size { + taffy::geometry::Size { width: from_val(scale_factor, size.width), height: from_val(scale_factor, size.height), } } -pub fn from_style(scale_factor: f64, value: &Style) -> sprawl::style::Style { - sprawl::style::Style { - overflow: sprawl::style::Overflow::Visible, +pub fn from_style(scale_factor: f64, value: &Style) -> taffy::style::Style { + taffy::style::Style { display: value.display.into(), position_type: value.position_type.into(), - direction: value.direction.into(), flex_direction: value.flex_direction.into(), flex_wrap: value.flex_wrap.into(), align_items: value.align_items.into(), @@ -56,117 +54,107 @@ pub fn from_style(scale_factor: f64, value: &Style) -> sprawl::style::Style { min_size: from_val_size(scale_factor, value.min_size), max_size: from_val_size(scale_factor, value.max_size), aspect_ratio: match value.aspect_ratio { - Some(value) => sprawl::number::Number::Defined(value), - None => sprawl::number::Number::Undefined, + Some(value) => taffy::number::Number::Defined(value), + None => taffy::number::Number::Undefined, }, } } -pub fn from_val(scale_factor: f64, val: Val) -> sprawl::style::Dimension { +pub fn from_val(scale_factor: f64, val: Val) -> taffy::style::Dimension { match val { - Val::Auto => sprawl::style::Dimension::Auto, - Val::Percent(value) => sprawl::style::Dimension::Percent(value / 100.0), - Val::Px(value) => sprawl::style::Dimension::Points((scale_factor * value as f64) as f32), - Val::Undefined => sprawl::style::Dimension::Undefined, + Val::Auto => taffy::style::Dimension::Auto, + Val::Percent(value) => taffy::style::Dimension::Percent(value / 100.0), + Val::Px(value) => taffy::style::Dimension::Points((scale_factor * value as f64) as f32), + Val::Undefined => taffy::style::Dimension::Undefined, } } -impl From for sprawl::style::AlignItems { +impl From for taffy::style::AlignItems { fn from(value: AlignItems) -> Self { match value { - AlignItems::FlexStart => sprawl::style::AlignItems::FlexStart, - AlignItems::FlexEnd => sprawl::style::AlignItems::FlexEnd, - AlignItems::Center => sprawl::style::AlignItems::Center, - AlignItems::Baseline => sprawl::style::AlignItems::Baseline, - AlignItems::Stretch => sprawl::style::AlignItems::Stretch, + AlignItems::FlexStart => taffy::style::AlignItems::FlexStart, + AlignItems::FlexEnd => taffy::style::AlignItems::FlexEnd, + AlignItems::Center => taffy::style::AlignItems::Center, + AlignItems::Baseline => taffy::style::AlignItems::Baseline, + AlignItems::Stretch => taffy::style::AlignItems::Stretch, } } } -impl From for sprawl::style::AlignSelf { +impl From for taffy::style::AlignSelf { fn from(value: AlignSelf) -> Self { match value { - AlignSelf::Auto => sprawl::style::AlignSelf::Auto, - AlignSelf::FlexStart => sprawl::style::AlignSelf::FlexStart, - AlignSelf::FlexEnd => sprawl::style::AlignSelf::FlexEnd, - AlignSelf::Center => sprawl::style::AlignSelf::Center, - AlignSelf::Baseline => sprawl::style::AlignSelf::Baseline, - AlignSelf::Stretch => sprawl::style::AlignSelf::Stretch, + AlignSelf::Auto => taffy::style::AlignSelf::Auto, + AlignSelf::FlexStart => taffy::style::AlignSelf::FlexStart, + AlignSelf::FlexEnd => taffy::style::AlignSelf::FlexEnd, + AlignSelf::Center => taffy::style::AlignSelf::Center, + AlignSelf::Baseline => taffy::style::AlignSelf::Baseline, + AlignSelf::Stretch => taffy::style::AlignSelf::Stretch, } } } -impl From for sprawl::style::AlignContent { +impl From for taffy::style::AlignContent { fn from(value: AlignContent) -> Self { match value { - AlignContent::FlexStart => sprawl::style::AlignContent::FlexStart, - AlignContent::FlexEnd => sprawl::style::AlignContent::FlexEnd, - AlignContent::Center => sprawl::style::AlignContent::Center, - AlignContent::Stretch => sprawl::style::AlignContent::Stretch, - AlignContent::SpaceBetween => sprawl::style::AlignContent::SpaceBetween, - AlignContent::SpaceAround => sprawl::style::AlignContent::SpaceAround, + AlignContent::FlexStart => taffy::style::AlignContent::FlexStart, + AlignContent::FlexEnd => taffy::style::AlignContent::FlexEnd, + AlignContent::Center => taffy::style::AlignContent::Center, + AlignContent::Stretch => taffy::style::AlignContent::Stretch, + AlignContent::SpaceBetween => taffy::style::AlignContent::SpaceBetween, + AlignContent::SpaceAround => taffy::style::AlignContent::SpaceAround, } } } -impl From for sprawl::style::Direction { - fn from(value: Direction) -> Self { - match value { - Direction::Inherit => sprawl::style::Direction::Inherit, - Direction::LeftToRight => sprawl::style::Direction::LTR, - Direction::RightToLeft => sprawl::style::Direction::RTL, - } - } -} - -impl From for sprawl::style::Display { +impl From for taffy::style::Display { fn from(value: Display) -> Self { match value { - Display::Flex => sprawl::style::Display::Flex, - Display::None => sprawl::style::Display::None, + Display::Flex => taffy::style::Display::Flex, + Display::None => taffy::style::Display::None, } } } -impl From for sprawl::style::FlexDirection { +impl From for taffy::style::FlexDirection { fn from(value: FlexDirection) -> Self { match value { - FlexDirection::Row => sprawl::style::FlexDirection::Row, - FlexDirection::Column => sprawl::style::FlexDirection::Column, - FlexDirection::RowReverse => sprawl::style::FlexDirection::RowReverse, - FlexDirection::ColumnReverse => sprawl::style::FlexDirection::ColumnReverse, + FlexDirection::Row => taffy::style::FlexDirection::Row, + FlexDirection::Column => taffy::style::FlexDirection::Column, + FlexDirection::RowReverse => taffy::style::FlexDirection::RowReverse, + FlexDirection::ColumnReverse => taffy::style::FlexDirection::ColumnReverse, } } } -impl From for sprawl::style::JustifyContent { +impl From for taffy::style::JustifyContent { fn from(value: JustifyContent) -> Self { match value { - JustifyContent::FlexStart => sprawl::style::JustifyContent::FlexStart, - JustifyContent::FlexEnd => sprawl::style::JustifyContent::FlexEnd, - JustifyContent::Center => sprawl::style::JustifyContent::Center, - JustifyContent::SpaceBetween => sprawl::style::JustifyContent::SpaceBetween, - JustifyContent::SpaceAround => sprawl::style::JustifyContent::SpaceAround, - JustifyContent::SpaceEvenly => sprawl::style::JustifyContent::SpaceEvenly, + JustifyContent::FlexStart => taffy::style::JustifyContent::FlexStart, + JustifyContent::FlexEnd => taffy::style::JustifyContent::FlexEnd, + JustifyContent::Center => taffy::style::JustifyContent::Center, + JustifyContent::SpaceBetween => taffy::style::JustifyContent::SpaceBetween, + JustifyContent::SpaceAround => taffy::style::JustifyContent::SpaceAround, + JustifyContent::SpaceEvenly => taffy::style::JustifyContent::SpaceEvenly, } } } -impl From for sprawl::style::PositionType { +impl From for taffy::style::PositionType { fn from(value: PositionType) -> Self { match value { - PositionType::Relative => sprawl::style::PositionType::Relative, - PositionType::Absolute => sprawl::style::PositionType::Absolute, + PositionType::Relative => taffy::style::PositionType::Relative, + PositionType::Absolute => taffy::style::PositionType::Absolute, } } } -impl From for sprawl::style::FlexWrap { +impl From for taffy::style::FlexWrap { fn from(value: FlexWrap) -> Self { match value { - FlexWrap::NoWrap => sprawl::style::FlexWrap::NoWrap, - FlexWrap::Wrap => sprawl::style::FlexWrap::Wrap, - FlexWrap::WrapReverse => sprawl::style::FlexWrap::WrapReverse, + FlexWrap::NoWrap => taffy::style::FlexWrap::NoWrap, + FlexWrap::Wrap => taffy::style::FlexWrap::Wrap, + FlexWrap::WrapReverse => taffy::style::FlexWrap::WrapReverse, } } } diff --git a/crates/bevy_ui/src/flex/mod.rs b/crates/bevy_ui/src/flex/mod.rs index 1a72f7eaa5f6d..7658be7bee79c 100644 --- a/crates/bevy_ui/src/flex/mod.rs +++ b/crates/bevy_ui/src/flex/mod.rs @@ -13,13 +13,13 @@ use bevy_math::Vec2; use bevy_transform::components::Transform; use bevy_utils::HashMap; use bevy_window::{Window, WindowId, WindowScaleFactorChanged, Windows}; -use sprawl::{number::Number, Sprawl}; use std::fmt; +use taffy::{number::Number, Taffy}; pub struct FlexSurface { - entity_to_sprawl: HashMap, - window_nodes: HashMap, - sprawl: Sprawl, + entity_to_sprawl: HashMap, + window_nodes: HashMap, + sprawl: Taffy, } // SAFE: as long as MeasureFunc is Send + Sync. https://github.com/vislyhq/sprawl/issues/69 @@ -30,8 +30,8 @@ unsafe impl Sync for FlexSurface {} fn _assert_send_sync_flex_surface_impl_safe() { fn _assert_send_sync() {} - _assert_send_sync::>(); - _assert_send_sync::>(); + _assert_send_sync::>(); + _assert_send_sync::>(); // FIXME https://github.com/vislyhq/sprawl/issues/69 // _assert_send_sync::(); } @@ -50,7 +50,7 @@ impl Default for FlexSurface { Self { entity_to_sprawl: Default::default(), window_nodes: Default::default(), - sprawl: Sprawl::new(), + sprawl: Taffy::new(), } } } @@ -79,8 +79,8 @@ impl FlexSurface { ) { let sprawl = &mut self.sprawl; let sprawl_style = convert::from_style(scale_factor, style); - let measure = sprawl::node::MeasureFunc::Boxed(Box::new( - move |constraints: sprawl::geometry::Size| { + let measure = taffy::node::MeasureFunc::Boxed(Box::new( + move |constraints: taffy::geometry::Size| { let mut size = convert::from_f32_size(scale_factor, calculated_size.size); match (constraints.width, constraints.height) { (Number::Undefined, Number::Undefined) => {} @@ -135,17 +135,17 @@ without UI components as a child of an entity with UI components, results may be let sprawl = &mut self.sprawl; let node = self.window_nodes.entry(window.id()).or_insert_with(|| { sprawl - .new_node(sprawl::style::Style::default(), &Vec::new()) + .new_node(taffy::style::Style::default(), &Vec::new()) .unwrap() }); sprawl .set_style( *node, - sprawl::style::Style { - size: sprawl::geometry::Size { - width: sprawl::style::Dimension::Points(window.physical_width() as f32), - height: sprawl::style::Dimension::Points(window.physical_height() as f32), + taffy::style::Style { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(window.physical_width() as f32), + height: taffy::style::Dimension::Points(window.physical_height() as f32), }, ..Default::default() }, @@ -161,7 +161,7 @@ without UI components as a child of an entity with UI components, results may be let sprawl_node = self.window_nodes.get(&window_id).unwrap(); let child_nodes = children .map(|e| *self.entity_to_sprawl.get(&e).unwrap()) - .collect::>(); + .collect::>(); self.sprawl .set_children(*sprawl_node, &child_nodes) .unwrap(); @@ -170,16 +170,16 @@ without UI components as a child of an entity with UI components, results may be pub fn compute_window_layouts(&mut self) { for window_node in self.window_nodes.values() { self.sprawl - .compute_layout(*window_node, sprawl::geometry::Size::undefined()) + .compute_layout(*window_node, taffy::geometry::Size::undefined()) .unwrap(); } } - pub fn get_layout(&self, entity: Entity) -> Result<&sprawl::layout::Layout, FlexError> { + pub fn get_layout(&self, entity: Entity) -> Result<&taffy::layout::Layout, FlexError> { if let Some(sprawl_node) = self.entity_to_sprawl.get(&entity) { self.sprawl .layout(*sprawl_node) - .map_err(FlexError::SprawlError) + .map_err(FlexError::TaffyError) } else { warn!( "Styled child in a non-UI entity hierarchy. You are using an entity \ @@ -193,7 +193,7 @@ with UI components as a child of an entity without UI components, results may be #[derive(Debug)] pub enum FlexError { InvalidHierarchy, - SprawlError(sprawl::Error), + TaffyError(taffy::Error), } #[allow(clippy::too_many_arguments, clippy::type_complexity)] From e7d340730a3419d85466c09f71ad43d9b13b40fd Mon Sep 17 00:00:00 2001 From: Cole Poirier Date: Fri, 10 Jun 2022 14:52:58 -0700 Subject: [PATCH 09/15] don't use bevy_ui::Direction for now as it isn't implemented in taffy --- crates/bevy_ui/src/flex/convert.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ui/src/flex/convert.rs b/crates/bevy_ui/src/flex/convert.rs index d49f36afa79e5..57c17cdad9dcc 100644 --- a/crates/bevy_ui/src/flex/convert.rs +++ b/crates/bevy_ui/src/flex/convert.rs @@ -1,6 +1,6 @@ use crate::{ - AlignContent, AlignItems, AlignSelf, Direction, Display, FlexDirection, FlexWrap, - JustifyContent, PositionType, Size, Style, UiRect, Val, + AlignContent, AlignItems, AlignSelf, Display, FlexDirection, FlexWrap, JustifyContent, + PositionType, Size, Style, UiRect, Val, }; pub fn from_rect( From 8036ac17bfb8f25c74e10292b9fb96fecafa6c4d Mon Sep 17 00:00:00 2001 From: Cole Poirier Date: Fri, 10 Jun 2022 14:54:51 -0700 Subject: [PATCH 10/15] change all remaining occurences of 'sprawl' to 'taffy' --- crates/bevy_ui/src/flex/mod.rs | 76 ++++++++++++++++------------------ 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/crates/bevy_ui/src/flex/mod.rs b/crates/bevy_ui/src/flex/mod.rs index 7658be7bee79c..0575ac4771ee0 100644 --- a/crates/bevy_ui/src/flex/mod.rs +++ b/crates/bevy_ui/src/flex/mod.rs @@ -17,12 +17,12 @@ use std::fmt; use taffy::{number::Number, Taffy}; pub struct FlexSurface { - entity_to_sprawl: HashMap, + entity_to_taffy: HashMap, window_nodes: HashMap, - sprawl: Taffy, + taffy: Taffy, } -// SAFE: as long as MeasureFunc is Send + Sync. https://github.com/vislyhq/sprawl/issues/69 +// SAFE: as long as MeasureFunc is Send + Sync. https://github.com/vislyhq/taffy/issues/69 // TODO: remove allow on lint - https://github.com/bevyengine/bevy/issues/3666 #[allow(clippy::non_send_fields_in_send_ty)] unsafe impl Send for FlexSurface {} @@ -32,14 +32,14 @@ fn _assert_send_sync_flex_surface_impl_safe() { fn _assert_send_sync() {} _assert_send_sync::>(); _assert_send_sync::>(); - // FIXME https://github.com/vislyhq/sprawl/issues/69 - // _assert_send_sync::(); + // FIXME https://github.com/vislyhq/taffy/issues/69 + // _assert_send_sync::(); } impl fmt::Debug for FlexSurface { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("FlexSurface") - .field("entity_to_sprawl", &self.entity_to_sprawl) + .field("entity_to_taffy", &self.entity_to_taffy) .field("window_nodes", &self.window_nodes) .finish() } @@ -48,9 +48,9 @@ impl fmt::Debug for FlexSurface { impl Default for FlexSurface { fn default() -> Self { Self { - entity_to_sprawl: Default::default(), + entity_to_taffy: Default::default(), window_nodes: Default::default(), - sprawl: Taffy::new(), + taffy: Taffy::new(), } } } @@ -58,15 +58,15 @@ impl Default for FlexSurface { impl FlexSurface { pub fn upsert_node(&mut self, entity: Entity, style: &Style, scale_factor: f64) { let mut added = false; - let sprawl = &mut self.sprawl; - let sprawl_style = convert::from_style(scale_factor, style); - let sprawl_node = self.entity_to_sprawl.entry(entity).or_insert_with(|| { + let taffy = &mut self.taffy; + let taffy_style = convert::from_style(scale_factor, style); + let taffy_node = self.entity_to_taffy.entry(entity).or_insert_with(|| { added = true; - sprawl.new_node(sprawl_style, &Vec::new()).unwrap() + taffy.new_node(taffy_style, &Vec::new()).unwrap() }); if !added { - self.sprawl.set_style(*sprawl_node, sprawl_style).unwrap(); + self.taffy.set_style(*taffy_node, taffy_style).unwrap(); } } @@ -77,8 +77,8 @@ impl FlexSurface { calculated_size: CalculatedSize, scale_factor: f64, ) { - let sprawl = &mut self.sprawl; - let sprawl_style = convert::from_style(scale_factor, style); + let taffy = &mut self.taffy; + let taffy_style = convert::from_style(scale_factor, style); let measure = taffy::node::MeasureFunc::Boxed(Box::new( move |constraints: taffy::geometry::Size| { let mut size = convert::from_f32_size(scale_factor, calculated_size.size); @@ -101,22 +101,20 @@ impl FlexSurface { }, )); - if let Some(sprawl_node) = self.entity_to_sprawl.get(&entity) { - self.sprawl.set_style(*sprawl_node, sprawl_style).unwrap(); - self.sprawl - .set_measure(*sprawl_node, Some(measure)) - .unwrap(); + if let Some(taffy_node) = self.entity_to_taffy.get(&entity) { + self.taffy.set_style(*taffy_node, taffy_style).unwrap(); + self.taffy.set_measure(*taffy_node, Some(measure)).unwrap(); } else { - let sprawl_node = sprawl.new_leaf(sprawl_style, measure).unwrap(); - self.entity_to_sprawl.insert(entity, sprawl_node); + let taffy_node = taffy.new_leaf(taffy_style, measure).unwrap(); + self.entity_to_taffy.insert(entity, taffy_node); } } pub fn update_children(&mut self, entity: Entity, children: &Children) { - let mut sprawl_children = Vec::with_capacity(children.len()); + let mut taffy_children = Vec::with_capacity(children.len()); for child in children.iter() { - if let Some(sprawl_node) = self.entity_to_sprawl.get(child) { - sprawl_children.push(*sprawl_node); + if let Some(taffy_node) = self.entity_to_taffy.get(child) { + taffy_children.push(*taffy_node); } else { warn!( "Unstyled child in a UI entity hierarchy. You are using an entity \ @@ -125,21 +123,21 @@ without UI components as a child of an entity with UI components, results may be } } - let sprawl_node = self.entity_to_sprawl.get(&entity).unwrap(); - self.sprawl - .set_children(*sprawl_node, &sprawl_children) + let taffy_node = self.entity_to_taffy.get(&entity).unwrap(); + self.taffy + .set_children(*taffy_node, &taffy_children) .unwrap(); } pub fn update_window(&mut self, window: &Window) { - let sprawl = &mut self.sprawl; + let taffy = &mut self.taffy; let node = self.window_nodes.entry(window.id()).or_insert_with(|| { - sprawl + taffy .new_node(taffy::style::Style::default(), &Vec::new()) .unwrap() }); - sprawl + taffy .set_style( *node, taffy::style::Style { @@ -158,27 +156,25 @@ without UI components as a child of an entity with UI components, results may be window_id: WindowId, children: impl Iterator, ) { - let sprawl_node = self.window_nodes.get(&window_id).unwrap(); + let taffy_node = self.window_nodes.get(&window_id).unwrap(); let child_nodes = children - .map(|e| *self.entity_to_sprawl.get(&e).unwrap()) + .map(|e| *self.entity_to_taffy.get(&e).unwrap()) .collect::>(); - self.sprawl - .set_children(*sprawl_node, &child_nodes) - .unwrap(); + self.taffy.set_children(*taffy_node, &child_nodes).unwrap(); } pub fn compute_window_layouts(&mut self) { for window_node in self.window_nodes.values() { - self.sprawl + self.taffy .compute_layout(*window_node, taffy::geometry::Size::undefined()) .unwrap(); } } pub fn get_layout(&self, entity: Entity) -> Result<&taffy::layout::Layout, FlexError> { - if let Some(sprawl_node) = self.entity_to_sprawl.get(&entity) { - self.sprawl - .layout(*sprawl_node) + if let Some(taffy_node) = self.entity_to_taffy.get(&entity) { + self.taffy + .layout(*taffy_node) .map_err(FlexError::TaffyError) } else { warn!( From 94797bcf29a8281d32a0701932e5bacd85b09366 Mon Sep 17 00:00:00 2001 From: Cole Poirier Date: Fri, 10 Jun 2022 14:57:34 -0700 Subject: [PATCH 11/15] fix capitaliztion of taffy->Taffy type in comment --- crates/bevy_ui/src/flex/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/flex/mod.rs b/crates/bevy_ui/src/flex/mod.rs index 0575ac4771ee0..35986fbdab719 100644 --- a/crates/bevy_ui/src/flex/mod.rs +++ b/crates/bevy_ui/src/flex/mod.rs @@ -33,7 +33,7 @@ fn _assert_send_sync_flex_surface_impl_safe() { _assert_send_sync::>(); _assert_send_sync::>(); // FIXME https://github.com/vislyhq/taffy/issues/69 - // _assert_send_sync::(); + // _assert_send_sync::(); } impl fmt::Debug for FlexSurface { From 8e3af1a7bfa26d9b3fea18388406c4e0e5b524e5 Mon Sep 17 00:00:00 2001 From: Cole Poirier Date: Fri, 10 Jun 2022 14:59:08 -0700 Subject: [PATCH 12/15] link to stretch issue that there is not a corresponding issue for in taffy --- crates/bevy_ui/src/flex/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/flex/mod.rs b/crates/bevy_ui/src/flex/mod.rs index 35986fbdab719..3ac9f20d4b4ee 100644 --- a/crates/bevy_ui/src/flex/mod.rs +++ b/crates/bevy_ui/src/flex/mod.rs @@ -32,7 +32,7 @@ fn _assert_send_sync_flex_surface_impl_safe() { fn _assert_send_sync() {} _assert_send_sync::>(); _assert_send_sync::>(); - // FIXME https://github.com/vislyhq/taffy/issues/69 + // FIXME https://github.com/vislyhq/stretch/issues/69 // _assert_send_sync::(); } From 5eef35a0dbd9b87e511e58e4010dd904044bdfb2 Mon Sep 17 00:00:00 2001 From: Cole Poirier Date: Fri, 10 Jun 2022 15:00:10 -0700 Subject: [PATCH 13/15] link to stretch issue that there is not a corresponding issue for in taffy in second location in the file --- crates/bevy_ui/src/flex/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ui/src/flex/mod.rs b/crates/bevy_ui/src/flex/mod.rs index 3ac9f20d4b4ee..420050f76404c 100644 --- a/crates/bevy_ui/src/flex/mod.rs +++ b/crates/bevy_ui/src/flex/mod.rs @@ -22,7 +22,7 @@ pub struct FlexSurface { taffy: Taffy, } -// SAFE: as long as MeasureFunc is Send + Sync. https://github.com/vislyhq/taffy/issues/69 +// SAFE: as long as MeasureFunc is Send + Sync. https://github.com/vislyhq/stretch/issues/69 // TODO: remove allow on lint - https://github.com/bevyengine/bevy/issues/3666 #[allow(clippy::non_send_fields_in_send_ty)] unsafe impl Send for FlexSurface {} From 32d6f1ff72cc717fd19d2970a0d5764f77149daa Mon Sep 17 00:00:00 2001 From: Cole Poirier Date: Fri, 10 Jun 2022 18:35:13 -0700 Subject: [PATCH 14/15] update MeasureFunc Send + Sync issue url to point to the migrated issue on the taffy repo --- crates/bevy_ui/src/flex/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ui/src/flex/mod.rs b/crates/bevy_ui/src/flex/mod.rs index 420050f76404c..5dc1e36e5ae2f 100644 --- a/crates/bevy_ui/src/flex/mod.rs +++ b/crates/bevy_ui/src/flex/mod.rs @@ -22,7 +22,7 @@ pub struct FlexSurface { taffy: Taffy, } -// SAFE: as long as MeasureFunc is Send + Sync. https://github.com/vislyhq/stretch/issues/69 +// SAFE: as long as MeasureFunc is Send + Sync. https://github.com/DioxusLabs/taffy/issues/146 // TODO: remove allow on lint - https://github.com/bevyengine/bevy/issues/3666 #[allow(clippy::non_send_fields_in_send_ty)] unsafe impl Send for FlexSurface {} @@ -32,7 +32,7 @@ fn _assert_send_sync_flex_surface_impl_safe() { fn _assert_send_sync() {} _assert_send_sync::>(); _assert_send_sync::>(); - // FIXME https://github.com/vislyhq/stretch/issues/69 + // FIXME https://github.com/DioxusLabs/taffy/issues/146 // _assert_send_sync::(); } From 2ed6eccd95c616799ba71ee54b233084c91eec11 Mon Sep 17 00:00:00 2001 From: Cole Poirier Date: Fri, 10 Jun 2022 18:36:26 -0700 Subject: [PATCH 15/15] remove stretch from deny.toml because we no longer depend on stretch --- deny.toml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/deny.toml b/deny.toml index d004aae6b4076..3537967a7e2d1 100644 --- a/deny.toml +++ b/deny.toml @@ -25,11 +25,6 @@ allow = [ ] default = "deny" -[[licenses.clarify]] -name = "stretch" -expression = "MIT" -license-files = [] - [bans] multiple-versions = "deny" wildcards = "deny"