pixifact 0.1.3 → 0.1.4
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/README.md +3 -3
- package/dist/builtin-scenes/CenterContainer.d.ts +13 -0
- package/dist/builtin-scenes/CenterContainer.js +71 -0
- package/dist/builtin-scenes/CenterContainer.scene +3 -0
- package/dist/builtin-scenes/CenterContainer.ts +77 -0
- package/dist/builtin-scenes/Control.d.ts +44 -0
- package/dist/builtin-scenes/Control.js +206 -0
- package/dist/builtin-scenes/Control.scene +3 -0
- package/dist/builtin-scenes/Control.ts +233 -0
- package/dist/builtin-scenes/FlexItem.d.ts +45 -0
- package/dist/builtin-scenes/FlexItem.js +164 -0
- package/dist/builtin-scenes/FlexItem.scene +3 -0
- package/dist/builtin-scenes/FlexItem.ts +180 -0
- package/dist/builtin-scenes/FlexLayout.d.ts +29 -0
- package/dist/builtin-scenes/FlexLayout.js +358 -0
- package/dist/builtin-scenes/FlexLayout.scene +3 -0
- package/dist/builtin-scenes/FlexLayout.ts +409 -0
- package/dist/builtin-scenes/HBoxContainer.d.ts +15 -0
- package/dist/builtin-scenes/HBoxContainer.js +70 -0
- package/dist/builtin-scenes/HBoxContainer.scene +3 -0
- package/dist/builtin-scenes/HBoxContainer.ts +75 -0
- package/dist/builtin-scenes/MarginContainer.d.ts +23 -0
- package/dist/builtin-scenes/MarginContainer.js +131 -0
- package/dist/builtin-scenes/MarginContainer.scene +3 -0
- package/dist/builtin-scenes/MarginContainer.ts +139 -0
- package/dist/builtin-scenes/VBoxContainer.d.ts +15 -0
- package/dist/builtin-scenes/VBoxContainer.js +70 -0
- package/dist/builtin-scenes/VBoxContainer.scene +3 -0
- package/dist/builtin-scenes/VBoxContainer.ts +75 -0
- package/dist/builtin-scenes/controlLayout.d.ts +57 -0
- package/dist/builtin-scenes/controlLayout.js +202 -0
- package/dist/builtin-scenes/controlLayout.ts +270 -0
- package/dist/compiler/builtinScenes.d.ts +14 -0
- package/dist/compiler/builtinScenes.js +62 -0
- package/dist/compiler/compileScenes.js +126 -19
- package/dist/compiler/decorators.js +3 -0
- package/dist/compiler/index.d.ts +1 -0
- package/dist/compiler/index.js +1 -0
- package/dist/compiler/sceneAssetPair.js +19 -0
- package/dist/compiler/sceneRuntime.d.ts +5 -4
- package/dist/compiler/scriptInterfaceExtractor.d.ts +5 -0
- package/dist/compiler/scriptInterfaceExtractor.js +214 -8
- package/dist/compiler/spec.d.ts +2 -0
- package/dist/compiler/templateParser.js +4 -3
- package/dist/compiler/templateSerializer.js +2 -1
- package/dist/compiler/typescriptCompiler.js +87 -13
- package/dist/compiler-node/builtinSceneAssets.d.ts +8 -0
- package/dist/compiler-node/builtinSceneAssets.js +57 -0
- package/dist/compiler-node/index.d.ts +1 -0
- package/dist/compiler-node/index.js +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +24 -0
- package/dist/index.d.ts +2 -5
- package/dist/index.js +2 -5
- package/dist/{authoring/ProjectConfig.d.ts → project/index.d.ts} +7 -0
- package/dist/{authoring/ProjectConfig.js → project/index.js} +22 -0
- package/dist/runtime/Group.d.ts +18 -0
- package/dist/runtime/Group.js +45 -0
- package/dist/runtime/index.d.ts +1 -9
- package/dist/runtime/index.js +1 -9
- package/package.json +4 -26
- package/dist/authoring/ActionRegistry.d.ts +0 -10
- package/dist/authoring/ActionRegistry.js +0 -26
- package/dist/authoring/ComponentPalette.d.ts +0 -16
- package/dist/authoring/ComponentPalette.js +0 -50
- package/dist/authoring/DesignToken.d.ts +0 -16
- package/dist/authoring/DesignToken.js +0 -33
- package/dist/authoring/DiffModel.d.ts +0 -10
- package/dist/authoring/DiffModel.js +0 -104
- package/dist/authoring/InspectorModel.d.ts +0 -27
- package/dist/authoring/InspectorModel.js +0 -139
- package/dist/authoring/LogicGraph.d.ts +0 -66
- package/dist/authoring/LogicGraph.js +0 -184
- package/dist/authoring/OverrideJournal.d.ts +0 -18
- package/dist/authoring/OverrideJournal.js +0 -23
- package/dist/authoring/PreferenceMemory.d.ts +0 -21
- package/dist/authoring/PreferenceMemory.js +0 -39
- package/dist/authoring/RuntimePreview.d.ts +0 -11
- package/dist/authoring/RuntimePreview.js +0 -25
- package/dist/authoring/SceneDocument.d.ts +0 -74
- package/dist/authoring/SceneDocument.js +0 -332
- package/dist/authoring/SceneProjectState.d.ts +0 -20
- package/dist/authoring/SceneProjectState.js +0 -8
- package/dist/authoring/SceneSelection.d.ts +0 -11
- package/dist/authoring/SceneSelection.js +0 -1
- package/dist/authoring/index.d.ts +0 -13
- package/dist/authoring/index.js +0 -13
- package/dist/commands/Command.d.ts +0 -63
- package/dist/commands/Command.js +0 -1
- package/dist/commands/CommandStack.d.ts +0 -14
- package/dist/commands/CommandStack.js +0 -45
- package/dist/commands/applyCommand.d.ts +0 -23
- package/dist/commands/applyCommand.js +0 -316
- package/dist/commands/index.d.ts +0 -4
- package/dist/commands/index.js +0 -4
- package/dist/commands/utils.d.ts +0 -17
- package/dist/commands/utils.js +0 -77
- package/dist/commands/validateCommand.d.ts +0 -12
- package/dist/commands/validateCommand.js +0 -285
- package/dist/nodes/Input.d.ts +0 -91
- package/dist/nodes/Input.js +0 -352
- package/dist/nodes/Textarea.d.ts +0 -10
- package/dist/nodes/Textarea.js +0 -38
- package/dist/nodes/components/Button.d.ts +0 -8
- package/dist/nodes/components/Button.js +0 -45
- package/dist/nodes/components/InputField.d.ts +0 -12
- package/dist/nodes/components/InputField.js +0 -53
- package/dist/nodes/components/ProgressBar.d.ts +0 -14
- package/dist/nodes/components/ProgressBar.js +0 -66
- package/dist/nodes/components/ScrollRect.d.ts +0 -23
- package/dist/nodes/components/ScrollRect.js +0 -108
- package/dist/nodes/components/Selectable.d.ts +0 -32
- package/dist/nodes/components/Selectable.js +0 -153
- package/dist/nodes/components/index.d.ts +0 -5
- package/dist/nodes/components/index.js +0 -5
- package/dist/nodes/graphics/Graphic.d.ts +0 -14
- package/dist/nodes/graphics/Graphic.js +0 -47
- package/dist/nodes/graphics/ImageGraphic.d.ts +0 -9
- package/dist/nodes/graphics/ImageGraphic.js +0 -42
- package/dist/nodes/graphics/RoundedRectGraphic.d.ts +0 -13
- package/dist/nodes/graphics/RoundedRectGraphic.js +0 -65
- package/dist/nodes/graphics/TextGraphic.d.ts +0 -13
- package/dist/nodes/graphics/TextGraphic.js +0 -70
- package/dist/nodes/graphics/index.d.ts +0 -4
- package/dist/nodes/graphics/index.js +0 -4
- package/dist/nodes/index.d.ts +0 -3
- package/dist/nodes/index.js +0 -3
- package/dist/runtime/Application.d.ts +0 -15
- package/dist/runtime/Application.js +0 -67
- package/dist/runtime/GameObject.d.ts +0 -100
- package/dist/runtime/GameObject.js +0 -297
- package/dist/runtime/GameObjectEvent.d.ts +0 -52
- package/dist/runtime/GameObjectEvent.js +0 -38
- package/dist/runtime/Transform.d.ts +0 -32
- package/dist/runtime/Transform.js +0 -157
- package/dist/runtime/component/Component.d.ts +0 -13
- package/dist/runtime/component/Component.js +0 -13
- package/dist/runtime/component/ComponentRegistry.d.ts +0 -49
- package/dist/runtime/component/ComponentRegistry.js +0 -25
- package/dist/runtime/component/Flex.d.ts +0 -6
- package/dist/runtime/component/Flex.js +0 -15
- package/dist/runtime/component/FlexGroup.d.ts +0 -26
- package/dist/runtime/component/FlexGroup.js +0 -136
- package/dist/runtime/component/GridLayout.d.ts +0 -47
- package/dist/runtime/component/GridLayout.js +0 -129
- package/dist/runtime/component/Layout.d.ts +0 -104
- package/dist/runtime/component/Layout.js +0 -248
- package/dist/runtime/component/decorators.d.ts +0 -4
- package/dist/runtime/component/decorators.js +0 -52
- package/dist/runtime/component/index.d.ts +0 -7
- package/dist/runtime/component/index.js +0 -7
- package/dist/runtime/graphics/index.d.ts +0 -11
- package/dist/runtime/graphics/index.js +0 -29
- package/dist/runtime/group/index.d.ts +0 -39
- package/dist/runtime/group/index.js +0 -102
- package/dist/runtime/image/Image.d.ts +0 -19
- package/dist/runtime/image/Image.js +0 -60
- package/dist/runtime/image/NineSliceImage.d.ts +0 -23
- package/dist/runtime/image/NineSliceImage.js +0 -64
- package/dist/runtime/image/index.d.ts +0 -2
- package/dist/runtime/image/index.js +0 -2
- package/dist/runtime/label/Label.d.ts +0 -11
- package/dist/runtime/label/Label.js +0 -26
- package/dist/runtime/label/LabelStyle.d.ts +0 -3
- package/dist/runtime/label/LabelStyle.js +0 -3
- package/dist/runtime/label/index.d.ts +0 -2
- package/dist/runtime/label/index.js +0 -2
- package/dist/runtime/utils/index.d.ts +0 -1
- package/dist/runtime/utils/index.js +0 -1
- package/dist/runtime/utils/onlyOnceQueueMicrotask.d.ts +0 -1
- package/dist/runtime/utils/onlyOnceQueueMicrotask.js +0 -12
- package/dist/runtime/utils/setProps.d.ts +0 -10
- package/dist/runtime/utils/setProps.js +0 -17
- package/dist/scene/dsl.d.ts +0 -25
- package/dist/scene/dsl.js +0 -112
- package/dist/scene/index.d.ts +0 -5
- package/dist/scene/index.js +0 -5
- package/dist/scene/instantiate.d.ts +0 -8
- package/dist/scene/instantiate.js +0 -208
- package/dist/scene/nodesDsl.d.ts +0 -42
- package/dist/scene/nodesDsl.js +0 -169
- package/dist/scene/spec.d.ts +0 -100
- package/dist/scene/spec.js +0 -1
- package/dist/scene/templates.d.ts +0 -21
- package/dist/scene/templates.js +0 -239
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { Vector2 } from '@math.gl/core';
|
|
2
|
-
import { GameObjectEvent } from './GameObjectEvent.js';
|
|
3
|
-
export class Transform {
|
|
4
|
-
gameObject;
|
|
5
|
-
// x: number;
|
|
6
|
-
// y: number;
|
|
7
|
-
// width: number;
|
|
8
|
-
// height: number;
|
|
9
|
-
// scaleX: number;
|
|
10
|
-
// scaleY: number;
|
|
11
|
-
constructor(gameObject) {
|
|
12
|
-
this.gameObject = gameObject;
|
|
13
|
-
}
|
|
14
|
-
_position = new Vector2(0, 0);
|
|
15
|
-
get position() {
|
|
16
|
-
return this._position;
|
|
17
|
-
}
|
|
18
|
-
set position(val) {
|
|
19
|
-
this.setPosition(val.x, val.y);
|
|
20
|
-
}
|
|
21
|
-
get x() {
|
|
22
|
-
return this.position.x;
|
|
23
|
-
}
|
|
24
|
-
set x(val) {
|
|
25
|
-
this.setPosition(val, this.position.y);
|
|
26
|
-
}
|
|
27
|
-
get y() {
|
|
28
|
-
return this.position.y;
|
|
29
|
-
}
|
|
30
|
-
set y(val) {
|
|
31
|
-
this.setPosition(this.position.x, val);
|
|
32
|
-
}
|
|
33
|
-
setPosition(x, y) {
|
|
34
|
-
const displayPosition = this.gameObject.display?.position;
|
|
35
|
-
const isPositionChanged = this.position.x !== x || this.position.y !== y;
|
|
36
|
-
const isDisplayPositionChanged = displayPosition
|
|
37
|
-
? displayPosition.x !== x || displayPosition.y !== y
|
|
38
|
-
: false;
|
|
39
|
-
if (!isPositionChanged && !isDisplayPositionChanged) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
this.position.set(x, y);
|
|
43
|
-
if (displayPosition) {
|
|
44
|
-
displayPosition.set(x, y);
|
|
45
|
-
}
|
|
46
|
-
this.emitTransformChange();
|
|
47
|
-
this.gameObject.emitter.emit(GameObjectEvent.REPOSITION);
|
|
48
|
-
}
|
|
49
|
-
emitTransformChange() {
|
|
50
|
-
this.gameObject.emitter.emit(GameObjectEvent.TRANSFORM_CHANGE);
|
|
51
|
-
}
|
|
52
|
-
// private _size = new Vector2();
|
|
53
|
-
// get size() {
|
|
54
|
-
// return this._size;
|
|
55
|
-
// }
|
|
56
|
-
// set size(val: Vector2) {
|
|
57
|
-
// this.width = val.x;
|
|
58
|
-
// this.height = val.y;
|
|
59
|
-
// }
|
|
60
|
-
// get width() {
|
|
61
|
-
// return this.size.x;
|
|
62
|
-
// }
|
|
63
|
-
// set width(val: number) {
|
|
64
|
-
// this.size.x = val;
|
|
65
|
-
// // this.gameObject.display.scale.x = this.scale.x;
|
|
66
|
-
// // this.gameObject.display.width = this.size.x;
|
|
67
|
-
// // this.gameObject.display.scale.x = this.scale.x;
|
|
68
|
-
// }
|
|
69
|
-
// get height() {
|
|
70
|
-
// return this.size.y;
|
|
71
|
-
// }
|
|
72
|
-
// set height(val: number) {
|
|
73
|
-
// this.size.y = val;
|
|
74
|
-
// this.gameObject.display.height = this.size.y * this.scale.y;
|
|
75
|
-
// }
|
|
76
|
-
_scale = new Vector2(1, 1);
|
|
77
|
-
get scale() {
|
|
78
|
-
return this._scale;
|
|
79
|
-
}
|
|
80
|
-
set scale(val) {
|
|
81
|
-
this.scaleX = val.x;
|
|
82
|
-
this.scaleY = val.y;
|
|
83
|
-
}
|
|
84
|
-
get scaleX() {
|
|
85
|
-
return this.scale.x;
|
|
86
|
-
}
|
|
87
|
-
set scaleX(val) {
|
|
88
|
-
if (this.scale.x === val && this.gameObject.display.scale.x === val) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
this.scale.x = val;
|
|
92
|
-
this.gameObject.display.scale.x = this.scale.x;
|
|
93
|
-
this.emitTransformChange();
|
|
94
|
-
}
|
|
95
|
-
get scaleY() {
|
|
96
|
-
return this.scale.y;
|
|
97
|
-
}
|
|
98
|
-
set scaleY(val) {
|
|
99
|
-
if (this.scale.y === val && this.gameObject.display.scale.y === val) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
this.scale.y = val;
|
|
103
|
-
this.gameObject.display.scale.y = this.scale.y;
|
|
104
|
-
this.emitTransformChange();
|
|
105
|
-
}
|
|
106
|
-
get pivotX() {
|
|
107
|
-
return this.gameObject.display.pivot.x;
|
|
108
|
-
}
|
|
109
|
-
set pivotX(val) {
|
|
110
|
-
if (this.gameObject.display.pivot.x === val) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
this.gameObject.display.pivot.x = val;
|
|
114
|
-
this.emitTransformChange();
|
|
115
|
-
}
|
|
116
|
-
get pivotY() {
|
|
117
|
-
return this.gameObject.display.pivot.y;
|
|
118
|
-
}
|
|
119
|
-
set pivotY(val) {
|
|
120
|
-
if (this.gameObject.display.pivot.y === val) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
this.gameObject.display.pivot.y = val;
|
|
124
|
-
this.emitTransformChange();
|
|
125
|
-
}
|
|
126
|
-
// this.label.display.transform.pivot.set(-50, 0);
|
|
127
|
-
get rotation() {
|
|
128
|
-
return this.gameObject.display.rotation;
|
|
129
|
-
}
|
|
130
|
-
set rotation(val) {
|
|
131
|
-
if (this.gameObject.display.rotation === val) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
this.gameObject.display.rotation = val;
|
|
135
|
-
this.emitTransformChange();
|
|
136
|
-
}
|
|
137
|
-
get skewX() {
|
|
138
|
-
return this.gameObject.display.skew.x;
|
|
139
|
-
}
|
|
140
|
-
set skewX(val) {
|
|
141
|
-
if (this.gameObject.display.skew.x === val) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
this.gameObject.display.skew.x = val;
|
|
145
|
-
this.emitTransformChange();
|
|
146
|
-
}
|
|
147
|
-
get skewY() {
|
|
148
|
-
return this.gameObject.display.skew.y;
|
|
149
|
-
}
|
|
150
|
-
set skewY(val) {
|
|
151
|
-
if (this.gameObject.display.skew.y === val) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
this.gameObject.display.skew.y = val;
|
|
155
|
-
this.emitTransformChange();
|
|
156
|
-
}
|
|
157
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { GameObject } from "../GameObject.js";
|
|
2
|
-
export declare abstract class Component<T extends GameObject = GameObject> {
|
|
3
|
-
gameObject: T;
|
|
4
|
-
constructor(gameObject: T);
|
|
5
|
-
awake?(): void;
|
|
6
|
-
start?(): void;
|
|
7
|
-
update?(_dt: number): void;
|
|
8
|
-
/**
|
|
9
|
-
* 销毁组件
|
|
10
|
-
*/
|
|
11
|
-
destroy(): void;
|
|
12
|
-
onDestroy?(): void;
|
|
13
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { Component } from "./Component.js";
|
|
2
|
-
export type ComponentConstructor<T extends Component = Component> = new (...args: any[]) => T;
|
|
3
|
-
export type PropFieldType = 'number' | 'string' | 'boolean' | 'color' | 'enum' | 'vec2' | 'rect' | 'assetRef' | 'nodeRef' | 'componentRef' | 'event';
|
|
4
|
-
export interface PropSchema {
|
|
5
|
-
key: string;
|
|
6
|
-
type: PropFieldType;
|
|
7
|
-
default?: unknown;
|
|
8
|
-
description?: string;
|
|
9
|
-
min?: number;
|
|
10
|
-
max?: number;
|
|
11
|
-
options?: readonly (string | number)[];
|
|
12
|
-
component?: string;
|
|
13
|
-
assetType?: string;
|
|
14
|
-
hidden?: boolean;
|
|
15
|
-
readOnly?: boolean;
|
|
16
|
-
serialize?: boolean;
|
|
17
|
-
examples?: readonly unknown[];
|
|
18
|
-
}
|
|
19
|
-
export interface ComponentSchema<T extends Component = Component> {
|
|
20
|
-
type: string;
|
|
21
|
-
ctor: ComponentConstructor<T>;
|
|
22
|
-
displayName?: string;
|
|
23
|
-
category?: string;
|
|
24
|
-
icon?: string;
|
|
25
|
-
description?: string;
|
|
26
|
-
disallowMultiple?: boolean;
|
|
27
|
-
require?: readonly string[];
|
|
28
|
-
props: readonly PropSchema[];
|
|
29
|
-
}
|
|
30
|
-
export interface ComponentMetaOptions {
|
|
31
|
-
type: string;
|
|
32
|
-
displayName?: string;
|
|
33
|
-
category?: string;
|
|
34
|
-
icon?: string;
|
|
35
|
-
description?: string;
|
|
36
|
-
disallowMultiple?: boolean;
|
|
37
|
-
require?: readonly string[];
|
|
38
|
-
}
|
|
39
|
-
export interface PropOptions extends Omit<PropSchema, 'key'> {
|
|
40
|
-
}
|
|
41
|
-
export declare class ComponentRegistry {
|
|
42
|
-
private static schemasByType;
|
|
43
|
-
private static schemasByCtor;
|
|
44
|
-
static register<T extends Component>(schema: ComponentSchema<T>): ComponentSchema<T>;
|
|
45
|
-
static get<T extends Component = Component>(type: string): ComponentSchema<T> | undefined;
|
|
46
|
-
static getByCtor<T extends Component = Component>(ctor: ComponentConstructor<T>): ComponentSchema<T> | undefined;
|
|
47
|
-
static list(): ComponentSchema<Component<import("..").GameObject<import("pixi.js").Container<import("pixi.js").ContainerChild>>>>[];
|
|
48
|
-
static clear(): void;
|
|
49
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export class ComponentRegistry {
|
|
2
|
-
static schemasByType = new Map();
|
|
3
|
-
static schemasByCtor = new Map();
|
|
4
|
-
static register(schema) {
|
|
5
|
-
if (this.schemasByType.has(schema.type)) {
|
|
6
|
-
throw new Error(`Component type "${schema.type}" is already registered.`);
|
|
7
|
-
}
|
|
8
|
-
this.schemasByType.set(schema.type, schema);
|
|
9
|
-
this.schemasByCtor.set(schema.ctor, schema);
|
|
10
|
-
return schema;
|
|
11
|
-
}
|
|
12
|
-
static get(type) {
|
|
13
|
-
return this.schemasByType.get(type);
|
|
14
|
-
}
|
|
15
|
-
static getByCtor(ctor) {
|
|
16
|
-
return this.schemasByCtor.get(ctor);
|
|
17
|
-
}
|
|
18
|
-
static list() {
|
|
19
|
-
return Array.from(this.schemasByType.values());
|
|
20
|
-
}
|
|
21
|
-
static clear() {
|
|
22
|
-
this.schemasByType.clear();
|
|
23
|
-
this.schemasByCtor.clear();
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Component } from "./Component.js";
|
|
2
|
-
import { GameObject } from "../GameObject.js";
|
|
3
|
-
export class Flex extends Component {
|
|
4
|
-
_grow = 1;
|
|
5
|
-
get grow() {
|
|
6
|
-
return this._grow;
|
|
7
|
-
}
|
|
8
|
-
set grow(val) {
|
|
9
|
-
if (this._grow === val) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
this._grow = val;
|
|
13
|
-
this.gameObject.parent?.emitter.emit(GameObject.Event.RESIZE);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Group } from "../group/index.js";
|
|
2
|
-
import { Component } from "./Component.js";
|
|
3
|
-
export declare enum FlexDirection {
|
|
4
|
-
ROW = 0,
|
|
5
|
-
COLUMN = 1
|
|
6
|
-
}
|
|
7
|
-
export declare class FlexGroup extends Component<Group> {
|
|
8
|
-
private _active;
|
|
9
|
-
private _applyingLayout;
|
|
10
|
-
private _direction;
|
|
11
|
-
get direction(): FlexDirection;
|
|
12
|
-
set direction(val: FlexDirection);
|
|
13
|
-
private _gap;
|
|
14
|
-
get gap(): number;
|
|
15
|
-
set gap(val: number);
|
|
16
|
-
awake(): void;
|
|
17
|
-
private handleResize;
|
|
18
|
-
private handleChildAdded;
|
|
19
|
-
private handleChildRemoved;
|
|
20
|
-
private handleChildResize;
|
|
21
|
-
private bindChild;
|
|
22
|
-
private unbindChild;
|
|
23
|
-
private markResize;
|
|
24
|
-
resize: () => void;
|
|
25
|
-
onDestroy(): void;
|
|
26
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { GameObject } from "../GameObject.js";
|
|
2
|
-
import { onlyOnceQueueMicrotask } from "../utils/onlyOnceQueueMicrotask.js";
|
|
3
|
-
import { Component } from "./Component.js";
|
|
4
|
-
import { Flex } from "./Flex.js";
|
|
5
|
-
export var FlexDirection;
|
|
6
|
-
(function (FlexDirection) {
|
|
7
|
-
FlexDirection[FlexDirection["ROW"] = 0] = "ROW";
|
|
8
|
-
FlexDirection[FlexDirection["COLUMN"] = 1] = "COLUMN";
|
|
9
|
-
})(FlexDirection || (FlexDirection = {}));
|
|
10
|
-
export class FlexGroup extends Component {
|
|
11
|
-
_active = false;
|
|
12
|
-
_applyingLayout = false;
|
|
13
|
-
_direction = FlexDirection.ROW;
|
|
14
|
-
get direction() {
|
|
15
|
-
return this._direction;
|
|
16
|
-
}
|
|
17
|
-
set direction(val) {
|
|
18
|
-
if (this._direction === val) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
this._direction = val;
|
|
22
|
-
this.markResize();
|
|
23
|
-
}
|
|
24
|
-
_gap = 0;
|
|
25
|
-
get gap() {
|
|
26
|
-
return this._gap;
|
|
27
|
-
}
|
|
28
|
-
set gap(val) {
|
|
29
|
-
if (this._gap === val) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
this._gap = val;
|
|
33
|
-
this.markResize();
|
|
34
|
-
}
|
|
35
|
-
awake() {
|
|
36
|
-
this._active = true;
|
|
37
|
-
this.gameObject.emitter.on(GameObject.Event.RESIZE, this.handleResize, this);
|
|
38
|
-
this.gameObject.emitter.on(GameObject.Event.CHILD_ADDED, this.handleChildAdded, this);
|
|
39
|
-
this.gameObject.emitter.on(GameObject.Event.CHILD_REMOVED, this.handleChildRemoved, this);
|
|
40
|
-
for (const child of this.gameObject.children) {
|
|
41
|
-
this.bindChild(child);
|
|
42
|
-
}
|
|
43
|
-
this.resize();
|
|
44
|
-
}
|
|
45
|
-
handleResize = () => {
|
|
46
|
-
this.markResize();
|
|
47
|
-
};
|
|
48
|
-
handleChildAdded = (child) => {
|
|
49
|
-
this.bindChild(child);
|
|
50
|
-
this.markResize();
|
|
51
|
-
};
|
|
52
|
-
handleChildRemoved = (child) => {
|
|
53
|
-
this.unbindChild(child);
|
|
54
|
-
this.markResize();
|
|
55
|
-
};
|
|
56
|
-
handleChildResize = () => {
|
|
57
|
-
if (this._applyingLayout) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
this.markResize();
|
|
61
|
-
};
|
|
62
|
-
bindChild(child) {
|
|
63
|
-
child.emitter.on(GameObject.Event.RESIZE, this.handleChildResize, this);
|
|
64
|
-
}
|
|
65
|
-
unbindChild(child) {
|
|
66
|
-
child.emitter.off(GameObject.Event.RESIZE, this.handleChildResize, this);
|
|
67
|
-
}
|
|
68
|
-
markResize() {
|
|
69
|
-
if (this._active) {
|
|
70
|
-
this.resize();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
resize = onlyOnceQueueMicrotask(() => {
|
|
74
|
-
if (!this._active && !this.gameObject.display) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const length = this.gameObject.children.length;
|
|
78
|
-
if (length === 0) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const isRow = this.direction === FlexDirection.ROW;
|
|
82
|
-
let total = 0;
|
|
83
|
-
let fixedSize = Math.max(0, length - 1) * this.gap;
|
|
84
|
-
for (let i = 0; i < length; i++) {
|
|
85
|
-
const child = this.gameObject.getChildAt(i);
|
|
86
|
-
const flex = child.getComponent(Flex);
|
|
87
|
-
if (flex && flex.grow > 0) {
|
|
88
|
-
total += flex.grow;
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
fixedSize += isRow ? child.width : child.height;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
// 起始位置
|
|
95
|
-
let location = 0;
|
|
96
|
-
// 可用空间
|
|
97
|
-
const available = Math.max(0, (isRow ? this.gameObject.width : this.gameObject.height) - fixedSize);
|
|
98
|
-
this._applyingLayout = true;
|
|
99
|
-
try {
|
|
100
|
-
for (let i = 0; i < length; i++) {
|
|
101
|
-
const child = this.gameObject.getChildAt(i);
|
|
102
|
-
const flex = child.getComponent(Flex);
|
|
103
|
-
const perc = flex && flex.grow > 0 && total > 0 ? flex.grow / total : 0;
|
|
104
|
-
if (isRow) {
|
|
105
|
-
child.x = location;
|
|
106
|
-
if (perc) {
|
|
107
|
-
child.width = available * perc;
|
|
108
|
-
}
|
|
109
|
-
location += child.width;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
child.y = location;
|
|
113
|
-
if (perc) {
|
|
114
|
-
child.height = available * perc;
|
|
115
|
-
}
|
|
116
|
-
location += child.height;
|
|
117
|
-
}
|
|
118
|
-
if (i < length - 1) {
|
|
119
|
-
location += this.gap;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
finally {
|
|
124
|
-
this._applyingLayout = false;
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
onDestroy() {
|
|
128
|
-
this._active = false;
|
|
129
|
-
this.gameObject.emitter.off(GameObject.Event.RESIZE, this.handleResize, this);
|
|
130
|
-
this.gameObject.emitter.off(GameObject.Event.CHILD_ADDED, this.handleChildAdded, this);
|
|
131
|
-
this.gameObject.emitter.off(GameObject.Event.CHILD_REMOVED, this.handleChildRemoved, this);
|
|
132
|
-
for (const child of this.gameObject.children) {
|
|
133
|
-
this.unbindChild(child);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Group } from "../group/index.js";
|
|
2
|
-
import { Component } from "./Component.js";
|
|
3
|
-
export declare class GridLayout extends Component<Group> {
|
|
4
|
-
private _active;
|
|
5
|
-
private _refresh;
|
|
6
|
-
/**
|
|
7
|
-
* 横向列数。
|
|
8
|
-
*/
|
|
9
|
-
private _col;
|
|
10
|
-
get col(): number;
|
|
11
|
-
set col(val: number);
|
|
12
|
-
/**
|
|
13
|
-
* 单元格宽度。
|
|
14
|
-
*/
|
|
15
|
-
private _gridWidth;
|
|
16
|
-
get gridWidth(): number;
|
|
17
|
-
set gridWidth(val: number);
|
|
18
|
-
/**
|
|
19
|
-
* 单元格高度。
|
|
20
|
-
*/
|
|
21
|
-
private _gridHeight;
|
|
22
|
-
get gridHeight(): number;
|
|
23
|
-
set gridHeight(val: number);
|
|
24
|
-
/**
|
|
25
|
-
* 横向间距,作用于 x 轴。
|
|
26
|
-
*/
|
|
27
|
-
private _gapHorizontal;
|
|
28
|
-
get gapHorizontal(): number;
|
|
29
|
-
set gapHorizontal(val: number);
|
|
30
|
-
/**
|
|
31
|
-
* 纵向间距,作用于 y 轴。
|
|
32
|
-
*/
|
|
33
|
-
private _gapVertical;
|
|
34
|
-
get gapVertical(): number;
|
|
35
|
-
set gapVertical(val: number);
|
|
36
|
-
private resizeLater;
|
|
37
|
-
private handleChildAdded;
|
|
38
|
-
private handleChildRemoved;
|
|
39
|
-
awake(): void;
|
|
40
|
-
private normalizeCount;
|
|
41
|
-
private markResize;
|
|
42
|
-
/**
|
|
43
|
-
* 计算布局
|
|
44
|
-
*/
|
|
45
|
-
resize(): void;
|
|
46
|
-
onDestroy(): void;
|
|
47
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { GameObject } from "../GameObject.js";
|
|
2
|
-
import { Component } from "./Component.js";
|
|
3
|
-
import { onlyOnceQueueMicrotask } from "../utils/onlyOnceQueueMicrotask.js";
|
|
4
|
-
export class GridLayout extends Component {
|
|
5
|
-
_active = false;
|
|
6
|
-
_refresh = false;
|
|
7
|
-
/**
|
|
8
|
-
* 横向列数。
|
|
9
|
-
*/
|
|
10
|
-
_col = 1;
|
|
11
|
-
get col() {
|
|
12
|
-
return this._col;
|
|
13
|
-
}
|
|
14
|
-
set col(val) {
|
|
15
|
-
const next = this.normalizeCount(val);
|
|
16
|
-
if (this._col === next) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
this._col = next;
|
|
20
|
-
this.markResize();
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* 单元格宽度。
|
|
24
|
-
*/
|
|
25
|
-
_gridWidth = 1;
|
|
26
|
-
get gridWidth() {
|
|
27
|
-
return this._gridWidth;
|
|
28
|
-
}
|
|
29
|
-
set gridWidth(val) {
|
|
30
|
-
if (this._gridWidth === val) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
this._gridWidth = val;
|
|
34
|
-
this.markResize();
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* 单元格高度。
|
|
38
|
-
*/
|
|
39
|
-
_gridHeight = 1;
|
|
40
|
-
get gridHeight() {
|
|
41
|
-
return this._gridHeight;
|
|
42
|
-
}
|
|
43
|
-
set gridHeight(val) {
|
|
44
|
-
if (this._gridHeight === val) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
this._gridHeight = val;
|
|
48
|
-
this.markResize();
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* 横向间距,作用于 x 轴。
|
|
52
|
-
*/
|
|
53
|
-
_gapHorizontal = 0;
|
|
54
|
-
get gapHorizontal() {
|
|
55
|
-
return this._gapHorizontal;
|
|
56
|
-
}
|
|
57
|
-
set gapHorizontal(val) {
|
|
58
|
-
if (this._gapHorizontal === val) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
this._gapHorizontal = val;
|
|
62
|
-
this.markResize();
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* 纵向间距,作用于 y 轴。
|
|
66
|
-
*/
|
|
67
|
-
_gapVertical = 0;
|
|
68
|
-
get gapVertical() {
|
|
69
|
-
return this._gapVertical;
|
|
70
|
-
}
|
|
71
|
-
set gapVertical(val) {
|
|
72
|
-
if (this._gapVertical === val) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
this._gapVertical = val;
|
|
76
|
-
this.markResize();
|
|
77
|
-
}
|
|
78
|
-
resizeLater = onlyOnceQueueMicrotask(() => {
|
|
79
|
-
if (!this._active || !this._refresh) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
this.resize();
|
|
83
|
-
});
|
|
84
|
-
handleChildAdded = () => {
|
|
85
|
-
this.markResize();
|
|
86
|
-
};
|
|
87
|
-
handleChildRemoved = () => {
|
|
88
|
-
this.markResize();
|
|
89
|
-
};
|
|
90
|
-
awake() {
|
|
91
|
-
this._active = true;
|
|
92
|
-
this.gameObject.emitter.on(GameObject.Event.CHILD_ADDED, this.handleChildAdded, this);
|
|
93
|
-
this.gameObject.emitter.on(GameObject.Event.CHILD_REMOVED, this.handleChildRemoved, this);
|
|
94
|
-
this.resize();
|
|
95
|
-
}
|
|
96
|
-
normalizeCount(val) {
|
|
97
|
-
if (!Number.isFinite(val)) {
|
|
98
|
-
return 1;
|
|
99
|
-
}
|
|
100
|
-
return Math.max(1, Math.floor(val));
|
|
101
|
-
}
|
|
102
|
-
markResize() {
|
|
103
|
-
this._refresh = true;
|
|
104
|
-
if (this._active) {
|
|
105
|
-
this.resizeLater();
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* 计算布局
|
|
110
|
-
*/
|
|
111
|
-
resize() {
|
|
112
|
-
this._refresh = false;
|
|
113
|
-
const children = this.gameObject.children;
|
|
114
|
-
const colCount = this.col;
|
|
115
|
-
for (let i = 0; i < children.length; i++) {
|
|
116
|
-
const child = children[i];
|
|
117
|
-
child.width = this.gridWidth;
|
|
118
|
-
child.height = this.gridHeight;
|
|
119
|
-
const col = i % colCount;
|
|
120
|
-
const row = Math.floor(i / colCount);
|
|
121
|
-
child.transform.setPosition(col * (this.gridWidth + this.gapHorizontal), row * (this.gridHeight + this.gapVertical));
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
onDestroy() {
|
|
125
|
-
this._active = false;
|
|
126
|
-
this.gameObject.emitter.off(GameObject.Event.CHILD_ADDED, this.handleChildAdded, this);
|
|
127
|
-
this.gameObject.emitter.off(GameObject.Event.CHILD_REMOVED, this.handleChildRemoved, this);
|
|
128
|
-
}
|
|
129
|
-
}
|