Skip to content

Commit 1df7a8c

Browse files
committed
Default settings work. Any styled applied globally override custom renderers
Signed-off-by: Itay Dafna <[email protected]>
1 parent ed811fe commit 1df7a8c

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed

js/datagrid.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import * as _ from 'underscore';
55

6-
import { BasicSelectionModel } from '@lumino/datagrid';
6+
import { BasicSelectionModel, TextRenderer } from '@lumino/datagrid';
77

88
import { CellRenderer } from '@lumino/datagrid';
99

@@ -30,6 +30,7 @@ import { MODULE_NAME, MODULE_VERSION } from './version';
3030

3131
import { CellRendererModel, CellRendererView } from './cellrenderer';
3232
import { FeatherGrid } from './feathergrid';
33+
import { Theme } from './utils';
3334

3435
// Import CSS
3536
import '../style/jupyter-widget.css';
@@ -439,7 +440,6 @@ export class DataGridView extends DOMWidgetView {
439440
return this.updateRenderers().then(() => {
440441
this.updateGridStyle();
441442
this.updateGridRenderers();
442-
this.grid.setGridStyle();
443443
this.pWidget.addWidget(this.grid);
444444
});
445445
}
@@ -519,7 +519,6 @@ export class DataGridView extends DOMWidgetView {
519519

520520
public updateGridStyle() {
521521
this.grid.updateGridStyle();
522-
this.grid.setGridStyle();
523522
}
524523

525524
set isLightTheme(value: boolean) {
@@ -535,7 +534,20 @@ export class DataGridView extends DOMWidgetView {
535534
}
536535

537536
private updateGridRenderers() {
538-
const defaultRenderer = this.default_renderer.renderer;
537+
let defaultRenderer = this.default_renderer.renderer;
538+
if (
539+
this.grid.grid.style.backgroundColor !== Theme.getBackgroundColor() ||
540+
this.grid.grid.style.rowBackgroundColor ||
541+
this.grid.grid.style.columnBackgroundColor
542+
) {
543+
// Making sure the default renderer doesn't paint over the global
544+
// grid background color, if the latter is set.
545+
defaultRenderer = new TextRenderer({
546+
...this.default_renderer.renderer,
547+
backgroundColor: undefined,
548+
});
549+
}
550+
539551
let columnHeaderRenderer = null;
540552
if (this.header_renderer) {
541553
columnHeaderRenderer = this.header_renderer.renderer;

js/feathergrid.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,16 @@ export class FeatherGrid extends Widget {
217217
this._defaultRenderer = new TextRenderer({
218218
font: '12px sans-serif',
219219
textColor: Theme.getFontColor(),
220-
backgroundColor: Theme.getBackgroundColor(),
220+
backgroundColor:
221+
this.grid.style.backgroundColor || Theme.getBackgroundColor(),
221222
horizontalAlignment: 'center',
222223
verticalAlignment: 'center',
223224
});
224225

225226
this._rowHeaderRenderer = new TextRenderer({
226227
textColor: Theme.getFontColor(1),
227-
backgroundColor: Theme.getBackgroundColor(2),
228+
backgroundColor:
229+
this.grid.style.headerBackgroundColor || Theme.getBackgroundColor(2),
228230
horizontalAlignment: 'center',
229231
verticalAlignment: 'center',
230232
});
@@ -392,15 +394,17 @@ export class FeatherGrid extends Widget {
392394
set columnHeaderRenderer(renderer: CellRenderer) {
393395
const textRenderer = renderer as TextRenderer;
394396

395-
// Need to create a HeadeRenderer object as TextRenderer
396-
// objects do not support merged cell rendering.
397+
// HeaderRenderer adds the filter dialogue box overlay
397398
this._columnHeaderRenderer = new HeaderRenderer({
398399
textOptions: {
399400
font: textRenderer.font,
400401
wrapText: textRenderer.wrapText,
401402
elideDirection: textRenderer.elideDirection,
402403
textColor: textRenderer.textColor,
403-
backgroundColor: textRenderer.backgroundColor,
404+
backgroundColor:
405+
this.grid.style.headerBackgroundColor ||
406+
textRenderer.backgroundColor ||
407+
Theme.getBackgroundColor(),
404408
verticalAlignment: textRenderer.verticalAlignment,
405409
horizontalAlignment: textRenderer.horizontalAlignment,
406410
format: textRenderer.format,
@@ -492,7 +496,6 @@ export class FeatherGrid extends Widget {
492496
this.grid.copyToClipboard = this.copyToClipboard.bind(this.grid);
493497

494498
this.grid.dataModel = this._dataModel;
495-
//@ts-ignore **added so we can remove basickeyhandler.ts from fork
496499
this.grid.keyHandler = new KeyHandler();
497500
const mouseHandler = new FeatherGridMouseHandler(this);
498501
mouseHandler.cellClicked.connect(
@@ -512,15 +515,14 @@ export class FeatherGrid extends Widget {
512515
});
513516
},
514517
);
515-
//@ts-ignore added so we don't have to add basicmousehandler.ts fork
518+
516519
this.grid.mouseHandler = mouseHandler;
517520
this.grid.selectionModel = this._selectionModel;
518521
this.grid.editingEnabled = this._editable;
519522

520523
this.updateGridStyle();
521524
this._updateGridRenderers();
522525
this._updateColumnWidths();
523-
this.setGridStyle();
524526
}
525527

526528
public setGridStyle() {
@@ -557,7 +559,7 @@ export class FeatherGrid extends Widget {
557559
selectionFillColor:
558560
this.grid.style.selectionFillColor || Theme.getBrandColor(2, 0.4),
559561
selectionBorderColor:
560-
this.grid.style.headerSelectionBorderColor || Theme.getBrandColor(1),
562+
this.grid.style.selectionBorderColor || Theme.getBrandColor(1),
561563
headerSelectionFillColor:
562564
this.grid.style.headerSelectionFillColor ||
563565
Theme.getBackgroundColor(3, 0.4),
@@ -572,37 +574,39 @@ export class FeatherGrid extends Widget {
572574
}
573575

574576
public updateGridStyle() {
577+
this.setGridStyle();
575578
this._updateHeaderRenderer();
576579

577580
if (!this._defaultRendererSet) {
578-
this._defaultRenderer = new TextRenderer({
581+
this.defaultRenderer = new TextRenderer({
579582
font: '12px sans-serif',
580583
textColor: Theme.getFontColor(),
581-
backgroundColor: Theme.getBackgroundColor(),
584+
backgroundColor:
585+
this.grid.style.backgroundColor || Theme.getBackgroundColor(),
582586
horizontalAlignment: 'left',
583587
verticalAlignment: 'center',
584588
});
585589
}
586590

587591
this._rowHeaderRenderer = new TextRenderer({
588592
textColor: Theme.getFontColor(1),
589-
backgroundColor: Theme.getBackgroundColor(2),
593+
backgroundColor:
594+
this.grid.style.headerBackgroundColor || Theme.getBackgroundColor(2),
590595
horizontalAlignment: 'center',
591596
verticalAlignment: 'center',
592597
});
593598

594599
this._columnHeaderRenderer = new HeaderRenderer({
595600
textOptions: {
596601
textColor: Theme.getFontColor(1),
597-
backgroundColor: Theme.getBackgroundColor(2),
602+
backgroundColor:
603+
this.grid.style.headerBackgroundColor || Theme.getBackgroundColor(2),
598604
horizontalAlignment: 'left',
599605
verticalAlignment: 'center',
600606
},
601607
isLightTheme: this._isLightTheme,
602608
grid: this.grid,
603609
});
604-
605-
this.setGridStyle();
606610
}
607611

608612
copyToClipboard(): void {

0 commit comments

Comments
 (0)