Skip to content

Commit 45a379c

Browse files
authored
Opt-out for UI clipping (#19826)
# Objective Opt-out for UI clipping, for motivation see issue #19821 ## Solution New zst component `OverrideClip`. A UI node entity with this component will ignore any inherited clipping rect, so it will never get clipped regardless of the `Overflow` settings of its ancestors. #### Why use a marker component and not add a new variant to `Overflow` instead? A separate marker component allows users to set both `Overflow` and `OverrideClip` on the same node. ## Testing Run the `overflow` example with the `OverrideClip` component added to the `ImagNode`s and you will see that clipping is disabled.
1 parent a0b90cd commit 45a379c

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

crates/bevy_ui/src/ui_node.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,11 @@ pub struct CalculatedClip {
22462246
pub clip: Rect,
22472247
}
22482248

2249+
/// UI node entities with this component will ignore any clipping rect they inherit,
2250+
/// the node will not be clipped regardless of its ancestors' `Overflow` setting.
2251+
#[derive(Component)]
2252+
pub struct OverrideClip;
2253+
22492254
/// Indicates that this [`Node`] entity's front-to-back ordering is not controlled solely
22502255
/// by its location in the UI hierarchy. A node with a higher z-index will appear on top
22512256
/// of sibling nodes with a lower z-index.

crates/bevy_ui/src/update.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
use crate::{
44
experimental::{UiChildren, UiRootNodes},
55
ui_transform::UiGlobalTransform,
6-
CalculatedClip, ComputedNodeTarget, DefaultUiCamera, Display, Node, OverflowAxis, UiScale,
7-
UiTargetCamera,
6+
CalculatedClip, ComputedNodeTarget, DefaultUiCamera, Display, Node, OverflowAxis, OverrideClip,
7+
UiScale, UiTargetCamera,
88
};
99

1010
use super::ComputedNode;
1111
use bevy_ecs::{
1212
change_detection::DetectChangesMut,
1313
entity::Entity,
1414
hierarchy::ChildOf,
15-
query::{Changed, With},
15+
query::{Changed, Has, With},
1616
system::{Commands, Query, Res},
1717
};
1818
use bevy_math::{Rect, UVec2};
@@ -28,6 +28,7 @@ pub fn update_clipping_system(
2828
&ComputedNode,
2929
&UiGlobalTransform,
3030
Option<&mut CalculatedClip>,
31+
Has<OverrideClip>,
3132
)>,
3233
ui_children: UiChildren,
3334
) {
@@ -50,15 +51,22 @@ fn update_clipping(
5051
&ComputedNode,
5152
&UiGlobalTransform,
5253
Option<&mut CalculatedClip>,
54+
Has<OverrideClip>,
5355
)>,
5456
entity: Entity,
5557
mut maybe_inherited_clip: Option<Rect>,
5658
) {
57-
let Ok((node, computed_node, transform, maybe_calculated_clip)) = node_query.get_mut(entity)
59+
let Ok((node, computed_node, transform, maybe_calculated_clip, has_override_clip)) =
60+
node_query.get_mut(entity)
5861
else {
5962
return;
6063
};
6164

65+
// If the UI node entity has an `OverrideClip` component, discard any inherited clip rect
66+
if has_override_clip {
67+
maybe_inherited_clip = None;
68+
}
69+
6270
// If `display` is None, clip the entire node and all its descendants by replacing the inherited clip with a default rect (which is empty)
6371
if node.display == Display::None {
6472
maybe_inherited_clip = Some(Rect::default());

0 commit comments

Comments
 (0)