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

Remove Val::Undefined #7485

Merged
merged 31 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ea7bc05
change `Size` default width and height to `Val::Auto`
ickshonpe Feb 2, 2023
5573ea6
changes:
ickshonpe Feb 2, 2023
26eeca7
changes:
ickshonpe Feb 3, 2023
78fe6ad
Merge branch 'bevyengine:main' into main
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
82273ec
Merge branch 'main' of https://github.com/ickshonpe/bevy
ickshonpe Feb 24, 2023
431d97e
Changed the doc comments to be explicit about the values the helper f…
ickshonpe Mar 2, 2023
a38647f
Merge branch 'main' into remove-val-undefined
ickshonpe Mar 2, 2023
c8f200e
fixed errors in ui example
ickshonpe Mar 2, 2023
f3f02d8
fixed positions
ickshonpe Mar 2, 2023
5e3e7cf
Removed position example from `UiRect`
ickshonpe Mar 8, 2023
d1c7e33
Merge branch 'main' into remove-val-undefined
ickshonpe Mar 9, 2023
6215dc6
Merge remote-tracking branch 'origin/main' into remove-val-undefined
ickshonpe Mar 9, 2023
e72dca8
update convert module
ickshonpe Mar 9, 2023
29db012
Fixed position in `bloom_3d` example
ickshonpe Mar 9, 2023
5cca520
Fixed position in `bloom_2d` example
ickshonpe Mar 9, 2023
51bd6df
cargo fmt
ickshonpe Mar 9, 2023
9369aa1
fix test
ickshonpe Mar 9, 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
203 changes: 194 additions & 9 deletions crates/bevy_ui/src/flex/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ impl Val {
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::Auto => taffy::style::LengthPercentageAuto::Auto,
Val::Percent(value) => taffy::style::LengthPercentageAuto::Percent(value / 100.0),
Val::Px(value) => taffy::style::LengthPercentageAuto::Points(value),
}
Expand Down Expand Up @@ -67,7 +66,7 @@ impl<T: From<Val>> From<Size> for taffy::prelude::Size<T> {
impl From<Val> for taffy::style::Dimension {
fn from(value: Val) -> Self {
match value {
Val::Auto | Val::Undefined => taffy::style::Dimension::Auto,
Val::Auto => taffy::style::Dimension::Auto,
Val::Percent(value) => taffy::style::Dimension::Percent(value / 100.0),
Val::Px(value) => taffy::style::Dimension::Points(value),
}
Expand All @@ -77,7 +76,7 @@ impl From<Val> for taffy::style::Dimension {
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::Auto => taffy::style::LengthPercentage::Points(0.0),
Val::Percent(value) => taffy::style::LengthPercentage::Percent(value / 100.0),
Val::Px(value) => taffy::style::LengthPercentage::Points(value),
}
Expand All @@ -90,7 +89,6 @@ impl From<Val> for taffy::style::LengthPercentageAuto {
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.),
}
}
}
Expand All @@ -106,10 +104,10 @@ pub fn from_style(scale_factor: f64, style: &Style) -> taffy::style::Style {
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(),
left: style.left.scaled(scale_factor).to_inset(),
right: style.right.scaled(scale_factor).to_inset(),
top: style.top.scaled(scale_factor).to_inset(),
bottom: style.bottom.scaled(scale_factor).to_inset(),
},
margin: style.margin.scaled(scale_factor).into(),
padding: style.padding.scaled(scale_factor).into(),
Expand Down Expand Up @@ -224,3 +222,190 @@ impl From<FlexWrap> for taffy::style::FlexWrap {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_convert_from() {
let bevy_style = crate::Style {
display: Display::Flex,
position_type: PositionType::Absolute,
left: Val::Px(0.),
right: Val::Percent(0.),
top: Val::Auto,
bottom: Val::Auto,
direction: crate::Direction::Inherit,
flex_direction: FlexDirection::ColumnReverse,
flex_wrap: FlexWrap::WrapReverse,
align_items: AlignItems::Baseline,
align_self: AlignSelf::Start,
align_content: AlignContent::SpaceAround,
justify_content: JustifyContent::SpaceEvenly,
margin: UiRect {
left: Val::Percent(0.),
right: Val::Px(0.),
top: Val::Auto,
bottom: Val::Auto,
},
padding: UiRect {
left: Val::Percent(0.),
right: Val::Px(0.),
top: Val::Percent(0.),
bottom: Val::Percent(0.),
},
border: UiRect {
left: Val::Px(0.),
right: Val::Px(0.),
top: Val::Auto,
bottom: Val::Px(0.),
},
flex_grow: 1.,
flex_shrink: 0.,
flex_basis: Val::Px(0.),
size: Size {
width: Val::Px(0.),
height: Val::Auto,
},
min_size: Size {
width: Val::Px(0.),
height: Val::Percent(0.),
},
max_size: Size {
width: Val::Auto,
height: Val::Px(0.),
},
aspect_ratio: None,
overflow: crate::Overflow::Hidden,
gap: Size {
width: Val::Px(0.),
height: Val::Percent(0.),
},
};
let taffy_style = from_style(1.0, &bevy_style);
assert_eq!(taffy_style.display, taffy::style::Display::Flex);
assert_eq!(taffy_style.position, taffy::style::Position::Absolute);
assert!(matches!(
taffy_style.inset.left,
taffy::style::LengthPercentageAuto::Points(_)
));
assert!(matches!(
taffy_style.inset.right,
taffy::style::LengthPercentageAuto::Percent(_)
));
assert!(matches!(
taffy_style.inset.top,
taffy::style::LengthPercentageAuto::Auto
));
assert!(matches!(
taffy_style.inset.bottom,
taffy::style::LengthPercentageAuto::Auto
));
assert_eq!(
taffy_style.flex_direction,
taffy::style::FlexDirection::ColumnReverse
);
assert_eq!(taffy_style.flex_wrap, taffy::style::FlexWrap::WrapReverse);
assert_eq!(
taffy_style.align_items,
Some(taffy::style::AlignItems::Baseline)
);
assert_eq!(taffy_style.align_self, Some(taffy::style::AlignSelf::Start));
assert_eq!(
taffy_style.align_content,
Some(taffy::style::AlignContent::SpaceAround)
);
assert_eq!(
taffy_style.justify_content,
Some(taffy::style::JustifyContent::SpaceEvenly)
);
assert!(matches!(
taffy_style.margin.left,
taffy::style::LengthPercentageAuto::Percent(_)
));
assert!(matches!(
taffy_style.margin.right,
taffy::style::LengthPercentageAuto::Points(_)
));
assert!(matches!(
taffy_style.margin.top,
taffy::style::LengthPercentageAuto::Auto
));
assert!(matches!(
taffy_style.margin.bottom,
taffy::style::LengthPercentageAuto::Auto
));
assert!(matches!(
taffy_style.padding.left,
taffy::style::LengthPercentage::Percent(_)
));
assert!(matches!(
taffy_style.padding.right,
taffy::style::LengthPercentage::Points(_)
));
assert!(matches!(
taffy_style.padding.top,
taffy::style::LengthPercentage::Percent(_)
));
assert!(matches!(
taffy_style.padding.bottom,
taffy::style::LengthPercentage::Percent(_)
));
assert!(matches!(
taffy_style.border.left,
taffy::style::LengthPercentage::Points(_)
));
assert!(matches!(
taffy_style.border.right,
taffy::style::LengthPercentage::Points(_)
));
assert!(matches!(
taffy_style.border.top,
taffy::style::LengthPercentage::Points(_)
));
assert!(matches!(
taffy_style.border.bottom,
taffy::style::LengthPercentage::Points(_)
));
assert_eq!(taffy_style.flex_grow, 1.);
assert_eq!(taffy_style.flex_shrink, 0.);
assert!(matches!(
taffy_style.flex_basis,
taffy::style::Dimension::Points(_)
));
assert!(matches!(
taffy_style.size.width,
taffy::style::Dimension::Points(_)
));
assert!(matches!(
taffy_style.size.height,
taffy::style::Dimension::Auto
));
assert!(matches!(
taffy_style.min_size.width,
taffy::style::Dimension::Points(_)
));
assert!(matches!(
taffy_style.min_size.height,
taffy::style::Dimension::Percent(_)
));
assert!(matches!(
taffy_style.max_size.width,
taffy::style::Dimension::Auto
));
assert!(matches!(
taffy_style.max_size.height,
taffy::style::Dimension::Points(_)
));
assert_eq!(taffy_style.aspect_ratio, None);
assert_eq!(
taffy_style.gap.width,
taffy::style::LengthPercentage::Points(0.)
);
assert_eq!(
taffy_style.gap.height,
taffy::style::LengthPercentage::Percent(0.)
);
}
}
Loading