Skip to content

Commit 7abf77f

Browse files
committed
Add support for changing opacity
1 parent 0ed0fb9 commit 7abf77f

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

ipygany/ipygany.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ class Scene(_GanyDOMWidgetBase):
364364
children = List(Instance(Block)).tag(sync=True, **widget_serialization)
365365

366366
background_color = Color('#fff').tag(sync=True)
367+
background_opacity = CFloat(0.).tag(sync=True)
367368

368369
def __init__(self, children=[], **kwargs):
369370
"""Construct a Scene."""

package-lock.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"@jupyter-widgets/base": "^1.1.10 || ^2",
5353
"backbone": "^1.4.0",
5454
"binary-search-tree": "^0.2.6",
55-
"ganyjs": "^0.1.6",
55+
"ganyjs": "^0.1.8",
5656
"three": "^0.110.0",
5757
"uuid": "^3.3.3"
5858
},

src/widget.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ class SceneModel extends _GanyDOMWidgetModel {
488488
_model_name: SceneModel.model_name,
489489
_view_name: SceneModel.view_name,
490490
background_color: '#fff',
491+
background_opacity: 0.,
491492
children: [],
492493
};
493494
}
@@ -501,6 +502,14 @@ class SceneModel extends _GanyDOMWidgetModel {
501502
this.on('change:children', this.updateChildren.bind(this));
502503
}
503504

505+
get backgroundColor () : string {
506+
return this.get('background_color')
507+
}
508+
509+
get backgroundOpacity () : number {
510+
return this.get('background_opacity')
511+
}
512+
504513
private updateChildren () {
505514
// TODO: Remove old children
506515

@@ -546,7 +555,8 @@ class SceneView extends DOMWidgetView {
546555

547556
this.displayed.then(() => {
548557
this.renderer.initialize();
549-
this.renderer.backgroundColor = this.model.get('background_color');
558+
this.renderer.backgroundColor = this.model.backgroundColor
559+
this.renderer.backgroundOpacity = this.model.backgroundOpacity;
550560

551561
this.initEventListeners();
552562
});
@@ -555,7 +565,8 @@ class SceneView extends DOMWidgetView {
555565
initEventListeners () {
556566
window.addEventListener('resize', this.resize.bind(this), false);
557567

558-
this.model.on('change:background_color', () => { this.renderer.backgroundColor = this.model.get('background_color'); });
568+
this.model.on('change:background_color', () => { this.renderer.backgroundColor = this.model.backgroundColor; });
569+
this.model.on('change:background_opacity', () => { this.renderer.backgroundOpacity = this.model.backgroundOpacity; });
559570
}
560571

561572
processPhosphorMessage (msg: Message) {

0 commit comments

Comments
 (0)