Skip to content

Commit

Permalink
introduce click_events argument for ui.scene
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Aug 9, 2024
1 parent fca2b55 commit a6f8115
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions nicegui/elements/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ export default {
shift_key: mouseEvent.shiftKey,
});
};
this.$el.onclick = click_handler;
this.$el.ondblclick = click_handler;
this.click_events.forEach((event) => this.$el.addEventListener(event, click_handler));

this.texture_loader = new THREE.TextureLoader();
this.stl_loader = new STLLoader();
Expand Down Expand Up @@ -475,6 +474,7 @@ export default {
grid: Object,
camera_type: String,
camera_params: Object,
click_events: Array,
drag_constraints: String,
background_color: String,
},
Expand Down
5 changes: 4 additions & 1 deletion nicegui/elements/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def __init__(self,
grid: Union[bool, Tuple[int, int]] = True,
camera: Optional[SceneCamera] = None,
on_click: Optional[Callable[..., Any]] = None,
click_events: List[str] = ['click', 'dblclick'], # noqa: B006
on_drag_start: Optional[Callable[..., Any]] = None,
on_drag_end: Optional[Callable[..., Any]] = None,
drag_constraints: str = '',
Expand All @@ -91,7 +92,8 @@ def __init__(self,
:param height: height of the canvas
:param grid: whether to display a grid (boolean or tuple of ``size`` and ``divisions`` for `Three.js' GridHelper <https://threejs.org/docs/#api/en/helpers/GridHelper>`_, default: 100x100)
:param camera: camera definition, either instance of ``ui.scene.perspective_camera`` (default) or ``ui.scene.orthographic_camera``
:param on_click: callback to execute when a 3D object is clicked
:param on_click: callback to execute when a 3D object is clicked (use ``click_events`` to specify which events to subscribe to)
:param click_events: list of JavaScript click events to subscribe to (default: ``['click', 'dblclick']``)
:param on_drag_start: callback to execute when a 3D object is dragged
:param on_drag_end: callback to execute when a 3D object is dropped
:param drag_constraints: comma-separated JavaScript expression for constraining positions of dragged objects (e.g. ``'x = 0, z = y / 2'``)
Expand All @@ -108,6 +110,7 @@ def __init__(self,
self.objects: Dict[str, Object3D] = {}
self.stack: List[Union[Object3D, SceneObject]] = [SceneObject()]
self._click_handlers = [on_click] if on_click else []
self._props['click_events'] = click_events
self._drag_start_handlers = [on_drag_start] if on_drag_start else []
self._drag_end_handlers = [on_drag_end] if on_drag_end else []
self.is_initialized = False
Expand Down

0 comments on commit a6f8115

Please sign in to comment.