rat_widget::layout

Struct StructuredLayout

Source
pub struct StructuredLayout { /* private fields */ }
Expand description

Container for the areas coming out of a layout function.

This is more or less a Vec<Rect>, but it takes a stride as parameter and treats N Rects as one unit.

This way it can add some structure to the list and express something like ‘the label area for the 5th item’.

As a second feature it returns a handle for each item, which can be used to retrieve the item later.

pub enum LW {
    Label,
    Widget
}

let mut l = StructuredLayout::new(LW::count());

// ... some layout calculations ...
let w0 = l.add(&[
        Rect::new(0,0,5,1),
        Rect::new(6,0,15,1)
]);

// ... something entirely else ...

Span::from("label")
    .render(l[w0][Label],&mut buf);

Checkbox::new()
    .text("Check this out")
    .render(l[w0][Widget], &mut buf, &mut state);

Implementations§

Source§

impl StructuredLayout

Source

pub fn new(stride: usize) -> Self

New layout with the given stride.

Source

pub fn area(&self) -> Rect

Original area for which this layout has been calculated. Can be used to invalidate a layout if the area changes.

Source

pub fn set_area(&mut self, area: Rect)

Original area for which this layout has been calculated. Can be used to invalidate a layout if the area changes.

Source

pub fn width_change(&self, width: u16) -> bool

Change detection.

Source

pub fn height_change(&self, height: u16) -> bool

Change detection.

Source

pub fn pos_change(&self, pos: Position) -> bool

Change detection.

Source

pub fn add(&mut self, areay: &[Rect]) -> AreaHandle

Add the areas for one item.

You can refer Returns a handle to access the item later. You can always use a simple index too.

Source

pub fn break_after_row(&mut self, y: u16)

Add a manual break after the given position.

See SinglePager and DualPager who can work with this. Other widgets may simply ignore this.

Source

pub fn break_before_row(&mut self, y: u16)

Add a manual break before the given position.

See SinglePager and DualPager who can work with this. Other widgets may simply ignore this.

Source

pub fn row_breaks(&self) -> &[u16]

Return the manual page breaks.

Source

pub fn row_breaks_mut(&mut self) -> &mut [u16]

Return the manual page breaks.

Source

pub fn sort_row_breaks_desc(&mut self)

Sort and dedup the row-breaks.

Source

pub fn len(&self) -> usize

Number of areas.

Source

pub fn is_empty(&self) -> bool

Any areas?

Source

pub fn stride(&self) -> usize

Stride per item.

Source

pub fn as_slice(&self) -> &[Rect]

All areas. If you want to access a specific item you must use the stride to calculate the offset.

Source

pub fn as_mut_slice(&mut self) -> &mut [Rect]

All areas. If you want to access a specific item you must use the stride to calculate the offset.

Source

pub fn iter(&self) -> impl Iterator<Item = &Rect>

Iterator over all areas.

Source

pub fn chunked(&self) -> impl Iterator<Item = &[Rect]>

Iterator over all areas chunked by stride.

Source

pub fn bounds(&self) -> Rect

Calculate the bounding box for all areas.

Trait Implementations§

Source§

impl Clone for StructuredLayout

Source§

fn clone(&self) -> StructuredLayout

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StructuredLayout

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StructuredLayout

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Index<AreaHandle> for StructuredLayout

Source§

type Output = [Rect]

The returned type after indexing.
Source§

fn index(&self, index: AreaHandle) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<DialogItem> for StructuredLayout

Source§

type Output = Rect

The returned type after indexing.
Source§

fn index(&self, index: DialogItem) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<usize> for StructuredLayout

Source§

type Output = [Rect]

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<AreaHandle> for StructuredLayout

Source§

fn index_mut(&mut self, index: AreaHandle) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<DialogItem> for StructuredLayout

Source§

fn index_mut(&mut self, index: DialogItem) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for StructuredLayout

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.