diff --git a/crates/bevy_app/src/app_builder.rs b/crates/bevy_app/src/app_builder.rs index cf64b6a4eb263..9b5c53ed0dff2 100644 --- a/crates/bevy_app/src/app_builder.rs +++ b/crates/bevy_app/src/app_builder.rs @@ -211,21 +211,19 @@ impl AppBuilder { } pub fn add_default_stages(&mut self) -> &mut Self { - self.add_stage( - CoreStage::Startup, - Schedule::default() - .with_run_criteria(RunOnce::default()) - .with_stage(StartupStage::PreStartup, SystemStage::parallel()) - .with_stage(StartupStage::Startup, SystemStage::parallel()) - .with_stage(StartupStage::PostStartup, SystemStage::parallel()), - ) - .add_stage(CoreStage::First, SystemStage::parallel()) - .add_stage(CoreStage::PreEvent, SystemStage::parallel()) - .add_stage(CoreStage::Event, SystemStage::parallel()) - .add_stage(CoreStage::PreUpdate, SystemStage::parallel()) - .add_stage(CoreStage::Update, SystemStage::parallel()) - .add_stage(CoreStage::PostUpdate, SystemStage::parallel()) - .add_stage(CoreStage::Last, SystemStage::parallel()) + self.add_stage(CoreStage::First, SystemStage::parallel()) + .add_stage( + CoreStage::Startup, + Schedule::default() + .with_run_criteria(RunOnce::default()) + .with_stage(StartupStage::PreStartup, SystemStage::parallel()) + .with_stage(StartupStage::Startup, SystemStage::parallel()) + .with_stage(StartupStage::PostStartup, SystemStage::parallel()), + ) + .add_stage(CoreStage::PreUpdate, SystemStage::parallel()) + .add_stage(CoreStage::Update, SystemStage::parallel()) + .add_stage(CoreStage::PostUpdate, SystemStage::parallel()) + .add_stage(CoreStage::Last, SystemStage::parallel()) } pub fn add_event(&mut self) -> &mut Self @@ -233,7 +231,7 @@ impl AppBuilder { T: Component, { self.insert_resource(Events::::default()) - .add_system_to_stage(CoreStage::Event, Events::::update_system.system()) + .add_system_to_stage(CoreStage::First, Events::::update_system.system()) } /// Inserts a resource to the current [App] and overwrites any resource previously added of the same type. diff --git a/crates/bevy_app/src/event.rs b/crates/bevy_app/src/event.rs index 491abe65b1914..d519b8e290af1 100644 --- a/crates/bevy_app/src/event.rs +++ b/crates/bevy_app/src/event.rs @@ -3,7 +3,11 @@ use bevy_ecs::{ system::{Local, Res, ResMut, SystemParam}, }; use bevy_utils::tracing::trace; -use std::{fmt, marker::PhantomData}; +use std::{ + fmt::{self}, + hash::Hash, + marker::PhantomData, +}; /// An `EventId` uniquely identifies an event. /// diff --git a/crates/bevy_app/src/lib.rs b/crates/bevy_app/src/lib.rs index ab329562760c7..13c3aacc22f43 100644 --- a/crates/bevy_app/src/lib.rs +++ b/crates/bevy_app/src/lib.rs @@ -31,10 +31,6 @@ pub enum CoreStage { Startup, /// Name of app stage that runs before all other app stages First, - /// Name of app stage that runs before EVENT - PreEvent, - /// Name of app stage that updates events. Runs before UPDATE - Event, /// Name of app stage responsible for performing setup before an update. Runs before UPDATE. PreUpdate, /// Name of app stage responsible for doing most app logic. Systems should be registered here by default. diff --git a/crates/bevy_core/src/lib.rs b/crates/bevy_core/src/lib.rs index 13700a005be79..a9280f0a95dc2 100644 --- a/crates/bevy_core/src/lib.rs +++ b/crates/bevy_core/src/lib.rs @@ -17,7 +17,7 @@ pub mod prelude { } use bevy_app::prelude::*; -use bevy_ecs::{entity::Entity, system::IntoSystem}; +use bevy_ecs::{entity::Entity, prelude::IntoExclusiveSystem, system::IntoSystem}; use bevy_utils::HashSet; use std::ops::Range; @@ -44,7 +44,9 @@ impl Plugin for CorePlugin { .register_type::() .register_type::>() .register_type::() - .add_system_to_stage(CoreStage::First, time_system.system()) + // time system is added as an "exclusive system" to ensure it runs before other systems in CoreStage::First + // this also ensures that it runs before other exclusive systems added after CorePlugin + .add_system_to_stage(CoreStage::First, time_system.exclusive_system()) .add_startup_system_to_stage(StartupStage::PostStartup, entity_labels_system.system()) .add_system_to_stage(CoreStage::PostUpdate, entity_labels_system.system()); diff --git a/crates/bevy_ecs/src/schedule/stage.rs b/crates/bevy_ecs/src/schedule/stage.rs index 77caaf8aa1a81..83f2b2b9b75a0 100644 --- a/crates/bevy_ecs/src/schedule/stage.rs +++ b/crates/bevy_ecs/src/schedule/stage.rs @@ -1,4 +1,5 @@ use crate::{ + component::ComponentId, schedule::{ BoxedSystemLabel, ExclusiveSystemContainer, InsertionPoint, ParallelExecutor, ParallelSystemContainer, ParallelSystemExecutor, RunCriteria, ShouldRun, @@ -263,15 +264,16 @@ impl SystemStage { } /// Logs execution order ambiguities between systems. System orders must be fresh. - fn report_ambiguities(&self) { + fn report_ambiguities(&self, world: &World) { debug_assert!(!self.systems_modified); use std::fmt::Write; fn write_display_names_of_pairs( string: &mut String, systems: &[impl SystemContainer], - mut ambiguities: Vec<(usize, usize)>, + mut ambiguities: Vec<(usize, usize, Vec)>, + world: &World, ) { - for (index_a, index_b) in ambiguities.drain(..) { + for (index_a, index_b, conflicts) in ambiguities.drain(..) { writeln!( string, " -- {:?} and {:?}", @@ -279,6 +281,13 @@ impl SystemStage { systems[index_b].name() ) .unwrap(); + if !conflicts.is_empty() { + let names = conflicts + .iter() + .map(|id| world.components().get_info(*id).unwrap().name()) + .collect::>(); + writeln!(string, " conflicts: {:?}", names).unwrap(); + } } } let parallel = find_ambiguities(&self.parallel); @@ -295,11 +304,16 @@ impl SystemStage { .to_owned(); if !parallel.is_empty() { writeln!(string, " * Parallel systems:").unwrap(); - write_display_names_of_pairs(&mut string, &self.parallel, parallel); + write_display_names_of_pairs(&mut string, &self.parallel, parallel, world); } if !at_start.is_empty() { writeln!(string, " * Exclusive systems at start of stage:").unwrap(); - write_display_names_of_pairs(&mut string, &self.exclusive_at_start, at_start); + write_display_names_of_pairs( + &mut string, + &self.exclusive_at_start, + at_start, + world, + ); } if !before_commands.is_empty() { writeln!(string, " * Exclusive systems before commands of stage:").unwrap(); @@ -307,11 +321,12 @@ impl SystemStage { &mut string, &self.exclusive_before_commands, before_commands, + world, ); } if !at_end.is_empty() { writeln!(string, " * Exclusive systems at end of stage:").unwrap(); - write_display_names_of_pairs(&mut string, &self.exclusive_at_end, at_end); + write_display_names_of_pairs(&mut string, &self.exclusive_at_end, at_end, world); } info!("{}", string); } @@ -456,7 +471,7 @@ fn topological_order( /// Returns vector containing all pairs of indices of systems with ambiguous execution order. /// Systems must be topologically sorted beforehand. -fn find_ambiguities(systems: &[impl SystemContainer]) -> Vec<(usize, usize)> { +fn find_ambiguities(systems: &[impl SystemContainer]) -> Vec<(usize, usize, Vec)> { let mut ambiguity_set_labels = HashMap::default(); for set in systems.iter().flat_map(|c| c.ambiguity_sets()) { let len = ambiguity_set_labels.len(); @@ -511,9 +526,17 @@ fn find_ambiguities(systems: &[impl SystemContainer]) -> Vec<(usize, usize)> { { if !processed.contains(index_b) && all_ambiguity_sets[index_a].is_disjoint(&all_ambiguity_sets[index_b]) - && !systems[index_a].is_compatible(&systems[index_b]) { - ambiguities.push((index_a, index_b)); + let a_access = systems[index_a].component_access(); + let b_access = systems[index_b].component_access(); + if let (Some(a), Some(b)) = (a_access, b_access) { + let conflicts = a.get_conflicts(b); + if !conflicts.is_empty() { + ambiguities.push((index_a, index_b, conflicts)) + } + } else { + ambiguities.push((index_a, index_b, Vec::new())); + } } } processed.insert(index_a); @@ -549,7 +572,7 @@ impl Stage for SystemStage { self.executor.rebuild_cached_data(&self.parallel); self.executor_modified = false; if world.contains_resource::() { - self.report_ambiguities(); + self.report_ambiguities(world); } } else if self.executor_modified { self.executor.rebuild_cached_data(&self.parallel); @@ -1184,7 +1207,7 @@ mod tests { ) -> Vec<(BoxedSystemLabel, BoxedSystemLabel)> { find_ambiguities(systems) .drain(..) - .map(|(index_a, index_b)| { + .map(|(index_a, index_b, _conflicts)| { ( systems[index_a].labels()[0].clone(), systems[index_b].labels()[0].clone(), diff --git a/crates/bevy_ecs/src/schedule/system_container.rs b/crates/bevy_ecs/src/schedule/system_container.rs index 60cc8e6f8b778..481b2d583ed27 100644 --- a/crates/bevy_ecs/src/schedule/system_container.rs +++ b/crates/bevy_ecs/src/schedule/system_container.rs @@ -1,4 +1,6 @@ use crate::{ + component::ComponentId, + query::Access, schedule::{ BoxedAmbiguitySetLabel, BoxedSystemLabel, ExclusiveSystemDescriptor, ParallelSystemDescriptor, @@ -16,7 +18,7 @@ pub(super) trait SystemContainer { fn before(&self) -> &[BoxedSystemLabel]; fn after(&self) -> &[BoxedSystemLabel]; fn ambiguity_sets(&self) -> &[BoxedAmbiguitySetLabel]; - fn is_compatible(&self, other: &Self) -> bool; + fn component_access(&self) -> Option<&Access>; } pub(super) struct ExclusiveSystemContainer { @@ -81,8 +83,8 @@ impl SystemContainer for ExclusiveSystemContainer { &self.ambiguity_sets } - fn is_compatible(&self, _: &Self) -> bool { - false + fn component_access(&self) -> Option<&Access> { + None } } @@ -178,9 +180,7 @@ impl SystemContainer for ParallelSystemContainer { &self.ambiguity_sets } - fn is_compatible(&self, other: &Self) -> bool { - self.system() - .component_access() - .is_compatible(other.system().component_access()) + fn component_access(&self) -> Option<&Access> { + Some(self.system().component_access()) } } diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index 9dcdb9f4d2201..06878e67a53c2 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -248,6 +248,7 @@ impl<'a, T: Component> SystemParam for Option> { unsafe impl SystemParamState for OptionResState { type Config = (); + fn init(world: &mut World, system_state: &mut SystemState, _config: Self::Config) -> Self { Self(ResState::init(world, system_state, ())) } @@ -383,6 +384,7 @@ impl<'a, T: Component> SystemParam for Option> { unsafe impl SystemParamState for OptionResMutState { type Config = (); + fn init(world: &mut World, system_state: &mut SystemState, _config: Self::Config) -> Self { Self(ResMutState::init(world, system_state, ())) } diff --git a/crates/bevy_gilrs/src/lib.rs b/crates/bevy_gilrs/src/lib.rs index 483ead514e05b..f8c168ec1d99c 100644 --- a/crates/bevy_gilrs/src/lib.rs +++ b/crates/bevy_gilrs/src/lib.rs @@ -24,7 +24,7 @@ impl Plugin for GilrsPlugin { gilrs_event_startup_system.exclusive_system(), ) .add_system_to_stage( - CoreStage::PreEvent, + CoreStage::PreUpdate, gilrs_event_system.exclusive_system(), ); } diff --git a/crates/bevy_input/src/lib.rs b/crates/bevy_input/src/lib.rs index 22a0a4e7d4dc7..4cb43c3bb9991 100644 --- a/crates/bevy_input/src/lib.rs +++ b/crates/bevy_input/src/lib.rs @@ -7,7 +7,10 @@ pub mod system; pub mod touch; pub use axis::*; -use bevy_ecs::system::IntoSystem; +use bevy_ecs::{ + schedule::{ParallelSystemDescriptorCoercion, SystemLabel}, + system::IntoSystem, +}; pub use input::*; pub mod prelude { @@ -37,27 +40,46 @@ use gamepad::{ #[derive(Default)] pub struct InputPlugin; +#[derive(Debug, PartialEq, Eq, Clone, Hash, SystemLabel)] +pub struct InputSystem; + impl Plugin for InputPlugin { fn build(&self, app: &mut AppBuilder) { - app.add_event::() + app + // keyboard + .add_event::() + .init_resource::>() + .add_system_to_stage( + CoreStage::PreUpdate, + keyboard_input_system.system().label(InputSystem), + ) + // mouse .add_event::() .add_event::() .add_event::() - .init_resource::>() - .add_system_to_stage(CoreStage::Event, keyboard_input_system.system()) .init_resource::>() - .add_system_to_stage(CoreStage::Event, mouse_button_input_system.system()) + .add_system_to_stage( + CoreStage::PreUpdate, + mouse_button_input_system.system().label(InputSystem), + ) + // gamepad .add_event::() .add_event::() .init_resource::() .init_resource::>() .init_resource::>() .init_resource::>() - .add_system_to_stage(CoreStage::Event, gamepad_event_system.system()) - .add_startup_system_to_stage(StartupStage::Startup, gamepad_event_system.system()) + .add_system_to_stage( + CoreStage::PreUpdate, + gamepad_event_system.system().label(InputSystem), + ) + // touch .add_event::() .init_resource::() - .add_system_to_stage(CoreStage::Event, touch_screen_input_system.system()); + .add_system_to_stage( + CoreStage::PreUpdate, + touch_screen_input_system.system().label(InputSystem), + ); } } diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index 18d80770e4b08..98fea3a99b2e1 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -13,9 +13,10 @@ pub mod texture; pub mod wireframe; use bevy_ecs::{ - schedule::SystemStage, + schedule::{ParallelSystemDescriptorCoercion, SystemStage}, system::{IntoExclusiveSystem, IntoSystem}, }; +use bevy_transform::TransformSystem; use draw::Visible; pub use once_cell; @@ -37,7 +38,7 @@ use crate::prelude::*; use base::Msaa; use bevy_app::prelude::*; use bevy_asset::{AddAsset, AssetStage}; -use bevy_ecs::schedule::StageLabel; +use bevy_ecs::schedule::{StageLabel, SystemLabel}; use camera::{ ActiveCameras, Camera, DepthCalculation, OrthographicProjection, PerspectiveProjection, RenderLayers, ScalingMode, VisibleEntities, WindowOrigin, @@ -57,6 +58,11 @@ use texture::HdrTextureLoader; #[cfg(feature = "png")] use texture::ImageTextureLoader; +#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemLabel)] +pub enum RenderSystem { + VisibleEntities, +} + /// The names of "render" App stages #[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)] pub enum RenderStage { @@ -157,16 +163,22 @@ impl Plugin for RenderPlugin { ) .add_system_to_stage( CoreStage::PostUpdate, - camera::camera_system::.system(), + camera::camera_system:: + .system() + .before(RenderSystem::VisibleEntities), ) .add_system_to_stage( CoreStage::PostUpdate, - camera::camera_system::.system(), + camera::camera_system:: + .system() + .before(RenderSystem::VisibleEntities), ) - // registration order matters here. this must come after all camera_system:: systems .add_system_to_stage( CoreStage::PostUpdate, - camera::visible_entities_system.system(), + camera::visible_entities_system + .system() + .label(RenderSystem::VisibleEntities) + .after(TransformSystem::TransformPropagate), ) .add_system_to_stage( RenderStage::RenderResource, diff --git a/crates/bevy_render/src/mesh/mesh.rs b/crates/bevy_render/src/mesh/mesh.rs index 95cdeeaf3ba28..73ec6b3b77547 100644 --- a/crates/bevy_render/src/mesh/mesh.rs +++ b/crates/bevy_render/src/mesh/mesh.rs @@ -233,13 +233,10 @@ pub struct Mesh { impl Mesh { /// Per vertex coloring. Use in conjunction with [`Mesh::set_attribute`] pub const ATTRIBUTE_COLOR: &'static str = "Vertex_Color"; - /// The direction the vertex normal is facing in. Use in conjunction with [`Mesh::set_attribute`] pub const ATTRIBUTE_NORMAL: &'static str = "Vertex_Normal"; - /// Where the vertex is located in space. Use in conjunction with [`Mesh::set_attribute`] pub const ATTRIBUTE_POSITION: &'static str = "Vertex_Position"; - /// Texture coordinates for the vertex. Use in conjunction with [`Mesh::set_attribute`] pub const ATTRIBUTE_UV_0: &'static str = "Vertex_Uv"; diff --git a/crates/bevy_scene/src/lib.rs b/crates/bevy_scene/src/lib.rs index 2c816227792ba..92b0fa33df904 100644 --- a/crates/bevy_scene/src/lib.rs +++ b/crates/bevy_scene/src/lib.rs @@ -19,33 +19,20 @@ pub mod prelude { use bevy_app::prelude::*; use bevy_asset::AddAsset; -use bevy_ecs::{ - schedule::{StageLabel, SystemStage}, - system::IntoExclusiveSystem, -}; +use bevy_ecs::{schedule::ExclusiveSystemDescriptorCoercion, system::IntoExclusiveSystem}; #[derive(Default)] pub struct ScenePlugin; -#[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)] -enum SceneStage { - SceneStage, -} - impl Plugin for ScenePlugin { fn build(&self, app: &mut AppBuilder) { app.add_asset::() .add_asset::() .init_asset_loader::() .init_resource::() - .add_stage_after( - CoreStage::Event, - SceneStage::SceneStage, - SystemStage::parallel(), - ) .add_system_to_stage( - SceneStage::SceneStage, - scene_spawner_system.exclusive_system(), + CoreStage::PreUpdate, + scene_spawner_system.exclusive_system().at_end(), ); } } diff --git a/crates/bevy_text/src/text.rs b/crates/bevy_text/src/text.rs index ddf9be3c6665d..b077c2821574c 100644 --- a/crates/bevy_text/src/text.rs +++ b/crates/bevy_text/src/text.rs @@ -102,6 +102,6 @@ impl Default for TextStyle { } #[derive(Default, Copy, Clone, Debug)] -pub struct CalculatedSize { +pub struct Text2dSize { pub size: Size, } diff --git a/crates/bevy_text/src/text2d.rs b/crates/bevy_text/src/text2d.rs index bfa5a3efbae5e..a821ee1a764d0 100644 --- a/crates/bevy_text/src/text2d.rs +++ b/crates/bevy_text/src/text2d.rs @@ -18,9 +18,7 @@ use bevy_transform::prelude::{GlobalTransform, Transform}; use bevy_window::Windows; use glyph_brush_layout::{HorizontalAlign, VerticalAlign}; -use crate::{ - CalculatedSize, DefaultTextPipeline, DrawableText, Font, FontAtlasSet, Text, TextError, -}; +use crate::{DefaultTextPipeline, DrawableText, Font, FontAtlasSet, Text, Text2dSize, TextError}; /// The bundle of components needed to draw text in a 2D scene via the Camera2dBundle. #[derive(Bundle, Clone, Debug)] @@ -31,7 +29,7 @@ pub struct Text2dBundle { pub transform: Transform, pub global_transform: GlobalTransform, pub main_pass: MainPass, - pub calculated_size: CalculatedSize, + pub text_2d_size: Text2dSize, } impl Default for Text2dBundle { @@ -48,7 +46,7 @@ impl Default for Text2dBundle { transform: Default::default(), global_transform: Default::default(), main_pass: MainPass {}, - calculated_size: CalculatedSize { + text_2d_size: Text2dSize { size: Size::default(), }, } @@ -72,7 +70,7 @@ pub fn draw_text2d_system( &Visible, &Text, &GlobalTransform, - &CalculatedSize, + &Text2dSize, ), With, >, @@ -138,7 +136,7 @@ pub fn text2d_system( mut text_pipeline: ResMut, mut text_queries: QuerySet<( Query, Changed)>, - Query<(&Text, &mut CalculatedSize), With>, + Query<(&Text, &mut Text2dSize), With>, )>, ) { // Adds all entities where the text or the style has changed to the local queue diff --git a/crates/bevy_ui/src/entity.rs b/crates/bevy_ui/src/entity.rs index e5a45118fd77c..d7312b4baf10a 100644 --- a/crates/bevy_ui/src/entity.rs +++ b/crates/bevy_ui/src/entity.rs @@ -2,7 +2,7 @@ use super::Node; use crate::{ render::UI_PIPELINE_HANDLE, widget::{Button, Image}, - FocusPolicy, Interaction, Style, + CalculatedSize, FocusPolicy, Interaction, Style, }; use bevy_asset::Handle; use bevy_ecs::bundle::Bundle; @@ -14,7 +14,7 @@ use bevy_render::{ prelude::Visible, }; use bevy_sprite::{ColorMaterial, QUAD_HANDLE}; -use bevy_text::{CalculatedSize, Text}; +use bevy_text::Text; use bevy_transform::prelude::{GlobalTransform, Transform}; #[derive(Bundle, Clone, Debug)] diff --git a/crates/bevy_ui/src/flex/mod.rs b/crates/bevy_ui/src/flex/mod.rs index 87aa13f3c768a..2b89351211cc9 100644 --- a/crates/bevy_ui/src/flex/mod.rs +++ b/crates/bevy_ui/src/flex/mod.rs @@ -1,15 +1,14 @@ mod convert; -use crate::{Node, Style}; +use crate::{CalculatedSize, Node, Style}; use bevy_app::EventReader; use bevy_ecs::{ entity::Entity, - query::{Changed, FilterFetch, Flags, With, Without, WorldQuery}, + query::{Changed, FilterFetch, With, Without, WorldQuery}, system::{Query, Res, ResMut}, }; use bevy_log::warn; use bevy_math::Vec2; -use bevy_text::CalculatedSize; use bevy_transform::prelude::{Children, Parent, Transform}; use bevy_utils::HashMap; use bevy_window::{Window, WindowId, WindowScaleFactorChanged, Windows}; @@ -201,13 +200,7 @@ pub fn flex_node_system( (With, Changed), >, children_query: Query<(Entity, &Children), (With, Changed)>, - mut node_transform_query: Query<( - Entity, - &mut Node, - &mut Transform, - Option<(&Parent, Flags)>, - Flags, - )>, + mut node_transform_query: Query<(Entity, &mut Node, &mut Transform, Option<&Parent>)>, ) { // update window root nodes for window in windows.iter() { @@ -272,9 +265,8 @@ pub fn flex_node_system( let to_logical = |v| (physical_to_logical_factor * v as f64) as f32; - for (entity, mut node, mut transform, parent, transform_flags) in - node_transform_query.iter_mut() - { + // PERF: try doing this incrementally + for (entity, mut node, mut transform, parent) in node_transform_query.iter_mut() { let layout = flex_surface.get_layout(entity).unwrap(); node.size = Vec2::new( to_logical(layout.size.width), @@ -283,12 +275,10 @@ pub fn flex_node_system( let position = &mut transform.translation; position.x = to_logical(layout.location.x + layout.size.width / 2.0); position.y = to_logical(layout.location.y + layout.size.height / 2.0); - if let Some((parent, parent_flags)) = parent { - if parent_flags.changed() || transform_flags.changed() { - if let Ok(parent_layout) = flex_surface.get_layout(parent.0) { - position.x -= to_logical(parent_layout.size.width / 2.0); - position.y -= to_logical(parent_layout.size.height / 2.0); - } + if let Some(parent) = parent { + if let Ok(parent_layout) = flex_surface.get_layout(parent.0) { + position.x -= to_logical(parent_layout.size.width / 2.0); + position.y -= to_logical(parent_layout.size.height / 2.0); } } } diff --git a/crates/bevy_ui/src/lib.rs b/crates/bevy_ui/src/lib.rs index cdbafe22172de..352dba04f4972 100644 --- a/crates/bevy_ui/src/lib.rs +++ b/crates/bevy_ui/src/lib.rs @@ -1,16 +1,15 @@ mod anchors; -pub mod entity; mod flex; mod focus; mod margins; mod render; mod ui_node; + +pub mod entity; pub mod update; pub mod widget; pub use anchors::*; -use bevy_math::{Rect, Size}; -use bevy_render::RenderStage; pub use flex::*; pub use focus::*; pub use margins::*; @@ -23,28 +22,24 @@ pub mod prelude { use bevy_app::prelude::*; use bevy_ecs::{ - schedule::{ParallelSystemDescriptorCoercion, StageLabel, SystemLabel, SystemStage}, + schedule::{ParallelSystemDescriptorCoercion, SystemLabel}, system::IntoSystem, }; +use bevy_input::InputSystem; +use bevy_math::{Rect, Size}; +use bevy_render::RenderStage; +use bevy_transform::TransformSystem; use update::ui_z_system; #[derive(Default)] pub struct UiPlugin; -#[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)] -pub enum UiStage { - Ui, -} - #[derive(Debug, Hash, PartialEq, Eq, Clone, SystemLabel)] pub enum UiSystem { + /// After this label, the ui flex state has been updated Flex, } -pub mod system { - pub const FLEX: &str = "flex"; -} - impl Plugin for UiPlugin { fn build(&self, app: &mut AppBuilder) { app.init_resource::() @@ -63,19 +58,33 @@ impl Plugin for UiPlugin { .register_type::>() .register_type::