Skip to content

Commit 911952f

Browse files
committed
Revert "Re-add ControlNode for UI"
This reverts commit 3819bc5.
1 parent 3819bc5 commit 911952f

File tree

3 files changed

+15
-103
lines changed

3 files changed

+15
-103
lines changed

pipelined/bevy_ui2/src/entity.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::{
22
widget::{Button, ImageMode},
3-
CalculatedSize, ControlNode, FocusPolicy, Interaction, Node, Style, UiColor, UiImage,
4-
CAMERA_UI,
3+
CalculatedSize, FocusPolicy, Interaction, Node, Style, UiColor, UiImage, CAMERA_UI,
54
};
65
use bevy_ecs::bundle::Bundle;
76
use bevy_render2::{
@@ -11,15 +10,6 @@ use bevy_render2::{
1110
use bevy_text2::Text;
1211
use bevy_transform::prelude::{GlobalTransform, Transform};
1312

14-
/// If you add this to an entity, it should be the *only* bundle on it from bevy_ui.
15-
/// This bundle will mark the entity as transparent to the UI layout system, meaning the
16-
/// children of this entity will be treated as the children of this entity s parent by the layout system.
17-
pub struct ControlBundle {
18-
pub control_node: ControlNode,
19-
pub transform: Transform,
20-
pub global_transform: GlobalTransform,
21-
}
22-
2313
#[derive(Bundle, Clone, Debug, Default)]
2414
pub struct NodeBundle {
2515
pub node: Node,

pipelined/bevy_ui2/src/flex/mod.rs

+13-83
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mod convert;
22

3-
use crate::{CalculatedSize, ControlNode, Node, Style};
3+
use crate::{CalculatedSize, Node, Style};
44
use bevy_app::EventReader;
55
use bevy_ecs::{
66
entity::Entity,
@@ -111,62 +111,19 @@ impl FlexSurface {
111111
}
112112
}
113113

114-
pub fn update_children(
115-
&mut self,
116-
entity: Entity,
117-
children: &Children,
118-
control_node_query: &mut Query<&mut ControlNode>,
119-
unfiltered_children_query: &Query<&Children>,
120-
) {
114+
pub fn update_children(&mut self, entity: Entity, children: &Children) {
121115
let mut stretch_children = Vec::with_capacity(children.len());
122-
fn inner(
123-
true_parent: Entity,
124-
child: Entity,
125-
control_node_query: &mut Query<&mut ControlNode>,
126-
unfiltered_children_query: &Query<&Children>,
127-
do_on_real: &mut impl FnMut(Entity),
128-
) {
129-
if let Ok(mut control_node) = control_node_query.get_mut(child) {
130-
control_node.true_parent = Some(true_parent);
131-
for &child in unfiltered_children_query
132-
.get(child)
133-
.ok()
134-
.into_iter()
135-
.map(|c| &**c)
136-
.flatten()
137-
{
138-
inner(
139-
true_parent,
140-
child,
141-
control_node_query,
142-
unfiltered_children_query,
143-
do_on_real,
144-
);
145-
}
116+
for child in children.iter() {
117+
if let Some(stretch_node) = self.entity_to_stretch.get(child) {
118+
stretch_children.push(*stretch_node);
146119
} else {
147-
do_on_real(child);
120+
warn!(
121+
"Unstyled child in a UI entity hierarchy. You are using an entity \
122+
without UI components as a child of an entity with UI components, results may be unexpected."
123+
);
148124
}
149125
}
150126

151-
for &child in children.iter() {
152-
inner(
153-
entity,
154-
child,
155-
control_node_query,
156-
unfiltered_children_query,
157-
&mut |e| {
158-
if let Some(stretch_node) = self.entity_to_stretch.get(&e) {
159-
stretch_children.push(*stretch_node);
160-
} else {
161-
warn!(
162-
"Unstyled child in a UI entity hierarchy. You are using an entity \
163-
without UI components as a child of an entity with UI components, results may be unexpected."
164-
);
165-
}
166-
},
167-
);
168-
}
169-
170127
let stretch_node = self.entity_to_stretch.get(&entity).unwrap();
171128
self.stretch
172129
.set_children(*stretch_node, stretch_children)
@@ -250,10 +207,7 @@ pub fn flex_node_system(
250207
(Entity, &Style, &CalculatedSize),
251208
(With<Node>, Changed<CalculatedSize>),
252209
>,
253-
changed_children_query: Query<(Entity, &Children), (With<Node>, Changed<Children>)>,
254-
unfiltered_children_query: Query<&Children>,
255-
mut control_node_query: Query<&mut ControlNode>,
256-
changed_cnc_query: Query<Entity, (Changed<Children>, With<ControlNode>)>,
210+
children_query: Query<(Entity, &Children), (With<Node>, Changed<Children>)>,
257211
mut node_transform_query: Query<(Entity, &mut Node, &mut Transform, Option<&Parent>)>,
258212
) {
259213
// update window root nodes
@@ -308,28 +262,8 @@ pub fn flex_node_system(
308262
}
309263

310264
// update children
311-
for (entity, children) in changed_children_query.iter() {
312-
flex_surface.update_children(
313-
entity,
314-
children,
315-
&mut control_node_query,
316-
&unfiltered_children_query,
317-
);
318-
}
319-
320-
for entity in changed_cnc_query.iter() {
321-
let true_parent = if let Some(e) = control_node_query.get_mut(entity).unwrap().true_parent {
322-
e
323-
} else {
324-
continue;
325-
};
326-
let children = unfiltered_children_query.get(true_parent).unwrap();
327-
flex_surface.update_children(
328-
true_parent,
329-
children,
330-
&mut control_node_query,
331-
&unfiltered_children_query,
332-
);
265+
for (entity, children) in children_query.iter() {
266+
flex_surface.update_children(entity, children);
333267
}
334268

335269
// compute layouts
@@ -350,11 +284,7 @@ pub fn flex_node_system(
350284
position.x = to_logical(layout.location.x + layout.size.width / 2.0);
351285
position.y = to_logical(layout.location.y + layout.size.height / 2.0);
352286
if let Some(parent) = parent {
353-
let parent = control_node_query
354-
.get_mut(parent.0)
355-
.map(|cn| cn.true_parent.unwrap())
356-
.unwrap_or(parent.0);
357-
if let Ok(parent_layout) = flex_surface.get_layout(parent) {
287+
if let Ok(parent_layout) = flex_surface.get_layout(parent.0) {
358288
position.x -= to_logical(parent_layout.size.width / 2.0);
359289
position.y -= to_logical(parent_layout.size.height / 2.0);
360290
}

pipelined/bevy_ui2/src/ui_node.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bevy_asset::Handle;
2-
use bevy_ecs::{prelude::*, reflect::ReflectComponent};
2+
use bevy_ecs::{prelude::Component, reflect::ReflectComponent};
33
use bevy_math::{Rect, Size, Vec2};
44
use bevy_reflect::{Reflect, ReflectDeserialize};
55
use bevy_render2::{color::Color, texture::Image};
@@ -12,14 +12,6 @@ pub struct Node {
1212
pub size: Vec2,
1313
}
1414

15-
/// If you add this to an entity, it should be the *only* component on it from bevy_ui.
16-
/// This component marks an entity as "transparent" to the UI layout system, meaning the
17-
/// children of this entity will be treated as the children of this entity s parent by the layout system.
18-
#[derive(Clone, Default, Component)]
19-
pub struct ControlNode {
20-
pub(crate) true_parent: Option<Entity>,
21-
}
22-
2315
#[derive(Copy, Clone, PartialEq, Debug, Serialize, Deserialize, Reflect)]
2416
#[reflect_value(PartialEq, Serialize, Deserialize)]
2517
pub enum Val {

0 commit comments

Comments
 (0)