Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Z-ordering of shapes #2482

Closed
wants to merge 15 commits into from
Closed

Z-ordering of shapes #2482

wants to merge 15 commits into from

Conversation

mxsdev
Copy link

@mxsdev mxsdev commented Dec 19, 2022

Closes #1516.

This PR implements the feature in the exact way described by @emilk. Library consumers are expected to set z-index using ui.with_z(...).

I've added an example to examples demonstrating the feature.

screenshot

@emilk
Copy link
Owner

emilk commented Dec 26, 2022

Thanks for working on this! 🙏

I'm heading off to a long vacation, so it will be at least a month until I will get to reviewing this. Just a heads-up!

Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice - thanks for working on this!

Most of my comments is about naming, but there is one real blocker which is the sorting of the layers. It should be done once, instead of on each interaction.

for &(prev_id, prev_rect) in rects.iter().rev() {
if prev_id == id {
if let Some(rects) = slf.layer_rects_prev_frame.get_mut(&layer.area_layer) {
rects.sort_by_key(|(_id, z, ..)| *z);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-sorting this on each interaction is unnecessary. Better to sort once at the end of each frame instead.

crates/egui/src/layers.rs Show resolved Hide resolved
crates/egui/src/ui.rs Show resolved Hide resolved
crates/egui/src/ui.rs Show resolved Hide resolved
crates/egui/src/ui.rs Show resolved Hide resolved
crates/egui/src/ui.rs Show resolved Hide resolved
painter.rect_filled(response.rect, Rounding::none(), Color32::BLUE);

if response.clicked() {
log::info!("Clicked blue");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really nice that you test interaction too ⭐

crates/egui/src/layers.rs Show resolved Hide resolved
@emilk emilk mentioned this pull request Jan 26, 2023
@emilk
Copy link
Owner

emilk commented Jan 26, 2023

Continued in #2633

@emilk emilk closed this Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Z-ordering of shapes
2 participants