[]Struct iced::widget::pane_grid::State

pub struct State<T> { /* fields omitted */ }

The state of a PaneGrid.

It keeps track of the state of each Pane and the position of each Split.

The State needs to own any mutable contents a Pane may need. This is why this struct is generic over the type T. Values of this type are provided to the view function of PaneGrid::new for displaying each Pane.

Methods

impl<T> State<T>

pub fn new(first_pane_state: T) -> (State<T>, Pane)

Creates a new State, initializing the first pane with the provided state.

Alongside the State, it returns the first Pane identifier.

pub fn len(&self) -> usize

Returns the total amount of panes in the State.

pub fn get_mut(&mut self, pane: &Pane) -> Option<&mut T>

Returns the internal state of the given Pane, if it exists.

pub fn iter(&self) -> impl Iterator<Item = (&Pane, &T)>

Returns an iterator over all the panes of the State, alongside its internal state.

pub fn iter_mut(&mut self) -> impl Iterator<Item = (&Pane, &mut T)>

Returns a mutable iterator over all the panes of the State, alongside its internal state.

pub fn active(&self) -> Option<Pane>

Returns the active Pane of the State, if there is one.

A Pane is active if it is focused and is not being dragged.

pub fn adjacent(&self, pane: &Pane, direction: Direction) -> Option<Pane>

Returns the adjacent Pane of another Pane in the given direction, if there is one.

Example

You can combine this with State::active to find the pane that is adjacent to the current active one, and then swap them. For instance:

if let Some(active) = state.active() {
    if let Some(adjacent) = state.adjacent(&active, pane_grid::Direction::Right) {
        state.swap(&active, &adjacent);
    }
}

pub fn focus(&mut self, pane: &Pane)

Focuses the given Pane.

pub fn split(&mut self, axis: Axis, pane: &Pane, state: T) -> Option<Pane>

Splits the given Pane into two in the given Axis and initializing the new Pane with the provided internal state.

pub fn swap(&mut self, a: &Pane, b: &Pane)

Swaps the position of the provided panes in the State.

If you want to swap panes on drag and drop in your PaneGrid, you will need to call this method when handling a DragEvent.

pub fn resize(&mut self, split: &Split, ratio: f32)

Resizes two panes by setting the position of the provided Split.

The ratio is a value in [0, 1], representing the exact position of a Split between two panes.

If you want to enable resize interactions in your PaneGrid, you will need to call this method when handling a ResizeEvent.

pub fn close(&mut self, pane: &Pane) -> Option<T>

Closes the given Pane and returns its internal state, if it exists.

Trait Implementations

impl<T> Debug for State<T> where
    T: Debug

Auto Trait Implementations

impl<T> RefUnwindSafe for State<T> where
    T: RefUnwindSafe

impl<T> Send for State<T> where
    T: Send

impl<T> Sync for State<T> where
    T: Sync

impl<T> Unpin for State<T> where
    T: Unpin

impl<T> UnwindSafe for State<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> SetParameter for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,