lyb-pixi-js 1.13.0 → 1.13.2
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.
- package/Components/Base/LibPixiBorderRect.d.ts +39 -0
- package/Components/Base/LibPixiBorderRect.js +29 -0
- package/Components/Base/index.d.ts +1 -0
- package/Components/Base/index.js +1 -0
- package/Components/Custom/LibPixiFlex.d.ts +105 -0
- package/Components/Custom/LibPixiFlex.js +313 -0
- package/Components/Custom/LibPixiGrid.d.ts +97 -0
- package/Components/Custom/LibPixiGrid.js +260 -0
- package/Components/Custom/LibPixiProgressBar.d.ts +63 -0
- package/Components/Custom/LibPixiProgressBar.js +103 -0
- package/Components/Custom/LibPixiScrollContainerY.d.ts +81 -47
- package/Components/Custom/LibPixiScrollContainerY.js +127 -73
- package/Components/Custom/index.d.ts +3 -2
- package/Components/Custom/index.js +3 -2
- package/README.md +140 -39
- package/index.d.ts +1 -11
- package/index.js +1 -11
- package/legacy.d.ts +11 -0
- package/legacy.js +11 -0
- package/package.json +4 -2
- package/Components/Custom/LibPixiGridColumnLayout.d.ts +0 -35
- package/Components/Custom/LibPixiGridColumnLayout.js +0 -40
- package/Components/Custom/LibPixiGridRowLayout.d.ts +0 -31
- package/Components/Custom/LibPixiGridRowLayout.js +0 -40
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Graphics } from "pixi.js";
|
|
2
|
+
/** @description 矩形描边参数 */
|
|
3
|
+
export interface LibPixiBorderRectParams {
|
|
4
|
+
/** 宽度 */
|
|
5
|
+
width: number;
|
|
6
|
+
/** 高度 */
|
|
7
|
+
height: number;
|
|
8
|
+
/** 圆角 */
|
|
9
|
+
radius?: number;
|
|
10
|
+
/** 描边宽度 */
|
|
11
|
+
lineWidth?: number;
|
|
12
|
+
/** 描边颜色 */
|
|
13
|
+
color?: string | number;
|
|
14
|
+
/** 描边透明度 */
|
|
15
|
+
alpha?: number;
|
|
16
|
+
/** 内缩偏移 */
|
|
17
|
+
inset?: number;
|
|
18
|
+
}
|
|
19
|
+
/** @description Pixi矩形描边 */
|
|
20
|
+
export declare class LibPixiBorderRect extends Graphics {
|
|
21
|
+
/** 宽度 */
|
|
22
|
+
private readonly _widthValue;
|
|
23
|
+
/** 高度 */
|
|
24
|
+
private readonly _heightValue;
|
|
25
|
+
/** 圆角 */
|
|
26
|
+
private readonly _radius;
|
|
27
|
+
/** 描边宽度 */
|
|
28
|
+
private readonly _lineWidth;
|
|
29
|
+
/** 描边颜色 */
|
|
30
|
+
private readonly _color;
|
|
31
|
+
/** 描边透明度 */
|
|
32
|
+
private readonly _alphaValue;
|
|
33
|
+
/** 内缩偏移 */
|
|
34
|
+
private readonly _inset;
|
|
35
|
+
/** @description 创建矩形描边 */
|
|
36
|
+
constructor(params: LibPixiBorderRectParams);
|
|
37
|
+
/** @description 重绘描边 */
|
|
38
|
+
private _drawBorder;
|
|
39
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Graphics } from "pixi.js";
|
|
2
|
+
/** @description Pixi矩形描边 */
|
|
3
|
+
export class LibPixiBorderRect extends Graphics {
|
|
4
|
+
/** @description 创建矩形描边 */
|
|
5
|
+
constructor(params) {
|
|
6
|
+
var _a, _b, _c, _d, _e;
|
|
7
|
+
super();
|
|
8
|
+
this._widthValue = params.width;
|
|
9
|
+
this._heightValue = params.height;
|
|
10
|
+
this._radius = (_a = params.radius) !== null && _a !== void 0 ? _a : 0;
|
|
11
|
+
this._lineWidth = (_b = params.lineWidth) !== null && _b !== void 0 ? _b : 1;
|
|
12
|
+
this._color = (_c = params.color) !== null && _c !== void 0 ? _c : "#ffffff";
|
|
13
|
+
this._alphaValue = (_d = params.alpha) !== null && _d !== void 0 ? _d : 1;
|
|
14
|
+
this._inset = (_e = params.inset) !== null && _e !== void 0 ? _e : 0;
|
|
15
|
+
this._drawBorder();
|
|
16
|
+
}
|
|
17
|
+
/** @description 重绘描边 */
|
|
18
|
+
_drawBorder() {
|
|
19
|
+
const drawWidth = Math.max(0, this._widthValue - this._inset * 2);
|
|
20
|
+
const drawHeight = Math.max(0, this._heightValue - this._inset * 2);
|
|
21
|
+
this.clear();
|
|
22
|
+
this.lineStyle(this._lineWidth, this._color, this._alphaValue);
|
|
23
|
+
if (this._radius > 0) {
|
|
24
|
+
this.drawRoundedRect(this._inset, this._inset, drawWidth, drawHeight, this._radius);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
this.drawRect(this._inset, this._inset, drawWidth, drawHeight);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./LibPixiArc.js";
|
|
2
2
|
export * from "./LibPixiBit.js";
|
|
3
3
|
export * from "./LibPixiBitText.js";
|
|
4
|
+
export * from "./LibPixiBorderRect.js";
|
|
4
5
|
export * from "./LibPixiCircular.js";
|
|
5
6
|
export * from "./LibPixiContainer.js";
|
|
6
7
|
export * from "./LibPixiHtmlText.js";
|
package/Components/Base/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./LibPixiArc.js";
|
|
2
2
|
export * from "./LibPixiBit.js";
|
|
3
3
|
export * from "./LibPixiBitText.js";
|
|
4
|
+
export * from "./LibPixiBorderRect.js";
|
|
4
5
|
export * from "./LibPixiCircular.js";
|
|
5
6
|
export * from "./LibPixiContainer.js";
|
|
6
7
|
export * from "./LibPixiHtmlText.js";
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Container, Sprite } from "pixi.js";
|
|
2
|
+
/** @description 布局方向 */
|
|
3
|
+
export type LibPixiFlexDirection = "row" | "column";
|
|
4
|
+
/** @description 列推进方向 */
|
|
5
|
+
export type LibPixiFlexColumnDirection = "ltr" | "rtl";
|
|
6
|
+
/** @description 主轴对齐方式 */
|
|
7
|
+
export type LibPixiFlexJustifyContent = "start" | "space-between";
|
|
8
|
+
/** @description 交叉轴对齐方式 */
|
|
9
|
+
export type LibPixiFlexAlignItems = "start" | "center";
|
|
10
|
+
/** @description 布局配置 */
|
|
11
|
+
export interface LibPixiFlexOptions {
|
|
12
|
+
/** 布局方向 */
|
|
13
|
+
direction?: LibPixiFlexDirection;
|
|
14
|
+
/** 统一内边距 */
|
|
15
|
+
padding?: number;
|
|
16
|
+
/** 横向内边距 */
|
|
17
|
+
paddingX?: number;
|
|
18
|
+
/** 纵向内边距 */
|
|
19
|
+
paddingY?: number;
|
|
20
|
+
/** 上内边距 */
|
|
21
|
+
paddingTop?: number;
|
|
22
|
+
/** 右内边距 */
|
|
23
|
+
paddingRight?: number;
|
|
24
|
+
/** 下内边距 */
|
|
25
|
+
paddingBottom?: number;
|
|
26
|
+
/** 左内边距 */
|
|
27
|
+
paddingLeft?: number;
|
|
28
|
+
/** 滚动可视高度 */
|
|
29
|
+
scrollHeight?: number;
|
|
30
|
+
/** 是否显示测试背景 */
|
|
31
|
+
showBg?: boolean;
|
|
32
|
+
/** 测试背景颜色 */
|
|
33
|
+
bgColor?: string;
|
|
34
|
+
/** 主轴对齐方式 */
|
|
35
|
+
justifyContent?: LibPixiFlexJustifyContent;
|
|
36
|
+
/** 交叉轴对齐方式 */
|
|
37
|
+
alignItems?: LibPixiFlexAlignItems;
|
|
38
|
+
/** 子项间距 */
|
|
39
|
+
gap?: number;
|
|
40
|
+
/** 行间距 */
|
|
41
|
+
rowGap?: number;
|
|
42
|
+
/** 列间距 */
|
|
43
|
+
columnGap?: number;
|
|
44
|
+
/** 最大宽度 */
|
|
45
|
+
maxWidth?: number;
|
|
46
|
+
/** 最大高度 */
|
|
47
|
+
maxHeight?: number;
|
|
48
|
+
/** 列推进方向 */
|
|
49
|
+
columnDirection?: LibPixiFlexColumnDirection;
|
|
50
|
+
}
|
|
51
|
+
/** @description Pixi弹性布局骨架类 */
|
|
52
|
+
export declare class LibPixiFlex extends Container {
|
|
53
|
+
/** 布局子项 */
|
|
54
|
+
private readonly _items;
|
|
55
|
+
/** 布局内容容器 */
|
|
56
|
+
private readonly _content;
|
|
57
|
+
/** 测试背景 */
|
|
58
|
+
private readonly _bg;
|
|
59
|
+
/** 滚动容器 */
|
|
60
|
+
private readonly _scrollContainer?;
|
|
61
|
+
/** 布局配置 */
|
|
62
|
+
private readonly _options;
|
|
63
|
+
/** @description 创建Pixi弹性布局骨架类 */
|
|
64
|
+
constructor(items: Container[], options?: LibPixiFlexOptions);
|
|
65
|
+
/** @description 创建Pixi弹性布局骨架类 */
|
|
66
|
+
constructor(items: Sprite[], options?: LibPixiFlexOptions);
|
|
67
|
+
/** @description 执行布局 */
|
|
68
|
+
layout(): this;
|
|
69
|
+
/** @description 统一修正子项基准点 */
|
|
70
|
+
private _normalizeItemsPivot;
|
|
71
|
+
/** @description 重绘测试背景 */
|
|
72
|
+
private _renderBg;
|
|
73
|
+
/** @description 更新滚动容器尺寸 */
|
|
74
|
+
private _updateScrollContainer;
|
|
75
|
+
/** @description 获取背景可视区域包围盒 */
|
|
76
|
+
private _getBgViewportBounds;
|
|
77
|
+
/** @description 获取可视区域包围盒 */
|
|
78
|
+
private _getViewportBounds;
|
|
79
|
+
/** @description 获取可视宽度 */
|
|
80
|
+
private _getViewportWidth;
|
|
81
|
+
/** @description 获取内容包围盒 */
|
|
82
|
+
private _getContentBounds;
|
|
83
|
+
/** @description 执行横向布局 */
|
|
84
|
+
private _layoutRow;
|
|
85
|
+
/** @description 执行纵向布局 */
|
|
86
|
+
private _layoutColumn;
|
|
87
|
+
/** @description 获取横向布局主轴间距 */
|
|
88
|
+
private _getRowGap;
|
|
89
|
+
/** @description 获取纵向布局主轴间距 */
|
|
90
|
+
private _getColumnGap;
|
|
91
|
+
/** @description 获取布局内边距 */
|
|
92
|
+
private _getPadding;
|
|
93
|
+
/** @description 获取可用内容宽度 */
|
|
94
|
+
private _getContentWidth;
|
|
95
|
+
/** @description 获取可用内容高度 */
|
|
96
|
+
private _getContentHeight;
|
|
97
|
+
/** @description 获取横向布局子项纵坐标 */
|
|
98
|
+
private _getRowItemY;
|
|
99
|
+
/** @description 获取纵向布局子项横坐标 */
|
|
100
|
+
private _getColumnItemX;
|
|
101
|
+
/** @description 创建横向行分组 */
|
|
102
|
+
private _createRowGroups;
|
|
103
|
+
/** @description 创建纵向列分组 */
|
|
104
|
+
private _createColumnGroups;
|
|
105
|
+
}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { Container, Graphics } from "pixi.js";
|
|
2
|
+
import { LibPixiScrollContainerY } from "./LibPixiScrollContainerY.js";
|
|
3
|
+
/** @description Pixi弹性布局骨架类 */
|
|
4
|
+
export class LibPixiFlex extends Container {
|
|
5
|
+
/** @description 创建Pixi弹性布局骨架类 */
|
|
6
|
+
constructor(items, options = {}) {
|
|
7
|
+
super();
|
|
8
|
+
this._items = items;
|
|
9
|
+
this._options = options;
|
|
10
|
+
this._content = new Container();
|
|
11
|
+
this._bg = new Graphics();
|
|
12
|
+
this._normalizeItemsPivot();
|
|
13
|
+
this.addChild(this._bg);
|
|
14
|
+
if (this._items.length > 0) {
|
|
15
|
+
this._content.addChild(...this._items);
|
|
16
|
+
}
|
|
17
|
+
if (this._options.scrollHeight) {
|
|
18
|
+
this._scrollContainer = new LibPixiScrollContainerY({
|
|
19
|
+
width: 1,
|
|
20
|
+
height: this._options.scrollHeight,
|
|
21
|
+
scrollContent: this._content,
|
|
22
|
+
scrollbarRgiht: LibPixiScrollContainerY.scrollbarStyle.scrollbarRgiht,
|
|
23
|
+
scrollbarWidth: LibPixiScrollContainerY.scrollbarStyle.scrollbarWidth,
|
|
24
|
+
scrollbarColor: LibPixiScrollContainerY.scrollbarStyle.scrollbarColor,
|
|
25
|
+
});
|
|
26
|
+
this.addChild(this._scrollContainer);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
this.addChild(this._content);
|
|
30
|
+
}
|
|
31
|
+
this.layout();
|
|
32
|
+
}
|
|
33
|
+
/** @description 执行布局 */
|
|
34
|
+
layout() {
|
|
35
|
+
var _a;
|
|
36
|
+
const direction = (_a = this._options.direction) !== null && _a !== void 0 ? _a : "row";
|
|
37
|
+
if (direction === "column") {
|
|
38
|
+
this._layoutColumn();
|
|
39
|
+
this._updateScrollContainer();
|
|
40
|
+
this._renderBg();
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
this._layoutRow();
|
|
44
|
+
this._updateScrollContainer();
|
|
45
|
+
this._renderBg();
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
/** @description 统一修正子项基准点 */
|
|
49
|
+
_normalizeItemsPivot() {
|
|
50
|
+
this._items.forEach((item) => {
|
|
51
|
+
const { x, y } = item.getLocalBounds();
|
|
52
|
+
item.pivot.x = x;
|
|
53
|
+
item.pivot.y = y;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/** @description 重绘测试背景 */
|
|
57
|
+
_renderBg() {
|
|
58
|
+
var _a;
|
|
59
|
+
this._bg.clear();
|
|
60
|
+
if (this._options.showBg === false) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const { width, height } = this._getBgViewportBounds();
|
|
64
|
+
if (width <= 0 || height <= 0) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
this._bg.beginFill((_a = this._options.bgColor) !== null && _a !== void 0 ? _a : "#000000");
|
|
68
|
+
this._bg.drawRect(0, 0, width, height);
|
|
69
|
+
this._bg.endFill();
|
|
70
|
+
}
|
|
71
|
+
/** @description 更新滚动容器尺寸 */
|
|
72
|
+
_updateScrollContainer() {
|
|
73
|
+
if (!this._scrollContainer || !this._options.scrollHeight) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const { width } = this._getContentBounds();
|
|
77
|
+
const viewportWidth = this._getViewportWidth(width);
|
|
78
|
+
this._scrollContainer.position.set(0, 0);
|
|
79
|
+
this._scrollContainer.setDimensions(viewportWidth, this._options.scrollHeight);
|
|
80
|
+
}
|
|
81
|
+
/** @description 获取背景可视区域包围盒 */
|
|
82
|
+
_getBgViewportBounds() {
|
|
83
|
+
if (this._options.scrollHeight !== undefined) {
|
|
84
|
+
const { width } = this._getContentBounds();
|
|
85
|
+
return {
|
|
86
|
+
width: this._getViewportWidth(width),
|
|
87
|
+
height: this._options.scrollHeight,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return this._getViewportBounds();
|
|
91
|
+
}
|
|
92
|
+
/** @description 获取可视区域包围盒 */
|
|
93
|
+
_getViewportBounds() {
|
|
94
|
+
if (this._scrollContainer) {
|
|
95
|
+
return {
|
|
96
|
+
width: this._scrollContainer.width,
|
|
97
|
+
height: this._scrollContainer.height,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const { width, height } = this._getContentBounds();
|
|
101
|
+
return {
|
|
102
|
+
width,
|
|
103
|
+
height,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** @description 获取可视宽度 */
|
|
107
|
+
_getViewportWidth(contentWidth) {
|
|
108
|
+
if (this._options.maxWidth !== undefined) {
|
|
109
|
+
return this._options.maxWidth;
|
|
110
|
+
}
|
|
111
|
+
return contentWidth;
|
|
112
|
+
}
|
|
113
|
+
/** @description 获取内容包围盒 */
|
|
114
|
+
_getContentBounds() {
|
|
115
|
+
const { width, height } = this._content.getLocalBounds();
|
|
116
|
+
const padding = this._getPadding();
|
|
117
|
+
return {
|
|
118
|
+
width: width + padding.left + padding.right,
|
|
119
|
+
height: height + padding.top + padding.bottom,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/** @description 执行横向布局 */
|
|
123
|
+
_layoutRow() {
|
|
124
|
+
const rowGroups = this._createRowGroups();
|
|
125
|
+
const padding = this._getPadding();
|
|
126
|
+
let rowStartY = padding.top;
|
|
127
|
+
rowGroups.forEach((group, groupIndex) => {
|
|
128
|
+
var _a;
|
|
129
|
+
const currentGap = this._getRowGap(group);
|
|
130
|
+
let currentX = padding.left;
|
|
131
|
+
group.items.forEach((item, itemIndex) => {
|
|
132
|
+
item.x = currentX;
|
|
133
|
+
item.y = this._getRowItemY(rowStartY, group.crossSize, item.height);
|
|
134
|
+
if (itemIndex < group.items.length - 1) {
|
|
135
|
+
currentX += item.width + currentGap;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
if (groupIndex < rowGroups.length - 1) {
|
|
139
|
+
rowStartY += group.crossSize + ((_a = this._options.rowGap) !== null && _a !== void 0 ? _a : 0);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/** @description 执行纵向布局 */
|
|
144
|
+
_layoutColumn() {
|
|
145
|
+
var _a;
|
|
146
|
+
const columnGroups = this._createColumnGroups();
|
|
147
|
+
const columnDirection = (_a = this._options.columnDirection) !== null && _a !== void 0 ? _a : "ltr";
|
|
148
|
+
const padding = this._getPadding();
|
|
149
|
+
let columnStartX = padding.left;
|
|
150
|
+
columnGroups.forEach((group, groupIndex) => {
|
|
151
|
+
var _a, _b;
|
|
152
|
+
const currentGap = this._getColumnGap(group);
|
|
153
|
+
let currentY = padding.top;
|
|
154
|
+
if (groupIndex > 0) {
|
|
155
|
+
const prevGroup = columnGroups[groupIndex - 1];
|
|
156
|
+
if (columnDirection === "rtl") {
|
|
157
|
+
columnStartX -= ((_a = this._options.columnGap) !== null && _a !== void 0 ? _a : 0) + group.crossSize;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
columnStartX += prevGroup.crossSize + ((_b = this._options.columnGap) !== null && _b !== void 0 ? _b : 0);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
group.items.forEach((item, itemIndex) => {
|
|
164
|
+
item.x = this._getColumnItemX(columnStartX, group.crossSize, item.width);
|
|
165
|
+
item.y = currentY;
|
|
166
|
+
if (itemIndex < group.items.length - 1) {
|
|
167
|
+
currentY += item.height + currentGap;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
/** @description 获取横向布局主轴间距 */
|
|
173
|
+
_getRowGap(group) {
|
|
174
|
+
var _a, _b, _c, _d;
|
|
175
|
+
const justifyContent = (_a = this._options.justifyContent) !== null && _a !== void 0 ? _a : "start";
|
|
176
|
+
if (justifyContent !== "space-between") {
|
|
177
|
+
return (_b = this._options.gap) !== null && _b !== void 0 ? _b : 0;
|
|
178
|
+
}
|
|
179
|
+
if (group.items.length <= 1 || this._options.maxWidth === undefined) {
|
|
180
|
+
return (_c = this._options.gap) !== null && _c !== void 0 ? _c : 0;
|
|
181
|
+
}
|
|
182
|
+
const contentWidth = this._getContentWidth(this._options.maxWidth);
|
|
183
|
+
const remainWidth = contentWidth - group.mainSize;
|
|
184
|
+
return ((_d = this._options.gap) !== null && _d !== void 0 ? _d : 0) + remainWidth / (group.items.length - 1);
|
|
185
|
+
}
|
|
186
|
+
/** @description 获取纵向布局主轴间距 */
|
|
187
|
+
_getColumnGap(group) {
|
|
188
|
+
var _a, _b, _c, _d;
|
|
189
|
+
const justifyContent = (_a = this._options.justifyContent) !== null && _a !== void 0 ? _a : "start";
|
|
190
|
+
if (justifyContent !== "space-between") {
|
|
191
|
+
return (_b = this._options.gap) !== null && _b !== void 0 ? _b : 0;
|
|
192
|
+
}
|
|
193
|
+
if (group.items.length <= 1 || this._options.maxHeight === undefined) {
|
|
194
|
+
return (_c = this._options.gap) !== null && _c !== void 0 ? _c : 0;
|
|
195
|
+
}
|
|
196
|
+
const contentHeight = this._getContentHeight(this._options.maxHeight);
|
|
197
|
+
const remainHeight = contentHeight - group.mainSize;
|
|
198
|
+
return ((_d = this._options.gap) !== null && _d !== void 0 ? _d : 0) + remainHeight / (group.items.length - 1);
|
|
199
|
+
}
|
|
200
|
+
/** @description 获取布局内边距 */
|
|
201
|
+
_getPadding() {
|
|
202
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
203
|
+
const padding = (_a = this._options.padding) !== null && _a !== void 0 ? _a : 0;
|
|
204
|
+
const paddingX = (_b = this._options.paddingX) !== null && _b !== void 0 ? _b : padding;
|
|
205
|
+
const paddingY = (_c = this._options.paddingY) !== null && _c !== void 0 ? _c : padding;
|
|
206
|
+
return {
|
|
207
|
+
top: (_d = this._options.paddingTop) !== null && _d !== void 0 ? _d : paddingY,
|
|
208
|
+
right: (_e = this._options.paddingRight) !== null && _e !== void 0 ? _e : paddingX,
|
|
209
|
+
bottom: (_f = this._options.paddingBottom) !== null && _f !== void 0 ? _f : paddingY,
|
|
210
|
+
left: (_g = this._options.paddingLeft) !== null && _g !== void 0 ? _g : paddingX,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
/** @description 获取可用内容宽度 */
|
|
214
|
+
_getContentWidth(totalWidth) {
|
|
215
|
+
const padding = this._getPadding();
|
|
216
|
+
return Math.max(0, totalWidth - padding.left - padding.right);
|
|
217
|
+
}
|
|
218
|
+
/** @description 获取可用内容高度 */
|
|
219
|
+
_getContentHeight(totalHeight) {
|
|
220
|
+
const padding = this._getPadding();
|
|
221
|
+
return Math.max(0, totalHeight - padding.top - padding.bottom);
|
|
222
|
+
}
|
|
223
|
+
/** @description 获取横向布局子项纵坐标 */
|
|
224
|
+
_getRowItemY(rowStartY, rowHeight, itemHeight) {
|
|
225
|
+
var _a;
|
|
226
|
+
const alignItems = (_a = this._options.alignItems) !== null && _a !== void 0 ? _a : "start";
|
|
227
|
+
if (alignItems === "start") {
|
|
228
|
+
return rowStartY;
|
|
229
|
+
}
|
|
230
|
+
return rowStartY + (rowHeight - itemHeight) / 2;
|
|
231
|
+
}
|
|
232
|
+
/** @description 获取纵向布局子项横坐标 */
|
|
233
|
+
_getColumnItemX(columnStartX, columnWidth, itemWidth) {
|
|
234
|
+
var _a;
|
|
235
|
+
const alignItems = (_a = this._options.alignItems) !== null && _a !== void 0 ? _a : "start";
|
|
236
|
+
if (alignItems === "start") {
|
|
237
|
+
return columnStartX;
|
|
238
|
+
}
|
|
239
|
+
return columnStartX + (columnWidth - itemWidth) / 2;
|
|
240
|
+
}
|
|
241
|
+
/** @description 创建横向行分组 */
|
|
242
|
+
_createRowGroups() {
|
|
243
|
+
var _a;
|
|
244
|
+
const groups = [];
|
|
245
|
+
let currentItems = [];
|
|
246
|
+
let currentMainSize = 0;
|
|
247
|
+
let currentCrossSize = 0;
|
|
248
|
+
const maxWidth = this._options.maxWidth === undefined ? undefined : this._getContentWidth(this._options.maxWidth);
|
|
249
|
+
const gap = (_a = this._options.gap) !== null && _a !== void 0 ? _a : 0;
|
|
250
|
+
this._items.forEach((item) => {
|
|
251
|
+
const itemWidth = item.width;
|
|
252
|
+
const itemHeight = item.height;
|
|
253
|
+
const nextMainSize = currentItems.length === 0 ? itemWidth : currentMainSize + gap + itemWidth;
|
|
254
|
+
if (currentItems.length > 0 && maxWidth !== undefined && nextMainSize > maxWidth) {
|
|
255
|
+
groups.push({
|
|
256
|
+
items: currentItems,
|
|
257
|
+
mainSize: currentMainSize,
|
|
258
|
+
crossSize: currentCrossSize,
|
|
259
|
+
});
|
|
260
|
+
currentItems = [];
|
|
261
|
+
currentMainSize = 0;
|
|
262
|
+
currentCrossSize = 0;
|
|
263
|
+
}
|
|
264
|
+
currentItems.push(item);
|
|
265
|
+
currentMainSize = currentItems.length === 1 ? itemWidth : currentMainSize + gap + itemWidth;
|
|
266
|
+
currentCrossSize = Math.max(currentCrossSize, itemHeight);
|
|
267
|
+
});
|
|
268
|
+
if (currentItems.length > 0) {
|
|
269
|
+
groups.push({
|
|
270
|
+
items: currentItems,
|
|
271
|
+
mainSize: currentMainSize,
|
|
272
|
+
crossSize: currentCrossSize,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
return groups;
|
|
276
|
+
}
|
|
277
|
+
/** @description 创建纵向列分组 */
|
|
278
|
+
_createColumnGroups() {
|
|
279
|
+
var _a;
|
|
280
|
+
const groups = [];
|
|
281
|
+
let currentItems = [];
|
|
282
|
+
let currentMainSize = 0;
|
|
283
|
+
let currentCrossSize = 0;
|
|
284
|
+
const maxHeight = this._options.maxHeight === undefined ? undefined : this._getContentHeight(this._options.maxHeight);
|
|
285
|
+
const gap = (_a = this._options.gap) !== null && _a !== void 0 ? _a : 0;
|
|
286
|
+
this._items.forEach((item) => {
|
|
287
|
+
const itemWidth = item.width;
|
|
288
|
+
const itemHeight = item.height;
|
|
289
|
+
const nextMainSize = currentItems.length === 0 ? itemHeight : currentMainSize + gap + itemHeight;
|
|
290
|
+
if (currentItems.length > 0 && maxHeight !== undefined && nextMainSize > maxHeight) {
|
|
291
|
+
groups.push({
|
|
292
|
+
items: currentItems,
|
|
293
|
+
mainSize: currentMainSize,
|
|
294
|
+
crossSize: currentCrossSize,
|
|
295
|
+
});
|
|
296
|
+
currentItems = [];
|
|
297
|
+
currentMainSize = 0;
|
|
298
|
+
currentCrossSize = 0;
|
|
299
|
+
}
|
|
300
|
+
currentItems.push(item);
|
|
301
|
+
currentMainSize = currentItems.length === 1 ? itemHeight : currentMainSize + gap + itemHeight;
|
|
302
|
+
currentCrossSize = Math.max(currentCrossSize, itemWidth);
|
|
303
|
+
});
|
|
304
|
+
if (currentItems.length > 0) {
|
|
305
|
+
groups.push({
|
|
306
|
+
items: currentItems,
|
|
307
|
+
mainSize: currentMainSize,
|
|
308
|
+
crossSize: currentCrossSize,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
return groups;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Container, Sprite } from "pixi.js";
|
|
2
|
+
/** @description 网格布局方向 */
|
|
3
|
+
export type LibPixiGridDirection = "row" | "column";
|
|
4
|
+
/** @description 网格列推进方向 */
|
|
5
|
+
export type LibPixiGridColumnDirection = "ltr" | "rtl";
|
|
6
|
+
/** @description 网格布局参数 */
|
|
7
|
+
export interface LibPixiGridOptions {
|
|
8
|
+
/** 网格布局方向 */
|
|
9
|
+
direction?: LibPixiGridDirection;
|
|
10
|
+
/** 每行或每列个数 */
|
|
11
|
+
count: number;
|
|
12
|
+
/** 滚动可视宽度 */
|
|
13
|
+
scrollWidth?: number;
|
|
14
|
+
/** 行间隔 */
|
|
15
|
+
rowGap?: number;
|
|
16
|
+
/** 列间隔 */
|
|
17
|
+
columnGap?: number;
|
|
18
|
+
/** 统一内边距 */
|
|
19
|
+
padding?: number;
|
|
20
|
+
/** 横向内边距 */
|
|
21
|
+
paddingX?: number;
|
|
22
|
+
/** 纵向内边距 */
|
|
23
|
+
paddingY?: number;
|
|
24
|
+
/** 上内边距 */
|
|
25
|
+
paddingTop?: number;
|
|
26
|
+
/** 右内边距 */
|
|
27
|
+
paddingRight?: number;
|
|
28
|
+
/** 下内边距 */
|
|
29
|
+
paddingBottom?: number;
|
|
30
|
+
/** 左内边距 */
|
|
31
|
+
paddingLeft?: number;
|
|
32
|
+
/** 列推进方向 */
|
|
33
|
+
columnDirection?: LibPixiGridColumnDirection;
|
|
34
|
+
/** 滚动可视高度 */
|
|
35
|
+
scrollHeight?: number;
|
|
36
|
+
/** 滚动条右边距 */
|
|
37
|
+
scrollbarRight?: number;
|
|
38
|
+
/** 滚动条宽度 */
|
|
39
|
+
scrollbarWidth?: number;
|
|
40
|
+
/** 滚动条颜色 */
|
|
41
|
+
scrollbarColor?: string;
|
|
42
|
+
/** 滚动内容顶部留白 */
|
|
43
|
+
scrollMarginTop?: number;
|
|
44
|
+
/** 滚动内容底部留白 */
|
|
45
|
+
scrollMarginBottom?: number;
|
|
46
|
+
/** 是否显示测试背景 */
|
|
47
|
+
showBg?: boolean;
|
|
48
|
+
/** 测试背景颜色 */
|
|
49
|
+
bgColor?: string;
|
|
50
|
+
}
|
|
51
|
+
/** @description Pixi网格布局组件 */
|
|
52
|
+
export declare class LibPixiGrid extends Container {
|
|
53
|
+
/** 布局子项 */
|
|
54
|
+
private readonly _items;
|
|
55
|
+
/** 布局内容容器 */
|
|
56
|
+
private readonly _content;
|
|
57
|
+
/** 测试背景 */
|
|
58
|
+
private readonly _bg;
|
|
59
|
+
/** 滚动容器 */
|
|
60
|
+
private readonly _scrollContainer?;
|
|
61
|
+
/** 布局配置 */
|
|
62
|
+
private readonly _options;
|
|
63
|
+
/** @description 创建Pixi网格布局组件 */
|
|
64
|
+
constructor(items: Container[], options: LibPixiGridOptions);
|
|
65
|
+
/** @description 创建Pixi网格布局组件 */
|
|
66
|
+
constructor(items: Sprite[], options: LibPixiGridOptions);
|
|
67
|
+
/** @description 执行布局 */
|
|
68
|
+
layout(): this;
|
|
69
|
+
/** @description 统一修正子项基准点 */
|
|
70
|
+
private _normalizeItemsPivot;
|
|
71
|
+
/** @description 重绘测试背景 */
|
|
72
|
+
private _renderBg;
|
|
73
|
+
/** @description 执行横向网格布局 */
|
|
74
|
+
private _layoutRow;
|
|
75
|
+
/** @description 执行纵向网格布局 */
|
|
76
|
+
private _layoutColumn;
|
|
77
|
+
/** @description 创建横向行分组 */
|
|
78
|
+
private _createRowGroups;
|
|
79
|
+
/** @description 创建纵向列分组 */
|
|
80
|
+
private _createColumnGroups;
|
|
81
|
+
/** @description 创建网格分组 */
|
|
82
|
+
private _createGroup;
|
|
83
|
+
/** @description 更新滚动容器尺寸 */
|
|
84
|
+
private _updateScrollContainer;
|
|
85
|
+
/** @description 获取背景可视区域包围盒 */
|
|
86
|
+
private _getBgViewportBounds;
|
|
87
|
+
/** @description 获取可视区域包围盒 */
|
|
88
|
+
private _getViewportBounds;
|
|
89
|
+
/** @description 获取可视宽度 */
|
|
90
|
+
private _getViewportWidth;
|
|
91
|
+
/** @description 获取内容包围盒 */
|
|
92
|
+
private _getContentBounds;
|
|
93
|
+
/** @description 获取子项包围盒 */
|
|
94
|
+
private _getItemsBounds;
|
|
95
|
+
/** @description 获取布局内边距 */
|
|
96
|
+
private _getPadding;
|
|
97
|
+
}
|