Skip to main content

Module clip

Module clip 

Source
Expand description

Render-world half of clip-independent layer capture: the extract-window clip swap, and the composite quad’s rect clamp.

The swap. Stock bevy_ui_render extraction copies each node’s CalculatedClip onto its extracted items, and the prepare stage bakes that clip into vertices — including inside our capture passes. To keep ancestor clips out of captures without forking any extractor (several, like the gradient one, live in private modules), the members’ clips are swapped for their interior values (crate::layer::clip::LayerClips) for exactly the duration of ExtractSchedule: swap_interior_clips_in runs before every stock UI extraction set and swap_interior_clips_out restores the originals after them. The main world is exclusively borrowed for the whole window (that is what ResMut<MainWorld> means), so no main-world system — picking, focus, bevy_ui itself — can ever observe a swapped value.

Swap mechanics: values are overwritten in place (never inserted/removed — a member whose interior clip is Some provably carries a real CalculatedClip, so there is no archetype churn), “unclipped” is an all-infinite rect (idiomatic — bevy_ui itself uses ±∞ clip axes for Visible overflow), and both directions bypass change detection (the net effect within a frame is identity; update_clipping’s own != guard must not see churn). Known gap: a UiMaterial extractor is generic and unordered relative to the swap window — unused in this repo.

The quad clamp. With captures unclipped, the composite quad applies the ancestor clipping instead: clip_quad clamps the quad’s corners to the layer’s quad clip and shifts UVs proportionally (the same positions_diff technique stock prepare uses on item vertices). A fully clipped-away layer yields None — its quad simply isn’t batched.

Structs§

ClippedQuad
A composite quad clamped to its clip: screen-space corners plus the matching capture-texture UV window.
SwappedClips
The originals stashed by swap_interior_clips_in, restored by swap_interior_clips_out. Render-world resource; drained every frame.

Constants§

UNCLIPPED
“No clip” as a value: bevy_ui expresses visible-overflow axes as ±∞, and the prepare-stage clip math is a no-op against it.

Functions§

clip_quad
Clamp a layer’s composite quad (min, size — the capture rect) to its quad clip. None clip = the full quad; an empty or degenerate intersection returns None (draw nothing). UVs shift proportionally on clamped sides only, so the visible part of the capture stays put on screen.
swap_in
Core of swap_interior_clips_in, factored on &mut World for tests.
swap_interior_clips_in
ExtractSchedule, before all stock UI extraction sets: overwrite each promoted-subtree member’s CalculatedClip with its interior clip.
swap_interior_clips_out
ExtractSchedule, after all stock UI extraction sets: restore the originals so the main world resumes with true inherited clips in place.
swap_out
Core of swap_interior_clips_out: restore every stashed original.