Skip to content

Commit

Permalink
trigger event in scroll utility
Browse files Browse the repository at this point in the history
  • Loading branch information
m00n620 committed Sep 18, 2024
1 parent 38aac18 commit ea4b2d8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
14 changes: 0 additions & 14 deletions packages/core/src/RenderingEngine/StackViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ import {
PixelDataTypedArray,
} from '../types';
import {
StackScrollOutOfBoundsEventDetail,
StackViewportNewStackEventDetail,
StackViewportScrollEventDetail,
VoiModifiedEventDetail,
Expand Down Expand Up @@ -2602,19 +2601,6 @@ class StackViewport extends Viewport implements IStackViewport, IImagesLoader {
}, 40);
}

const imageIdIndex = this.getCurrentImageIdIndex();

if (
imageIdIndex + delta > this.getImageIds().length - 1 ||
imageIdIndex + delta < 0
) {
const eventData: StackScrollOutOfBoundsEventDetail = {
imageIdIndex,
direction: delta,
};
triggerEvent(this.element, Events.STACK_SCROLL_OUT_OF_BOUNDS, eventData);
}

const eventData: StackViewportScrollEventDetail = {
newImageIdIndex: newTargetImageIdIndex,
imageId: targetImageId,
Expand Down
9 changes: 7 additions & 2 deletions packages/tools/examples/stackManipulationTools/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { RenderingEngine, Types, Enums } from '@cornerstonejs/core';
import {
eventTarget,
RenderingEngine,
Types,
Enums,
} from '@cornerstonejs/core';
import {
initDemo,
createImageIdsAndCacheMetaData,
Expand Down Expand Up @@ -112,7 +117,7 @@ let eventNumber = 1;

const { STACK_SCROLL_OUT_OF_BOUNDS } = Enums.Events;

element.addEventListener(STACK_SCROLL_OUT_OF_BOUNDS, ((
eventTarget.addEventListener(STACK_SCROLL_OUT_OF_BOUNDS, ((
evt: StackScrollOutOfBoundsEvent
) => {
updateLastEvents(
Expand Down
18 changes: 18 additions & 0 deletions packages/tools/src/utilities/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ export default function scroll(
if (viewport instanceof VolumeViewport) {
scrollVolume(viewport, volumeId, delta, scrollSlabs);
} else {
const imageIdIndex = viewport.getCurrentImageIdIndex();

if (
imageIdIndex + delta >
(viewport as Types.IStackViewport).getImageIds().length - 1 ||
imageIdIndex + delta < 0
) {
const eventData: Types.EventTypes.StackScrollOutOfBoundsEventDetail = {
imageIdIndex,
direction: delta,
};
csUtils.triggerEvent(
eventTarget,
EVENTS.STACK_SCROLL_OUT_OF_BOUNDS,
eventData
);
}

(viewport as Types.IStackViewport).scroll(
delta,
options.debounceLoading,
Expand Down

0 comments on commit ea4b2d8

Please sign in to comment.