use different implementations of clampScrollX in different scrollers
This commit is contained in:
@@ -119,12 +119,7 @@ class Desktop {
|
||||
}
|
||||
|
||||
private clampScrollX(x: number) {
|
||||
let minScroll = 0;
|
||||
let maxScroll = this.grid.getWidth() - this.tilingArea.width;
|
||||
if (maxScroll < 0) {
|
||||
return Math.round(maxScroll / 2);
|
||||
}
|
||||
return clamp(x, minScroll, maxScroll);
|
||||
return this.config.scroller.clampScrollX(this, x);
|
||||
}
|
||||
|
||||
public setScroll(x: number, force: boolean) {
|
||||
@@ -233,5 +228,6 @@ namespace Desktop {
|
||||
|
||||
export type Scroller = {
|
||||
scrollToColumn(desktop: Desktop, column: Column): void;
|
||||
clampScrollX(desktop: Desktop, x: number): number;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,4 +2,20 @@ class ScrollerCentered {
|
||||
public scrollToColumn(desktop: Desktop, column: Column) {
|
||||
desktop.scrollCenterRange(column);
|
||||
}
|
||||
|
||||
public clampScrollX(desktop: Desktop, x: number) {
|
||||
return ScrollerCentered.clampScrollX(desktop, x);
|
||||
}
|
||||
|
||||
public static clampScrollX(desktop: Desktop, x: number) {
|
||||
const firstColumn = desktop.grid.getFirstColumn();
|
||||
if (firstColumn === null) {
|
||||
return 0;
|
||||
}
|
||||
const lastColumn = desktop.grid.getLastColumn()!;
|
||||
|
||||
let minScroll = Math.round((firstColumn.getWidth() - desktop.tilingArea.width) / 2);
|
||||
let maxScroll = Math.round(desktop.grid.getWidth() - (desktop.tilingArea.width + lastColumn.getWidth()) / 2);
|
||||
return clamp(x, minScroll, maxScroll);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,10 @@ class ScrollerGrouped {
|
||||
columnRange.addNeighbors(visibleRange, this.layoutConfig.gapsInnerHorizontal, false);
|
||||
desktop.scrollCenterRange(columnRange);
|
||||
}
|
||||
|
||||
public clampScrollX(desktop: Desktop, x: number) {
|
||||
return ScrollerCentered.clampScrollX(desktop, x);
|
||||
}
|
||||
}
|
||||
|
||||
namespace ScrollerGrouped {
|
||||
|
||||
@@ -2,4 +2,13 @@ class ScrollerLazy {
|
||||
public scrollToColumn(desktop: Desktop, column: Column) {
|
||||
desktop.scrollToRange(column);
|
||||
}
|
||||
|
||||
public clampScrollX(desktop: Desktop, x: number) {
|
||||
let minScroll = 0;
|
||||
let maxScroll = desktop.grid.getWidth() - desktop.tilingArea.width;
|
||||
if (maxScroll < 0) {
|
||||
return Math.round(maxScroll / 2);
|
||||
}
|
||||
return clamp(x, minScroll, maxScroll);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user