Skip to content

Commit e6445b2

Browse files
authored
Merge pull request #69 from EclipseTrading/feature/fix-scrollbars-overlaying-the-grid
VC-11205 Fix scrollbars obscuring the grid canvas
2 parents bfe0096 + 07ca676 commit e6445b2

17 files changed

+145
-103
lines changed

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cSpell.words": [
3+
"finbars",
4+
"Hypergrid"
5+
]
6+
}

src/Hypergrid/events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ exports.mixin = {
9595
},
9696

9797
/**
98-
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672)
98+
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672}
9999
* @param {boolean} allow
100100
* @this {any}
101101
*/

src/Hypergrid/scrolling.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { FinBar } from '../finbars/finbars';
22
import modules from './modules';
3+
import { Hypergrid } from './types';
34
const Scrollbar = modules.Scrollbar;
45

56
/**
@@ -35,14 +36,14 @@ exports.mixin = {
3536
* @type {FinBar}
3637
* @memberOf Hypergrid#
3738
*/
38-
sbVScroller: null as FinBar|null,
39+
sbVScroller: null as FinBar | null,
3940

4041
/**
4142
* The horizontal scroll bar model/controller.
4243
* @type {FinBar}
4344
* @memberOf Hypergrid#
4445
*/
45-
sbHScroller: null as FinBar|null,
46+
sbHScroller: null as FinBar | null,
4647

4748
/**
4849
* The previous value of sbVScrollVal.
@@ -61,7 +62,7 @@ exports.mixin = {
6162
scrollingNow: false,
6263

6364
/**
64-
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672)
65+
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672}
6566
* @memberOf Hypergrid#
6667
* @summary Set for `scrollingNow` field.
6768
* @param {boolean} isItNow - The type of event we are interested in.
@@ -161,7 +162,7 @@ exports.mixin = {
161162
},
162163

163164
/**
164-
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672)
165+
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672}
165166
* @memberOf Hypergrid#
166167
* @this {Hypergrid}
167168
* @desc Set the vertical scroll value.
@@ -194,11 +195,11 @@ exports.mixin = {
194195
},
195196

196197
/**
197-
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672)
198+
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672}
198199
* @memberOf Hypergrid#
199200
* @this {Hypergrid}
200201
* @desc Set the horizontal scroll value.
201-
* @param {number} newValue - The new scroll value.
202+
* @param {number} x - The new scroll value.
202203
*/
203204
setHScrollValue: function (x) {
204205
var self = this;
@@ -228,7 +229,7 @@ exports.mixin = {
228229
},
229230

230231
/**
231-
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672)
232+
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672}
232233
* @memberOf Hypergrid#
233234
* @this {Hypergrid}
234235
* @desc Initialize the scroll bars.
@@ -276,20 +277,28 @@ exports.mixin = {
276277
this.resizeScrollbars();
277278
},
278279

279-
resizeScrollbars: function () {
280+
resizeScrollbars(this: Hypergrid) {
281+
// Cache the current visibility state of the scrollbars.
282+
const hVisible = this.sbHScroller.isVisible;
283+
const vVisible = this.sbVScroller.isVisible;
284+
285+
// Let the scrollbars resize themselves based on the content and container sizes.
280286
this.sbHScroller.shortenBy(this.sbVScroller).resize();
281287
this.sbVScroller
282288
// NOTE: Below is commented out because it would show a square in the corner not covered by the scroll bar.
283289
//.shortenBy(this.sbHScroller)
284290
.resize();
291+
292+
// If visibility changed during scrollbar resize, then the grid shape changed, and the canvas should resize.
293+
if (this.sbHScroller.isVisible !== hVisible || this.sbVScroller.isVisible !== vVisible) {
294+
this.canvas.resize();
295+
}
285296
},
286297

287298
/**
288-
* @memberOf Hypergrid#
289-
* @this {Hypergrid}
290-
* @desc Scroll values have changed, we've been notified.
299+
* Scroll values have changed, we've been notified.
291300
*/
292-
setVScrollbarValues: function (max, containerSize) {
301+
setVScrollbarValues(this: Hypergrid, max: number, containerSize: number) {
293302
// Set the scroll range, which by default resets the contentSize.
294303
this.sbVScroller.range = {
295304
min: 0,
@@ -300,7 +309,7 @@ exports.mixin = {
300309
this.sbVScroller.containerSize = containerSize;
301310
},
302311

303-
setHScrollbarValues: function (max, containerSize) {
312+
setHScrollbarValues(this: Hypergrid, max: number, containerSize: number) {
304313
// Set the scroll range, which by default resets the contentSize.
305314
this.sbHScroller.range = {
306315
min: 0,
@@ -312,7 +321,7 @@ exports.mixin = {
312321
},
313322

314323
/**
315-
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672)
324+
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672}
316325
* @this {Hypergrid}
317326
*/
318327
scrollValueChangedNotification: function () {
@@ -337,7 +346,7 @@ exports.mixin = {
337346
* @desc The data dimensions have changed, or our pixel boundaries have changed.
338347
* Adjust the scrollbar properties as necessary.
339348
*/
340-
synchronizeScrollingBoundaries: function () {
349+
synchronizeScrollingBoundaries() {
341350
var bounds = this.getBounds();
342351
if (!bounds) {
343352
return;
@@ -346,7 +355,7 @@ exports.mixin = {
346355
var numFixedColumns = this.getFixedColumnCount(),
347356
numColumns = this.getColumnCount(),
348357
numRows = this.getRowCount(),
349-
scrollableWidth = bounds.width - this.behavior.getFixedColumnsMaxWidth() - this.sbHScroller.thickness,
358+
scrollableWidth = bounds.width - this.behavior.getFixedColumnsMaxWidth(),
350359
gridProps = this.properties,
351360
borderBox = gridProps.boxSizing === 'border-box',
352361
lineGap = borderBox ? 0 : gridProps.gridLinesVWidth;
@@ -363,8 +372,8 @@ exports.mixin = {
363372
}
364373

365374
// Note: Scrollable height excludes the header.
366-
var scrollableHeight = this.renderer.getVisibleScrollHeight() - this.sbVScroller.thickness;
367-
lineGap = borderBox ? 0 : gridProps.gridLinesHWidth;
375+
var scrollableHeight = this.renderer.getVisibleScrollHeight();
376+
lineGap = borderBox ? 0 : gridProps.gridLinesHWidth; // NOTE: Excludes total row thickness.
368377

369378
for (
370379
var rowsHeight = 0, lastPageRowCount = 0;

src/Hypergrid/selection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var SelectionRectangle = require('../lib/SelectionRectangle');
1616
*/
1717
exports.mixin = {
1818
/**
19-
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672)
19+
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672}
2020
* @this {any} TODO
2121
*/
2222
selectionInitialize: function() {

src/Hypergrid/stash-selections.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ exports.mixin = {
1414
*
1515
* This call should be paired with a subsequent call to `reselectRowsByUnderlyingIndexes`.
1616
* @private
17-
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672)
17+
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672}
1818
* @this {Hypergrid}
1919
* @returns {number|undefined} Number of selected rows or `undefined` if `restoreRowSelections` is falsy.
2020
*/
@@ -72,7 +72,7 @@ exports.mixin = {
7272
*
7373
* This call should be paired with a subsequent call to `reselectColumnsByNames`.
7474
* @private
75-
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672)
75+
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672}
7676
* @this {Hypergrid}
7777
* @param sourceColumnNames
7878
* @returns {number|undefined} Number of selected columns or `undefined` if `restoreColumnSelections` is falsy.

src/Hypergrid/types.d.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1+
import type { FinBar } from '../finbars/finbars';
2+
import { HypergridCanvas } from '../lib/Canvas';
3+
14
export type Hypergrid = {
25
behavior: Behavior;
36
div: HTMLElement;
4-
canvas: HTMLCanvasElement;
7+
canvas: HypergridCanvas;
58
hoverCell: any;
6-
renderer: Renderer
9+
renderer: Renderer;
710
repaint: () => void;
811

912
getRenderedWidth(colIndex: number): number;
1013
getRenderedHeight(rowIndex: number): number;
11-
}
1214

13-
export type Renderer = {
14-
visibleColumns: any[];
15-
visibleRows: any[];
16-
visibleColumnsByIndex: any[];
17-
visibleRowsByDataRowIndex: any[];
15+
sbVScroller: FinBar;
16+
sbHScroller: FinBar;
17+
18+
getBounds(): Rectangle;
19+
20+
/** The dimensions of the grid data have changed. You've been notified. */
21+
behaviorShapeChanged(): void;
1822
}

src/behaviors/Column.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ Column.prototype = {
305305
* @param {object|undefined} properties - Properties to copy to column's properties object. If `undefined`, this call is a no-op.
306306
* @param {boolean} [settingState] - Clear column's properties object before copying properties.
307307
* @this ColumnType
308-
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672)
308+
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672}
309309
*/
310310
addProperties: function(properties, settingState) {
311311
if (!properties) {

src/behaviors/Local/columnEnum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function warnColumnEnumDeprecation(method, msg) {
1717

1818
exports.mixin = {
1919
/**
20-
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672)
20+
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672}
2121
*/
2222
columnEnumSynchronize: function() {
2323
this._columnEnumKey = this._columnEnumKey || 'toAllCaps';

src/behaviors/Local/fallbacks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module.exports = {
9292
},
9393

9494
/**
95-
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672)
95+
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672}
9696
* @implements DataModel#setMetadataStore
9797
*/
9898
setMetadataStore: function(newMetadataStore) {

src/behaviors/Local/polyfills.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = {
3030
},
3131

3232
/**
33-
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672)
33+
* @type {any} // Handle TS bug, remove this issue after resolved {@link https://github.com/microsoft/TypeScript/issues/41672}
3434
*/
3535
addListener: function(handler) {
3636
if (!this.handlers) {

0 commit comments

Comments
 (0)