Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for returning bounds of entire scroll area #788

Merged
merged 6 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,10 @@ Causes the data grid to rerender these specific cells. Rerendering a single cell
## getBounds

```ts
getBounds: (col: number, row?: number) => Rectangle | undefined;
getBounds: (col?: number, row?: number) => Rectangle | undefined;
```

`getBounds` returns the current bounding box of a cell. This does not need to be a currently rendered cell.
`getBounds` returns the current bounding box of a cell. This does not need to be a currently rendered cell. If called with `col` and `row` as undefined, the bounding box of the entire data grid scroll area is returned.

---

Expand Down
18 changes: 17 additions & 1 deletion packages/core/src/data-editor/data-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3440,7 +3440,23 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
return gridRef.current?.damage(damageList);
},
getBounds: (col, row) => {
return gridRef.current?.getBounds(col + rowMarkerOffset, row);

if (canvasRef?.current === null || scrollRef?.current === null) {
return undefined
}

if (col === undefined && row === undefined) {
// Return the bounds of the entire scroll area:
const rect = canvasRef.current.getBoundingClientRect()
jassmith marked this conversation as resolved.
Show resolved Hide resolved
const scale = rect.width / scrollRef.current.clientWidth
return {
x: rect.x - scrollRef.current.scrollLeft * scale,
y: rect.y - scrollRef.current.scrollTop * scale,
width: scrollRef.current.scrollWidth * scale,
height: scrollRef.current.scrollHeight * scale,
};
}
return gridRef.current?.getBounds( col ?? 0 + rowMarkerOffset, row);
},
focus: () => gridRef.current?.focus(),
emit: async e => {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/data-grid/data-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ type DamageUpdateList = readonly {

export interface DataGridRef {
focus: () => void;
getBounds: (col: number, row?: number) => Rectangle | undefined;
getBounds: (col?: number, row?: number) => Rectangle | undefined;
jassmith marked this conversation as resolved.
Show resolved Hide resolved
damage: (cells: DamageUpdateList) => void;
}

Expand Down Expand Up @@ -1499,12 +1499,12 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
});
}
},
getBounds: (col: number, row?: number) => {
getBounds: (col?: number, row?: number) => {
if (canvasRef === undefined || canvasRef.current === null) {
return undefined;
}

return getBoundsForItem(canvasRef.current, col, row ?? -1);
return getBoundsForItem(canvasRef.current, col ?? 0, row ?? -1);
jassmith marked this conversation as resolved.
Show resolved Hide resolved
},
damage,
}),
Expand Down
Loading