Skip to content

Commit

Permalink
Flexbox -> Flex in type names
Browse files Browse the repository at this point in the history
  • Loading branch information
alice-i-cecile committed Jul 31, 2022
1 parent 2c8f065 commit a6dc7a9
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 56 deletions.
20 changes: 10 additions & 10 deletions crates/bevy_ui/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use crate::{
layout_components::{
flex::FlexboxLayout, LayoutStrategy, Offset, Overflow, PositionType, SizeConstraints,
Spacing, TextDirection, Wrap,
flex::FlexLayout, LayoutStrategy, Offset, Overflow, PositionType, SizeConstraints, Spacing,
TextDirection, Wrap,
},
widget::{Button, ImageMode},
CalculatedSize, FocusPolicy, Interaction, Node, UiColor, UiImage,
Expand Down Expand Up @@ -36,7 +36,7 @@ pub struct NodeBundle {
/// The margin, padding and border of the UI node
pub spacing: Spacing,
/// The flexbox layout parameters
pub flexbox_layout: FlexboxLayout,
pub flex_layout: FlexLayout,
/// The direction of the text
pub text_direction: TextDirection,
/// Controls how the content wraps
Expand Down Expand Up @@ -75,7 +75,7 @@ pub struct ImageBundle {
/// The margin, padding and border of the UI node
pub spacing: Spacing,
/// The flexbox layout parameters
pub flexbox_layout: FlexboxLayout,
pub flex_layout: FlexLayout,
/// The direction of the text
pub text_direction: TextDirection,
/// Controls how the content wraps
Expand Down Expand Up @@ -118,7 +118,7 @@ pub struct TextBundle {
/// The margin, padding and border of the UI node
pub spacing: Spacing,
/// The flexbox layout parameters
pub flexbox_layout: FlexboxLayout,
pub flex_layout: FlexLayout,
/// The direction of the text
pub text_direction: TextDirection,
/// Controls how the content wraps
Expand Down Expand Up @@ -168,9 +168,9 @@ impl TextBundle {
self
}

/// Returns this [`TextBundle`] with a new [`FlexboxLayout`].
pub const fn with_flex_layout(mut self, layout: FlexboxLayout) -> Self {
self.flexbox_layout = layout;
/// Returns this [`TextBundle`] with a new [`FlexLayout`].
pub const fn with_flex_layout(mut self, layout: FlexLayout) -> Self {
self.flex_layout = layout;
self
}
}
Expand All @@ -185,7 +185,7 @@ impl Default for TextBundle {
layout_strategy: Default::default(),
position_type: Default::default(),
size_constraints: Default::default(),
flexbox_layout: Default::default(),
flex_layout: Default::default(),
text_direction: Default::default(),
wrap: Default::default(),
overflow: Default::default(),
Expand Down Expand Up @@ -217,7 +217,7 @@ pub struct ButtonBundle {
/// The margin, padding and border of the UI node
pub spacing: Spacing,
/// The flexbox layout parameters
pub flexbox_layout: FlexboxLayout,
pub flex_layout: FlexLayout,
/// The direction of the text
pub text_direction: TextDirection,
/// Controls how the content wraps
Expand Down
25 changes: 11 additions & 14 deletions crates/bevy_ui/src/flex/convert.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::layout_components::{
flex::{
AlignContent, AlignItems, AlignSelf, FlexDirection, FlexboxLayoutQueryItem, JustifyContent,
AlignContent, AlignItems, AlignSelf, FlexDirection, FlexLayoutQueryItem, JustifyContent,
},
LayoutStrategy, PositionType, Wrap,
};
Expand Down Expand Up @@ -36,26 +36,23 @@ pub fn from_val_size(
}
}

pub fn from_flexbox_layout(
scale_factor: f64,
value: FlexboxLayoutQueryItem<'_>,
) -> taffy::style::Style {
pub fn from_flex_layout(scale_factor: f64, value: FlexLayoutQueryItem<'_>) -> taffy::style::Style {
taffy::style::Style {
display: (*value.layout_strategy).into(),
position_type: (*value.position_type).into(),
flex_direction: value.flexbox_layout.flex_direction.into(),
flex_direction: value.flex_layout.flex_direction.into(),
flex_wrap: (*value.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(),
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(),
position: from_rect(scale_factor, value.offset.0),
margin: from_rect(scale_factor, value.spacing.margin),
padding: from_rect(scale_factor, value.spacing.padding),
border: from_rect(scale_factor, value.spacing.border),
flex_grow: value.flexbox_layout.grow,
flex_shrink: value.flexbox_layout.shrink,
flex_basis: from_val(scale_factor, value.flexbox_layout.basis),
flex_grow: value.flex_layout.grow,
flex_shrink: value.flex_layout.shrink,
flex_basis: from_val(scale_factor, value.flex_layout.basis),
size: from_val_size(scale_factor, value.size_constraints.suggested),
min_size: from_val_size(scale_factor, value.size_constraints.min),
max_size: from_val_size(scale_factor, value.size_constraints.max),
Expand Down Expand Up @@ -116,7 +113,7 @@ impl From<AlignContent> for taffy::style::AlignContent {
impl From<LayoutStrategy> for taffy::style::Display {
fn from(value: LayoutStrategy) -> Self {
match value {
LayoutStrategy::Flexbox => taffy::style::Display::Flex,
LayoutStrategy::Flex => taffy::style::Display::Flex,
LayoutStrategy::None => taffy::style::Display::None,
}
}
Expand Down
20 changes: 10 additions & 10 deletions crates/bevy_ui/src/flex/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod convert;

use crate::{
layout_components::flex::{FlexboxLayoutChanged, FlexboxLayoutQuery, FlexboxLayoutQueryItem},
layout_components::flex::{FlexLayoutChanged, FlexLayoutQuery, FlexLayoutQueryItem},
CalculatedSize, Node,
};
use bevy_ecs::{
Expand Down Expand Up @@ -62,12 +62,12 @@ impl FlexSurface {
pub fn upsert_node(
&mut self,
entity: Entity,
layout: FlexboxLayoutQueryItem<'_>,
layout: FlexLayoutQueryItem<'_>,
scale_factor: f64,
) {
let mut added = false;
let taffy = &mut self.taffy;
let taffy_style = convert::from_flexbox_layout(scale_factor, layout);
let taffy_style = convert::from_flex_layout(scale_factor, layout);
let taffy_node = self.entity_to_taffy.entry(entity).or_insert_with(|| {
added = true;
taffy.new_node(taffy_style, &Vec::new()).unwrap()
Expand All @@ -81,12 +81,12 @@ impl FlexSurface {
pub fn upsert_leaf(
&mut self,
entity: Entity,
layout: FlexboxLayoutQueryItem<'_>,
layout: FlexLayoutQueryItem<'_>,
calculated_size: CalculatedSize,
scale_factor: f64,
) {
let taffy = &mut self.taffy;
let taffy_style = convert::from_flexbox_layout(scale_factor, layout);
let taffy_style = convert::from_flex_layout(scale_factor, layout);
let measure = taffy::node::MeasureFunc::Boxed(Box::new(
move |constraints: taffy::geometry::Size<Number>| {
let mut size = convert::from_f32_size(scale_factor, calculated_size.size);
Expand Down Expand Up @@ -207,12 +207,12 @@ pub fn flex_node_system(
mut flex_surface: ResMut<FlexSurface>,
root_node_query: Query<Entity, (With<Node>, Without<Parent>)>,
node_query: Query<
(Entity, FlexboxLayoutQuery, Option<&CalculatedSize>),
(With<Node>, FlexboxLayoutChanged),
(Entity, FlexLayoutQuery, Option<&CalculatedSize>),
(With<Node>, FlexLayoutChanged),
>,
full_node_query: Query<(Entity, FlexboxLayoutQuery, Option<&CalculatedSize>), With<Node>>,
full_node_query: Query<(Entity, FlexLayoutQuery, Option<&CalculatedSize>), With<Node>>,
changed_size_query: Query<
(Entity, FlexboxLayoutQuery, &CalculatedSize),
(Entity, FlexLayoutQuery, &CalculatedSize),
(With<Node>, Changed<CalculatedSize>),
>,
children_query: Query<(Entity, &Children), (With<Node>, Changed<Children>)>,
Expand All @@ -239,7 +239,7 @@ pub fn flex_node_system(
fn update_changed<F: WorldQuery>(
flex_surface: &mut FlexSurface,
scaling_factor: f64,
query: Query<(Entity, FlexboxLayoutQuery, Option<&CalculatedSize>), F>,
query: Query<(Entity, FlexLayoutQuery, Option<&CalculatedSize>), F>,
) {
// update changed nodes
for (entity, layout, calculated_size) in &query {
Expand Down
26 changes: 12 additions & 14 deletions crates/bevy_ui/src/layout_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub enum LayoutStrategy {
///
/// As implemented by [`taffy`]: some bugs or limitations may exist; please file an issue!\
#[default]
Flexbox,
Flex,
}

/// The strategy used to position this node
Expand Down Expand Up @@ -142,11 +142,11 @@ pub mod flex {
use bevy_reflect::prelude::*;
use serde::{Deserialize, Serialize};

/// A query for all of the components in a [`FlexboxLayoutBundle`].
/// A query for all of the components need for flexbox layout.
///
/// See [`FlexboxLayoutChanged`] when attempting to use this as a query filter.
/// See [`FlexLayoutChanged`] when attempting to use this as a query filter.
#[derive(WorldQuery)]
pub struct FlexboxLayoutQuery {
pub struct FlexLayoutQuery {
/// The layout algorithm used
pub layout_strategy: &'static LayoutStrategy,
/// The position of this UI node
Expand All @@ -158,7 +158,7 @@ pub mod flex {
/// The margin, padding and border of the UI node
pub spacing: &'static Spacing,
/// The flexbox layout parameters
pub flexbox_layout: &'static FlexboxLayout,
pub flex_layout: &'static FlexLayout,
/// The direction of the text
pub text_direction: &'static TextDirection,
/// Controls how the content wraps
Expand All @@ -167,15 +167,13 @@ pub mod flex {
pub overflow: &'static Overflow,
}

/// A type alias for when any of the components in the [`FlexboxLayoutBundle`] has been changed
///
/// See [`FlexboxLayoutQuery`] for the data-fetching equivalent.
pub type FlexboxLayoutChanged = Or<(
/// A type alias for when any of the components in a [`FlexLayoutQuery`] have changed.
pub type FlexLayoutChanged = Or<(
Changed<LayoutStrategy>,
Changed<PositionType>,
Changed<SizeConstraints>,
Changed<Spacing>,
Changed<FlexboxLayout>,
Changed<FlexLayout>,
Changed<TextDirection>,
Changed<Overflow>,
)>;
Expand All @@ -186,7 +184,7 @@ pub mod flex {
/// you can use [guides](https://css-tricks.com/snippets/css/a-guide-to-flexbox/) for additional documentation.
#[derive(Component, Serialize, Deserialize, Reflect, Debug, PartialEq, Clone, Copy)]
#[reflect_value(PartialEq, Serialize, Deserialize)]
pub struct FlexboxLayout {
pub struct FlexLayout {
/// How items are ordered inside a flexbox
///
/// Sets the main and cross-axis: if this is a "row" variant, the main axis will be rows.
Expand All @@ -207,9 +205,9 @@ pub mod flex {
pub basis: Val,
}

impl Default for FlexboxLayout {
fn default() -> FlexboxLayout {
FlexboxLayout {
impl Default for FlexLayout {
fn default() -> FlexLayout {
FlexLayout {
flex_direction: Default::default(),
align_items: Default::default(),
align_self: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Plugin for UiPlugin {
.register_type::<Size<f32>>()
.register_type::<Size<Val>>()
.register_type::<UiRect<Val>>()
.register_type::<FlexboxLayout>()
.register_type::<FlexLayout>()
.register_type::<UiColor>()
.register_type::<UiImage>()
.register_type::<Val>()
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_ui/src/update.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This module contains systems that update the UI when something changes
use crate::{layout_components::Overflow, prelude::flex::FlexboxLayoutQuery, CalculatedClip};
use crate::{layout_components::Overflow, prelude::flex::FlexLayoutQuery, CalculatedClip};

use super::Node;
use bevy_ecs::{
Expand Down Expand Up @@ -71,7 +71,7 @@ pub fn update_clipping_system(
mut node_query: Query<(
&Node,
&GlobalTransform,
FlexboxLayoutQuery,
FlexLayoutQuery,
Option<&mut CalculatedClip>,
)>,
children_query: Query<&Children>,
Expand All @@ -93,7 +93,7 @@ fn update_clipping(
node_query: &mut Query<(
&Node,
&GlobalTransform,
FlexboxLayoutQuery,
FlexLayoutQuery,
Option<&mut CalculatedClip>,
)>,
entity: Entity,
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_ui/src/widget/text.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
layout_components::flex::{FlexboxLayout, FlexboxLayoutChanged, FlexboxLayoutQuery},
layout_components::flex::{FlexLayout, FlexLayoutChanged, FlexLayoutQuery},
CalculatedSize, Size, Val,
};
use bevy_asset::Assets;
Expand Down Expand Up @@ -50,9 +50,9 @@ pub fn text_system(
mut font_atlas_set_storage: ResMut<Assets<FontAtlasSet>>,
mut text_pipeline: ResMut<DefaultTextPipeline>,
mut text_queries: ParamSet<(
Query<Entity, Or<(Changed<Text>, FlexboxLayoutChanged)>>,
Query<Entity, (With<Text>, With<FlexboxLayout>)>,
Query<(&Text, FlexboxLayoutQuery, &mut CalculatedSize)>,
Query<Entity, Or<(Changed<Text>, FlexLayoutChanged)>>,
Query<Entity, (With<Text>, With<FlexLayout>)>,
Query<(&Text, FlexLayoutQuery, &mut CalculatedSize)>,
)>,
) {
let scale_factor = windows.scale_factor(WindowId::primary());
Expand Down

0 comments on commit a6dc7a9

Please sign in to comment.