-
- Notifications
You must be signed in to change notification settings - Fork 4.3k
Resolve BorderRect ambiguity #21915
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
base: main
Are you sure you want to change the base?
Resolve BorderRect ambiguity #21915
Conversation
…m) with `min` and `max` `Vec2` fields.
…onpe/bevy into rename-border-rects-fields
kfc35 left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this!
| right: horizontal, | ||
| top: vertical, | ||
| bottom: vertical, | ||
| min_inset: insets, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: for consistency with the other constructors, you can assign these insets to separate Vec2::new’s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean, this?
pub const fn axes(horizontal: f32, vertical: f32) -> Self { Self { min_inset: Vec2::new(horizontal, vertical), max_inset: Vec2::new(horizontal, vertical), } }I prefer the the single Vec2 constructor version I think as less error prone, though the difference is very marginal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also considered swapping axes parameters to a Vec2. I think it might be more ergonomic, but a vector implies direction. The inputs here are directionless, so the semantics with separate f32's feel better to me.
Hilpogar left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I understand, the min_inset is supposed to be the top_left corner in the UI coordinates and the bottom_left corner in the 2D World coordinate. But in the code, you consistently used the top_left corner as the min_inset for both the sprite and the UI. Is it an error or am I missing something ?
Objective
In UI and world coordinates, “top” and “bottom” mean opposite things, so these fields are ambiguous. Anyone using
BorderRectmust decide themselves how to apply the vertical insets.Fixes #21913
For more in detail motivation, see the replies to issue #21913
Solution
Replace the directional
BorderRectfields (left,right,top, andbottom) withmin_insetandmax_insetVec2fields.Using
min_insetandmax_insetremoves the need to interprettoporbottomrelative to the coordinate system, so the same logic will work consistently in both UI and 2D.