Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Merged by Bors] - Upgrade to Taffy 0.3.3 #7859

Closed
wants to merge 88 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
5573ea6
changes:
ickshonpe Feb 2, 2023
26eeca7
changes:
ickshonpe Feb 3, 2023
b274e9e
Changed inset doc comments
ickshonpe Feb 3, 2023
9cffde9
cargo fmt --all
ickshonpe Feb 3, 2023
8ed613f
fixed UiRect doc tests
ickshonpe Feb 3, 2023
9bdf85e
Another Doc comment fix
ickshonpe Feb 3, 2023
54f68ce
fix doc comments
ickshonpe Feb 3, 2023
ce52876
renamed Inset to Position
ickshonpe Feb 3, 2023
abdef25
cargo fmt --all
ickshonpe Feb 3, 2023
5e814cf
update ui example
ickshonpe Feb 3, 2023
2087be6
Removed Position struct, added its fields directly to Style
ickshonpe Feb 3, 2023
99b93f8
fix doc comments
ickshonpe Feb 3, 2023
5ab3ffd
fix doc comment
ickshonpe Feb 3, 2023
eb88a97
added some simple tests
ickshonpe Feb 7, 2023
6113911
cargo fmt
ickshonpe Feb 7, 2023
cc8d6d4
Merge branch 'main' of https://github.com/bevyengine/bevy into remove…
ickshonpe Feb 8, 2023
684b32a
changes:
ickshonpe Feb 8, 2023
4b2c93b
improved the `Breadth` doc comment description
ickshonpe Feb 8, 2023
9597f15
impl From<UiRect<Breadth> for <UiRect<Val> and use it to convert the…
ickshonpe Feb 8, 2023
7d02b25
cargo fmt --all
ickshonpe Feb 8, 2023
7ef9ca4
added plugin type registrations for `Breadth` and `UiRect<Breadth>`
ickshonpe Feb 9, 2023
087fc9e
Improved the doc comments for `Breadth`
ickshonpe Feb 9, 2023
d558224
collected and tidied up test imports
ickshonpe Feb 9, 2023
3a09af9
changes:
ickshonpe Feb 17, 2023
b1712b8
cargo fmt
ickshonpe Feb 17, 2023
080aae7
fix lints
ickshonpe Feb 17, 2023
9c4c01d
cargo fmt
ickshonpe Feb 17, 2023
8934a6f
impl Measure for Fn
ickshonpe Feb 18, 2023
fc9b2d9
Changes:
ickshonpe Feb 19, 2023
f7d20ea
cargo fmt --all
ickshonpe Feb 19, 2023
13091a3
remove `text_constraint` function
ickshonpe Feb 21, 2023
cfdb649
Merge branch 'split-text-system' of https://github.com/ickshonpe/bevy…
ickshonpe Feb 21, 2023
621a117
Merge branch 'add-TextLayoutInfo-to-TextBundle' into split-text-system
ickshonpe Feb 21, 2023
3981c7f
add TextLayoutInfo to default TextBundle
ickshonpe Feb 21, 2023
b004072
changes:
ickshonpe Feb 21, 2023
af7b6f2
changes:
ickshonpe Feb 21, 2023
2280bb0
changes:
ickshonpe Feb 21, 2023
f510899
Clean up and bug fixes.
ickshonpe Feb 21, 2023
95d7c96
simplified text size code
ickshonpe Feb 21, 2023
91a05d2
fix derivable impls
ickshonpe Feb 21, 2023
c6602c7
changed taffy dependecy, fixed `PositionType` conversion
ickshonpe Feb 25, 2023
48746e0
Merge remote-tracking branch 'origin/remove-val-undefined' into taffy…
ickshonpe Feb 25, 2023
637711e
fix missed merge conflict
ickshonpe Feb 25, 2023
84ac898
updated taffy version
ickshonpe Feb 25, 2023
48c456e
Merge branch 'split-text-system' into taffy-latest
ickshonpe Feb 25, 2023
547f99c
fix available space import
ickshonpe Feb 25, 2023
cc4ec14
Changed taffy dependency version to "0.3.3"
ickshonpe Mar 1, 2023
1471f3b
Merge remote-tracking branch 'origin/remove-val-undefined' into taffy…
ickshonpe Mar 1, 2023
02679cd
update convert
ickshonpe Mar 1, 2023
aec59ec
Merge branch 'taffy-latest' of https://github.com/ickshonpe/bevy into…
ickshonpe Mar 1, 2023
2572c39
Fixed `FlexSurface` for Taffy 0.3.3
ickshonpe Mar 1, 2023
a513acb
Merge branch 'breadth' of https://github.com/ickshonpe/bevy into taff…
ickshonpe Mar 1, 2023
33c8e91
Changes:
ickshonpe Mar 1, 2023
796b2e1
cargo fmt --all
ickshonpe Mar 1, 2023
115f98c
Fixed some integration test complaints
ickshonpe Mar 1, 2023
492bbaf
Added a doc comment for the start variant of `JustifySelf`
ickshonpe Mar 1, 2023
21fd333
Register `JustifySelf` and `Size<Breadth>`
ickshonpe Mar 1, 2023
623c287
Tidied up imports
ickshonpe Mar 1, 2023
e5a6144
Removed Text2d changes.
ickshonpe Mar 1, 2023
035f0dc
Update crates/bevy_ui/src/ui_node.rs
ickshonpe Mar 1, 2023
6f32916
Removed `JustifySelf`
ickshonpe Mar 1, 2023
cfadf55
Merge branch 'taffy-0.3.3' of https://github.com/ickshonpe/bevy into …
ickshonpe Mar 1, 2023
3117ed5
Revert "Update crates/bevy_ui/src/ui_node.rs"
ickshonpe Mar 1, 2023
b2000fb
Revert "Removed `JustifySelf`"
ickshonpe Mar 1, 2023
b52f7ac
Revert "Removed Text2d changes."
ickshonpe Mar 1, 2023
333dda0
Revert "Tidied up imports"
ickshonpe Mar 1, 2023
0a99ab8
Revert "Register `JustifySelf` and `Size<Breadth>`"
ickshonpe Mar 1, 2023
e7665c1
Revert "Added a doc comment for the start variant of `JustifySelf`"
ickshonpe Mar 1, 2023
108d7a7
Revert "Fixed some integration test complaints"
ickshonpe Mar 1, 2023
6f70b0a
Revert "cargo fmt --all"
ickshonpe Mar 1, 2023
7405f47
Revert "Changes:"
ickshonpe Mar 1, 2023
c7b19e9
Revert "Merge branch 'breadth' of https://github.com/ickshonpe/bevy i…
ickshonpe Mar 1, 2023
1b2aece
Revert "Fixed `FlexSurface` for Taffy 0.3.3"
ickshonpe Mar 1, 2023
e897d42
Revert "Merge branch 'taffy-latest' of https://github.com/ickshonpe/b…
ickshonpe Mar 1, 2023
434db4f
Revert "update convert"
ickshonpe Mar 1, 2023
4383fe0
Revert "Merge remote-tracking branch 'origin/remove-val-undefined' in…
ickshonpe Mar 1, 2023
3db183f
changes:
ickshonpe Mar 2, 2023
1dc0c48
Made minor changes to flex module to support Taffy 0.3.3
ickshonpe Mar 2, 2023
dcfda78
Change margins conversion to map `Val::Undefined` to `LengthPercentag…
ickshonpe Mar 2, 2023
9d0bc99
Changed convert helper functions to private
ickshonpe Mar 2, 2023
d55df84
cargo fmt
ickshonpe Mar 2, 2023
5c814d2
renamed convert's helper functions for clarity
ickshonpe Mar 2, 2023
370b851
changes:
ickshonpe Mar 2, 2023
126c9fc
cargo fmt --all
ickshonpe Mar 2, 2023
65f732b
clean up convert
ickshonpe Mar 3, 2023
a89104e
cargo fmt --all
ickshonpe Mar 3, 2023
efb48ed
fix lints
ickshonpe Mar 3, 2023
5cf3bbe
Removed the `Unset` variant of `AlignItems` and the `Stretch` variant…
ickshonpe Mar 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bevy_window = { path = "../bevy_window", version = "0.9.0" }
bevy_utils = { path = "../bevy_utils", version = "0.9.0" }

# other
taffy = "0.2.2"
taffy = { version = "0.3.3", default-features = false, features = ["std"] }
serde = { version = "1", features = ["derive"] }
smallvec = { version = "1.6", features = ["union", "const_generics"] }
bytemuck = { version = "1.5", features = ["derive"] }
Expand Down
188 changes: 132 additions & 56 deletions crates/bevy_ui/src/flex/convert.rs
Original file line number Diff line number Diff line change
@@ -1,67 +1,136 @@
use taffy::style::LengthPercentageAuto;

use crate::{
AlignContent, AlignItems, AlignSelf, Display, FlexDirection, FlexWrap, JustifyContent,
PositionType, Size, Style, UiRect, Val,
};

pub fn from_rect(
scale_factor: f64,
rect: UiRect,
) -> taffy::geometry::Rect<taffy::style::Dimension> {
taffy::geometry::Rect {
left: from_val(scale_factor, rect.left),
right: from_val(scale_factor, rect.right),
top: from_val(scale_factor, rect.top),
bottom: from_val(scale_factor, rect.bottom),
impl Val {
fn scaled(self, scale_factor: f64) -> Self {
match self {
Val::Auto => Val::Auto,
Val::Percent(value) => Val::Percent(value),
Val::Px(value) => Val::Px((scale_factor * value as f64) as f32),
Val::Undefined => Val::Undefined,
}
}

fn to_inset(self) -> LengthPercentageAuto {
match self {
Val::Auto | Val::Undefined => taffy::style::LengthPercentageAuto::Auto,
Val::Percent(value) => taffy::style::LengthPercentageAuto::Percent(value / 100.0),
Val::Px(value) => taffy::style::LengthPercentageAuto::Points(value),
}
}
}

impl UiRect {
fn scaled(self, scale_factor: f64) -> Self {
Self {
left: self.left.scaled(scale_factor),
right: self.right.scaled(scale_factor),
top: self.top.scaled(scale_factor),
bottom: self.bottom.scaled(scale_factor),
}
}
}

impl Size {
fn scaled(self, scale_factor: f64) -> Self {
Self {
width: self.width.scaled(scale_factor),
height: self.height.scaled(scale_factor),
}
}
}

impl<T: From<Val>> From<UiRect> for taffy::prelude::Rect<T> {
fn from(value: UiRect) -> Self {
Self {
left: value.left.into(),
right: value.right.into(),
top: value.top.into(),
bottom: value.bottom.into(),
}
}
}

pub fn from_val_size(
scale_factor: f64,
size: Size,
) -> taffy::geometry::Size<taffy::style::Dimension> {
taffy::geometry::Size {
width: from_val(scale_factor, size.width),
height: from_val(scale_factor, size.height),
impl<T: From<Val>> From<Size> for taffy::prelude::Size<T> {
fn from(value: Size) -> Self {
Self {
width: value.width.into(),
height: value.height.into(),
}
}
}

impl From<Val> for taffy::style::Dimension {
fn from(value: Val) -> Self {
match value {
Val::Auto | Val::Undefined => taffy::style::Dimension::Auto,
Val::Percent(value) => taffy::style::Dimension::Percent(value / 100.0),
Val::Px(value) => taffy::style::Dimension::Points(value),
}
}
}

impl From<Val> for taffy::style::LengthPercentage {
fn from(value: Val) -> Self {
match value {
Val::Auto | Val::Undefined => taffy::style::LengthPercentage::Points(0.0),
Val::Percent(value) => taffy::style::LengthPercentage::Percent(value / 100.0),
Val::Px(value) => taffy::style::LengthPercentage::Points(value),
}
}
}

impl From<Val> for taffy::style::LengthPercentageAuto {
fn from(value: Val) -> Self {
match value {
Val::Auto => taffy::style::LengthPercentageAuto::Auto,
Val::Percent(value) => taffy::style::LengthPercentageAuto::Percent(value / 100.0),
Val::Px(value) => taffy::style::LengthPercentageAuto::Points(value),
Val::Undefined => taffy::style::LengthPercentageAuto::Points(0.),
}
}
}

pub fn from_style(scale_factor: f64, value: &Style) -> taffy::style::Style {
pub fn from_style(scale_factor: f64, style: &Style) -> taffy::style::Style {
taffy::style::Style {
display: value.display.into(),
position_type: value.position_type.into(),
flex_direction: value.flex_direction.into(),
flex_wrap: value.flex_wrap.into(),
align_items: value.align_items.into(),
align_self: value.align_self.into(),
align_content: value.align_content.into(),
justify_content: value.justify_content.into(),
position: from_rect(scale_factor, value.position),
margin: from_rect(scale_factor, value.margin),
padding: from_rect(scale_factor, value.padding),
border: from_rect(scale_factor, value.border),
flex_grow: value.flex_grow,
flex_shrink: value.flex_shrink,
flex_basis: from_val(scale_factor, value.flex_basis),
size: from_val_size(scale_factor, value.size),
min_size: from_val_size(scale_factor, value.min_size),
max_size: from_val_size(scale_factor, value.max_size),
aspect_ratio: value.aspect_ratio,
gap: from_val_size(scale_factor, value.gap),
}
}

pub fn from_val(scale_factor: f64, val: Val) -> taffy::style::Dimension {
match val {
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,
display: style.display.into(),
position: style.position_type.into(),
flex_direction: style.flex_direction.into(),
flex_wrap: style.flex_wrap.into(),
align_items: Some(style.align_items.into()),
align_self: style.align_self.into(),
align_content: Some(style.align_content.into()),
justify_content: Some(style.justify_content.into()),
inset: taffy::prelude::Rect {
left: style.position.left.scaled(scale_factor).to_inset(),
right: style.position.right.scaled(scale_factor).to_inset(),
top: style.position.top.scaled(scale_factor).to_inset(),
bottom: style.position.bottom.scaled(scale_factor).to_inset(),
},
margin: style.margin.scaled(scale_factor).into(),
padding: style.padding.scaled(scale_factor).into(),
border: style.border.scaled(scale_factor).into(),
flex_grow: style.flex_grow,
flex_shrink: style.flex_shrink,
flex_basis: style.flex_basis.scaled(scale_factor).into(),
size: style.size.scaled(scale_factor).into(),
min_size: style.size.scaled(scale_factor).into(),
max_size: style.size.scaled(scale_factor).into(),
aspect_ratio: style.aspect_ratio,
gap: style.gap.scaled(scale_factor).into(),
justify_self: None,
}
}

impl From<AlignItems> for taffy::style::AlignItems {
fn from(value: AlignItems) -> Self {
match value {
AlignItems::Start => taffy::style::AlignItems::Start,
AlignItems::End => taffy::style::AlignItems::End,
AlignItems::FlexStart => taffy::style::AlignItems::FlexStart,
AlignItems::FlexEnd => taffy::style::AlignItems::FlexEnd,
AlignItems::Center => taffy::style::AlignItems::Center,
Expand All @@ -71,28 +140,33 @@ impl From<AlignItems> for taffy::style::AlignItems {
}
}

impl From<AlignSelf> for taffy::style::AlignSelf {
impl From<AlignSelf> for Option<taffy::style::AlignSelf> {
fn from(value: AlignSelf) -> Self {
match value {
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,
AlignSelf::Auto => None,
AlignSelf::Start => taffy::style::AlignSelf::Start.into(),
AlignSelf::End => taffy::style::AlignSelf::End.into(),
AlignSelf::FlexStart => taffy::style::AlignSelf::FlexStart.into(),
AlignSelf::FlexEnd => taffy::style::AlignSelf::FlexEnd.into(),
AlignSelf::Center => taffy::style::AlignSelf::Center.into(),
AlignSelf::Baseline => taffy::style::AlignSelf::Baseline.into(),
AlignSelf::Stretch => taffy::style::AlignSelf::Stretch.into(),
}
}
}

impl From<AlignContent> for taffy::style::AlignContent {
fn from(value: AlignContent) -> Self {
match value {
AlignContent::Start => taffy::style::AlignContent::Start,
AlignContent::End => taffy::style::AlignContent::End,
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,
AlignContent::SpaceEvenly => taffy::style::AlignContent::SpaceEvenly,
}
}
}
Expand Down Expand Up @@ -120,6 +194,8 @@ impl From<FlexDirection> for taffy::style::FlexDirection {
impl From<JustifyContent> for taffy::style::JustifyContent {
fn from(value: JustifyContent) -> Self {
match value {
JustifyContent::Start => taffy::style::JustifyContent::Start,
JustifyContent::End => taffy::style::JustifyContent::End,
JustifyContent::FlexStart => taffy::style::JustifyContent::FlexStart,
JustifyContent::FlexEnd => taffy::style::JustifyContent::FlexEnd,
JustifyContent::Center => taffy::style::JustifyContent::Center,
Expand All @@ -130,11 +206,11 @@ impl From<JustifyContent> for taffy::style::JustifyContent {
}
}

impl From<PositionType> for taffy::style::PositionType {
impl From<PositionType> for taffy::style::Position {
fn from(value: PositionType) -> Self {
match value {
PositionType::Relative => taffy::style::PositionType::Relative,
PositionType::Absolute => taffy::style::PositionType::Absolute,
PositionType::Relative => taffy::style::Position::Relative,
PositionType::Absolute => taffy::style::Position::Absolute,
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions crates/bevy_ui/src/flex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use bevy_window::{PrimaryWindow, Window, WindowResolution, WindowScaleFactorChan
use std::fmt;
use taffy::{
prelude::{AvailableSpace, Size},
style_helpers::TaffyMaxContent,
Taffy,
};

Expand Down Expand Up @@ -61,14 +62,17 @@ impl FlexSurface {
pub fn upsert_node(&mut self, entity: Entity, style: &Style, scale_factor: f64) {
let mut added = false;
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;
taffy.new_leaf(taffy_style).unwrap()
taffy
.new_leaf(convert::from_style(scale_factor, style))
.unwrap()
});

if !added {
self.taffy.set_style(*taffy_node, taffy_style).unwrap();
self.taffy
.set_style(*taffy_node, convert::from_style(scale_factor, style))
.unwrap();
}
}

Expand Down
Loading