From 2d3f35dfb4da0e3d3590a8e64eec352049df9aee Mon Sep 17 00:00:00 2001 From: geom3trik Date: Thu, 30 Sep 2021 02:43:51 +0100 Subject: [PATCH] Fix lifetimes to work with new System Param Lifetime Split #2605 --- crates/bevy_ui/src/layout/mod.rs | 48 ++++++++++++++++---------------- crates/bevy_ui/src/lib.rs | 5 ++-- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/crates/bevy_ui/src/layout/mod.rs b/crates/bevy_ui/src/layout/mod.rs index b08f30c5dc920..0b1c0a3f1b04f 100644 --- a/crates/bevy_ui/src/layout/mod.rs +++ b/crates/bevy_ui/src/layout/mod.rs @@ -20,7 +20,7 @@ impl NodeEntity { } impl<'world> morphorm::Node<'world> for NodeEntity { - type Data = Query<'world, &'static Style>; + type Data = Query<'world, 'world, &'static Style>; fn layout_type(&self, query: &Self::Data) -> Option { query.get(self.entity()).map_or(None, |style| Some(style.layout_type)) @@ -169,16 +169,16 @@ pub struct NodeFirstChild(pub NodeEntity); pub struct NodeNextSibling(pub NodeEntity); -pub struct Tree<'borrow, 'world> { +pub struct Tree<'borrow, 'world, 'state> { root: NodeEntity, - parent_query: &'borrow Query<'world, &'static NodeParent>, - first_child_query: &'borrow Query<'world, &'static NodeFirstChild>, - next_sibling_query: &'borrow Query<'world, &'static NodeNextSibling>, + parent_query: &'borrow Query<'world, 'state, &'static NodeParent>, + first_child_query: &'borrow Query<'world, 'state, &'static NodeFirstChild>, + next_sibling_query: &'borrow Query<'world, 'state, &'static NodeNextSibling>, } -impl<'borrow,'world> Tree<'borrow,'world> +impl<'borrow,'world,'state> Tree<'borrow,'world,'state> { - pub fn new(root: NodeEntity, parent_query: &'borrow Query<'world, &'static NodeParent>, first_child_query: &'borrow Query<'world, &'static NodeFirstChild>, next_sibling_query: &'borrow Query<'world, &'static NodeNextSibling>) -> Self { + pub fn new(root: NodeEntity, parent_query: &'borrow Query<'world, 'state, &'static NodeParent>, first_child_query: &'borrow Query<'world, 'state, &'static NodeFirstChild>, next_sibling_query: &'borrow Query<'world, 'state, &'static NodeNextSibling>) -> Self { Self { root, parent_query, @@ -188,7 +188,7 @@ impl<'borrow,'world> Tree<'borrow,'world> } } -impl<'borrow,'world> Tree<'borrow,'world> +impl<'borrow,'world,'state> Tree<'borrow,'world,'state> { pub fn flatten(&self) -> Vec { @@ -212,12 +212,12 @@ impl<'borrow,'world> Tree<'borrow,'world> } } -impl<'borrow,'world> morphorm::Hierarchy<'borrow> for Tree<'borrow,'world> +impl<'borrow,'world,'state> morphorm::Hierarchy<'borrow> for Tree<'borrow,'world,'state> { type Item = NodeEntity; type DownIter = std::vec::IntoIter; type UpIter = Rev>; - type ChildIter = ChildIterator<'borrow, 'world>; + type ChildIter = ChildIterator<'borrow, 'world, 'state>; fn up_iter(&self) -> Self::UpIter { self.flatten().into_iter().rev() @@ -268,14 +268,14 @@ impl<'borrow,'world> morphorm::Hierarchy<'borrow> for Tree<'borrow,'world> } -pub struct DownwardIterator<'borrow,'world> { - parent_query: &'borrow Query<'world, &'static NodeParent>, - first_child_query: &'borrow Query<'world, &'static NodeFirstChild>, - next_sibling_query: &'borrow Query<'world, &'static NodeNextSibling>, +pub struct DownwardIterator<'borrow,'world,'state> { + parent_query: &'borrow Query<'world, 'state, &'static NodeParent>, + first_child_query: &'borrow Query<'world, 'state, &'static NodeFirstChild>, + next_sibling_query: &'borrow Query<'world, 'state, &'static NodeNextSibling>, current_node: Option, } -impl<'borrow,'world> Iterator for DownwardIterator<'borrow,'world> { +impl<'borrow,'world,'state> Iterator for DownwardIterator<'borrow,'world,'state> { type Item = NodeEntity; fn next(&mut self) -> Option { @@ -304,12 +304,12 @@ impl<'borrow,'world> Iterator for DownwardIterator<'borrow,'world> { } } -pub struct ChildIterator<'borrow, 'world> { - pub next_sibling_query: &'borrow Query<'world, &'static NodeNextSibling>, +pub struct ChildIterator<'borrow, 'world,'state> { + pub next_sibling_query: &'borrow Query<'world, 'state, &'static NodeNextSibling>, pub current_node: Option, } -impl<'borrow, 'world> Iterator for ChildIterator<'borrow, 'world> { +impl<'borrow, 'world, 'state> Iterator for ChildIterator<'borrow, 'world, 'state> { type Item = NodeEntity; fn next(&mut self) -> Option { if let Some(entity) = self.current_node { @@ -691,19 +691,19 @@ impl Command for PushNodes { } } -pub struct NodeBuilder<'a, 'b> { - commands: &'b mut Commands<'a>, +pub struct NodeBuilder<'a, 'b, 'state> { + commands: &'b mut Commands<'a, 'state>, push_children: PushNodes, } -impl<'a, 'b> NodeBuilder<'a, 'b> { - pub fn spawn_bundle(&mut self, bundle: impl Bundle) -> EntityCommands<'a, '_> { +impl<'a, 'b, 'state> NodeBuilder<'a, 'b, 'state> { + pub fn spawn_bundle(&mut self, bundle: impl Bundle) -> EntityCommands<'a, 'state, '_> { let e = self.commands.spawn_bundle(bundle); self.push_children.children.push(e.id()); e } - pub fn spawn(&mut self) -> EntityCommands<'a, '_> { + pub fn spawn(&mut self) -> EntityCommands<'a, 'state, '_> { let e = self.commands.spawn(); self.push_children.children.push(e.id()); e @@ -724,7 +724,7 @@ pub trait TreeBuilder { fn with_node_children(&mut self, f: impl FnOnce(&mut NodeBuilder)) -> &mut Self; } -impl<'a, 'b> TreeBuilder for EntityCommands<'a, 'b> { +impl<'a, 'b, 'state> TreeBuilder for EntityCommands<'a, 'state, 'b> { fn with_node_children(&mut self, spawn_children: impl FnOnce(&mut NodeBuilder)) -> &mut Self { let parent = self.id(); let push_children = { diff --git a/crates/bevy_ui/src/lib.rs b/crates/bevy_ui/src/lib.rs index b29436ff8b2c7..cbce60b756ed8 100644 --- a/crates/bevy_ui/src/lib.rs +++ b/crates/bevy_ui/src/lib.rs @@ -48,7 +48,7 @@ pub enum UiSystem { } impl Plugin for UiPlugin { - fn build(&self, app: &mut AppBuilder) { + fn build(&self, app: &mut App) { app.init_resource::() // .register_type::() // .register_type::() @@ -104,6 +104,7 @@ impl Plugin for UiPlugin { // ) //.add_system_to_stage(RenderStage::Draw, widget::draw_text_system.system()); - crate::render::add_ui_graph(app.world_mut()); + //crate::render::add_ui_graph(app.world_mut()); + crate::render::add_ui_graph(&mut app.world) } }