Skip to content

Commit 7933df7

Browse files
authored
Merge pull request #371 from martinRenou/improve_rubberband
Improve rubberband for dark mode
2 parents 84d3e49 + e63be36 commit 7933df7

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

src/mpl_widget.ts

+21-10
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,8 @@ export class MPLCanvasView extends DOMWidgetView {
519519
return;
520520
}
521521

522+
this.top_context.save();
523+
522524
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
523525
this.context.drawImage(this.model.offscreen_canvas, 0, 0);
524526

@@ -534,6 +536,13 @@ export class MPLCanvasView extends DOMWidgetView {
534536
this.model.get('_rubberband_width') !== 0 &&
535537
this.model.get('_rubberband_height') !== 0
536538
) {
539+
this.top_context.strokeStyle = 'gray';
540+
this.top_context.lineWidth = 1;
541+
this.top_context.shadowColor = 'black';
542+
this.top_context.shadowBlur = 2;
543+
this.top_context.shadowOffsetX = 1;
544+
this.top_context.shadowOffsetY = 1;
545+
537546
this.top_context.strokeRect(
538547
this.model.get('_rubberband_x'),
539548
this.model.get('_rubberband_y'),
@@ -544,18 +553,19 @@ export class MPLCanvasView extends DOMWidgetView {
544553

545554
// Draw resize handle
546555
if (this.model.get('resizable')) {
547-
this.top_context.save();
548-
549556
const gradient = this.top_context.createLinearGradient(
550-
this.top_canvas.width - this.resize_handle_size / 3,
551-
this.top_canvas.height - this.resize_handle_size / 3,
552-
this.top_canvas.width - this.resize_handle_size / 4,
553-
this.top_canvas.height - this.resize_handle_size / 4
557+
// Start
558+
this.top_canvas.width - this.resize_handle_size,
559+
this.top_canvas.height - this.resize_handle_size,
560+
// Stop
561+
this.top_canvas.width,
562+
this.top_canvas.height
554563
);
555-
gradient.addColorStop(0, 'rgba(0, 0, 0, 0)');
556-
gradient.addColorStop(1, 'rgba(0, 0, 0, 255)');
564+
gradient.addColorStop(0, 'white');
565+
gradient.addColorStop(1, 'black');
557566

558567
this.top_context.fillStyle = gradient;
568+
this.top_context.strokeStyle = 'gray';
559569

560570
this.top_context.globalAlpha = 0.3;
561571
this.top_context.beginPath();
@@ -573,9 +583,10 @@ export class MPLCanvasView extends DOMWidgetView {
573583
);
574584
this.top_context.closePath();
575585
this.top_context.fill();
576-
577-
this.top_context.restore();
586+
this.top_context.stroke();
578587
}
588+
589+
this.top_context.restore();
579590
}
580591

581592
_update_cursor() {

0 commit comments

Comments
 (0)