Browse Source

feat(Cursor): Make ScrollPosition configurable (cursor.ScrollPosition = "start" -> scroll position to top of screen, default center)

sschmidTU 2 years ago
parent
commit
9888feee64
1 changed files with 8 additions and 1 deletions
  1. 8 1
      src/OpenSheetMusicDisplay/Cursor.ts

+ 8 - 1
src/OpenSheetMusicDisplay/Cursor.ts

@@ -109,6 +109,11 @@ export class Cursor implements IPlaybackListener {
   public currentPageNumber: number = 1;
   private cursorOptions: CursorOptions;
   private skipInvisibleNotes: boolean = true;
+  /** Where to scroll to when FollowCursor is enabled.
+   *  Default center (will scroll so that the current cursor position is in the center of the screen),
+   *  alternatively set to "start" to scroll so that the current position is at the top of the screen.
+   */
+  public ScrollPosition: ScrollLogicalPosition = "center";
 
   /** Initialize the cursor. Necessary before using functions like show() and next(). */
   public init(manager: MusicPartManager, graphic: GraphicalMusicSheet): void {
@@ -196,7 +201,9 @@ export class Cursor implements IPlaybackListener {
 
     if (this.openSheetMusicDisplay.FollowCursor) {
       const diff: number = this.cursorElement.getBoundingClientRect().top;
-      this.cursorElement.scrollIntoView({behavior: diff < 1000 ? "smooth" : "auto", block: "center"});
+      this.cursorElement.scrollIntoView(
+        {behavior: diff < 1000 ? "smooth" : "auto", block: this.ScrollPosition}
+      );
     }
     // Show cursor
     // // Old cursor: this.graphic.Cursors.push(cursor);