lyb-pixi-js 1.12.16 → 1.12.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import { Container } from "pixi.js";
|
|
1
|
+
import type { Container } from "pixi.js";
|
|
2
2
|
/**
|
|
3
|
-
* @description
|
|
4
|
-
* @param items
|
|
5
|
-
* @param gap
|
|
6
|
-
* @param direction
|
|
7
|
-
* @param cols
|
|
8
|
-
* @
|
|
3
|
+
* @description 线性排列 PIXI.Container 元素(支持横向/纵向排列,多列布局、固定或自定义间隔)
|
|
4
|
+
* @param items 需要排列的容器数组
|
|
5
|
+
* @param gap 间隔,可为固定值或数组(数组长度必须等于 items.length - 1)
|
|
6
|
+
* @param direction 排列方向:"x" 横向排列,"y" 纵向排列
|
|
7
|
+
* @param cols 每行(或每列)最多的元素个数,默认为 Infinity(单行/单列)
|
|
8
|
+
* @example
|
|
9
|
+
* // 横向排列
|
|
10
|
+
* LibPixiArrangeLinear([sprite1, sprite2, sprite3], 10, "x");
|
|
11
|
+
* // 纵向排列
|
|
12
|
+
* LibPixiArrangeLinear([sprite1, sprite2, sprite3], 20, "y");
|
|
13
|
+
* // 两列布局
|
|
14
|
+
* LibPixiArrangeLinear([sprite1, sprite2, sprite3, sprite4], 10, "x", 2);
|
|
9
15
|
*/
|
|
10
16
|
export declare const LibPixiArrangeLinear: (items: Container[], gap: number | number[], direction?: "x" | "y", cols?: number) => void;
|
|
@@ -1,44 +1,61 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @description
|
|
3
|
-
* @param items
|
|
4
|
-
* @param gap
|
|
5
|
-
* @param direction
|
|
6
|
-
* @param cols
|
|
7
|
-
* @
|
|
2
|
+
* @description 线性排列 PIXI.Container 元素(支持横向/纵向排列,多列布局、固定或自定义间隔)
|
|
3
|
+
* @param items 需要排列的容器数组
|
|
4
|
+
* @param gap 间隔,可为固定值或数组(数组长度必须等于 items.length - 1)
|
|
5
|
+
* @param direction 排列方向:"x" 横向排列,"y" 纵向排列
|
|
6
|
+
* @param cols 每行(或每列)最多的元素个数,默认为 Infinity(单行/单列)
|
|
7
|
+
* @example
|
|
8
|
+
* // 横向排列
|
|
9
|
+
* LibPixiArrangeLinear([sprite1, sprite2, sprite3], 10, "x");
|
|
10
|
+
* // 纵向排列
|
|
11
|
+
* LibPixiArrangeLinear([sprite1, sprite2, sprite3], 20, "y");
|
|
12
|
+
* // 两列布局
|
|
13
|
+
* LibPixiArrangeLinear([sprite1, sprite2, sprite3, sprite4], 10, "x", 2);
|
|
8
14
|
*/
|
|
9
15
|
export const LibPixiArrangeLinear = (items, gap, direction = "x", cols = Infinity) => {
|
|
16
|
+
// 验证 gap 数组长度是否正确
|
|
10
17
|
if (Array.isArray(gap)) {
|
|
11
18
|
if (gap.length !== items.length - 1) {
|
|
12
19
|
console.error(new Error("间隔的数组长度只能等于元素数组长度-1"));
|
|
13
20
|
return;
|
|
14
21
|
}
|
|
15
22
|
}
|
|
16
|
-
let lastRowMax = 0; //
|
|
17
|
-
let rowOffset = 0; //
|
|
23
|
+
let lastRowMax = 0; // 当前行(或列)的最大高度(或宽度),用于多行/多列换行时计算偏移
|
|
24
|
+
let rowOffset = 0; // 累计偏移量,控制换行后的整体偏移位置
|
|
18
25
|
items.forEach((item, index) => {
|
|
19
26
|
var _a, _b;
|
|
20
|
-
const row = Math.floor(index / cols);
|
|
21
|
-
const col = index % cols;
|
|
27
|
+
const row = Math.floor(index / cols); // 当前行号
|
|
28
|
+
const col = index % cols; // 当前列号
|
|
22
29
|
if (direction === "x") {
|
|
30
|
+
//间隔
|
|
23
31
|
const gapValue = Array.isArray(gap) ? (_a = gap[index - 1]) !== null && _a !== void 0 ? _a : 0 : gap;
|
|
32
|
+
//在每行第一列重置列偏移量
|
|
24
33
|
if (col === 0 && row > 0) {
|
|
25
34
|
rowOffset += lastRowMax + gapValue;
|
|
26
35
|
lastRowMax = 0;
|
|
27
36
|
}
|
|
37
|
+
// 横向位置 = 前一个元素的右侧 + 间隔;首列则从 0 开始
|
|
28
38
|
item.x =
|
|
29
39
|
col === 0 ? 0 : items[index - 1].x + items[index - 1].width + gapValue;
|
|
30
|
-
|
|
40
|
+
// 纵向位置 = 当前累计的行偏移
|
|
41
|
+
rowOffset && (item.y = rowOffset);
|
|
42
|
+
// 更新当前行的最大高度
|
|
31
43
|
lastRowMax = Math.max(lastRowMax, item.height);
|
|
32
44
|
}
|
|
33
45
|
else {
|
|
46
|
+
//间隔
|
|
34
47
|
const gapValue = Array.isArray(gap) ? (_b = gap[index - 1]) !== null && _b !== void 0 ? _b : 0 : gap;
|
|
48
|
+
//在每列第一行重置行偏移
|
|
35
49
|
if (col === 0 && row > 0) {
|
|
36
50
|
rowOffset += lastRowMax + gapValue;
|
|
37
51
|
lastRowMax = 0;
|
|
38
52
|
}
|
|
53
|
+
// 纵向位置 = 首列则从 0 开始,其余从前一个元素的y坐标 + 高度 + 间隔;
|
|
39
54
|
item.y =
|
|
40
55
|
col === 0 ? 0 : items[index - 1].y + items[index - 1].height + gapValue;
|
|
41
|
-
|
|
56
|
+
// 横向位置 = 当前累计的列偏移
|
|
57
|
+
rowOffset && (item.x = rowOffset);
|
|
58
|
+
// 更新当前列的最大宽度
|
|
42
59
|
lastRowMax = Math.max(lastRowMax, item.width);
|
|
43
60
|
}
|
|
44
61
|
});
|
|
@@ -31,7 +31,7 @@ export declare class LibPixiDialog extends LibPixiBaseContainer {
|
|
|
31
31
|
/** @description 设置弹窗内容 */
|
|
32
32
|
setDialogContent(content: Container): void;
|
|
33
33
|
/** @description 重绘弹窗 */
|
|
34
|
-
redraw(w
|
|
34
|
+
redraw(w?: number, h?: number): void;
|
|
35
35
|
/** @description 关闭 */
|
|
36
36
|
close(): Promise<void>;
|
|
37
37
|
}
|
|
@@ -46,9 +46,7 @@ export class LibPixiDialog extends LibPixiBaseContainer {
|
|
|
46
46
|
/** @description 设置弹窗内容 */
|
|
47
47
|
setDialogContent(content) {
|
|
48
48
|
this._dialogContainer.addChild(content);
|
|
49
|
-
|
|
50
|
-
const h = this._dialogContainer.height / 2;
|
|
51
|
-
this._dialogContainer.pivot.set(w, h);
|
|
49
|
+
this.redraw();
|
|
52
50
|
this._dialogContainer.scale.set(0);
|
|
53
51
|
this._dialogContainer.alpha = 0;
|
|
54
52
|
gsap.to(this._maskUI, {
|
|
@@ -61,7 +59,10 @@ export class LibPixiDialog extends LibPixiBaseContainer {
|
|
|
61
59
|
});
|
|
62
60
|
}
|
|
63
61
|
/** @description 重绘弹窗 */
|
|
64
|
-
redraw(w, h) {
|
|
62
|
+
redraw(w = window.innerWidth, h = window.innerHeight) {
|
|
63
|
+
const dialogW = this._dialogContainer.width / 2;
|
|
64
|
+
const dialogH = this._dialogContainer.height / 2;
|
|
65
|
+
this._dialogContainer.pivot.set(dialogW, dialogH);
|
|
65
66
|
const halfW = 1920 / 2;
|
|
66
67
|
const halfH = 1080 / 2;
|
|
67
68
|
if (w > h) {
|
package/lyb-pixi.js
CHANGED
|
@@ -55129,7 +55129,7 @@ void main(void){
|
|
|
55129
55129
|
lastRowMax = 0;
|
|
55130
55130
|
}
|
|
55131
55131
|
item.x = col === 0 ? 0 : items[index - 1].x + items[index - 1].width + gapValue;
|
|
55132
|
-
item.y = rowOffset;
|
|
55132
|
+
rowOffset && (item.y = rowOffset);
|
|
55133
55133
|
lastRowMax = Math.max(lastRowMax, item.height);
|
|
55134
55134
|
} else {
|
|
55135
55135
|
const gapValue = Array.isArray(gap) ? gap[index - 1] ?? 0 : gap;
|
|
@@ -55138,7 +55138,7 @@ void main(void){
|
|
|
55138
55138
|
lastRowMax = 0;
|
|
55139
55139
|
}
|
|
55140
55140
|
item.y = col === 0 ? 0 : items[index - 1].y + items[index - 1].height + gapValue;
|
|
55141
|
-
item.x = rowOffset;
|
|
55141
|
+
rowOffset && (item.x = rowOffset);
|
|
55142
55142
|
lastRowMax = Math.max(lastRowMax, item.width);
|
|
55143
55143
|
}
|
|
55144
55144
|
});
|