Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the calc cursor handle being offset during animated scroll #10778

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion browser/src/canvas/CanvasSectionContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2082,13 +2082,16 @@ class CanvasSectionContainer {
this.continueAnimating = false;
}

const section: CanvasSectionObject = this.getSectionWithName(this.getAnimatingSectionName());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to add this. onDraw function is called on animation steps. It looks like moving the last if block to the top of onDraw function would do the same thing (in ScrollSection.ts)? Maybe we can find a way withouth adding this function. Thanks for checking the issue:)

Copy link
Contributor Author

@Cwiiis Cwiiis Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wouldn't do the same thing - this is moving the altering of scroll position outside of the middle of the drawing chain. The problem isn't fixed by altering the scroll position before drawing the scrollbars. The scroll position has external dependents and needs to be changed before drawing begins, not in the middle of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other thing we could do is add an onBeforeDraw function, I suppose - the result would be the same, although the impact would be slightly greater (it's negligible either way, but this way, only animated containers are affected, if we add an onBeforeDraw, every container will be affected, animating or not).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this also requires: Removal of (frameCount?: number, elapsedTime?: number) from onDraw function variables, for a better API design. We don't have to do this now but i guess that would be better, since we separate the drawing and before-drawing phases.

Let me check drawingOrder and processingOrder variables first. They should indicate the wrong order of processing, about external dependents of scroll section.

Even if we can solve this without new callback, this idea is better i think. Will check this and other PR in a bit. Thanks :)

if (section)
section.onAnimationStep(this.frameCount, this.elapsedTime);

if (this.continueAnimating) {
this.drawSections(this.frameCount, this.elapsedTime);
this.frameCount++;
requestAnimationFrame(this.animate.bind(this));
}
else {
var section: CanvasSectionObject = this.getSectionWithName(this.getAnimatingSectionName());
if (section) {
section.isAnimating = false;
section.onAnimationEnded(this.frameCount, this.elapsedTime);
Expand Down
1 change: 1 addition & 0 deletions browser/src/canvas/CanvasSectionObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class CanvasSectionObject {
onResize(): void { return; }
onDraw(frameCount?: number, elapsedTime?: number, subsetBounds?: cool.Bounds): void { return; }
onDrawArea(area?: cool.Bounds, paneTopLeft?: cool.Point, canvasContext?: CanvasRenderingContext2D): void { return; } // area is the area to be painted using canvasContext.
onAnimationStep(frameCount: number, elapsedTime: number): void { return; }
onAnimationEnded(frameCount: number, elapsedTime: number): void { return; } // frameCount, elapsedTime. Sections that will use animation, have to have this function defined.
onNewDocumentTopLeft(size: Array<number>): void { return; }
onRemove(): void { return; } // This Function is called right before section is removed.
Expand Down
32 changes: 17 additions & 15 deletions browser/src/canvas/sections/ScrollSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,21 +514,7 @@ export class ScrollSection extends CanvasSectionObject {
}
}

public onDraw (frameCount: number, elapsedTime: number): void {
if (this.isAnimating && frameCount >= 0)
this.calculateCurrentAlpha(elapsedTime);

if ((this.sectionProperties.drawVerticalScrollBar || this.sectionProperties.animatingVerticalScrollBar)) {
if ((<any>window).mode.isMobile())
this.DrawVerticalScrollBarMobile();
else
this.drawVerticalScrollBar();
}

if ((this.sectionProperties.drawHorizontalScrollBar || this.sectionProperties.animatingHorizontalScrollBar)) {
this.drawHorizontalScrollBar();
}

public onAnimationStep (frameCount: number, elapsedTime: number): void {
if (this.sectionProperties.animatingScroll) {
const lineHeight = this.containerObject.getScrollLineHeight();
const accel = lineHeight * ScrollSection.scrollAnimationAcceleration;
Expand Down Expand Up @@ -567,6 +553,22 @@ export class ScrollSection extends CanvasSectionObject {
}
}

public onDraw (frameCount: number, elapsedTime: number): void {
if (this.isAnimating && frameCount >= 0)
this.calculateCurrentAlpha(elapsedTime);

if ((this.sectionProperties.drawVerticalScrollBar || this.sectionProperties.animatingVerticalScrollBar)) {
if ((<any>window).mode.isMobile())
this.DrawVerticalScrollBarMobile();
else
this.drawVerticalScrollBar();
}

if ((this.sectionProperties.drawHorizontalScrollBar || this.sectionProperties.animatingHorizontalScrollBar)) {
this.drawHorizontalScrollBar();
}
}

public onAnimationEnded (frameCount: number, elapsedTime: number): void {
this.sectionProperties.animatingVerticalScrollBar = false;
this.sectionProperties.animatingHorizontalScrollBar = false;
Expand Down
Loading