Skip to content

Commit

Permalink
docs(layout): document the difference in the split methods (#750)
Browse files Browse the repository at this point in the history
* docs(layout): document the difference in the split methods

* fix: doc suggestion
  • Loading branch information
joshka authored Jan 5, 2024
1 parent fb93db0 commit fe84141
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/layout/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ impl Layout {
/// LruCache, and grows until [`Self::DEFAULT_CACHE_SIZE`] is reached by default, if the cache
/// is initialized with the [Layout::init_cache()] grows until the initialized cache size.
///
/// There is a helper method on Rect that can be used to split the whole area into smaller ones
/// based on the layout: [`Rect::split()`]. That method is a shortcut for calling this method.
/// It allows you to destructure the result directly into variables, which is useful when you
/// know at compile time the number of areas that will be created.
///
/// # Examples
///
/// ```
Expand Down
5 changes: 5 additions & 0 deletions src/layout/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ impl Rect {
/// An ergonomic wrapper around [`Layout::split`] that returns an array of `Rect`s instead of
/// `Rc<[Rect]>`.
///
/// This method requires the number of constraints to be known at compile time. If you don't
/// know the number of constraints at compile time, use [`Layout::split`] instead.
///
/// # Panics
///
/// Panics if the number of constraints is not equal to the length of the returned array.
Expand All @@ -185,6 +188,8 @@ impl Rect {
/// let area = frame.size();
/// let layout = Layout::vertical([Constraint::Length(1), Constraint::Min(0)]);
/// let [top, main] = area.split(&layout);
/// // or explicitly specify the number of constraints:
/// let rects = area.split::<2>(&layout);
/// # }
pub fn split<const N: usize>(self, layout: &Layout) -> [Rect; N] {
layout
Expand Down

0 comments on commit fe84141

Please sign in to comment.