diff --git a/src/lib/keyBindings/Actions.ts b/src/lib/keyBindings/Actions.ts index 28ff378..f1342fd 100644 --- a/src/lib/keyBindings/Actions.ts +++ b/src/lib/keyBindings/Actions.ts @@ -202,7 +202,7 @@ class Actions { ); visibleColumns.forEach((column, index) => column.setWidth(widths[index], true)); - desktop.scrollCenterRange(Desktop.RangeImpl.fromRanges( + desktop.scrollCenterRange(Range.Basic.fromRanges( visibleColumns[0], visibleColumns[visibleColumns.length - 1], )); @@ -279,7 +279,7 @@ class Actions { const widths = fillSpace(availableSpace - gapsWidth, columnConstraints); columns.forEach((column, index) => column.setWidth(widths[index], true)); - desktop.scrollCenterRange(Desktop.RangeImpl.fromRanges(firstColumn, lastColumn)); + desktop.scrollCenterRange(Range.Basic.fromRanges(firstColumn, lastColumn)); return true; } diff --git a/src/lib/layout/Column.ts b/src/lib/layout/Column.ts index 6e76cbe..9c2dd09 100644 --- a/src/lib/layout/Column.ts +++ b/src/lib/layout/Column.ts @@ -203,7 +203,7 @@ class Column { window.focus(); } - public arrange(x: number, visibleRange: Desktop.SuperRange, forceOpaque: boolean) { + public arrange(x: number, visibleRange: SuperRange, forceOpaque: boolean) { if (this.grid.config.offScreenOpacity < 1.0 && !forceOpaque) { const opacity = visibleRange.contains(this) ? 100 : this.grid.config.offScreenOpacity; for (const window of this.windows.iterator()) { diff --git a/src/lib/layout/Desktop.ts b/src/lib/layout/Desktop.ts index 20dc4a9..f0b0a1e 100644 --- a/src/lib/layout/Desktop.ts +++ b/src/lib/layout/Desktop.ts @@ -55,7 +55,7 @@ class Desktop { ) } - public scrollIntoView(range: Desktop.Range) { + public scrollIntoView(range: Range) { const left = range.getLeft(); const right = range.getRight(); const initialVisibleRange = this.getCurrentVisibleRange(); @@ -72,7 +72,7 @@ class Desktop { this.setScroll(targetScrollX, false); } - public scrollCenterRange(range: Desktop.Range) { + public scrollCenterRange(range: Range) { const windowCenter = range.getLeft() + range.getWidth() / 2; const screenCenter = this.scrollX + this.tilingArea.width / 2; this.adjustScroll(Math.round(windowCenter - screenCenter), true); @@ -101,7 +101,7 @@ class Desktop { } private getVisibleRange(scrollX: number) { - return new Desktop.RangeImpl(scrollX, this.tilingArea.width); + return new Range.Basic(scrollX, this.tilingArea.width); } public getCurrentVisibleRange() { @@ -161,49 +161,6 @@ namespace Desktop { clamper: Desktop.Clamper; }; - export type Range = { - getLeft(): number; - getRight(): number; - getWidth(): number; - }; - - export type SuperRange = Range & { - contains(child: Range): boolean; - }; - - export class RangeImpl { - private readonly x: number; - private 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; - } - - public getWidth() { - return this.width; - } - - public contains(child: Range) { - return child.getLeft() >= this.getLeft() && - child.getRight() <= this.getRight(); - } - - public static fromRanges(leftRange: Range, rightRange: Range) { - const left = leftRange.getLeft(); - const right = rightRange.getRight(); - return new RangeImpl(left, right - left); - } - } - export class ColumnRange { private left: Column; private right: Column; @@ -215,7 +172,7 @@ namespace Desktop { this.width = initialColumn.getWidth(); } - public addNeighbors(visibleRange: Desktop.Range, gap: number) { + public addNeighbors(visibleRange: Range, gap: number) { const grid = this.left.grid; const columnRange = this; diff --git a/src/lib/layout/Grid.ts b/src/lib/layout/Grid.ts index e1cfc2f..3a32d0c 100644 --- a/src/lib/layout/Grid.ts +++ b/src/lib/layout/Grid.ts @@ -104,7 +104,7 @@ class Grid { this.width = x - this.config.gapsInnerHorizontal; } - public getLeftmostVisibleColumn(visibleRange: Desktop.SuperRange, fullyVisible: boolean) { + public getLeftmostVisibleColumn(visibleRange: SuperRange, fullyVisible: boolean) { for (const column of this.columns.iterator()) { if (visibleRange.contains(column)) { return column; @@ -113,7 +113,7 @@ class Grid { return null; } - public getRightmostVisibleColumn(visibleRange: Desktop.SuperRange, fullyVisible: boolean) { + public getRightmostVisibleColumn(visibleRange: SuperRange, fullyVisible: boolean) { let last = null; for (const column of this.columns.iterator()) { if (visibleRange.contains(column)) { @@ -125,7 +125,7 @@ class Grid { return last; } - public *getVisibleColumns(visibleRange: Desktop.SuperRange, fullyVisible: boolean) { + public *getVisibleColumns(visibleRange: SuperRange, fullyVisible: boolean) { for (const column of this.columns.iterator()) { if (visibleRange.contains(column)) { yield column; @@ -133,7 +133,7 @@ class Grid { } } - public arrange(x: number, visibleRange: Desktop.SuperRange) { + public arrange(x: number, visibleRange: SuperRange) { for (const column of this.columns.iterator()) { column.arrange(x, visibleRange, this.userResize); x += column.getWidth() + this.config.gapsInnerHorizontal; diff --git a/src/lib/layout/Range.ts b/src/lib/layout/Range.ts new file mode 100644 index 0000000..f0d7f9a --- /dev/null +++ b/src/lib/layout/Range.ts @@ -0,0 +1,44 @@ +type Range = { + getLeft(): number; + getRight(): number; + getWidth(): number; +}; + +type SuperRange = Range & { + contains(child: Range): boolean; +}; + +namespace Range { + export class Basic { + private readonly x: number; + private 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; + } + + public getWidth() { + return this.width; + } + + public contains(child: Range) { + return child.getLeft() >= this.getLeft() && + child.getRight() <= this.getRight(); + } + + public static fromRanges(leftRange: Range, rightRange: Range) { + const left = leftRange.getLeft(); + const right = rightRange.getRight(); + return new Basic(left, right - left); + } + } +}