-
-
Notifications
You must be signed in to change notification settings - Fork 377
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::split method #729
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #729 +/- ##
=====================================
Coverage 92.3% 92.3%
=====================================
Files 55 55
Lines 14811 14830 +19
=====================================
+ Hits 13674 13693 +19
Misses 1137 1137 ☔ View full report in Codecov by Sentry. |
I want two approvals on this one - mainly for working out whether the naming makes sense. |
In terms of names, I would have preferred let [top, main] =
Layout::vertical([Constraint::Length(1), Constraint::Min(0)])
.split_array(area); versus let [top, main] =
Layout::vertical([Constraint::Length(1), Constraint::Min(0)])
.area(area)
.split_into(); With the functionality as is, I think the name |
I have a small preference for layout.split(area)
.to_vec()
.try_into()
.unwrap() is replaced by this: layout.split_into_array(area) |
I like
Once merged, I assume this will be the main splitting method used. |
Maybe it is worth introducing a breaking change for this and replacing |
I'm 👎 on breaking .spilt - 1.1K calls But what about split_area() as a compromise on verbosity?
There's a PR that shows how the code would look using this #731 |
I like in order of preference:
|
I think 1,2, and 3 are all problematic because they imply that the area is the (linguistic) object associated with the verb (split_into, split_into_array, split_array). Area is not the object of the sentence its the subject. Only a bare verb, or a verb phrase that repeats the subject communicates this properly. Put in a sentence we want:
|
4adb638
to
2753e9c
Compare
Chatting on Discord - @kdheepak made the observation that this then leads to: area.split(Layout::horizontal([constraints])); which I've added. |
Needs:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me!
But maybe useful to get one more review for feedback on area.split(&layout)
?
Yep - definitely want one on this. I'm going to rebase and rewrite the commit for the CHANGELOG also. |
b27c2b7
to
30ee130
Compare
rebased and commit message / PR text updated. |
30ee130
to
0155df8
Compare
This method splits a Rect and returns a fixed-size array of the resulting Rects. This allows the caller to use array destructuring to get the individual Rects. ```rust use Constraint::*; let layout = &Layout::vertical([Length(1), Min(0)]); let [top, main] = area.split(&layout); ```
0155df8
to
f2eaac9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice if we could write
area.split([Constraint::Length(10), Constraint::Length(10)]);
area.split([10, 10]);
Not too sure about the second one but the first one is definitely something I'd like.
Approving as this can be part of another PR.
Direction to split is necessary, so perhaps fn split_horizontal<const N: usize, T: IntoIterator<Item = Into<Constraint>>(self, constraints: T) -> [Rect; N] {
self.split(Layout::horizontal(constraints));
} But at that point we're just losing a single word (Layout), which is a good one to keep as it makes it a little more obvious what the [1,2,3] does. I like there to be a solid obvious way to do something. Do you think having both |
I wasn't too sure about that, let's forget that for now.
Probably yes, this is confusing. I though of my suggestion as fn split<const N: usize, L: Into<Layout>>(self, layout: L) That way you can still write That would require implementing
As for direction I'd just use the default one. Use layout if you want something else. |
I'd prefer to avoid defaulting the direction implicitly as it makes the code difficult to read unless you know what that default is. Happy to do it with `default(), but it should be explicit otherwise. |
Alright lets leave it as is for now. On second thought after reading the updated examples it seems fine to me. |
This method splits a Rect and returns a fixed-size array of the
resulting Rects. This allows the caller to use array destructuring
to get the individual Rects.