Skip to main content

LiveGridHandle

Struct LiveGridHandle 

Source
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

Source

pub fn new<D: LiveGridDelegate>(grid: &Entity<LiveGridState<D>>) -> Self

A handle of grid.

Source

pub fn entity_id(&self) -> EntityId

The grid entity’s id.

Source

pub fn downgrade(&self) -> WeakLiveGridHandle

A handle that does not keep the grid alive.

Source

pub fn focus_handle(&self, cx: &App) -> FocusHandle

The grid’s focus handle: focus it to give the grid the keyboard.

Source

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).

Source

pub fn column(&self, id: &str, cx: &App) -> Option<ColumnInfo>

The schema column id; None if the schema has none.

Source

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.

Source

pub fn show_all_columns(&self, cx: &mut App)

Shows every column, with one LayoutChange.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn autofit_columns(&self, cx: &mut App)

Fits every visible column to its header and painted rows, as LiveGridState::autofit_columns does.

Source

pub fn view_id(&self, cx: &App) -> Option<SharedString>

The view id of the grid’s saved layouts, if it has one.

Source

pub fn layout(&self, cx: &App) -> GridLayout

The current layout (LiveGridState::layout).

Source

pub fn set_layout( &self, layout: &GridLayout, cx: &mut App, ) -> Result<LayoutReport, LayoutError>

Restores a saved layout (LiveGridState::set_layout).

Source

pub fn reset_layout(&self, cx: &mut App)

Restores the default layout (LiveGridState::reset_layout).

Source

pub fn sort(&self, cx: &App) -> Vec<LayoutSort>

The sort by column id, most significant first; empty when unsorted.

Source

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.

Source

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.

Source

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.

Source

pub fn expand_depth(&self, cx: &App) -> ExpandDepth

How deep groups and tree rows are expanded by default.

Source

pub fn set_expand_depth(&self, depth: ExpandDepth, cx: &mut App)

Sets the default depth and clears every toggle (LiveGridState::set_expand_depth).

Source

pub fn quick_filter(&self, cx: &App) -> SharedString

The quick filter text; empty when the filter is off.

Source

pub fn set_quick_filter(&self, text: impl Into<SharedString>, cx: &mut App)

Sets the quick filter text (LiveGridState::set_quick_filter).

Source

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.

Source

pub fn total_row_count(&self, cx: &App) -> usize

The live rows of the shown snapshot: the “4000” of “120 of 4000”.

Source

pub fn selected_count(&self, cx: &App) -> usize

The selected rows, those a filter hides included.

Source

pub fn is_order_held(&self, cx: &App) -> bool

Returns true if a newer order is ready but held by the reorder policy.

Source

pub fn apply_held_order(&self, cx: &mut App)

Shows the held order now.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

pub fn show_column_chooser(&self, window: &mut Window, cx: &mut App)

Opens the grid’s column chooser, as LiveGridState::show_column_chooser does.

Source

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

Source§

fn clone(&self) -> LiveGridHandle

Returns a duplicate 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 LiveGridHandle

Source§

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

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

impl<D: LiveGridDelegate> From<&Entity<LiveGridState<D>>> for LiveGridHandle

Source§

fn from(grid: &Entity<LiveGridState<D>>) -> Self

Converts to this type from the input type.

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, dest: *mut u8)

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

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,