Skip to content

Commit 86dd6f0

Browse files
committed
depend on dioxus(and bevy)-maintained fork of stretch (taffy) (#4716)
# Objective DioxusLabs and Bevy have taken over maintaining what was our abandoned ui layout dependency [stretch](https://github.com/vislyhq/stretch). Dioxus' fork has had a lot of work done on it by @alice-i-cecile, @Weibye , @jkelleyrtp, @mockersf, @HackerFoo, @TimJentzsch and a dozen other contributors and now is in much better shape than stretch was. The updated crate is called taffy and is available on github [here](https://github.com/DioxusLabs/taffy) ([taffy](https://crates.io/crates/taffy) on crates.io). The goal of this PR is to replace stretch v0.3.2 with taffy v0.1.0. ## Solution I changed the bevy_ui Cargo.toml to depend on taffy instead of stretch and fixed all the errors rustc complained about. --- ## Changelog Changed bevy_ui layout dependency from stretch to taffy (the maintained fork of stretch). fixes #677 ## Migration Guide The public api of taffy is different from that of stretch so please advise me on what to do here @alice-i-cecile.
1 parent 114d169 commit 86dd6f0

File tree

4 files changed

+133
-154
lines changed

4 files changed

+133
-154
lines changed

crates/bevy_ui/Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ bevy_hierarchy = { path = "../bevy_hierarchy", version = "0.8.0-dev" }
1919
bevy_input = { path = "../bevy_input", version = "0.8.0-dev" }
2020
bevy_log = { path = "../bevy_log", version = "0.8.0-dev" }
2121
bevy_math = { path = "../bevy_math", version = "0.8.0-dev" }
22-
bevy_reflect = { path = "../bevy_reflect", version = "0.8.0-dev", features = ["bevy"] }
22+
bevy_reflect = { path = "../bevy_reflect", version = "0.8.0-dev", features = [
23+
"bevy",
24+
] }
2325
bevy_render = { path = "../bevy_render", version = "0.8.0-dev" }
2426
bevy_sprite = { path = "../bevy_sprite", version = "0.8.0-dev" }
2527
bevy_text = { path = "../bevy_text", version = "0.8.0-dev" }
@@ -28,7 +30,7 @@ bevy_window = { path = "../bevy_window", version = "0.8.0-dev" }
2830
bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" }
2931

3032
# other
31-
stretch = "0.3.2"
33+
taffy = "0.1.0"
3234
serde = { version = "1", features = ["derive"] }
3335
smallvec = { version = "1.6", features = ["union", "const_generics"] }
3436
bytemuck = { version = "1.5", features = ["derive"] }

crates/bevy_ui/src/flex/convert.rs

+59-71
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use crate::{
2-
AlignContent, AlignItems, AlignSelf, Direction, Display, FlexDirection, FlexWrap,
3-
JustifyContent, PositionType, Size, Style, UiRect, Val,
2+
AlignContent, AlignItems, AlignSelf, Display, FlexDirection, FlexWrap, JustifyContent,
3+
PositionType, Size, Style, UiRect, Val,
44
};
55

66
pub fn from_rect(
77
scale_factor: f64,
88
rect: UiRect<Val>,
9-
) -> stretch::geometry::Rect<stretch::style::Dimension> {
10-
stretch::geometry::Rect {
9+
) -> taffy::geometry::Rect<taffy::style::Dimension> {
10+
taffy::geometry::Rect {
1111
start: from_val(scale_factor, rect.left),
1212
end: from_val(scale_factor, rect.right),
1313
// NOTE: top and bottom are intentionally flipped. stretch has a flipped y-axis
@@ -16,8 +16,8 @@ pub fn from_rect(
1616
}
1717
}
1818

19-
pub fn from_f32_size(scale_factor: f64, size: Size<f32>) -> stretch::geometry::Size<f32> {
20-
stretch::geometry::Size {
19+
pub fn from_f32_size(scale_factor: f64, size: Size<f32>) -> taffy::geometry::Size<f32> {
20+
taffy::geometry::Size {
2121
width: (scale_factor * size.width as f64) as f32,
2222
height: (scale_factor * size.height as f64) as f32,
2323
}
@@ -26,19 +26,17 @@ pub fn from_f32_size(scale_factor: f64, size: Size<f32>) -> stretch::geometry::S
2626
pub fn from_val_size(
2727
scale_factor: f64,
2828
size: Size<Val>,
29-
) -> stretch::geometry::Size<stretch::style::Dimension> {
30-
stretch::geometry::Size {
29+
) -> taffy::geometry::Size<taffy::style::Dimension> {
30+
taffy::geometry::Size {
3131
width: from_val(scale_factor, size.width),
3232
height: from_val(scale_factor, size.height),
3333
}
3434
}
3535

36-
pub fn from_style(scale_factor: f64, value: &Style) -> stretch::style::Style {
37-
stretch::style::Style {
38-
overflow: stretch::style::Overflow::Visible,
36+
pub fn from_style(scale_factor: f64, value: &Style) -> taffy::style::Style {
37+
taffy::style::Style {
3938
display: value.display.into(),
4039
position_type: value.position_type.into(),
41-
direction: value.direction.into(),
4240
flex_direction: value.flex_direction.into(),
4341
flex_wrap: value.flex_wrap.into(),
4442
align_items: value.align_items.into(),
@@ -56,117 +54,107 @@ pub fn from_style(scale_factor: f64, value: &Style) -> stretch::style::Style {
5654
min_size: from_val_size(scale_factor, value.min_size),
5755
max_size: from_val_size(scale_factor, value.max_size),
5856
aspect_ratio: match value.aspect_ratio {
59-
Some(value) => stretch::number::Number::Defined(value),
60-
None => stretch::number::Number::Undefined,
57+
Some(value) => taffy::number::Number::Defined(value),
58+
None => taffy::number::Number::Undefined,
6159
},
6260
}
6361
}
6462

65-
pub fn from_val(scale_factor: f64, val: Val) -> stretch::style::Dimension {
63+
pub fn from_val(scale_factor: f64, val: Val) -> taffy::style::Dimension {
6664
match val {
67-
Val::Auto => stretch::style::Dimension::Auto,
68-
Val::Percent(value) => stretch::style::Dimension::Percent(value / 100.0),
69-
Val::Px(value) => stretch::style::Dimension::Points((scale_factor * value as f64) as f32),
70-
Val::Undefined => stretch::style::Dimension::Undefined,
65+
Val::Auto => taffy::style::Dimension::Auto,
66+
Val::Percent(value) => taffy::style::Dimension::Percent(value / 100.0),
67+
Val::Px(value) => taffy::style::Dimension::Points((scale_factor * value as f64) as f32),
68+
Val::Undefined => taffy::style::Dimension::Undefined,
7169
}
7270
}
7371

74-
impl From<AlignItems> for stretch::style::AlignItems {
72+
impl From<AlignItems> for taffy::style::AlignItems {
7573
fn from(value: AlignItems) -> Self {
7674
match value {
77-
AlignItems::FlexStart => stretch::style::AlignItems::FlexStart,
78-
AlignItems::FlexEnd => stretch::style::AlignItems::FlexEnd,
79-
AlignItems::Center => stretch::style::AlignItems::Center,
80-
AlignItems::Baseline => stretch::style::AlignItems::Baseline,
81-
AlignItems::Stretch => stretch::style::AlignItems::Stretch,
75+
AlignItems::FlexStart => taffy::style::AlignItems::FlexStart,
76+
AlignItems::FlexEnd => taffy::style::AlignItems::FlexEnd,
77+
AlignItems::Center => taffy::style::AlignItems::Center,
78+
AlignItems::Baseline => taffy::style::AlignItems::Baseline,
79+
AlignItems::Stretch => taffy::style::AlignItems::Stretch,
8280
}
8381
}
8482
}
8583

86-
impl From<AlignSelf> for stretch::style::AlignSelf {
84+
impl From<AlignSelf> for taffy::style::AlignSelf {
8785
fn from(value: AlignSelf) -> Self {
8886
match value {
89-
AlignSelf::Auto => stretch::style::AlignSelf::Auto,
90-
AlignSelf::FlexStart => stretch::style::AlignSelf::FlexStart,
91-
AlignSelf::FlexEnd => stretch::style::AlignSelf::FlexEnd,
92-
AlignSelf::Center => stretch::style::AlignSelf::Center,
93-
AlignSelf::Baseline => stretch::style::AlignSelf::Baseline,
94-
AlignSelf::Stretch => stretch::style::AlignSelf::Stretch,
87+
AlignSelf::Auto => taffy::style::AlignSelf::Auto,
88+
AlignSelf::FlexStart => taffy::style::AlignSelf::FlexStart,
89+
AlignSelf::FlexEnd => taffy::style::AlignSelf::FlexEnd,
90+
AlignSelf::Center => taffy::style::AlignSelf::Center,
91+
AlignSelf::Baseline => taffy::style::AlignSelf::Baseline,
92+
AlignSelf::Stretch => taffy::style::AlignSelf::Stretch,
9593
}
9694
}
9795
}
9896

99-
impl From<AlignContent> for stretch::style::AlignContent {
97+
impl From<AlignContent> for taffy::style::AlignContent {
10098
fn from(value: AlignContent) -> Self {
10199
match value {
102-
AlignContent::FlexStart => stretch::style::AlignContent::FlexStart,
103-
AlignContent::FlexEnd => stretch::style::AlignContent::FlexEnd,
104-
AlignContent::Center => stretch::style::AlignContent::Center,
105-
AlignContent::Stretch => stretch::style::AlignContent::Stretch,
106-
AlignContent::SpaceBetween => stretch::style::AlignContent::SpaceBetween,
107-
AlignContent::SpaceAround => stretch::style::AlignContent::SpaceAround,
100+
AlignContent::FlexStart => taffy::style::AlignContent::FlexStart,
101+
AlignContent::FlexEnd => taffy::style::AlignContent::FlexEnd,
102+
AlignContent::Center => taffy::style::AlignContent::Center,
103+
AlignContent::Stretch => taffy::style::AlignContent::Stretch,
104+
AlignContent::SpaceBetween => taffy::style::AlignContent::SpaceBetween,
105+
AlignContent::SpaceAround => taffy::style::AlignContent::SpaceAround,
108106
}
109107
}
110108
}
111109

112-
impl From<Direction> for stretch::style::Direction {
113-
fn from(value: Direction) -> Self {
114-
match value {
115-
Direction::Inherit => stretch::style::Direction::Inherit,
116-
Direction::LeftToRight => stretch::style::Direction::LTR,
117-
Direction::RightToLeft => stretch::style::Direction::RTL,
118-
}
119-
}
120-
}
121-
122-
impl From<Display> for stretch::style::Display {
110+
impl From<Display> for taffy::style::Display {
123111
fn from(value: Display) -> Self {
124112
match value {
125-
Display::Flex => stretch::style::Display::Flex,
126-
Display::None => stretch::style::Display::None,
113+
Display::Flex => taffy::style::Display::Flex,
114+
Display::None => taffy::style::Display::None,
127115
}
128116
}
129117
}
130118

131-
impl From<FlexDirection> for stretch::style::FlexDirection {
119+
impl From<FlexDirection> for taffy::style::FlexDirection {
132120
fn from(value: FlexDirection) -> Self {
133121
match value {
134-
FlexDirection::Row => stretch::style::FlexDirection::Row,
135-
FlexDirection::Column => stretch::style::FlexDirection::Column,
136-
FlexDirection::RowReverse => stretch::style::FlexDirection::RowReverse,
137-
FlexDirection::ColumnReverse => stretch::style::FlexDirection::ColumnReverse,
122+
FlexDirection::Row => taffy::style::FlexDirection::Row,
123+
FlexDirection::Column => taffy::style::FlexDirection::Column,
124+
FlexDirection::RowReverse => taffy::style::FlexDirection::RowReverse,
125+
FlexDirection::ColumnReverse => taffy::style::FlexDirection::ColumnReverse,
138126
}
139127
}
140128
}
141129

142-
impl From<JustifyContent> for stretch::style::JustifyContent {
130+
impl From<JustifyContent> for taffy::style::JustifyContent {
143131
fn from(value: JustifyContent) -> Self {
144132
match value {
145-
JustifyContent::FlexStart => stretch::style::JustifyContent::FlexStart,
146-
JustifyContent::FlexEnd => stretch::style::JustifyContent::FlexEnd,
147-
JustifyContent::Center => stretch::style::JustifyContent::Center,
148-
JustifyContent::SpaceBetween => stretch::style::JustifyContent::SpaceBetween,
149-
JustifyContent::SpaceAround => stretch::style::JustifyContent::SpaceAround,
150-
JustifyContent::SpaceEvenly => stretch::style::JustifyContent::SpaceEvenly,
133+
JustifyContent::FlexStart => taffy::style::JustifyContent::FlexStart,
134+
JustifyContent::FlexEnd => taffy::style::JustifyContent::FlexEnd,
135+
JustifyContent::Center => taffy::style::JustifyContent::Center,
136+
JustifyContent::SpaceBetween => taffy::style::JustifyContent::SpaceBetween,
137+
JustifyContent::SpaceAround => taffy::style::JustifyContent::SpaceAround,
138+
JustifyContent::SpaceEvenly => taffy::style::JustifyContent::SpaceEvenly,
151139
}
152140
}
153141
}
154142

155-
impl From<PositionType> for stretch::style::PositionType {
143+
impl From<PositionType> for taffy::style::PositionType {
156144
fn from(value: PositionType) -> Self {
157145
match value {
158-
PositionType::Relative => stretch::style::PositionType::Relative,
159-
PositionType::Absolute => stretch::style::PositionType::Absolute,
146+
PositionType::Relative => taffy::style::PositionType::Relative,
147+
PositionType::Absolute => taffy::style::PositionType::Absolute,
160148
}
161149
}
162150
}
163151

164-
impl From<FlexWrap> for stretch::style::FlexWrap {
152+
impl From<FlexWrap> for taffy::style::FlexWrap {
165153
fn from(value: FlexWrap) -> Self {
166154
match value {
167-
FlexWrap::NoWrap => stretch::style::FlexWrap::NoWrap,
168-
FlexWrap::Wrap => stretch::style::FlexWrap::Wrap,
169-
FlexWrap::WrapReverse => stretch::style::FlexWrap::WrapReverse,
155+
FlexWrap::NoWrap => taffy::style::FlexWrap::NoWrap,
156+
FlexWrap::Wrap => taffy::style::FlexWrap::Wrap,
157+
FlexWrap::WrapReverse => taffy::style::FlexWrap::WrapReverse,
170158
}
171159
}
172160
}

0 commit comments

Comments
 (0)