From 210bea1bdf1db8ff17b5a1b20960718eed9b47cc Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 12 Nov 2026 04:35:28 +0000 Subject: [PATCH] CellGrid: a pinch or Cmd/Ctrl+wheel zooms about the pointer; the zoom and the scroll live in GridState --- crates/table/src/ui/grid.rs | 52 +++++++++++++++++++++++++++---- crates/table/src/ui/grid/model.rs | 10 +++--- crates/table/tests/it/grid.rs | 32 +++++++++++++++++-- 3 files changed, 81 insertions(+), 13 deletions(-) diff --git a/crates/table/src/ui/grid.rs b/crates/table/src/ui/grid.rs index 2100a888e..13c3c5069 100644 --- a/crates/table/src/ui/grid.rs +++ b/crates/table/src/ui/grid.rs @@ -6,7 +6,7 @@ //! parts and paint. pub use craft_behavior::{CellAdvance, CellAt, CellDirection, CellRange, CellSelection, CellSpace, LineIndex, Positions, SHEET_ZOOM}; -use craft_behavior::{DisplayOrder, ItemSource, Metrics, SheetLayout}; +use craft_behavior::{DisplayOrder, EditEvent, ItemSource, Metrics, Mixed, ScrollPos, SheetLayout}; use craft_ui::contract::{ Bind, BindMut, Collection, CollectionEvent, CollectionProps, CollectionResponse, Common, ContainerProps, ContextMenuRequest, Cx, Outcome, PaintUi, Props as _, Remember as _, Role, SelectMode, Sizing, @@ -151,7 +151,8 @@ pub struct CellGridStyle { /// - The editor: typing opens the active cell in Enter mode (the arrows move to another cell and commit), F2 in Edit /// mode (the arrows move the caret), `=` and an operator in point mode (the arrows move a reference cursor). /// -/// The scroll lives in the collection. +/// A pinch or Cmd/Ctrl+wheel over the grid zooms it within [`SHEET_ZOOM`] about the pointer, keeping the cell under +/// the pointer in place. The zoom and the scroll live in the [`GridState`]. #[derive(craft_ui::contract::Component, craft_ui::contract::Props)] #[component(collection)] pub struct CellGrid<'a> { @@ -174,7 +175,11 @@ pub struct CellGrid<'a> { selection: Bind<'a, CellSelection>, /// The selection as the app held it when the pass began, for the parts that declare before the item step runs. snapshot: CellSelection, + /// The zoom this pass shows, clamped from the state's. zoom: f32, + /// The state's zoom, which a pinch writes for the next pass. + zoom_kept: &'a mut f32, + scroll: Bind<'a, ScrollPos>, /// The ranges the copy marks surround. #[prop] copy_mark: &'a [CellRange], @@ -195,8 +200,8 @@ pub struct CellGrid<'a> { impl<'a> CellGrid<'a> { /// A grid named `label` over `model` that keeps its selection and zoom in `state`. pub fn new(label: impl Into