Skip to content

Commit

Permalink
Move Wrap back to a subcomponent
Browse files Browse the repository at this point in the history
This reverts commit 8824e3a.
  • Loading branch information
alice-i-cecile committed Aug 1, 2022
1 parent 6f9ed8a commit be47f70
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 47 deletions.
9 changes: 0 additions & 9 deletions crates/bevy_ui/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ pub struct NodeBundle {
pub flex_layout: FlexLayout,
/// The direction of the text
pub text_direction: TextDirection,
/// Controls how the content wraps
pub wrap: Wrap,
/// The behavior in case the node overflows its allocated space
pub overflow: Overflow,
/// Describes the color of the node
Expand Down Expand Up @@ -78,8 +76,6 @@ pub struct ImageBundle {
pub flex_layout: FlexLayout,
/// The direction of the text
pub text_direction: TextDirection,
/// Controls how the content wraps
pub wrap: Wrap,
/// The behavior in case the node overflows its allocated space
pub overflow: Overflow,
/// Configures how the image should scale
Expand Down Expand Up @@ -121,8 +117,6 @@ pub struct TextBundle {
pub flex_layout: FlexLayout,
/// The direction of the text
pub text_direction: TextDirection,
/// Controls how the content wraps
pub wrap: Wrap,
/// The behavior in case the node overflows its allocated space
pub overflow: Overflow,
/// Contains the text of the node
Expand Down Expand Up @@ -187,7 +181,6 @@ impl Default for TextBundle {
size_constraints: Default::default(),
flex_layout: Default::default(),
text_direction: Default::default(),
wrap: Default::default(),
overflow: Default::default(),
transform: Default::default(),
global_transform: Default::default(),
Expand Down Expand Up @@ -220,8 +213,6 @@ pub struct ButtonBundle {
pub flex_layout: FlexLayout,
/// The direction of the text
pub text_direction: TextDirection,
/// Controls how the content wraps
pub wrap: Wrap,
/// The behavior in case the node overflows its allocated space
pub overflow: Overflow,
/// Describes whether and how the button has been interacted with by the input
Expand Down
24 changes: 12 additions & 12 deletions crates/bevy_ui/src/flex/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::layout_components::{
flex::{
AlignContent, AlignItems, AlignSelf, FlexDirection, FlexLayoutQueryItem, JustifyContent,
},
LayoutStrategy, PositionType, Wrap,
prelude::{flex::FlexboxLayoutQueryItem, LayoutStrategy},
};
use crate::{Size, UiRect, Val};

Expand Down Expand Up @@ -40,12 +40,12 @@ pub fn from_flex_layout(scale_factor: f64, value: FlexLayoutQueryItem<'_>) -> ta
taffy::style::Style {
display: (*value.layout_strategy).into(),
position_type: (*value.position_type).into(),
flex_direction: value.flex_layout.flex_direction.into(),
flex_wrap: (*value.wrap).into(),
align_items: value.flex_layout.align_items.into(),
align_self: value.flex_layout.align_self.into(),
align_content: value.flex_layout.align_content.into(),
justify_content: value.flex_layout.justify_content.into(),
flex_direction: value.flexbox_layout.flex_direction.into(),
flex_wrap: value.flexbox_layout.wrap.into(),
align_items: value.flexbox_layout.align_items.into(),
align_self: value.flexbox_layout.align_self.into(),
align_content: value.flexbox_layout.align_content.into(),
justify_content: value.flexbox_layout.justify_content.into(),
position: from_rect(scale_factor, value.offset.0),
margin: from_rect(scale_factor, value.spacing.margin),
padding: from_rect(scale_factor, value.spacing.padding),
Expand Down Expand Up @@ -152,12 +152,12 @@ impl From<PositionType> for taffy::style::PositionType {
}
}

impl From<Wrap> for taffy::style::FlexWrap {
fn from(value: Wrap) -> Self {
impl From<FlexWrap> for taffy::style::FlexWrap {
fn from(value: FlexWrap) -> Self {
match value {
Wrap::NoWrap => taffy::style::FlexWrap::NoWrap,
Wrap::Wrap => taffy::style::FlexWrap::Wrap,
Wrap::WrapReverse => taffy::style::FlexWrap::WrapReverse,
FlexWrap::NoWrap => taffy::style::FlexWrap::NoWrap,
FlexWrap::Wrap => taffy::style::FlexWrap::Wrap,
FlexWrap::WrapReverse => taffy::style::FlexWrap::WrapReverse,
}
}
}
44 changes: 19 additions & 25 deletions crates/bevy_ui/src/layout_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,32 +204,12 @@ pub enum Overflow {
Hidden,
}

/// Defines if child UI items appear on a single line or on multiple lines
#[derive(
Component, Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect,
)]
#[reflect_value(PartialEq, Serialize, Deserialize)]
pub enum Wrap {
/// Single line, will overflow if needed
#[default]
NoWrap,
/// Multiple lines, if needed
Wrap,
/// Same as [`FlexWrap::Wrap`] but new lines will appear before the previous one
WrapReverse,
}

/// Flexbox-specific layout components
pub mod flex {
use super::{
LayoutStrategy, Offset, Overflow, PositionType, SizeConstraints, Spacing, TextDirection,
Wrap,
};
use crate::Val;
use bevy_ecs::prelude::Component;

use bevy_ecs::query::{Changed, Or, WorldQuery};
use bevy_reflect::prelude::*;
use serde::{Deserialize, Serialize};

use super::*;

/// A query for all of the components need for flexbox layout.
///
Expand All @@ -250,8 +230,6 @@ pub mod flex {
pub flex_layout: &'static FlexLayout,
/// The direction of the text
pub text_direction: &'static TextDirection,
/// Controls how the content wraps
pub wrap: &'static Wrap,
/// The behavior in case the node overflows its allocated space
pub overflow: &'static Overflow,
}
Expand Down Expand Up @@ -286,6 +264,8 @@ pub mod flex {
pub align_content: AlignContent,
/// Aligns this containers items along the main-axis
pub justify_content: JustifyContent,
/// Controls how the content wraps
pub wrap: FlexWrap,
/// Defines how much a flexbox item should grow if there's space available
pub grow: f32,
/// How to shrink if there's not enough space available
Expand All @@ -302,6 +282,7 @@ pub mod flex {
align_self: Default::default(),
align_content: Default::default(),
justify_content: Default::default(),
wrap: Default::default(),
grow: 0.0,
shrink: 1.0,
basis: Val::Auto,
Expand Down Expand Up @@ -401,4 +382,17 @@ pub mod flex {
/// Like [`JustifyContent::SpaceAround`] but with even spacing between items
SpaceEvenly,
}

/// Defines if flexbox items appear on a single line or on multiple lines
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect)]
#[reflect_value(PartialEq, Serialize, Deserialize)]
pub enum FlexWrap {
/// Single line, will overflow if needed
#[default]
NoWrap,
/// Multiple lines, if needed
Wrap,
/// Same as [`FlexWrap::Wrap`] but new lines will appear before the previous one
WrapReverse,
}
}
2 changes: 1 addition & 1 deletion crates/bevy_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Plugin for UiPlugin {
.register_type::<TextDirection>()
.register_type::<LayoutStrategy>()
.register_type::<FlexDirection>()
.register_type::<Wrap>()
.register_type::<FlexWrap>()
.register_type::<FocusPolicy>()
.register_type::<Interaction>()
.register_type::<JustifyContent>()
Expand Down

0 comments on commit be47f70

Please sign in to comment.