Skip to content

Conversation

@ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented Nov 21, 2025

Objective

Add helper functions to ComputedNode that return the bounds of the node's border, padding, and content areas.

Solution

Add helper functions border_box, padding_box, and content_box to ComputedNode.

Included a release note. These changes are very trivial and don't really need one, but I've got quite a few more less trivial changes to ComputedNode that I want to add later.

Testing

This PR also includes a couple of trivial tests.

@ickshonpe ickshonpe added A-UI Graphical user interfaces, styles, layouts, and widgets M-Release-Note Work that should be called out in the blog due to impact D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Nov 21, 2025
let mut out = self.border_box();
out.min.x += self.border.left;
out.max.x -= self.border.right;
out.min.y += self.border.top;
Copy link

Choose a reason for hiding this comment

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

This might be a stupid comment because I am new, but is this supposed to be out.min.y += self.border.bottom (and the next line should be out.max.y -= self.border.top)? Same comment about this belongs in content_box too

From reading Rect, I had the impression visually that Rect.min is the lower left point defined as (min.x, min.y) and Rect.max is the upper right point e.g (max.x, max.y), and that the BorderRect left/right/top/bottom values are units “towards its center.” If that’s the case, should min.y should be affected by border.bottom instead?

Copy link
Contributor Author

@ickshonpe ickshonpe Nov 21, 2025

Choose a reason for hiding this comment

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

It's confusing but, opposite to bevy_sprite, in bevy_ui the y-axis increases downwards. So Rect::min corresponds to the position of the top-left corner of the UI node and Rect::max corresponds to its bottom-right corner.

Copy link

Choose a reason for hiding this comment

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

🤦 Thanks for clarifying for me, I must commit this to memory!

@ickshonpe ickshonpe removed the M-Release-Note Work that should be called out in the blog due to impact label Nov 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-UI Graphical user interfaces, styles, layouts, and widgets D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants