diff --git a/src/layout/Column.ts b/src/layout/Column.ts index d4c2254..e4ce670 100644 --- a/src/layout/Column.ts +++ b/src/layout/Column.ts @@ -208,7 +208,7 @@ class Column { this.stacked = !this.stacked; } - public isVisible(scrollPos: ScrollPos, fullyVisible: boolean) { + public isVisible(scrollPos: ScrollView.Pos, fullyVisible: boolean) { if (fullyVisible) { return this.getLeft() >= scrollPos.getLeft() && this.getRight() <= scrollPos.getRight(); diff --git a/src/layout/Grid.ts b/src/layout/Grid.ts index e7718ba..8cc5b9a 100644 --- a/src/layout/Grid.ts +++ b/src/layout/Grid.ts @@ -78,7 +78,7 @@ class Grid { this.width = x - this.config.gapsInnerHorizontal; } - public getLeftmostVisibleColumn(scrollPos: ScrollPos, fullyVisible: boolean) { + public getLeftmostVisibleColumn(scrollPos: ScrollView.Pos, fullyVisible: boolean) { const scrollX = scrollPos.getLeft(); for (const column of this.columns.iterator()) { const x = fullyVisible ? column.getLeft() : column.getRight() + (this.config.gapsInnerHorizontal - 1); @@ -89,7 +89,7 @@ class Grid { return null; } - public getRightmostVisibleColumn(scrollPos: ScrollPos, fullyVisible: boolean) { + public getRightmostVisibleColumn(scrollPos: ScrollView.Pos, fullyVisible: boolean) { const scrollX = scrollPos.getRight(); let last = null; for (const column of this.columns.iterator()) { @@ -103,7 +103,7 @@ class Grid { return last; } - public getVisibleColumnsWidth(scrollPos: ScrollPos, fullyVisible: boolean) { + public getVisibleColumnsWidth(scrollPos: ScrollView.Pos, fullyVisible: boolean) { let width = 0; let nVisible = 0; for (const column of this.columns.iterator()) { @@ -120,7 +120,7 @@ class Grid { return width; } - private getLeftOffScreenColumn(scrollPos: ScrollPos) { + private getLeftOffScreenColumn(scrollPos: ScrollView.Pos) { const leftVisible = this.getLeftmostVisibleColumn(scrollPos, true); if (leftVisible === null) { return null; @@ -128,7 +128,7 @@ class Grid { return this.getPrevColumn(leftVisible); } - private getRightOffScreenColumn(scrollPos: ScrollPos) { + private getRightOffScreenColumn(scrollPos: ScrollView.Pos) { const rightVisible = this.getRightmostVisibleColumn(scrollPos, true); if (rightVisible === null) { return null; diff --git a/src/layout/ScrollPos.ts b/src/layout/ScrollPos.ts deleted file mode 100644 index 081e92b..0000000 --- a/src/layout/ScrollPos.ts +++ /dev/null @@ -1,17 +0,0 @@ -class ScrollPos { - public readonly x: number; - public readonly width: number; - - constructor(x: number, width: number) { - this.x = x; - this.width = width; - } - - public getLeft() { - return this.x; - } - - public getRight() { - return this.x + this.width; - } -} diff --git a/src/layout/ScrollView.ts b/src/layout/ScrollView.ts index b0bfa7c..1c9d6b8 100644 --- a/src/layout/ScrollView.ts +++ b/src/layout/ScrollView.ts @@ -34,7 +34,7 @@ class ScrollView { this.autoAdjustScroll(); } - // calculates ScrollPos that scrolls the column into view + // calculates ScrollView.Pos that scrolls the column into view public getScrollPosForColumn(column: Column) { const left = column.getLeft(); const right = column.getRight(); @@ -89,7 +89,7 @@ class ScrollView { } private getScrollPos(scrollX: number) { - return new ScrollPos(scrollX, this.tilingArea.width); + return new ScrollView.Pos(scrollX, this.tilingArea.width); } public getCurrentScrollPos() { @@ -111,7 +111,7 @@ class ScrollView { this.scrollX = force ? x : this.clampScrollX(x); } - private applyScrollPos(scrollPos: ScrollPos) { + private applyScrollPos(scrollPos: ScrollView.Pos) { this.scrollX = scrollPos.x; } @@ -151,4 +151,22 @@ module ScrollView { marginRight: number, overscroll: number, } + + export class Pos { + public readonly x: number; + public readonly width: number; + + constructor(x: number, width: number) { + this.x = x; + this.width = width; + } + + public getLeft() { + return this.x; + } + + public getRight() { + return this.x + this.width; + } + } }