Repository navigation
Conversation
… the layer order, and UiSubZLayers enum to identify the builtin layers. Doesn't compile yet.
On changes to the sub layers ordering, reextract everything.
Contributor
Author
|
Closed by accident. |
UiSubZLayer -> PaintLayer UiZubZLayers -> NodePaintLayers bevy_ui_render::sub_z_layers -> bevy_ui_render::paint_layers
Now it wraps an `IndexSet` instead of `Vec`. Added a `get_layer_index` helper function to replace the duplicated error handling code in the methods.
More idiomatic From impls. Renamed `insert_before`/`after` to `insert_before_label`/ `after_label` to avoid shadowing.
Added `remove_layer` method to `PaintOrder` Added tests sub module with default order test
If you insert the same label twice in the from impls, the label is moved to the second position.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Replace the hardcod
f32z-offsets that we add to the stack index to order each element with local named Z layers that can be ordered relative to each other.Related issues (doesn't exactly solve) #1275, #24564.
Solution
Add paint layers to
bevy_ui_render.The
PaintOrderresource holds the list of paint layers, in the order they’re drawn from back to front..The built-in layers are identified by the
NodePaintLayerenum:UiRenderPlugininitializesPaintOrderwith all the builtin layers in the correct order.Custom layers
To create a new
PaintLayer, you derivePaintLayer:Or you can define multiple layers at once with an enum:
Ordering
insert_before_layer/insert_after_layerplace a layer directly below or above an existing layer.insert_top/insert_bottomplace a layer above or below all the other layers.remove_layerremoves a layer. A built-in element whose layer is removed isn't drawn.The insert methods move the layer if it's already present.
The
UiMaterialtrait has a newpaint_layer()method that chooses the layer the layer the material is drawn to.It defaults to
NodePaintLayer::Material.PaintOrderjust newtypes anIndexSet, so you can also use theIndexSetmethods to reorder it arbitrarily.Extraction
Extraction functions should look up the z-offsets for their elements layer with
PaintOrder::get_offset, which returns a value in the range0.0..1.0. The z-offset should be looked up once at the start of the extraction function, and shouldn't be looked up per node if at all possible.The
PaintOrderresource is also extracted separately, so the offsets can be applied in some queue functions instead for some elements. This is because extraction isn't as centralized as it should be.Changing
PaintOrderat all is expensive as it triggers a reextraction of all elements.Implementation
The
paint_layersmodule contains all the new functionality.The proc macro for the
PaintLayerlabel derive is in a newrendlayers/macrossubscrate. It's adapted frombevy_render's macros crate.The paint order is global. There's no builtin support for reordering painting per node.
Testing
The UI testbed shouldn't exhibit any changes:
There are some tests for
PaintOrderin thepaint_layersmodule.AI Disclosure
I used claude to work out some errors with the macro crate to get the imports and paths right so it would compile, and write most of the
paint_layerstests.