pub struct GridLayoutState { /* private fields */ }Expand description
The state of a GridLayout: the items’ areas, the
rules the layout settles under, and any gesture in progress.
The application owns the layout. Create the state with the grid’s rules,
then its areas, and subscribe to GridLayoutEvent::Change to persist
what the user arranges.
let state = cx.new(|cx| {
GridLayoutState::new(cx).cols(12).default_areas([
GridArea::new("revenue").col_span(8).row_span(4),
GridArea::new("orders").col(8).col_span(4).row_span(4),
])
});Implementations§
Source§impl GridLayoutState
impl GridLayoutState
Sourcepub fn new(cx: &mut App) -> GridLayoutState
pub fn new(cx: &mut App) -> GridLayoutState
An empty, 12-column grid that compacts vertically.
Sourcepub fn cols(self, cols: usize) -> GridLayoutState
pub fn cols(self, cols: usize) -> GridLayoutState
The number of equal columns the width is divided into. Defaults to 12.
Sourcepub fn compaction(self, compaction: Option<Axis>) -> GridLayoutState
pub fn compaction(self, compaction: Option<Axis>) -> GridLayoutState
The direction items float toward when space opens up, or None to
leave them wherever they are put. Defaults to Some(Axis::Vertical).
Sourcepub fn prevent_collision(self, prevent_collision: bool) -> GridLayoutState
pub fn prevent_collision(self, prevent_collision: bool) -> GridLayoutState
Refuse a move or resize that would overlap another item, instead of
pushing that item out of the way. Defaults to false.
Sourcepub fn draggable(self, draggable: bool) -> GridLayoutState
pub fn draggable(self, draggable: bool) -> GridLayoutState
Whether items can be moved. Defaults to true.
Sourcepub fn resizable(self, resizable: bool) -> GridLayoutState
pub fn resizable(self, resizable: bool) -> GridLayoutState
Whether items can be resized. Defaults to true.
Sourcepub fn default_areas(
self,
areas: impl IntoIterator<Item = GridArea>,
) -> GridLayoutState
pub fn default_areas( self, areas: impl IntoIterator<Item = GridArea>, ) -> GridLayoutState
The areas the grid starts with, settled under the rules set so far: overlaps are pushed apart and, with compaction on, gaps close. Set the rules first.
pub fn column_count(&self) -> usize
pub fn compaction_axis(&self) -> Option<Axis>
pub fn is_collision_prevented(&self) -> bool
pub fn is_draggable(&self) -> bool
pub fn is_resizable(&self) -> bool
Sourcepub fn selected_item(&self) -> Option<&SharedString>
pub fn selected_item(&self) -> Option<&SharedString>
The item keyboard commands act on.
Sourcepub fn active_item(&self) -> Option<&SharedString>
pub fn active_item(&self) -> Option<&SharedString>
The item being dragged or resized, if a gesture is in progress.
Sourcepub fn set_areas(
&mut self,
areas: impl IntoIterator<Item = GridArea>,
cx: &mut Context<'_, GridLayoutState>,
)
pub fn set_areas( &mut self, areas: impl IntoIterator<Item = GridArea>, cx: &mut Context<'_, GridLayoutState>, )
Replace the layout, settling it under the grid’s rules. Cancels any
gesture in progress, and does not emit GridLayoutEvent::Change.
pub fn set_cols(&mut self, cols: usize, cx: &mut Context<'_, GridLayoutState>)
pub fn set_compaction( &mut self, compaction: Option<Axis>, cx: &mut Context<'_, GridLayoutState>, )
pub fn set_prevent_collision( &mut self, prevent_collision: bool, cx: &mut Context<'_, GridLayoutState>, )
pub fn set_draggable( &mut self, draggable: bool, cx: &mut Context<'_, GridLayoutState>, )
pub fn set_resizable( &mut self, resizable: bool, cx: &mut Context<'_, GridLayoutState>, )
Sourcepub fn set_selected_item(
&mut self,
id: Option<SharedString>,
cx: &mut Context<'_, GridLayoutState>,
)
pub fn set_selected_item( &mut self, id: Option<SharedString>, cx: &mut Context<'_, GridLayoutState>, )
Select the item keyboard commands act on.
Sourcepub fn move_item(
&mut self,
id: &str,
col: usize,
row: usize,
cx: &mut Context<'_, GridLayoutState>,
) -> bool
pub fn move_item( &mut self, id: &str, col: usize, row: usize, cx: &mut Context<'_, GridLayoutState>, ) -> bool
Move the item id so its leading column is col and its top row
row, pushing whatever it lands on out of the way. Returns whether the
layout changed; a refused or no-op move returns false.
Sourcepub fn resize_item(
&mut self,
id: &str,
col_span: usize,
row_span: usize,
cx: &mut Context<'_, GridLayoutState>,
) -> bool
pub fn resize_item( &mut self, id: &str, col_span: usize, row_span: usize, cx: &mut Context<'_, GridLayoutState>, ) -> bool
Resize the item id to cover col_span columns and row_span rows,
clamped to its limits. Returns whether the layout changed.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for GridLayoutState
impl !UnwindSafe for GridLayoutState
impl Forget for GridLayoutState
impl Freeze for GridLayoutState
impl Send for GridLayoutState
impl Sync for GridLayoutState
impl Unpin for GridLayoutState
impl UnsafeUnpin for GridLayoutState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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