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

feat(layout): add Rect -> Size conversion methods #789

Merged
merged 1 commit into from
Jan 11, 2024
Merged

feat(layout): add Rect -> Size conversion methods #789

merged 1 commit into from
Jan 11, 2024

Conversation

joshka
Copy link
Member

@joshka joshka commented Jan 11, 2024

  • add Size::new() constructor
  • add Rect::as_size()
  • impl From for Size
  • document and add tests for Size

- add Size::new() constructor
- add Rect::as_size()
- impl From<Rect> for Size
- document and add tests for Size
Copy link

codecov bot commented Jan 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (ffd5fc7) 92.4% compared to head (6e2e4b1) 92.5%.

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #789   +/-   ##
=====================================
  Coverage   92.4%   92.5%           
=====================================
  Files         57      57           
  Lines      15038   15078   +40     
=====================================
+ Hits       13904   13948   +44     
+ Misses      1134    1130    -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@Valentin271 Valentin271 left a comment

Choose a reason for hiding this comment

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

Looks good. Why do we need that? Maybe it's worth adding an example somewhere if its relevant to users.

@joshka
Copy link
Member Author

joshka commented Jan 11, 2024

In Oatmeal, I noticed some code where app was storing the most recent height and width of a rect and then later comparing those with each other (paraphrased a bit)

if area.width != state.width || area.height != state.height {
    state.width = area.width;
    state.height = area.height;
    do_some_update();
}

This simplifies that use case to:

if area.as_size() != state.size {
    state.size = area.as_size();
    do_some_update();
}

Maybe it's worth adding an example somewhere if its relevant to users.

I think this is more of a utility type method. Something that can be used optimistically when needed rather than something that needs a demo or examples.

I'm also going to add a Position { x, y } struct as a followup PR for similar reasons.

@Valentin271
Copy link
Member

I think this is more of a utility type method. Something that can be used optimistically when needed rather than something that needs a demo or examples.

Seeing the usecase I agree. All good to me then.

@Valentin271 Valentin271 merged commit 1561d64 into main Jan 11, 2024
34 checks passed
@Valentin271 Valentin271 deleted the size branch January 11, 2024 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants