Skip to content

Commit be47f70

Browse files
Move Wrap back to a subcomponent
This reverts commit 8824e3a.
1 parent 6f9ed8a commit be47f70

File tree

4 files changed

+32
-47
lines changed

4 files changed

+32
-47
lines changed

crates/bevy_ui/src/entity.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ pub struct NodeBundle {
3939
pub flex_layout: FlexLayout,
4040
/// The direction of the text
4141
pub text_direction: TextDirection,
42-
/// Controls how the content wraps
43-
pub wrap: Wrap,
4442
/// The behavior in case the node overflows its allocated space
4543
pub overflow: Overflow,
4644
/// Describes the color of the node
@@ -78,8 +76,6 @@ pub struct ImageBundle {
7876
pub flex_layout: FlexLayout,
7977
/// The direction of the text
8078
pub text_direction: TextDirection,
81-
/// Controls how the content wraps
82-
pub wrap: Wrap,
8379
/// The behavior in case the node overflows its allocated space
8480
pub overflow: Overflow,
8581
/// Configures how the image should scale
@@ -121,8 +117,6 @@ pub struct TextBundle {
121117
pub flex_layout: FlexLayout,
122118
/// The direction of the text
123119
pub text_direction: TextDirection,
124-
/// Controls how the content wraps
125-
pub wrap: Wrap,
126120
/// The behavior in case the node overflows its allocated space
127121
pub overflow: Overflow,
128122
/// Contains the text of the node
@@ -187,7 +181,6 @@ impl Default for TextBundle {
187181
size_constraints: Default::default(),
188182
flex_layout: Default::default(),
189183
text_direction: Default::default(),
190-
wrap: Default::default(),
191184
overflow: Default::default(),
192185
transform: Default::default(),
193186
global_transform: Default::default(),
@@ -220,8 +213,6 @@ pub struct ButtonBundle {
220213
pub flex_layout: FlexLayout,
221214
/// The direction of the text
222215
pub text_direction: TextDirection,
223-
/// Controls how the content wraps
224-
pub wrap: Wrap,
225216
/// The behavior in case the node overflows its allocated space
226217
pub overflow: Overflow,
227218
/// Describes whether and how the button has been interacted with by the input

crates/bevy_ui/src/flex/convert.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::layout_components::{
22
flex::{
33
AlignContent, AlignItems, AlignSelf, FlexDirection, FlexLayoutQueryItem, JustifyContent,
44
},
5-
LayoutStrategy, PositionType, Wrap,
5+
prelude::{flex::FlexboxLayoutQueryItem, LayoutStrategy},
66
};
77
use crate::{Size, UiRect, Val};
88

@@ -40,12 +40,12 @@ pub fn from_flex_layout(scale_factor: f64, value: FlexLayoutQueryItem<'_>) -> ta
4040
taffy::style::Style {
4141
display: (*value.layout_strategy).into(),
4242
position_type: (*value.position_type).into(),
43-
flex_direction: value.flex_layout.flex_direction.into(),
44-
flex_wrap: (*value.wrap).into(),
45-
align_items: value.flex_layout.align_items.into(),
46-
align_self: value.flex_layout.align_self.into(),
47-
align_content: value.flex_layout.align_content.into(),
48-
justify_content: value.flex_layout.justify_content.into(),
43+
flex_direction: value.flexbox_layout.flex_direction.into(),
44+
flex_wrap: value.flexbox_layout.wrap.into(),
45+
align_items: value.flexbox_layout.align_items.into(),
46+
align_self: value.flexbox_layout.align_self.into(),
47+
align_content: value.flexbox_layout.align_content.into(),
48+
justify_content: value.flexbox_layout.justify_content.into(),
4949
position: from_rect(scale_factor, value.offset.0),
5050
margin: from_rect(scale_factor, value.spacing.margin),
5151
padding: from_rect(scale_factor, value.spacing.padding),
@@ -152,12 +152,12 @@ impl From<PositionType> for taffy::style::PositionType {
152152
}
153153
}
154154

155-
impl From<Wrap> for taffy::style::FlexWrap {
156-
fn from(value: Wrap) -> Self {
155+
impl From<FlexWrap> for taffy::style::FlexWrap {
156+
fn from(value: FlexWrap) -> Self {
157157
match value {
158-
Wrap::NoWrap => taffy::style::FlexWrap::NoWrap,
159-
Wrap::Wrap => taffy::style::FlexWrap::Wrap,
160-
Wrap::WrapReverse => taffy::style::FlexWrap::WrapReverse,
158+
FlexWrap::NoWrap => taffy::style::FlexWrap::NoWrap,
159+
FlexWrap::Wrap => taffy::style::FlexWrap::Wrap,
160+
FlexWrap::WrapReverse => taffy::style::FlexWrap::WrapReverse,
161161
}
162162
}
163163
}

crates/bevy_ui/src/layout_components.rs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -204,32 +204,12 @@ pub enum Overflow {
204204
Hidden,
205205
}
206206

207-
/// Defines if child UI items appear on a single line or on multiple lines
208-
#[derive(
209-
Component, Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect,
210-
)]
211-
#[reflect_value(PartialEq, Serialize, Deserialize)]
212-
pub enum Wrap {
213-
/// Single line, will overflow if needed
214-
#[default]
215-
NoWrap,
216-
/// Multiple lines, if needed
217-
Wrap,
218-
/// Same as [`FlexWrap::Wrap`] but new lines will appear before the previous one
219-
WrapReverse,
220-
}
221-
222207
/// Flexbox-specific layout components
223208
pub mod flex {
224-
use super::{
225-
LayoutStrategy, Offset, Overflow, PositionType, SizeConstraints, Spacing, TextDirection,
226-
Wrap,
227-
};
228-
use crate::Val;
229-
use bevy_ecs::prelude::Component;
209+
230210
use bevy_ecs::query::{Changed, Or, WorldQuery};
231-
use bevy_reflect::prelude::*;
232-
use serde::{Deserialize, Serialize};
211+
212+
use super::*;
233213

234214
/// A query for all of the components need for flexbox layout.
235215
///
@@ -250,8 +230,6 @@ pub mod flex {
250230
pub flex_layout: &'static FlexLayout,
251231
/// The direction of the text
252232
pub text_direction: &'static TextDirection,
253-
/// Controls how the content wraps
254-
pub wrap: &'static Wrap,
255233
/// The behavior in case the node overflows its allocated space
256234
pub overflow: &'static Overflow,
257235
}
@@ -286,6 +264,8 @@ pub mod flex {
286264
pub align_content: AlignContent,
287265
/// Aligns this containers items along the main-axis
288266
pub justify_content: JustifyContent,
267+
/// Controls how the content wraps
268+
pub wrap: FlexWrap,
289269
/// Defines how much a flexbox item should grow if there's space available
290270
pub grow: f32,
291271
/// How to shrink if there's not enough space available
@@ -302,6 +282,7 @@ pub mod flex {
302282
align_self: Default::default(),
303283
align_content: Default::default(),
304284
justify_content: Default::default(),
285+
wrap: Default::default(),
305286
grow: 0.0,
306287
shrink: 1.0,
307288
basis: Val::Auto,
@@ -401,4 +382,17 @@ pub mod flex {
401382
/// Like [`JustifyContent::SpaceAround`] but with even spacing between items
402383
SpaceEvenly,
403384
}
385+
386+
/// Defines if flexbox items appear on a single line or on multiple lines
387+
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect)]
388+
#[reflect_value(PartialEq, Serialize, Deserialize)]
389+
pub enum FlexWrap {
390+
/// Single line, will overflow if needed
391+
#[default]
392+
NoWrap,
393+
/// Multiple lines, if needed
394+
Wrap,
395+
/// Same as [`FlexWrap::Wrap`] but new lines will appear before the previous one
396+
WrapReverse,
397+
}
404398
}

crates/bevy_ui/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl Plugin for UiPlugin {
6565
.register_type::<TextDirection>()
6666
.register_type::<LayoutStrategy>()
6767
.register_type::<FlexDirection>()
68-
.register_type::<Wrap>()
68+
.register_type::<FlexWrap>()
6969
.register_type::<FocusPolicy>()
7070
.register_type::<Interaction>()
7171
.register_type::<JustifyContent>()

0 commit comments

Comments
 (0)