Skip to main content

GridState

Struct GridState 

Source
pub struct GridState {
Show 36 fields pub data: GridData, pub config: GridConfig, pub window: Option<RowWindow>, pub resolved_formats: Vec<ResolvedColumnFormat>, pub display_indices: Arc<Vec<usize>>, pub selection: Selection, pub sort: Option<(usize, SortDirection)>, pub filters: Vec<ColumnFilter>, pub scroll_handle: ScrollHandle, pub focus_handle: FocusHandle, pub bounds: Bounds<Pixels>, pub row_height: f32, pub header_height: f32, pub row_header_width: f32, pub font_size: f32, pub char_width: f32, pub theme: GridTheme, pub is_dragging: bool, pub drag_start: Option<Point<Pixels>>, pub drag_start_hit: Option<HitResult>, pub scroll_at_click: Option<Point<Pixels>>, pub last_mouse_pos: Option<Point<Pixels>>, pub status_bar_height: f32, pub debug_bar_enabled: bool, pub click_pos: Option<Point<Pixels>>, pub click_hit: Option<HitResult>, pub hover_hit: Option<HitResult>, pub resizing_col: Option<usize>, pub resize_start_x: f32, pub resize_start_width: f32, pub context_menu: Option<ContextMenu>, pub filter_panel: Option<FilterPanel>, pub pending_action: Option<(MenuAction, usize)>, pub scrollbar_drag: Option<ScrollbarAxis>, pub scrollbar_drag_start_offset: f32, pub scrollbar_drag_start_pos: f32, /* private fields */
}
Expand description

Complete grid state owned by a GPUI Entity<GridState>.

Fields§

§data: GridData§config: GridConfig§window: Option<RowWindow>

When Some, the grid is in windowed-row mode (see RowWindow).

§resolved_formats: Vec<ResolvedColumnFormat>

Cached resolved-format list, kept in sync with data.columns and config. Paint, copy, and filter read this directly instead of recomputing per cell.

§display_indices: Arc<Vec<usize>>§selection: Selection§sort: Option<(usize, SortDirection)>§filters: Vec<ColumnFilter>§scroll_handle: ScrollHandle§focus_handle: FocusHandle§bounds: Bounds<Pixels>§row_height: f32§header_height: f32§row_header_width: f32§font_size: f32§char_width: f32§theme: GridTheme§is_dragging: bool§drag_start: Option<Point<Pixels>>§drag_start_hit: Option<HitResult>§scroll_at_click: Option<Point<Pixels>>§last_mouse_pos: Option<Point<Pixels>>§status_bar_height: f32§debug_bar_enabled: bool

When true, the debug status bar is painted at the bottom of the grid showing click position, scroll offset, and hovered cell. Off by default; enable via [SqllyDataTableBuilder::debug_bar] or GridState::set_debug_bar_enabled.

§click_pos: Option<Point<Pixels>>§click_hit: Option<HitResult>§hover_hit: Option<HitResult>§resizing_col: Option<usize>§resize_start_x: f32§resize_start_width: f32§context_menu: Option<ContextMenu>§filter_panel: Option<FilterPanel>§pending_action: Option<(MenuAction, usize)>§scrollbar_drag: Option<ScrollbarAxis>§scrollbar_drag_start_offset: f32§scrollbar_drag_start_pos: f32

Implementations§

Source§

impl GridState

Source

pub fn new( data: GridData, config: GridConfig, focus_handle: FocusHandle, ) -> Self

Source

pub fn set_config(&mut self, config: GridConfig)

Source

pub fn append_rows( &mut self, rows: Vec<Vec<CellValue>>, ) -> Result<(), GridDataError>

Append rows to the grid in place — the streaming-results fast path.

Rows are validated against the rectangular invariant, then appended to the canonical data.rows, the paint-path data_rows snapshot, and the display order. With no active sort or per-column filter this is O(new rows): the fresh indices are pushed onto display_indices directly. When a sort or filter is active, GridState::recompute re-derives the full display order so the new rows land in the right place.

The data_rows Arc is extended via Arc::make_mut; a clone only occurs if a paint or context-menu snapshot is still alive, so repeated appends stay cheap. Selection, scroll position, filters, and sort state are untouched.

§Errors

Returns GridDataError::RaggedRow (with the would-be absolute row index) if any incoming row’s length differs from the column count; the grid is left unmodified in that case.

Source

pub fn display_row_count(&self) -> usize

Number of rows the grid PRESENTS — the basis for the scrollbar, row numbers, hit-testing, and selection clamping. Equal to the sort/filter display order length normally, or the virtual total in windowed mode.

Source

pub fn resident_row_for_display(&self, display_row: usize) -> Option<usize>

Maps a display-row index to an index into data.rows. Normal mode goes through the sort/filter display order; windowed mode subtracts the window offset. None when the display row is out of range or not currently resident (windowed rows that have not been paged in).

Source

pub fn set_row_window( &mut self, total_rows: usize, offset: usize, rows: Vec<Vec<CellValue>>, ) -> Result<(), GridDataError>

Enter (or update) windowed-row mode: the grid presents total_rows virtual rows while holding only rows in memory, positioned so that rows[0] is virtual row offset. Replaces the resident rows, the paint snapshot, and the display order in one step; selection and scroll position (both in virtual space) are untouched. Clears any active sort/filter — they are unsupported while windowed.

§Errors

Returns GridDataError::RaggedRow if any incoming row’s length differs from the column count; the grid is left unmodified.

Source

pub fn visible_row_range(&self) -> (usize, usize)

The half-open display-row range currently visible in the viewport, derived from the scroll offset and painted bounds — the same math the paint pass uses. Hosts drive window paging from this: when the range nears the resident window’s edges, page more rows in via GridState::set_row_window. Returns (0, 0) before first paint.

Source

pub fn set_debug_bar_enabled(&mut self, enabled: bool)

Enable or disable the debug status bar at runtime. When enabled, a bar is painted at the bottom of the grid showing click position, scroll offset, and hovered cell coordinates.

Source

pub fn is_busy(&self) -> bool

Whether a background task is currently running (the loading overlay is shown).

Source

pub fn busy(&self) -> Option<&BusyState>

The current busy state, if any.

Source

pub fn set_busy(&mut self, label: impl Into<String>)

Show the loading overlay with the given label and indeterminate progress. Call GridState::clear_busy to hide it. For work that should run off the UI thread, prefer GridState::spawn_background, which manages this automatically.

Source

pub fn set_busy_progress(&mut self, progress: f32)

Update the determinate progress (0.0..=1.0) of the current busy state. No-op if not busy.

Source

pub fn clear_busy(&mut self)

Hide the loading overlay.

Source

pub fn spawn_background<R, W, D>( &mut self, cx: &mut App, label: impl Into<String>, work: W, on_done: D, )
where R: Send + 'static, W: FnOnce() -> R + Send + 'static, D: FnOnce(R, &mut GridState, &mut App) + 'static,

Run work on a background thread, showing the loading overlay labelled label for the duration, then deliver the result back on the UI thread via on_done (which receives &mut GridState and &mut App).

This is the recommended way to do expensive work triggered from a context-menu action (e.g. building an export from a large selection): the right-click stays instant, the work does not block the UI, and a loading indicator is shown until it completes.

work and its result R must be Send + 'static; on_done runs on the UI thread and need not be Send. A cloned ContextMenuRequest can be moved into work (it is Send + Sync + 'static).

If this state has no entity handle yet (constructed via GridState::new directly, e.g. in tests rather than through the builder), work runs synchronously as a fallback.

Source

pub fn recompute(&mut self)

Source

pub fn toggle_sort(&mut self, col: usize)

Source

pub fn handle_mouse_down(&mut self, pos: Point<Pixels>, shift: bool)

Source

pub fn execute_action(&mut self, action: MenuAction, col: usize, cx: &mut App)

Source

pub fn open_filter_panel(&mut self, col: usize, _anchor: Option<Point<Pixels>>)

Open the rich per-column filter popover for col, seeding its working state from any filter already committed on that column. The overlay is rendered by widget.rs as a deferred + anchored element so it can paint and receive events outside the grid’s own layout bounds, exactly like the right-click context menu.

anchor overrides the panel’s spawn position; pass the original context-menu / header right-click position so the panel doesn’t jump to the mouse’s current location (which by now has moved to the menu item). Falls back to last_mouse_pos when None.

Source

pub fn apply_filter_panel(&mut self)

Commit the panel’s working state to Self::filters and re-filter. Called automatically on every interaction (auto-apply).

Source

pub fn maybe_auto_apply(&mut self)

Apply immediately — the panel always auto-applies.

Source

pub fn clear_filter_panel(&mut self)

Reset both the committed filter for the panel’s column and the panel’s working state (all values checked, no operator), then re-filter.

Source

pub fn set_panel_sort(&mut self, direction: SortDirection)

Set the sort direction on the panel’s column (the panel’s Sort buttons). Clicking the already-active direction turns the sort off.

Source

pub fn toggle_filter_value(&mut self, index: usize)

Toggle the checked state of a single distinct value row (by index into FilterPanel::distinct), then auto-apply if enabled.

Source

pub fn toggle_filter_select_all(&mut self)

Toggle every distinct value row at once, then auto-apply if enabled. Mirrors the “(Select All)” checkbox. Operates on all values regardless of the active search, so searching never changes what “(Select All)” does.

Source

pub fn set_filter_operator(&mut self, op_index: usize)

Select an operator by its index in FilterPanel::op_labels, close the dropdown, and auto-apply if enabled.

Source

pub fn toggle_filter_op_menu(&mut self)

Toggle the operator dropdown’s expanded state.

Source

pub fn set_filter_focus(&mut self, focus: FilterInput)

Point keyboard focus at one of the panel’s text fields.

Source

pub fn toggle_filter_auto_apply(&mut self)

Toggle the panel’s auto-apply flag; kept for API completeness.

Source

pub fn drag_screen_rect(&self) -> Option<(Point<Pixels>, Point<Pixels>)>

Source

pub fn handle_mouse_move( &mut self, pos: Point<Pixels>, pressed_button: Option<MouseButton>, )

Source

pub fn handle_scroll_drag(&mut self)

Source

pub fn handle_mouse_up(&mut self)

Source

pub fn apply_edge_scroll(&mut self) -> bool

Source

pub fn select_all(&mut self)

Source

pub fn copy_selection(&self, with_headers: bool, cx: &mut App)

Source

pub fn page_up(&mut self)

Source

pub fn page_down(&mut self)

Source

pub fn handle_key(&mut self, keystroke: &Keystroke)

Source

pub fn wants_edge_scroll_tick(&self) -> bool

Trait Implementations§

Source§

impl Debug for GridState

Source§

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

Formats the value using the given formatter. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

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

Source§

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.
Source§

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.
Source§

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.
Source§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

Source§

impl<T> Same for T

Source§

type Output = T

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

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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