pub struct LiveGridHandle { /* private fields */ }Expand description
A grid without its delegate type: columns, layout, sort, grouping, quick filter, counts, the held order, copy and export, and its events, all by column id. What a toolbar, a status bar or a column chooser needs.
Clones refer to the same grid and keep it alive, as an Entity does;
downgrade for a back reference. Each method is one
read or one update of the grid: never call it from inside an update of
the same grid, such as a delegate hook (the borrow panics). Edits are
not here: they need row keys, the application’s own type.
use gpui_kit::{App, IntoElement, ParentElement as _, div};
use gpui_kit_grid::LiveGridHandle;
/// "120 of 4000 rows", whatever the grid's rows are.
fn row_counts(grid: &LiveGridHandle, cx: &App) -> impl IntoElement {
div().child(format!(
"{} of {} rows",
grid.row_count(cx),
grid.total_row_count(cx)
))
}Implementations§
Source§impl LiveGridHandle
impl LiveGridHandle
Sourcepub fn new<D: LiveGridDelegate>(grid: &Entity<LiveGridState<D>>) -> Self
pub fn new<D: LiveGridDelegate>(grid: &Entity<LiveGridState<D>>) -> Self
A handle of grid.
Sourcepub fn downgrade(&self) -> WeakLiveGridHandle
pub fn downgrade(&self) -> WeakLiveGridHandle
A handle that does not keep the grid alive.
Sourcepub fn focus_handle(&self, cx: &App) -> FocusHandle
pub fn focus_handle(&self, cx: &App) -> FocusHandle
The grid’s focus handle: focus it to give the grid the keyboard.
Sourcepub fn columns(&self, cx: &App) -> Vec<ColumnInfo>
pub fn columns(&self, cx: &App) -> Vec<ColumnInfo>
Every schema column in display order (left, scrolling, right zone), hidden ones at their place. O(columns).
Sourcepub fn column(&self, id: &str, cx: &App) -> Option<ColumnInfo>
pub fn column(&self, id: &str, cx: &App) -> Option<ColumnInfo>
The schema column id; None if the schema has none.
Sourcepub fn set_column_visible(&self, id: &str, visible: bool, cx: &mut App) -> bool
pub fn set_column_visible(&self, id: &str, visible: bool, cx: &mut App) -> bool
Shows or hides the column id, as
LiveGridState::set_column_visible does. Returns false, changing
nothing, if the column is unknown or is the last visible one.
Sourcepub fn show_all_columns(&self, cx: &mut App)
pub fn show_all_columns(&self, cx: &mut App)
Shows every column, with one LayoutChange.
Sourcepub fn move_column(&self, id: &str, before: Option<&str>, cx: &mut App) -> bool
pub fn move_column(&self, id: &str, before: Option<&str>, cx: &mut App) -> bool
Moves the column id before the column before (None: to the end
of its zone), as LiveGridState::move_column does. Returns false,
changing nothing, if a column is unknown, the zones differ or the
move policy refuses.
Sourcepub fn move_band(&self, band: &str, before: Option<&str>, cx: &mut App) -> bool
pub fn move_band(&self, band: &str, before: Option<&str>, cx: &mut App) -> bool
Moves every column of band before the column before (None: to
the end of the zone), as LiveGridState::move_band does. Returns
false, changing nothing, if the band or the column is unknown, the
zones differ or the move policy refuses.
Sourcepub fn set_column_zone(&self, id: &str, zone: ColumnZone, cx: &mut App) -> bool
pub fn set_column_zone(&self, id: &str, zone: ColumnZone, cx: &mut App) -> bool
Moves the column id to zone, as
LiveGridState::set_column_zone does. Returns false if the column
is unknown.
Sourcepub fn set_column_width(&self, id: &str, width: Pixels, cx: &mut App) -> bool
pub fn set_column_width(&self, id: &str, width: Pixels, cx: &mut App) -> bool
Sets the width of the column id, within its limits. Returns false
if the column is unknown.
Sourcepub fn autofit_columns(&self, cx: &mut App)
pub fn autofit_columns(&self, cx: &mut App)
Fits every visible column to its header and painted rows, as
LiveGridState::autofit_columns does.
Sourcepub fn view_id(&self, cx: &App) -> Option<SharedString>
pub fn view_id(&self, cx: &App) -> Option<SharedString>
The view id of the grid’s saved layouts, if it has one.
Sourcepub fn layout(&self, cx: &App) -> GridLayout
pub fn layout(&self, cx: &App) -> GridLayout
The current layout (LiveGridState::layout).
Sourcepub fn set_layout(
&self,
layout: &GridLayout,
cx: &mut App,
) -> Result<LayoutReport, LayoutError>
pub fn set_layout( &self, layout: &GridLayout, cx: &mut App, ) -> Result<LayoutReport, LayoutError>
Restores a saved layout (LiveGridState::set_layout).
Sourcepub fn reset_layout(&self, cx: &mut App)
pub fn reset_layout(&self, cx: &mut App)
Restores the default layout (LiveGridState::reset_layout).
Sourcepub fn sort(&self, cx: &App) -> Vec<LayoutSort>
pub fn sort(&self, cx: &App) -> Vec<LayoutSort>
The sort by column id, most significant first; empty when unsorted.
Sourcepub fn set_sort(
&self,
sort: impl IntoIterator<Item = LayoutSort>,
cx: &mut App,
) -> bool
pub fn set_sort( &self, sort: impl IntoIterator<Item = LayoutSort>, cx: &mut App, ) -> bool
Replaces the sort, as LiveGridState::set_sort does. Returns
false, changing nothing, if a column is unknown.
Sourcepub fn group_by(&self, cx: &App) -> Vec<LayoutGroup>
pub fn group_by(&self, cx: &App) -> Vec<LayoutGroup>
The grouping levels by id, the top level first: a column level by its
column’s id, a GroupKey level by its own.
Sourcepub fn set_group_by(
&self,
levels: impl IntoIterator<Item = LayoutGroup>,
cx: &mut App,
) -> bool
pub fn set_group_by( &self, levels: impl IntoIterator<Item = LayoutGroup>, cx: &mut App, ) -> bool
Replaces the grouping by column levels, as
LiveGridState::set_group_by does; no levels turn grouping off.
Returns false, changing nothing, if a column is unknown: a GroupKey
level needs the typed state.
Sourcepub fn expand_depth(&self, cx: &App) -> ExpandDepth
pub fn expand_depth(&self, cx: &App) -> ExpandDepth
How deep groups and tree rows are expanded by default.
Sourcepub fn set_expand_depth(&self, depth: ExpandDepth, cx: &mut App)
pub fn set_expand_depth(&self, depth: ExpandDepth, cx: &mut App)
Sets the default depth and clears every toggle
(LiveGridState::set_expand_depth).
Sourcepub fn quick_filter(&self, cx: &App) -> SharedString
pub fn quick_filter(&self, cx: &App) -> SharedString
The quick filter text; empty when the filter is off.
Sourcepub fn set_quick_filter(&self, text: impl Into<SharedString>, cx: &mut App)
pub fn set_quick_filter(&self, text: impl Into<SharedString>, cx: &mut App)
Sets the quick filter text (LiveGridState::set_quick_filter).
Sourcepub fn row_count(&self, cx: &App) -> usize
pub fn row_count(&self, cx: &App) -> usize
The data rows of the shown order (Projection::row_count): rows of
collapsed groups count, pinned rows do not.
Sourcepub fn total_row_count(&self, cx: &App) -> usize
pub fn total_row_count(&self, cx: &App) -> usize
The live rows of the shown snapshot: the “4000” of “120 of 4000”.
Sourcepub fn selected_count(&self, cx: &App) -> usize
pub fn selected_count(&self, cx: &App) -> usize
The selected rows, those a filter hides included.
Sourcepub fn is_order_held(&self, cx: &App) -> bool
pub fn is_order_held(&self, cx: &App) -> bool
Returns true if a newer order is ready but held by the reorder policy.
Sourcepub fn apply_held_order(&self, cx: &mut App)
pub fn apply_held_order(&self, cx: &mut App)
Shows the held order now.
Sourcepub fn set_reorder_policy(&self, policy: impl ReorderPolicy, cx: &mut App)
pub fn set_reorder_policy(&self, policy: impl ReorderPolicy, cx: &mut App)
Replaces the reorder policy, as LiveGridState::set_reorder_policy
does: a held order is offered to the new policy at once. A toolbar’s
Live / Hold / Manual switch, without the delegate type.
Sourcepub fn copy_scope(&self, scope: ExportScope, cx: &mut App) -> bool
pub fn copy_scope(&self, scope: ExportScope, cx: &mut App) -> bool
Copies scope to the clipboard (LiveGridState::copy_scope).
Returns false, leaving the clipboard alone, if there is nothing to
copy.
Sourcepub fn is_export_empty(&self, scope: ExportScope, cx: &App) -> bool
pub fn is_export_empty(&self, scope: ExportScope, cx: &App) -> bool
Returns true if an export of scope would have nothing to write
(LiveGridState::is_export_empty).
Sourcepub fn export_to_path(
&self,
scope: ExportScope,
format: CsvFormat,
path: impl Into<PathBuf>,
cx: &mut App,
) -> Result<ExportJob<PathBuf>, ExportError>
pub fn export_to_path( &self, scope: ExportScope, format: CsvFormat, path: impl Into<PathBuf>, cx: &mut App, ) -> Result<ExportJob<PathBuf>, ExportError>
Exports scope as CSV to a file at path, with a header line and
the grid’s cell export (LiveGridState::export_to_path). Other
formats and requests go through the typed state. Not on the web.
Sourcepub fn subscribe(
&self,
cx: &mut App,
on_event: impl FnMut(&GridHandleEvent, &mut App) + 'static,
) -> Subscription
pub fn subscribe( &self, cx: &mut App, on_event: impl FnMut(&GridHandleEvent, &mut App) + 'static, ) -> Subscription
Calls on_event with what each event of the grid says without keys
and columns (GridHandleEvent), until the subscription is
dropped. Events with keys (Click, Confirm, FocusChange, edits)
need the typed subscription.
Sourcepub fn observe(
&self,
cx: &mut App,
on_notify: impl FnMut(&mut App) + 'static,
) -> Subscription
pub fn observe( &self, cx: &mut App, on_notify: impl FnMut(&mut App) + 'static, ) -> Subscription
Calls on_notify whenever the grid notifies, until the subscription
is dropped: for a status bar that reads the counts again.
Sourcepub fn show_column_chooser(&self, window: &mut Window, cx: &mut App)
pub fn show_column_chooser(&self, window: &mut Window, cx: &mut App)
Opens the grid’s column chooser, as
LiveGridState::show_column_chooser does.
Sourcepub fn is_column_chooser_open(&self, cx: &App) -> bool
pub fn is_column_chooser_open(&self, cx: &App) -> bool
Returns true while the grid shows its column chooser.
Trait Implementations§
Source§impl Clone for LiveGridHandle
impl Clone for LiveGridHandle
Source§fn clone(&self) -> LiveGridHandle
fn clone(&self) -> LiveGridHandle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LiveGridHandle
impl Debug for LiveGridHandle
Source§impl<D: LiveGridDelegate> From<&Entity<LiveGridState<D>>> for LiveGridHandle
impl<D: LiveGridDelegate> From<&Entity<LiveGridState<D>>> for LiveGridHandle
Source§fn from(grid: &Entity<LiveGridState<D>>) -> Self
fn from(grid: &Entity<LiveGridState<D>>) -> Self
Auto Trait Implementations§
impl Freeze for LiveGridHandle
impl !RefUnwindSafe for LiveGridHandle
impl !Send for LiveGridHandle
impl !Sync for LiveGridHandle
impl Unpin for LiveGridHandle
impl UnsafeUnpin for LiveGridHandle
impl !UnwindSafe for LiveGridHandle
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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