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 2 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
13 changes: 12 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,18 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
return gridRef.current?.damage(damageList);
},
getBounds: (col, row) => {
return gridRef.current?.getBounds(col + rowMarkerOffset, row);
if (col === undefined && row === undefined && scrollRef.current && canvasRef.current) {
jassmith marked this conversation as resolved.
Show resolved Hide resolved
// 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 !== undefined ? col + rowMarkerOffset : undefined, row);
jassmith marked this conversation as resolved.
Show resolved Hide resolved
},
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