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

Add UiRect::px() and UiRect::percent() utils #8866

Merged
merged 2 commits into from
Jun 19, 2023

Conversation

djeedai
Copy link
Contributor

@djeedai djeedai commented Jun 17, 2023

Objective

Make the UI code more concise.

Solution

Add two utility methods to make manipulating UiRect from code more concise:

  • UiRect::px() create a new UiRect like the new() function, but with values in logical pixels directly.
  • UiRect::percent() is similar, with values as percentages.

This saves a lot of typing and makes UI code more compact while retaining readability.


Changelog

Added

Added two new constructors UiRect::px() and UiRect::percent() to create a new UiRect from values directly specified in logical pixels and percentages, respectively. The argument order is the same as UiRect::new(), but avoids having to repeat Val::Px and Val::Percent, respectively.

Add two utility methods to make manipulating `UiRect` from code more
concise:
- `UiRect::px()` create a new `UiRect` like the `new()` function, but
  with values in logical pixels directly.
- `UiRect::percent()` is similar, with values as percentages.

This saves a lot of typing and makes UI code more compact while
retaining readability.
@djeedai djeedai requested a review from Aceeri June 17, 2023 10:32
@djeedai djeedai added A-UI Graphical user interfaces, styles, layouts, and widgets C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Jun 17, 2023
@djeedai djeedai added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jun 18, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 19, 2023
Merged via the queue into bevyengine:main with commit 960e797 Jun 19, 2023
james7132 pushed a commit to james7132/bevy that referenced this pull request Jun 19, 2023
# Objective

Make the UI code more concise.

## Solution

Add two utility methods to make manipulating `UiRect` from code more
concise:
- `UiRect::px()` create a new `UiRect` like the `new()` function, but
with values in logical pixels directly.
- `UiRect::percent()` is similar, with values as percentages.

This saves a lot of typing and makes UI code more compact while
retaining readability.

---

## Changelog

### Added

Added two new constructors `UiRect::px()` and `UiRect::percent()` to
create a new `UiRect` from values directly specified in logical pixels
and percentages, respectively. The argument order is the same as
`UiRect::new()`, but avoids having to repeat `Val::Px` and
`Val::Percent`, respectively.
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 C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants