Skip to content

Commit 66a5be3

Browse files
committed
Global alpha
1 parent 724d733 commit 66a5be3

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

ipycanvas/canvas.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Canvas(DOMWidget):
2323

2424
fill_style = Color('black').tag(sync=True)
2525
stroke_style = Color('black').tag(sync=True)
26+
global_alpha = Float(1.0).tag(sync=True)
2627

2728
# Rectangles methods
2829
def fill_rect(self, x, y, width, height):

src/widget.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ class CanvasView extends DOMWidgetView {
4848
this.canvas = document.createElement('canvas');
4949
this.canvas.classList.add('ipycanvas_canvas');
5050

51-
this.ctx = this.canvas.getContext('2d');
52-
5351
this.el.appendChild(this.canvas);
5452
this.el.classList.add('ipycanvas');
5553

54+
this.ctx = this.canvas.getContext('2d');
55+
56+
this.ctx.globalAlpha = this.model.get('global_alpha');
57+
5658
this.resize_canvas();
5759

5860
this.model_events();
@@ -66,7 +68,8 @@ class CanvasView extends DOMWidgetView {
6668
this.ctx[event.msg](...event.args);
6769
});
6870

69-
this.model.on('change;size', () => { this.resize_canvas(); });
71+
this.model.on('change:size', () => { this.resize_canvas(); });
72+
this.model.on('change:global_alpha', () => { this.ctx.globalAlpha = this.model.get('global_alpha'); });
7073
}
7174

7275
resize_canvas() {

0 commit comments

Comments
 (0)