Skip to content

CenteredZoomState - Prevent timeline.offset on right side? #37

@justinlevi

Description

@justinlevi

I have created a CustomCenteredZoomState class which extends ui.states.CenteredZoomState. I see the example to prevent the timeline.offset from going negative, but I'm struggling with how to limit the user from scrolling the waveform infinitely in the positive direction.

I see Example 2, but I'm not sure the best way to get the view.width in this class? I would like to limit dragging to the maximum of the audio track if that makes sense. I'll keep working at it, just wondering if this is something that has already been solved...

    // Example 1: Prevent timeline.offset to be negative
    timeContext.offset = Math.min(timeContext.offset, 0);
    //
    // Example 2: Keep in container when zoomed out
    // if (timeContext.stretchRatio < 1) {
    //   const minOffset = timeContext.timeToPixel.invert(0);
    //   const maxOffset = timeContext.timeToPixel.invert(view.width - timeContext.timeToPixel(timeContext.duration));
    //   timeContext.offset = Math.max(timeContext.offset, minOffset);
    //   timeContext.offset = Math.min(timeContext.offset, maxOffset);
    // }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions