mirror of
https://github.com/Bismuth-Forge/bismuth.git
synced 2024-09-11 00:15:37 +03:00
refactor: ♻️ move RectDelta to rect.ts
This commit is contained in:
parent
014a777ff5
commit
fbcb4c002a
@ -4,7 +4,7 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
import Config from "../config";
|
import Config from "../config";
|
||||||
import Rect from "../util/rect";
|
import { Rect } from "../util/rect";
|
||||||
|
|
||||||
export interface DriverSurface {
|
export interface DriverSurface {
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import { DriverSurface, DriverSurfaceImpl } from "./surface";
|
import { DriverSurface, DriverSurfaceImpl } from "./surface";
|
||||||
|
|
||||||
import Rect from "../util/rect";
|
import { Rect } from "../util/rect";
|
||||||
import { clip, matchWords } from "../util/func";
|
import { clip, matchWords } from "../util/func";
|
||||||
import Config from "../config";
|
import Config from "../config";
|
||||||
import { Log } from "../util/log";
|
import { Log } from "../util/log";
|
||||||
|
@ -12,7 +12,7 @@ import { Controller } from "../controller";
|
|||||||
import { DriverSurface } from "../driver/surface";
|
import { DriverSurface } from "../driver/surface";
|
||||||
|
|
||||||
import { Log } from "../util/log";
|
import { Log } from "../util/log";
|
||||||
import Rect from "../util/rect";
|
import { Rect } from "../util/rect";
|
||||||
import TileLayout from "./layout/tile_layout";
|
import TileLayout from "./layout/tile_layout";
|
||||||
import LayoutStore from "./layout_store";
|
import LayoutStore from "./layout_store";
|
||||||
import { EngineWindow, WindowState } from "./window";
|
import { EngineWindow, WindowState } from "./window";
|
||||||
|
@ -13,8 +13,7 @@ import { Controller } from "../controller";
|
|||||||
|
|
||||||
import { DriverSurface } from "../driver/surface";
|
import { DriverSurface } from "../driver/surface";
|
||||||
|
|
||||||
import Rect from "../util/rect";
|
import { Rect, RectDelta } from "../util/rect";
|
||||||
import RectDelta from "../util/rectdelta";
|
|
||||||
import { overlap, wrapIndex } from "../util/func";
|
import { overlap, wrapIndex } from "../util/func";
|
||||||
import Config from "../config";
|
import Config from "../config";
|
||||||
import { Log } from "../util/log";
|
import { Log } from "../util/log";
|
||||||
|
@ -15,7 +15,7 @@ import {
|
|||||||
} from "../../controller/action";
|
} from "../../controller/action";
|
||||||
import { Controller } from "../../controller";
|
import { Controller } from "../../controller";
|
||||||
|
|
||||||
import Rect from "../../util/rect";
|
import { Rect } from "../../util/rect";
|
||||||
|
|
||||||
export enum CascadeDirection {
|
export enum CascadeDirection {
|
||||||
NorthWest = 0,
|
NorthWest = 0,
|
||||||
|
@ -7,7 +7,7 @@ import { WindowsLayout } from ".";
|
|||||||
|
|
||||||
import { WindowState, EngineWindow } from "../window";
|
import { WindowState, EngineWindow } from "../window";
|
||||||
|
|
||||||
import Rect from "../../util/rect";
|
import { Rect } from "../../util/rect";
|
||||||
import { Controller } from "../../controller";
|
import { Controller } from "../../controller";
|
||||||
|
|
||||||
export default class FloatingLayout implements WindowsLayout {
|
export default class FloatingLayout implements WindowsLayout {
|
||||||
|
@ -9,8 +9,7 @@ import { Engine } from "..";
|
|||||||
import { Controller } from "../../controller";
|
import { Controller } from "../../controller";
|
||||||
import { Action } from "../../controller/action";
|
import { Action } from "../../controller/action";
|
||||||
|
|
||||||
import Rect from "../../util/rect";
|
import { Rect, RectDelta } from "../../util/rect";
|
||||||
import RectDelta from "../../util/rectdelta";
|
|
||||||
import Config from "../../config";
|
import Config from "../../config";
|
||||||
|
|
||||||
export interface WindowsLayoutClass {
|
export interface WindowsLayoutClass {
|
||||||
|
@ -8,8 +8,7 @@ import LayoutUtils from "./layout_utils";
|
|||||||
import { EngineWindow } from "../window";
|
import { EngineWindow } from "../window";
|
||||||
|
|
||||||
import Config from "../../config";
|
import Config from "../../config";
|
||||||
import Rect from "../../util/rect";
|
import { Rect, RectDelta } from "../../util/rect";
|
||||||
import RectDelta from "../../util/rectdelta";
|
|
||||||
|
|
||||||
export interface ILayoutPart {
|
export interface ILayoutPart {
|
||||||
adjust(
|
adjust(
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
import { clip } from "../../util/func";
|
import { clip } from "../../util/func";
|
||||||
import Rect from "../../util/rect";
|
import { Rect, RectDelta } from "../../util/rect";
|
||||||
import RectDelta from "../../util/rectdelta";
|
|
||||||
|
|
||||||
export default class LayoutUtils {
|
export default class LayoutUtils {
|
||||||
/**
|
/**
|
||||||
|
@ -17,7 +17,7 @@ import {
|
|||||||
FocusUpperWindow,
|
FocusUpperWindow,
|
||||||
} from "../../controller/action";
|
} from "../../controller/action";
|
||||||
|
|
||||||
import Rect from "../../util/rect";
|
import { Rect } from "../../util/rect";
|
||||||
import Config from "../../config";
|
import Config from "../../config";
|
||||||
import { Controller } from "../../controller";
|
import { Controller } from "../../controller";
|
||||||
import { Engine } from "..";
|
import { Engine } from "..";
|
||||||
|
@ -8,8 +8,7 @@ import { WindowsLayout } from ".";
|
|||||||
import { WindowState, EngineWindow } from "../window";
|
import { WindowState, EngineWindow } from "../window";
|
||||||
|
|
||||||
import { clip } from "../../util/func";
|
import { clip } from "../../util/func";
|
||||||
import Rect from "../../util/rect";
|
import { Rect, RectDelta } from "../../util/rect";
|
||||||
import RectDelta from "../../util/rectdelta";
|
|
||||||
import Config from "../../config";
|
import Config from "../../config";
|
||||||
import { Controller } from "../../controller";
|
import { Controller } from "../../controller";
|
||||||
|
|
||||||
|
@ -9,8 +9,7 @@ import { WindowsLayout } from ".";
|
|||||||
|
|
||||||
import { WindowState, EngineWindow } from "../window";
|
import { WindowState, EngineWindow } from "../window";
|
||||||
|
|
||||||
import Rect from "../../util/rect";
|
import { Rect, RectDelta } from "../../util/rect";
|
||||||
import RectDelta from "../../util/rectdelta";
|
|
||||||
import Config from "../../config";
|
import Config from "../../config";
|
||||||
import { Controller } from "../../controller";
|
import { Controller } from "../../controller";
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ import {
|
|||||||
IncreaseMasterAreaWindowCount,
|
IncreaseMasterAreaWindowCount,
|
||||||
} from "../../controller/action";
|
} from "../../controller/action";
|
||||||
|
|
||||||
import Rect from "../../util/rect";
|
import { Rect } from "../../util/rect";
|
||||||
import { Controller } from "../../controller";
|
import { Controller } from "../../controller";
|
||||||
import { Engine } from "..";
|
import { Engine } from "..";
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ import {
|
|||||||
IncreaseMasterAreaWindowCount,
|
IncreaseMasterAreaWindowCount,
|
||||||
} from "../../controller/action";
|
} from "../../controller/action";
|
||||||
|
|
||||||
import Rect from "../../util/rect";
|
import { Rect } from "../../util/rect";
|
||||||
import { Controller } from "../../controller";
|
import { Controller } from "../../controller";
|
||||||
import { Engine } from "..";
|
import { Engine } from "..";
|
||||||
|
|
||||||
|
@ -17,8 +17,7 @@ import {
|
|||||||
} from "../../controller/action";
|
} from "../../controller/action";
|
||||||
|
|
||||||
import { partitionArrayBySizes, clip, slide } from "../../util/func";
|
import { partitionArrayBySizes, clip, slide } from "../../util/func";
|
||||||
import Rect from "../../util/rect";
|
import { Rect, RectDelta } from "../../util/rect";
|
||||||
import RectDelta from "../../util/rectdelta";
|
|
||||||
import Config from "../../config";
|
import Config from "../../config";
|
||||||
import { Controller } from "../../controller";
|
import { Controller } from "../../controller";
|
||||||
import { Engine } from "..";
|
import { Engine } from "..";
|
||||||
|
@ -23,8 +23,7 @@ import {
|
|||||||
} from "../../controller/action";
|
} from "../../controller/action";
|
||||||
|
|
||||||
import { clip, slide } from "../../util/func";
|
import { clip, slide } from "../../util/func";
|
||||||
import Rect from "../../util/rect";
|
import { Rect, RectDelta } from "../../util/rect";
|
||||||
import RectDelta from "../../util/rectdelta";
|
|
||||||
import Config from "../../config";
|
import Config from "../../config";
|
||||||
import { Controller } from "../../controller";
|
import { Controller } from "../../controller";
|
||||||
import { Engine } from "..";
|
import { Engine } from "..";
|
||||||
|
@ -8,8 +8,7 @@ import { DriverSurface } from "../driver/surface";
|
|||||||
|
|
||||||
import Config from "../config";
|
import Config from "../config";
|
||||||
import { Log } from "../util/log";
|
import { Log } from "../util/log";
|
||||||
import Rect from "../util/rect";
|
import { Rect, RectDelta } from "../util/rect";
|
||||||
import RectDelta from "../util/rectdelta";
|
|
||||||
|
|
||||||
export enum WindowState {
|
export enum WindowState {
|
||||||
/**
|
/**
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
export default class Rect {
|
export class Rect {
|
||||||
constructor(
|
constructor(
|
||||||
public x: number,
|
public x: number,
|
||||||
public y: number,
|
public y: number,
|
||||||
@ -94,3 +94,31 @@ export default class Rect {
|
|||||||
return "Rect(" + [this.x, this.y, this.width, this.height].join(", ") + ")";
|
return "Rect(" + [this.x, this.y, this.width, this.height].join(", ") + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes geometric changes of a rectangle, in terms of changes per edge.
|
||||||
|
* Outward changes are in positive, and inward changes are in negative.
|
||||||
|
*/
|
||||||
|
export class RectDelta {
|
||||||
|
/** Generate a delta that transforms basis to target. */
|
||||||
|
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}}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2018-2019 Eon S. Jeon <esjeon@hyunmu.am>
|
|
||||||
// SPDX-FileCopyrightText: 2021 Mikhail Zolotukhin <mail@genda.life>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
import Rect from "./rect";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Describes geometric changes of a rectangle, in terms of changes per edge.
|
|
||||||
* Outward changes are in positive, and inward changes are in negative.
|
|
||||||
*/
|
|
||||||
export default class RectDelta {
|
|
||||||
/** Generate a delta that transforms basis to target. */
|
|
||||||
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}}`;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user