Add optional alpha-threshold passthrough to the UI picking backend - #25077
Add optional alpha-threshold passthrough to the UI picking backend#25077mgi388 wants to merge 16 commits into
Conversation
|
The generated |
|
Probably should have done this back when we did the non-ui version. Sorry that's on me for not thinking 😂 Nice one! |
Not at all! You deserve the credit here and paved the way for this so thank you! |
| // bottom right. | ||
| let relative_cursor_position = | ||
| node.transform.inverse().transform_point2(*cursor_position) | ||
| / node.node.size(); |
There was a problem hiding this comment.
Is this right with respect to borders and padding? I would like some tests to verify: it's easy for this to get confused.
| // A backing panel that fills the node's rectangle, so the | ||
| // transparent parts of the image are visible against it. | ||
| ImageNode { image: "branding/bevy_bird_dark.png" } | ||
| BackgroundColor(Color::srgb(0.15, 0.15, 0.15)) |
There was a problem hiding this comment.
We should account for the effects of the BackgroundColor as well, right? Can you add a test to make sure that works?
|
|
||
| let Ok(color) = image.get_color_at(texture_position.x as u32, texture_position.y as u32) else { | ||
| // We don't know how to interpret the pixel. | ||
| return false; |
There was a problem hiding this comment.
We should at least warn! here.
There was a problem hiding this comment.
I believe this will be too spammy if we log anything here but I'll double check when I resolve the other feedback.
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { |
There was a problem hiding this comment.
These tests need more coverage of the node -> correct UV path.
| /// `0..1` with `(0, 0)` at the top left) has an alpha value greater than | ||
| /// `cutoff`. | ||
| /// | ||
| /// Nodes whose image can't be sampled are treated as hits. This includes nodes |
There was a problem hiding this comment.
The semantics feel weird here. Should we be returning something other than a bool?
alice-i-cecile
left a comment
There was a problem hiding this comment.
More cleanup to do, and a couple of possible bugs <3 More tests please!
|
@alice-i-cecile I'm still working on resolving the rest of your comments, so I'm reverting the label change if that's OK :) |
Objective
Solution
bevy_ui.Testing
sprite_pickingexample:Showcase
Screen.Recording.2026-07-20.at.10.35.18.pm.mov