pixifact 0.1.4 → 0.2.0
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/dist/compiler/builtinScenes.d.ts +2 -2
- package/dist/compiler/builtinScenes.js +1 -9
- package/dist/compiler/compileScenes.js +16 -0
- package/dist/compiler/pixiNodeSchema.d.ts +17 -7
- package/dist/compiler/pixiNodeSchema.js +219 -0
- package/dist/compiler/sceneValidation.js +13 -2
- package/dist/compiler/spec.d.ts +5 -1
- package/dist/compiler/templateParser.js +18 -10
- package/dist/compiler/templateSerializer.js +1 -0
- package/dist/compiler/typescriptCompiler.js +53 -8
- package/dist/project/index.d.ts +5 -0
- package/dist/project/index.js +22 -0
- package/dist/runtime/Control.d.ts +18 -0
- package/dist/runtime/Control.js +49 -0
- package/dist/runtime/GridContainer.d.ts +25 -0
- package/dist/runtime/GridContainer.js +115 -0
- package/dist/runtime/Group.d.ts +2 -0
- package/dist/runtime/Group.js +30 -10
- package/dist/runtime/HBoxContainer.d.ts +21 -0
- package/dist/runtime/HBoxContainer.js +74 -0
- package/dist/runtime/Image.d.ts +47 -0
- package/dist/runtime/Image.js +220 -0
- package/dist/runtime/NineImage.d.ts +22 -0
- package/dist/runtime/NineImage.js +54 -0
- package/dist/runtime/Rect.d.ts +48 -0
- package/dist/runtime/Rect.js +162 -0
- package/dist/runtime/ScrollContainer.d.ts +28 -0
- package/dist/runtime/ScrollContainer.js +370 -0
- package/dist/runtime/TileImage.d.ts +27 -0
- package/dist/runtime/TileImage.js +57 -0
- package/dist/runtime/VBoxContainer.d.ts +21 -0
- package/dist/runtime/VBoxContainer.js +74 -0
- package/dist/runtime/frameLayout.d.ts +11 -0
- package/dist/runtime/frameLayout.js +116 -0
- package/dist/runtime/frameLayoutAccessors.d.ts +4 -0
- package/dist/runtime/frameLayoutAccessors.js +7 -0
- package/dist/runtime/index.d.ts +12 -0
- package/dist/runtime/index.js +12 -0
- package/dist/runtime/stackLayout.d.ts +16 -0
- package/dist/runtime/stackLayout.js +59 -0
- package/dist/viewport.d.ts +43 -0
- package/dist/viewport.js +93 -0
- package/package.json +2 -2
- package/dist/builtin-scenes/CenterContainer.d.ts +0 -13
- package/dist/builtin-scenes/CenterContainer.js +0 -71
- package/dist/builtin-scenes/CenterContainer.scene +0 -3
- package/dist/builtin-scenes/CenterContainer.ts +0 -77
- package/dist/builtin-scenes/Control.d.ts +0 -44
- package/dist/builtin-scenes/Control.js +0 -206
- package/dist/builtin-scenes/Control.scene +0 -3
- package/dist/builtin-scenes/Control.ts +0 -233
- package/dist/builtin-scenes/FlexItem.d.ts +0 -45
- package/dist/builtin-scenes/FlexItem.js +0 -164
- package/dist/builtin-scenes/FlexItem.scene +0 -3
- package/dist/builtin-scenes/FlexItem.ts +0 -180
- package/dist/builtin-scenes/FlexLayout.d.ts +0 -29
- package/dist/builtin-scenes/FlexLayout.js +0 -358
- package/dist/builtin-scenes/FlexLayout.scene +0 -3
- package/dist/builtin-scenes/FlexLayout.ts +0 -409
- package/dist/builtin-scenes/HBoxContainer.d.ts +0 -15
- package/dist/builtin-scenes/HBoxContainer.js +0 -70
- package/dist/builtin-scenes/HBoxContainer.scene +0 -3
- package/dist/builtin-scenes/HBoxContainer.ts +0 -75
- package/dist/builtin-scenes/MarginContainer.d.ts +0 -23
- package/dist/builtin-scenes/MarginContainer.js +0 -131
- package/dist/builtin-scenes/MarginContainer.scene +0 -3
- package/dist/builtin-scenes/MarginContainer.ts +0 -139
- package/dist/builtin-scenes/VBoxContainer.d.ts +0 -15
- package/dist/builtin-scenes/VBoxContainer.js +0 -70
- package/dist/builtin-scenes/VBoxContainer.scene +0 -3
- package/dist/builtin-scenes/VBoxContainer.ts +0 -75
- package/dist/builtin-scenes/controlLayout.d.ts +0 -57
- package/dist/builtin-scenes/controlLayout.js +0 -202
- package/dist/builtin-scenes/controlLayout.ts +0 -270
|
@@ -1,409 +0,0 @@
|
|
|
1
|
-
import { Container, type ContainerChild } from 'pixi.js';
|
|
2
|
-
import { prop, scene, slot } from 'pixifact/compiler';
|
|
3
|
-
import { Control } from './Control';
|
|
4
|
-
import type { Size } from './controlLayout';
|
|
5
|
-
import type { FlexAlignSelf, FlexBasis, FlexItemLayoutProps } from './FlexItem';
|
|
6
|
-
|
|
7
|
-
type FlexAxis = 'row' | 'column';
|
|
8
|
-
type FlexDirection = 'row' | 'column';
|
|
9
|
-
type FlexAlign = 'start' | 'center' | 'end' | 'stretch';
|
|
10
|
-
type FlexJustify = 'start' | 'center' | 'end' | 'space-between';
|
|
11
|
-
type LayoutChild = ContainerChild & {
|
|
12
|
-
getFlexItemLayoutProps?: () => FlexItemLayoutProps;
|
|
13
|
-
measureControlNaturalSize?: () => Size;
|
|
14
|
-
setControlLayoutBox?: (x: number, y: number, width: number, height: number) => void;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
interface LayoutItem {
|
|
18
|
-
child: LayoutChild;
|
|
19
|
-
props: FlexItemLayoutProps;
|
|
20
|
-
baseMain: number;
|
|
21
|
-
baseCross: number;
|
|
22
|
-
mainSize: number;
|
|
23
|
-
crossSize: number;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
@scene()
|
|
27
|
-
export class FlexLayout extends Control {
|
|
28
|
-
@slot()
|
|
29
|
-
declare readonly default: Container;
|
|
30
|
-
|
|
31
|
-
#direction: FlexDirection = 'row';
|
|
32
|
-
#align: FlexAlign = 'start';
|
|
33
|
-
#justify: FlexJustify = 'start';
|
|
34
|
-
#gap = 0;
|
|
35
|
-
#paddingX = 0;
|
|
36
|
-
#paddingY = 0;
|
|
37
|
-
#paddingLeft: number | undefined;
|
|
38
|
-
#paddingRight: number | undefined;
|
|
39
|
-
#paddingTop: number | undefined;
|
|
40
|
-
#paddingBottom: number | undefined;
|
|
41
|
-
#baseSizes = new WeakMap<object, Size>();
|
|
42
|
-
|
|
43
|
-
get direction() {
|
|
44
|
-
return this.#direction;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
@prop({ type: String, default: 'row' })
|
|
48
|
-
set direction(value: string) {
|
|
49
|
-
this.#direction = value === 'column' ? 'column' : 'row';
|
|
50
|
-
this.refreshControlLayout();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
get align() {
|
|
54
|
-
return this.#align;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
@prop({ type: String, default: 'start' })
|
|
58
|
-
set align(value: string) {
|
|
59
|
-
this.#align = parseAlign(value);
|
|
60
|
-
this.layout();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
get justify() {
|
|
64
|
-
return this.#justify;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
@prop({ type: String, default: 'start' })
|
|
68
|
-
set justify(value: string) {
|
|
69
|
-
this.#justify = parseJustify(value);
|
|
70
|
-
this.layout();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
get gap() {
|
|
74
|
-
return this.#gap;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
@prop({ type: Number, default: 0 })
|
|
78
|
-
set gap(value: number) {
|
|
79
|
-
this.#gap = Math.max(0, finiteNumber(value, 0));
|
|
80
|
-
this.refreshControlLayout();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
get paddingX() {
|
|
84
|
-
return this.#paddingX;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
@prop({ type: Number, default: 0 })
|
|
88
|
-
set paddingX(value: number) {
|
|
89
|
-
this.#paddingX = Math.max(0, finiteNumber(value, 0));
|
|
90
|
-
this.refreshControlLayout();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
get paddingY() {
|
|
94
|
-
return this.#paddingY;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
@prop({ type: Number, default: 0 })
|
|
98
|
-
set paddingY(value: number) {
|
|
99
|
-
this.#paddingY = Math.max(0, finiteNumber(value, 0));
|
|
100
|
-
this.refreshControlLayout();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
get paddingLeft() {
|
|
104
|
-
return this.#paddingLeft ?? this.#paddingX;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
@prop({ type: Number })
|
|
108
|
-
set paddingLeft(value: number) {
|
|
109
|
-
this.#paddingLeft = Math.max(0, finiteNumber(value, 0));
|
|
110
|
-
this.refreshControlLayout();
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
get paddingRight() {
|
|
114
|
-
return this.#paddingRight ?? this.#paddingX;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
@prop({ type: Number })
|
|
118
|
-
set paddingRight(value: number) {
|
|
119
|
-
this.#paddingRight = Math.max(0, finiteNumber(value, 0));
|
|
120
|
-
this.refreshControlLayout();
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
get paddingTop() {
|
|
124
|
-
return this.#paddingTop ?? this.#paddingY;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
@prop({ type: Number })
|
|
128
|
-
set paddingTop(value: number) {
|
|
129
|
-
this.#paddingTop = Math.max(0, finiteNumber(value, 0));
|
|
130
|
-
this.refreshControlLayout();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
get paddingBottom() {
|
|
134
|
-
return this.#paddingBottom ?? this.#paddingY;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
@prop({ type: Number })
|
|
138
|
-
set paddingBottom(value: number) {
|
|
139
|
-
this.#paddingBottom = Math.max(0, finiteNumber(value, 0));
|
|
140
|
-
this.refreshControlLayout();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
override layout() {
|
|
144
|
-
const children = this.default?.children as LayoutChild[] | undefined;
|
|
145
|
-
if (!children || children.length === 0) {
|
|
146
|
-
this.syncControlBoxSize();
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
for (const child of children) {
|
|
151
|
-
this.#rememberBaseSize(child);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const horizontal = this.#direction === 'row';
|
|
155
|
-
const mainAxis: FlexAxis = horizontal ? 'row' : 'column';
|
|
156
|
-
const crossAxis: FlexAxis = horizontal ? 'column' : 'row';
|
|
157
|
-
const paddingMainStart = horizontal ? this.paddingLeft : this.paddingTop;
|
|
158
|
-
const paddingMainEnd = horizontal ? this.paddingRight : this.paddingBottom;
|
|
159
|
-
const paddingCrossStart = horizontal ? this.paddingTop : this.paddingLeft;
|
|
160
|
-
const paddingCrossEnd = horizontal ? this.paddingBottom : this.paddingRight;
|
|
161
|
-
const items = children.map((child) => this.#createLayoutItem(child, mainAxis, crossAxis));
|
|
162
|
-
const gapTotal = this.#gap * Math.max(0, items.length - 1);
|
|
163
|
-
const naturalMain = items.reduce((sum, item) => sum + item.baseMain + marginMain(item.props, horizontal), 0);
|
|
164
|
-
const naturalCross = items.reduce((max, item) => Math.max(max, item.baseCross + marginCross(item.props, horizontal)), 0);
|
|
165
|
-
const naturalWidth = horizontal
|
|
166
|
-
? naturalMain + gapTotal + paddingMainStart + paddingMainEnd
|
|
167
|
-
: naturalCross + paddingCrossStart + paddingCrossEnd;
|
|
168
|
-
const naturalHeight = horizontal
|
|
169
|
-
? naturalCross + paddingCrossStart + paddingCrossEnd
|
|
170
|
-
: naturalMain + gapTotal + paddingMainStart + paddingMainEnd;
|
|
171
|
-
const assigned = this.getAssignedControlBoxSize();
|
|
172
|
-
const containerWidth = assigned.width ?? naturalWidth;
|
|
173
|
-
const containerHeight = assigned.height ?? naturalHeight;
|
|
174
|
-
const containerMain = horizontal ? containerWidth : containerHeight;
|
|
175
|
-
const containerCross = horizontal ? containerHeight : containerWidth;
|
|
176
|
-
const innerMain = Math.max(0, containerMain - paddingMainStart - paddingMainEnd - gapTotal);
|
|
177
|
-
const innerCross = Math.max(0, containerCross - paddingCrossStart - paddingCrossEnd);
|
|
178
|
-
const freeMain = innerMain - naturalMain;
|
|
179
|
-
|
|
180
|
-
this.#resolveMainSizes(items, freeMain, horizontal);
|
|
181
|
-
this.#resolveCrossSizes(items, innerCross, horizontal);
|
|
182
|
-
this.#placeItems(items, containerMain, paddingMainStart, paddingMainEnd, paddingCrossStart, innerCross, horizontal);
|
|
183
|
-
|
|
184
|
-
this.syncControlBoxSize();
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
override measureControlNaturalSize(): Size {
|
|
188
|
-
const children = this.default?.children as LayoutChild[] | undefined;
|
|
189
|
-
if (!children || children.length === 0) {
|
|
190
|
-
return { width: 0, height: 0 };
|
|
191
|
-
}
|
|
192
|
-
const gapTotal = this.#gap * Math.max(0, children.length - 1);
|
|
193
|
-
const sizes = children.map((child) => this.#naturalSize(child));
|
|
194
|
-
if (this.#direction === 'row') {
|
|
195
|
-
return {
|
|
196
|
-
width: this.paddingLeft + this.paddingRight + gapTotal + sizes.reduce((sum, size) => sum + size.width, 0),
|
|
197
|
-
height: this.paddingTop + this.paddingBottom + sizes.reduce((max, size) => Math.max(max, size.height), 0),
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
return {
|
|
201
|
-
width: this.paddingLeft + this.paddingRight + sizes.reduce((max, size) => Math.max(max, size.width), 0),
|
|
202
|
-
height: this.paddingTop + this.paddingBottom + gapTotal + sizes.reduce((sum, size) => sum + size.height, 0),
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
#createLayoutItem(child: LayoutChild, mainAxis: FlexAxis, crossAxis: FlexAxis): LayoutItem {
|
|
207
|
-
const props = child.getFlexItemLayoutProps?.() ?? defaultItemProps;
|
|
208
|
-
const natural = this.#naturalSize(child);
|
|
209
|
-
const naturalMain = mainAxis === 'row' ? natural.width : natural.height;
|
|
210
|
-
const naturalCross = crossAxis === 'row' ? natural.width : natural.height;
|
|
211
|
-
const minMain = mainAxis === 'row' ? props.minWidth : props.minHeight;
|
|
212
|
-
const maxMain = maxSize(mainAxis === 'row' ? props.maxWidth : props.maxHeight);
|
|
213
|
-
const minCross = crossAxis === 'row' ? props.minWidth : props.minHeight;
|
|
214
|
-
const maxCross = maxSize(crossAxis === 'row' ? props.maxWidth : props.maxHeight);
|
|
215
|
-
const basis = basisSize(props.basis, naturalMain);
|
|
216
|
-
const baseMain = clamp(basis, minMain, maxMain);
|
|
217
|
-
const baseCross = clamp(naturalCross, minCross, maxCross);
|
|
218
|
-
return {
|
|
219
|
-
child,
|
|
220
|
-
props,
|
|
221
|
-
baseMain,
|
|
222
|
-
baseCross,
|
|
223
|
-
mainSize: baseMain,
|
|
224
|
-
crossSize: baseCross,
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
#resolveMainSizes(items: LayoutItem[], freeMain: number, horizontal: boolean) {
|
|
229
|
-
if (freeMain > 0) {
|
|
230
|
-
const totalGrow = items.reduce((sum, item) => sum + item.props.grow, 0);
|
|
231
|
-
if (totalGrow > 0) {
|
|
232
|
-
for (const item of items) {
|
|
233
|
-
item.mainSize = clampMain(item.baseMain + freeMain * (item.props.grow / totalGrow), item.props, horizontal);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
if (freeMain < 0) {
|
|
240
|
-
const totalShrink = items.reduce((sum, item) => sum + item.props.shrink * item.baseMain, 0);
|
|
241
|
-
if (totalShrink > 0) {
|
|
242
|
-
for (const item of items) {
|
|
243
|
-
const weighted = item.props.shrink * item.baseMain;
|
|
244
|
-
item.mainSize = clampMain(item.baseMain + freeMain * (weighted / totalShrink), item.props, horizontal);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
#resolveCrossSizes(items: LayoutItem[], innerCross: number, horizontal: boolean) {
|
|
251
|
-
for (const item of items) {
|
|
252
|
-
const alignSelf = item.props.alignSelf === 'auto' ? this.#align : item.props.alignSelf;
|
|
253
|
-
if (alignSelf === 'stretch') {
|
|
254
|
-
item.crossSize = clampCross(innerCross - marginCross(item.props, horizontal), item.props, horizontal);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
#placeItems(
|
|
260
|
-
items: LayoutItem[],
|
|
261
|
-
containerMain: number,
|
|
262
|
-
paddingMainStart: number,
|
|
263
|
-
paddingMainEnd: number,
|
|
264
|
-
paddingCrossStart: number,
|
|
265
|
-
innerCross: number,
|
|
266
|
-
horizontal: boolean,
|
|
267
|
-
) {
|
|
268
|
-
const usedMain = items.reduce((sum, item) => sum + item.mainSize + marginMain(item.props, horizontal), 0);
|
|
269
|
-
const remaining = Math.max(0, containerMain - paddingMainStart - paddingMainEnd - usedMain - this.#gap * Math.max(0, items.length - 1));
|
|
270
|
-
const actualGap = this.#justify === 'space-between' && items.length > 1
|
|
271
|
-
? this.#gap + remaining / (items.length - 1)
|
|
272
|
-
: this.#gap;
|
|
273
|
-
let cursor = paddingMainStart + justifyOffset(this.#justify, remaining);
|
|
274
|
-
|
|
275
|
-
for (const item of items) {
|
|
276
|
-
const mainStartMargin = horizontal ? item.props.marginLeft : item.props.marginTop;
|
|
277
|
-
const mainEndMargin = horizontal ? item.props.marginRight : item.props.marginBottom;
|
|
278
|
-
const crossStartMargin = horizontal ? item.props.marginTop : item.props.marginLeft;
|
|
279
|
-
const crossEndMargin = horizontal ? item.props.marginBottom : item.props.marginRight;
|
|
280
|
-
const alignSelf = item.props.alignSelf === 'auto' ? this.#align : item.props.alignSelf;
|
|
281
|
-
const crossFree = Math.max(0, innerCross - item.crossSize - crossStartMargin - crossEndMargin);
|
|
282
|
-
const main = cursor + mainStartMargin;
|
|
283
|
-
const cross = paddingCrossStart + crossStartMargin + alignOffset(alignSelf, crossFree);
|
|
284
|
-
const x = horizontal ? main : cross;
|
|
285
|
-
const y = horizontal ? cross : main;
|
|
286
|
-
const width = horizontal ? item.mainSize : item.crossSize;
|
|
287
|
-
const height = horizontal ? item.crossSize : item.mainSize;
|
|
288
|
-
|
|
289
|
-
setChildBox(item.child, x, y, width, height);
|
|
290
|
-
cursor = main + item.mainSize + mainEndMargin + actualGap;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
#rememberBaseSize(child: LayoutChild) {
|
|
295
|
-
if (!this.#baseSizes.has(child)) {
|
|
296
|
-
this.#baseSizes.set(child, {
|
|
297
|
-
width: child.width,
|
|
298
|
-
height: child.height,
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
#naturalSize(child: LayoutChild): Size {
|
|
304
|
-
const measured = child.measureControlNaturalSize?.();
|
|
305
|
-
if (measured) {
|
|
306
|
-
return measured;
|
|
307
|
-
}
|
|
308
|
-
return this.#baseSizes.get(child) ?? { width: child.width, height: child.height };
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
const defaultItemProps: FlexItemLayoutProps = {
|
|
313
|
-
grow: 0,
|
|
314
|
-
shrink: 1,
|
|
315
|
-
basis: 'auto',
|
|
316
|
-
minWidth: 0,
|
|
317
|
-
minHeight: 0,
|
|
318
|
-
maxWidth: -1,
|
|
319
|
-
maxHeight: -1,
|
|
320
|
-
marginLeft: 0,
|
|
321
|
-
marginRight: 0,
|
|
322
|
-
marginTop: 0,
|
|
323
|
-
marginBottom: 0,
|
|
324
|
-
alignSelf: 'auto',
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
function setChildBox(child: LayoutChild, x: number, y: number, width: number, height: number) {
|
|
328
|
-
if (child.setControlLayoutBox) {
|
|
329
|
-
child.setControlLayoutBox(x, y, width, height);
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
child.position.set(x, y);
|
|
333
|
-
child.width = width;
|
|
334
|
-
child.height = height;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
function marginMain(props: FlexItemLayoutProps, horizontal: boolean) {
|
|
338
|
-
return horizontal
|
|
339
|
-
? props.marginLeft + props.marginRight
|
|
340
|
-
: props.marginTop + props.marginBottom;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
function marginCross(props: FlexItemLayoutProps, horizontal: boolean) {
|
|
344
|
-
return horizontal
|
|
345
|
-
? props.marginTop + props.marginBottom
|
|
346
|
-
: props.marginLeft + props.marginRight;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
function clampMain(value: number, props: FlexItemLayoutProps, horizontal: boolean) {
|
|
350
|
-
return horizontal
|
|
351
|
-
? clamp(value, props.minWidth, maxSize(props.maxWidth))
|
|
352
|
-
: clamp(value, props.minHeight, maxSize(props.maxHeight));
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
function clampCross(value: number, props: FlexItemLayoutProps, horizontal: boolean) {
|
|
356
|
-
return horizontal
|
|
357
|
-
? clamp(value, props.minHeight, maxSize(props.maxHeight))
|
|
358
|
-
: clamp(value, props.minWidth, maxSize(props.maxWidth));
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
function basisSize(basis: FlexBasis, naturalSize: number) {
|
|
362
|
-
return basis === 'auto' ? naturalSize : basis;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
function maxSize(value: number) {
|
|
366
|
-
return value >= 0 ? value : Number.POSITIVE_INFINITY;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
function clamp(value: number, min: number, max: number) {
|
|
370
|
-
return Math.min(max, Math.max(min, value));
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
function justifyOffset(justify: FlexJustify, remaining: number) {
|
|
374
|
-
if (justify === 'center') {
|
|
375
|
-
return remaining / 2;
|
|
376
|
-
}
|
|
377
|
-
if (justify === 'end') {
|
|
378
|
-
return remaining;
|
|
379
|
-
}
|
|
380
|
-
return 0;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
function alignOffset(align: FlexAlign | FlexAlignSelf, remaining: number) {
|
|
384
|
-
if (align === 'center') {
|
|
385
|
-
return remaining / 2;
|
|
386
|
-
}
|
|
387
|
-
if (align === 'end') {
|
|
388
|
-
return remaining;
|
|
389
|
-
}
|
|
390
|
-
return 0;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
function parseAlign(value: string): FlexAlign {
|
|
394
|
-
if (value === 'center' || value === 'end' || value === 'stretch') {
|
|
395
|
-
return value;
|
|
396
|
-
}
|
|
397
|
-
return 'start';
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
function parseJustify(value: string): FlexJustify {
|
|
401
|
-
if (value === 'center' || value === 'end' || value === 'space-between') {
|
|
402
|
-
return value;
|
|
403
|
-
}
|
|
404
|
-
return 'start';
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
function finiteNumber(value: number, fallback: number) {
|
|
408
|
-
return Number.isFinite(value) ? value : fallback;
|
|
409
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Container } from 'pixi.js';
|
|
2
|
-
import { Control } from './Control.js';
|
|
3
|
-
import { type Size } from './controlLayout.js';
|
|
4
|
-
export declare class HBoxContainer extends Control {
|
|
5
|
-
#private;
|
|
6
|
-
readonly default: Container;
|
|
7
|
-
get gap(): number;
|
|
8
|
-
set gap(value: number);
|
|
9
|
-
get alignY(): string;
|
|
10
|
-
set alignY(value: string);
|
|
11
|
-
get justify(): string;
|
|
12
|
-
set justify(value: string);
|
|
13
|
-
layout(): void;
|
|
14
|
-
measureControlNaturalSize(): Size;
|
|
15
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { prop, scene, slot } from 'pixifact/compiler';
|
|
8
|
-
import { Control } from './Control.js';
|
|
9
|
-
import { finiteNumber, layoutStack, measureStackNaturalSize, parseAlign, parseJustify, } from './controlLayout.js';
|
|
10
|
-
let HBoxContainer = class HBoxContainer extends Control {
|
|
11
|
-
#gap = 0;
|
|
12
|
-
#alignY = 'start';
|
|
13
|
-
#justify = 'start';
|
|
14
|
-
#baseSizes = new WeakMap();
|
|
15
|
-
get gap() {
|
|
16
|
-
return this.#gap;
|
|
17
|
-
}
|
|
18
|
-
set gap(value) {
|
|
19
|
-
this.#gap = Math.max(0, finiteNumber(value, 0));
|
|
20
|
-
this.refreshControlLayout();
|
|
21
|
-
}
|
|
22
|
-
get alignY() {
|
|
23
|
-
return this.#alignY;
|
|
24
|
-
}
|
|
25
|
-
set alignY(value) {
|
|
26
|
-
this.#alignY = parseAlign(value);
|
|
27
|
-
this.layout();
|
|
28
|
-
}
|
|
29
|
-
get justify() {
|
|
30
|
-
return this.#justify;
|
|
31
|
-
}
|
|
32
|
-
set justify(value) {
|
|
33
|
-
this.#justify = parseJustify(value);
|
|
34
|
-
this.layout();
|
|
35
|
-
}
|
|
36
|
-
layout() {
|
|
37
|
-
this.syncControlBoxSize();
|
|
38
|
-
const assigned = this.getAssignedControlBoxSize();
|
|
39
|
-
layoutStack({
|
|
40
|
-
axis: 'horizontal',
|
|
41
|
-
children: this.default?.children,
|
|
42
|
-
gap: this.#gap,
|
|
43
|
-
alignCross: this.#alignY,
|
|
44
|
-
justify: this.#justify,
|
|
45
|
-
baseSizes: this.#baseSizes,
|
|
46
|
-
width: assigned.width,
|
|
47
|
-
height: assigned.height,
|
|
48
|
-
naturalSize: () => this.measureControlNaturalSize(),
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
measureControlNaturalSize() {
|
|
52
|
-
return measureStackNaturalSize('horizontal', this.default?.children, this.#gap, this.#baseSizes);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
__decorate([
|
|
56
|
-
slot()
|
|
57
|
-
], HBoxContainer.prototype, "default", void 0);
|
|
58
|
-
__decorate([
|
|
59
|
-
prop({ type: Number, default: 0 })
|
|
60
|
-
], HBoxContainer.prototype, "gap", null);
|
|
61
|
-
__decorate([
|
|
62
|
-
prop({ type: String, default: 'start' })
|
|
63
|
-
], HBoxContainer.prototype, "alignY", null);
|
|
64
|
-
__decorate([
|
|
65
|
-
prop({ type: String, default: 'start' })
|
|
66
|
-
], HBoxContainer.prototype, "justify", null);
|
|
67
|
-
HBoxContainer = __decorate([
|
|
68
|
-
scene()
|
|
69
|
-
], HBoxContainer);
|
|
70
|
-
export { HBoxContainer };
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { Container } from 'pixi.js';
|
|
2
|
-
import { prop, scene, slot } from 'pixifact/compiler';
|
|
3
|
-
import { Control } from './Control';
|
|
4
|
-
import {
|
|
5
|
-
finiteNumber,
|
|
6
|
-
layoutStack,
|
|
7
|
-
measureStackNaturalSize,
|
|
8
|
-
parseAlign,
|
|
9
|
-
parseJustify,
|
|
10
|
-
type ControlAlign,
|
|
11
|
-
type ControlJustify,
|
|
12
|
-
type ControlLayoutChild,
|
|
13
|
-
type Size,
|
|
14
|
-
} from './controlLayout';
|
|
15
|
-
|
|
16
|
-
@scene()
|
|
17
|
-
export class HBoxContainer extends Control {
|
|
18
|
-
@slot()
|
|
19
|
-
declare readonly default: Container;
|
|
20
|
-
|
|
21
|
-
#gap = 0;
|
|
22
|
-
#alignY: ControlAlign = 'start';
|
|
23
|
-
#justify: ControlJustify = 'start';
|
|
24
|
-
#baseSizes = new WeakMap<object, Size>();
|
|
25
|
-
|
|
26
|
-
get gap() {
|
|
27
|
-
return this.#gap;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
@prop({ type: Number, default: 0 })
|
|
31
|
-
set gap(value: number) {
|
|
32
|
-
this.#gap = Math.max(0, finiteNumber(value, 0));
|
|
33
|
-
this.refreshControlLayout();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
get alignY() {
|
|
37
|
-
return this.#alignY;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
@prop({ type: String, default: 'start' })
|
|
41
|
-
set alignY(value: string) {
|
|
42
|
-
this.#alignY = parseAlign(value);
|
|
43
|
-
this.layout();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
get justify() {
|
|
47
|
-
return this.#justify;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
@prop({ type: String, default: 'start' })
|
|
51
|
-
set justify(value: string) {
|
|
52
|
-
this.#justify = parseJustify(value);
|
|
53
|
-
this.layout();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
override layout() {
|
|
57
|
-
this.syncControlBoxSize();
|
|
58
|
-
const assigned = this.getAssignedControlBoxSize();
|
|
59
|
-
layoutStack({
|
|
60
|
-
axis: 'horizontal',
|
|
61
|
-
children: this.default?.children as ControlLayoutChild[] | undefined,
|
|
62
|
-
gap: this.#gap,
|
|
63
|
-
alignCross: this.#alignY,
|
|
64
|
-
justify: this.#justify,
|
|
65
|
-
baseSizes: this.#baseSizes,
|
|
66
|
-
width: assigned.width,
|
|
67
|
-
height: assigned.height,
|
|
68
|
-
naturalSize: () => this.measureControlNaturalSize(),
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
override measureControlNaturalSize(): Size {
|
|
73
|
-
return measureStackNaturalSize('horizontal', this.default?.children as ControlLayoutChild[] | undefined, this.#gap, this.#baseSizes);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Container } from 'pixi.js';
|
|
2
|
-
import { Control } from './Control.js';
|
|
3
|
-
import { type Size } from './controlLayout.js';
|
|
4
|
-
export declare class MarginContainer extends Control {
|
|
5
|
-
#private;
|
|
6
|
-
readonly default: Container;
|
|
7
|
-
get margin(): number;
|
|
8
|
-
set margin(value: number);
|
|
9
|
-
get marginLeft(): number;
|
|
10
|
-
set marginLeft(value: number);
|
|
11
|
-
get marginRight(): number;
|
|
12
|
-
set marginRight(value: number);
|
|
13
|
-
get marginTop(): number;
|
|
14
|
-
set marginTop(value: number);
|
|
15
|
-
get marginBottom(): number;
|
|
16
|
-
set marginBottom(value: number);
|
|
17
|
-
get alignX(): string;
|
|
18
|
-
set alignX(value: string);
|
|
19
|
-
get alignY(): string;
|
|
20
|
-
set alignY(value: string);
|
|
21
|
-
layout(): void;
|
|
22
|
-
measureControlNaturalSize(): Size;
|
|
23
|
-
}
|