Skip to content

Conversation

@ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented Nov 23, 2025

Objective

In UI and world coordinates, “top” and “bottom” mean opposite things, so these fields are ambiguous. Anyone using BorderRect must 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 BorderRect fields (left, right, top, and bottom) with min_inset and max_inset Vec2 fields.

Using min_inset and max_inset removes the need to interpret top or bottom relative to the coordinate system, so the same logic will work consistently in both UI and 2D.

@ickshonpe ickshonpe added D-Trivial Nice and easy! A great choice to get started with Bevy A-Rendering Drawing game state to the screen A-UI Graphical user interfaces, styles, layouts, and widgets C-Code-Quality A section of code that is hard to understand or change S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Nov 25, 2025
@ickshonpe ickshonpe added the M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Nov 26, 2025
Copy link
Contributor

@kfc35 kfc35 left a 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,
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

@ickshonpe ickshonpe Nov 28, 2025

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.

Copy link

@Hilpogar Hilpogar left a 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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen A-UI Graphical user interfaces, styles, layouts, and widgets C-Code-Quality A section of code that is hard to understand or change D-Trivial Nice and easy! A great choice to get started with Bevy M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Needs-Review Needs reviewer attention (from anyone!) to move forward

3 participants