mirror of
https://github.com/esjeon/krohnkite.git
synced 2024-10-03 23:07:13 +03:00
rename WindowResizeDelta to RectDelta
This commit is contained in:
parent
da74b3bfea
commit
c7fee18a10
@ -18,35 +18,6 @@
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
class WindowResizeDelta {
|
||||
public static fromWindow(window: Window): WindowResizeDelta {
|
||||
const diff = window.actualGeometry.subtract(window.geometry);
|
||||
return new WindowResizeDelta(
|
||||
diff.width + diff.x,
|
||||
-diff.x,
|
||||
diff.height + diff.y,
|
||||
-diff.y,
|
||||
);
|
||||
}
|
||||
|
||||
constructor(
|
||||
public readonly east: number,
|
||||
public readonly west: number,
|
||||
public readonly south: number,
|
||||
public readonly north: number,
|
||||
) {
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
return "WindowResizeDelta(" + [
|
||||
"east=" + this.east,
|
||||
"west=" + this.west,
|
||||
"north=" + this.north,
|
||||
"south=" + this.south,
|
||||
].join(" ") + ")";
|
||||
}
|
||||
}
|
||||
|
||||
class Window {
|
||||
/* read-only */
|
||||
public readonly id: string;
|
||||
@ -57,6 +28,10 @@ class Window {
|
||||
public get shouldFloat(): boolean { return this.window.shouldFloat; }
|
||||
public get shouldIgnore(): boolean { return this.window.shouldIgnore; }
|
||||
|
||||
public get geometryDelta(): RectDelta {
|
||||
return RectDelta.fromRects(this.geometry, this.actualGeometry);
|
||||
}
|
||||
|
||||
public get tileable(): boolean {
|
||||
return (this.state === WindowState.Tile) || (this.state === WindowState.FreeTile);
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class ColumnLayout implements ILayout {
|
||||
|
||||
const numColumns = this.columnMasters.length;
|
||||
const [basisColumn, basisIndex] = entry;
|
||||
const delta = WindowResizeDelta.fromWindow(basis);
|
||||
const delta = basis.geometryDelta;
|
||||
|
||||
/* horizontal adjustment */
|
||||
if (basisColumn === null) {
|
||||
@ -73,14 +73,14 @@ class ColumnLayout implements ILayout {
|
||||
/* the last column is resized */
|
||||
/* adjust columns-stack ratio */
|
||||
if (delta.east !== 0) {
|
||||
const columnsDelta = new WindowResizeDelta(delta.east, 0, 0, 0);
|
||||
const columnsDelta = new RectDelta(delta.east, 0, 0, 0);
|
||||
this.stackRatio = 1 - LayoutUtils.adjustAreaHalfWeights(area, 1 - this.stackRatio, 20,
|
||||
0, columnsDelta, true);
|
||||
}
|
||||
|
||||
/* adjust colums ratio */
|
||||
if (delta.west !== 0) {
|
||||
const columnDelta = new WindowResizeDelta(0, delta.west, 0, 0);
|
||||
const columnDelta = new RectDelta(0, delta.west, 0, 0);
|
||||
const newWeights = LayoutUtils.adjustAreaWeights(area, this.columnWeights, 20,
|
||||
basisColumn, columnDelta, true);
|
||||
this.columnWeights = newWeights;
|
||||
|
@ -141,7 +141,7 @@ class LayoutUtils {
|
||||
weights: number[],
|
||||
gap: number,
|
||||
target: number,
|
||||
delta: WindowResizeDelta,
|
||||
delta: RectDelta,
|
||||
horizontal?: boolean,
|
||||
): number[] {
|
||||
const line: [number, number] = (horizontal) ? [area.x, area.width] : [area.y, area.height];
|
||||
@ -157,7 +157,7 @@ class LayoutUtils {
|
||||
weight: number,
|
||||
gap: number,
|
||||
target: number,
|
||||
delta: WindowResizeDelta,
|
||||
delta: RectDelta,
|
||||
horizontal?: boolean,
|
||||
): number {
|
||||
const weights = [weight, 1 - weight];
|
||||
|
@ -43,7 +43,7 @@ class QuarterLayout implements ILayout {
|
||||
if (idx < 0)
|
||||
return;
|
||||
|
||||
const delta = WindowResizeDelta.fromWindow(basis);
|
||||
const delta = basis.geometryDelta;
|
||||
|
||||
/* vertical split */
|
||||
if ((idx === 0 || idx === 3) && delta.east !== 0)
|
||||
|
@ -44,7 +44,7 @@ class TileLayout implements ILayout {
|
||||
if (idx < 0)
|
||||
return;
|
||||
|
||||
const delta = WindowResizeDelta.fromWindow(basis);
|
||||
const delta = basis.geometryDelta;
|
||||
if (idx < this.numMaster) { /* master tiles */
|
||||
if (delta.east !== 0) {
|
||||
const newMasterWidth = Math.floor(area.width * this.masterRatio) + delta.east;
|
||||
|
48
src/util/rectdelta.ts
Normal file
48
src/util/rectdelta.ts
Normal file
@ -0,0 +1,48 @@
|
||||
// Copyright (c) 2018-2019 Eon S. Jeon <esjeon@hyunmu.am>
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
class RectDelta {
|
||||
public static fromRects(basis: Rect, target: Rect): RectDelta {
|
||||
const diff = target.subtract(basis);
|
||||
return new RectDelta(
|
||||
diff.width + diff.x,
|
||||
-diff.x,
|
||||
diff.height + diff.y,
|
||||
-diff.y,
|
||||
);
|
||||
}
|
||||
|
||||
constructor(
|
||||
public readonly east: number,
|
||||
public readonly west: number,
|
||||
public readonly south: number,
|
||||
public readonly north: number,
|
||||
) {
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
return "WindowResizeDelta(" + [
|
||||
"east=" + this.east,
|
||||
"west=" + this.west,
|
||||
"north=" + this.north,
|
||||
"south=" + this.south,
|
||||
].join(" ") + ")";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user