bevy/crates
ickshonpe 6d3965f520
Overflow clip margin (#15561)
# Objective

Limited implementation of the CSS property `overflow-clip-margin`
https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-clip-margin

Allows you to control the visible area for clipped content when using
overfllow-clip, -hidden, or -scroll and expand it with a margin.

Based on #15442

Fixes #15468

## Solution

Adds a new field to Style: `overflow_clip_margin: OverflowClipMargin`.
The field is ignored unless overflow-clip, -hidden or -scroll is set on
at least one axis.

`OverflowClipMargin` has these associated constructor functions:
```
pub const fn content_box() -> Self;
pub const fn padding_box() -> Self;
pub const fn border_box() -> Self;
```
You can also use the method `with_margin` to increases the size of the
visible area:
```
commands
  .spawn(NodeBundle {
      style: Style {
          width: Val::Px(100.),
          height: Val::Px(100.),
          padding: UiRect::all(Val::Px(20.)),
          border: UiRect::all(Val::Px(5.)),
          overflow: Overflow::clip(),
          overflow_clip_margin: OverflowClipMargin::border_box().with_margin(25.),
          ..Default::default()
      },
      border_color: Color::BLACK.into(),
      background_color: GRAY.into(),
      ..Default::default()
  })
```
`with_margin` expects a length in logical pixels, negative values are
clamped to zero.

## Notes
* To keep this PR as simple as possible I omitted responsive margin
values support. This could be added in a follow up if we want it.
* CSS also supports a `margin-box` option but we don't have access to
the margin values in `Node` so it's probably not feasible to implement
atm.

## Testing

```cargo run --example overflow_clip_margin```

<img width="396" alt="overflow-clip-margin" src="https://github.com/user-attachments/assets/07b51cd6-a565-4451-87a0-fa079429b04b">

## Migration Guide

Style has a new field `OverflowClipMargin`.  It allows users to set the visible area for clipped content when using overflow-clip, -hidden, or -scroll and expand it with a margin.

There are three associated constructor functions `content_box`, `padding_box` and `border_box`:
* `content_box`: elements painted outside of the content box area (the innermost part of the node excluding the padding and border) of the node are clipped. This is the new default behaviour.
* `padding_box`: elements painted outside outside of the padding area of the node are clipped. 
* `border_box`:  elements painted outside of the bounds of the node are clipped. This matches the behaviour from Bevy 0.14.

There is also a `with_margin` method that increases the size of the visible area by the given number in logical pixels, negative margin values are clamped to zero.

`OverflowClipMargin` is ignored unless overflow-clip, -hidden or -scroll is also set on at least one axis of the UI node.

---------

Co-authored-by: UkoeHB <37489173+UkoeHB@users.noreply.github.com>
2024-10-16 13:17:49 +00:00
..
bevy_a11y Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
bevy_animation Some animation doc improvements (#15860) 2024-10-11 20:52:58 +00:00
bevy_app Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
bevy_asset [Adopted] Add a method for asynchronously waiting for an asset to load (#15913) 2024-10-15 02:50:33 +00:00
bevy_audio Fix audio not playing (#15638) 2024-10-04 01:07:09 +00:00
bevy_color Fix bevy_color not compiling standalone. (#15938) 2024-10-15 23:52:45 +00:00
bevy_core Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
bevy_core_pipeline Implement WorldQuery for MainWorld and RenderWorld components (#15745) 2024-10-13 20:58:46 +00:00
bevy_derive move ANDROID_APP to bevy_window (#15585) 2024-10-02 03:01:06 +00:00
bevy_dev_tools Text Rework cleanup (#15887) 2024-10-15 02:32:34 +00:00
bevy_diagnostic Update sysinfo requirement from 0.31.0 to 0.32.0 (#15697) 2024-10-07 07:31:17 +00:00
bevy_dylib Generate links to definition in source code pages on docs.rs and dev-docs.bevyengine.org (#12965) 2024-07-29 23:10:16 +00:00
bevy_ecs Add Trigger::components, which lists the component targets that were triggered (#15811) 2024-10-15 02:17:03 +00:00
bevy_encase_derive Update `glam to 0.29, encase` to 0.10. (#15249) 2024-09-23 19:44:02 +00:00
bevy_gilrs Remove thiserror from bevy_gilrs (#15773) 2024-10-09 14:21:25 +00:00
bevy_gizmos Fix gizmos (#15836) 2024-10-10 22:04:04 +00:00
bevy_gltf Remove incorrect equality comparisons for asset load error types (#15890) 2024-10-14 01:00:45 +00:00
bevy_hierarchy Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
bevy_image Fix typos from greyscale -> grayscale (#15947) 2024-10-16 12:30:23 +00:00
bevy_input Remove thiserror from bevy_input (#15770) 2024-10-09 14:23:01 +00:00
bevy_internal Add mesh picking backend and MeshRayCast system parameter (#15800) 2024-10-13 17:24:19 +00:00
bevy_log Use oslog for ios (#13364) 2024-10-11 08:58:14 +00:00
bevy_macro_utils Modify derive_label to support no_std environments (#15465) 2024-09-27 20:23:26 +00:00
bevy_math Use #[doc(fake_variadic)] on StableInterpolate (#15933) 2024-10-15 23:40:42 +00:00
bevy_mesh Fix *most* clippy lints (#15906) 2024-10-14 20:52:35 +00:00
bevy_mikktspace Add no_std support to bevy_mikktspace (#15528) 2024-09-30 18:17:03 +00:00
bevy_pbr Fix typos from greyscale -> grayscale (#15947) 2024-10-16 12:30:23 +00:00
bevy_picking Add mesh picking backend and MeshRayCast system parameter (#15800) 2024-10-13 17:24:19 +00:00
bevy_ptr Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
bevy_reflect bevy_reflect: get_represented_kind_info APIs for reflected kinds (#14380) 2024-10-15 02:08:31 +00:00
bevy_remote Remove a dbg! statement left over from debugging (#15867) 2024-10-12 09:07:01 +00:00
bevy_render Remove ExtractComponent::Out (#15926) 2024-10-15 23:42:35 +00:00
bevy_scene Rename App/World::observe to add_observer, EntityWorldMut::observe_entity to observe. (#15754) 2024-10-09 15:39:29 +00:00
bevy_sprite Revert default mesh materials (#15930) 2024-10-15 19:47:40 +00:00
bevy_state Add World::get_resource_or_init as an alternative to World::get_resource_or_insert_with (#15758) 2024-10-09 20:56:26 +00:00
bevy_tasks bump async-channel to 2.3.0 (#15497) 2024-09-28 19:21:59 +00:00
bevy_text Text Rework cleanup (#15887) 2024-10-15 02:32:34 +00:00
bevy_time Fix overflow panic on Stopwatch at Duration::MAX (#15927) 2024-10-15 14:14:44 +00:00
bevy_transform Remove thiserror from bevy_transform (#15761) 2024-10-09 14:27:30 +00:00
bevy_ui Overflow clip margin (#15561) 2024-10-16 13:17:49 +00:00
bevy_utils Fix detailed_trace module scope (#15912) 2024-10-15 02:48:36 +00:00
bevy_window Add window drag move and drag resize without decoration example. (#15814) 2024-10-15 23:38:35 +00:00
bevy_winit Add window drag move and drag resize without decoration example. (#15814) 2024-10-15 23:38:35 +00:00