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(rect): add Rect::positions iterator #928

Merged
merged 1 commit into from Feb 6, 2024
Merged

Conversation

joshka
Copy link
Member

@joshka joshka commented Feb 6, 2024

Useful for performing some action on all the cells in a particular area. E.g.,

fn render(area: Rect, buf: &mut Buffer) {
   for position in area.positions() {
        buf.get_mut(position.x, position.y).set_symbol("x");
    }
}

@joshka joshka changed the title add positions iter feat: add Rect::positions iterator Feb 6, 2024
Copy link

codecov bot commented Feb 6, 2024

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (c3fb258) 92.0% compared to head (d0cab5a) 92.0%.

Files Patch % Lines
src/layout/rect.rs 0.0% 3 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #928   +/-   ##
=====================================
  Coverage   92.0%   92.0%           
=====================================
  Files         61      61           
  Lines      15521   15552   +31     
=====================================
+ Hits       14286   14315   +29     
- Misses      1235    1237    +2     

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

@kdheepak
Copy link
Collaborator

kdheepak commented Feb 6, 2024

Is there value in iterating vertically and horizontally? I'm not sure what to call it but the feature equivalent of positions_row_major() vs positions_column_major()?

@joshka
Copy link
Member Author

joshka commented Feb 6, 2024

Is there value in iterating vertically and horizontally? I'm not sure what to call it but the feature equivalent of positions_row_major() vs positions_column_major()?

Probably not, mainly because we're usually dealing with text, but area.columns().flat_map(Area::positions) gets you that in a one liner if needed.

@orhun orhun changed the title feat: add Rect::positions iterator feat(rect): add Rect::positions iterator Feb 6, 2024
Copy link
Sponsor Member

@orhun orhun left a comment

Choose a reason for hiding this comment

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

LGTM

@joshka joshka merged commit 74a0511 into main Feb 6, 2024
41 of 42 checks passed
@joshka joshka deleted the add-positions-iter branch February 6, 2024 17: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.

None yet

3 participants