mirror of
https://github.com/Bismuth-Forge/bismuth.git
synced 2024-11-05 00:54:24 +03:00
rotatable HalfSplitLayoutPart
This commit is contained in:
parent
87bf403f6d
commit
eadea76c57
@ -17,14 +17,34 @@ class FillLayoutPart implements ILayoutPart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class HalfSplitLayoutPart<L extends ILayoutPart, R extends ILayoutPart> implements ILayoutPart {
|
class HalfSplitLayoutPart<L extends ILayoutPart, R extends ILayoutPart> implements ILayoutPart {
|
||||||
|
/** the rotation angle for this part.
|
||||||
|
*
|
||||||
|
* | angle | direction | primary |
|
||||||
|
* | ----- | ---------- | ------- |
|
||||||
|
* | 0 | horizontal | left |
|
||||||
|
* | 90 | vertical | top |
|
||||||
|
* | 180 | horizontal | right |
|
||||||
|
* | 270 | vertical | bottom |
|
||||||
|
*/
|
||||||
|
public angle: 0 | 90 | 180 | 270;
|
||||||
|
|
||||||
public gap: number;
|
public gap: number;
|
||||||
public primarySize: number;
|
public primarySize: number;
|
||||||
public ratio: number;
|
public ratio: number;
|
||||||
|
|
||||||
|
private get horizontal(): boolean {
|
||||||
|
return this.angle === 0 || this.angle === 180;
|
||||||
|
}
|
||||||
|
|
||||||
|
private get reversed(): boolean {
|
||||||
|
return this.angle === 180 || this.angle === 270;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public primary: L,
|
public primary: L,
|
||||||
public secondary: R,
|
public secondary: R,
|
||||||
) {
|
) {
|
||||||
|
this.angle = 0;
|
||||||
this.gap = 0;
|
this.gap = 0;
|
||||||
this.primarySize = 1;
|
this.primarySize = 1;
|
||||||
this.ratio = 0.5;
|
this.ratio = 0.5;
|
||||||
@ -49,12 +69,14 @@ class HalfSplitLayoutPart<L extends ILayoutPart, R extends ILayoutPart> implemen
|
|||||||
|
|
||||||
this.ratio = LayoutUtils.adjustAreaHalfWeights(
|
this.ratio = LayoutUtils.adjustAreaHalfWeights(
|
||||||
area,
|
area,
|
||||||
this.ratio,
|
(this.reversed) ? 1 - this.ratio: this.ratio,
|
||||||
this.gap,
|
this.gap,
|
||||||
targetIndex,
|
targetIndex,
|
||||||
delta,
|
delta,
|
||||||
true,
|
this.horizontal,
|
||||||
);
|
);
|
||||||
|
if (this.reversed)
|
||||||
|
this.ratio = 1 - this.ratio;
|
||||||
|
|
||||||
if (targetIndex === /* primary */ 0) {
|
if (targetIndex === /* primary */ 0) {
|
||||||
this.primary.adjust(area, tiles.slice(0, this.primarySize), basis, delta);
|
this.primary.adjust(area, tiles.slice(0, this.primarySize), basis, delta);
|
||||||
@ -73,7 +95,8 @@ class HalfSplitLayoutPart<L extends ILayoutPart, R extends ILayoutPart> implemen
|
|||||||
return this.secondary.apply(area, tiles);
|
return this.secondary.apply(area, tiles);
|
||||||
} else {
|
} else {
|
||||||
/* both parts */
|
/* both parts */
|
||||||
const [primaryArea, secondaryArea] = LayoutUtils.splitAreaHalfWeighted(area, this.ratio, this.gap, true);
|
const ratio = (this.reversed) ? 1 - this.ratio: this.ratio;
|
||||||
|
const [primaryArea, secondaryArea] = LayoutUtils.splitAreaHalfWeighted(area, ratio, this.gap, this.horizontal);
|
||||||
const primaryResult = this.primary.apply(primaryArea, tiles.slice(0, this.primarySize));
|
const primaryResult = this.primary.apply(primaryArea, tiles.slice(0, this.primarySize));
|
||||||
const secondaryResult = this.secondary.apply(secondaryArea, tiles.slice(this.primarySize));
|
const secondaryResult = this.secondary.apply(secondaryArea, tiles.slice(this.primarySize));
|
||||||
return primaryResult.concat(secondaryResult);
|
return primaryResult.concat(secondaryResult);
|
||||||
|
Loading…
Reference in New Issue
Block a user