Skip to content

Commit a0645f5

Browse files
Implement scaleX and scaleY node properties (#74)
I've extracted this from my work on font scaling (as part of #35). Resolves #73
2 parents 6e9dc53 + 3c475eb commit a0645f5

File tree

19 files changed

+625
-50
lines changed

19 files changed

+625
-50
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* If not stated otherwise in this file or this component's LICENSE file the
3+
* following copyright and licenses apply:
4+
*
5+
* Copyright 2023 Comcast Cable Communications Management, LLC.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the License);
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
import type { INode, RendererMain } from '../../dist/exports/main-api.js';
21+
import { waitForTextDimensions } from './utils.js';
22+
23+
const SQUARE_SIZE = 200;
24+
const PADDING = 20;
25+
26+
export async function constructTestRow(
27+
renderer: RendererMain,
28+
rowNode: INode,
29+
testNodes: (INode | string)[],
30+
): Promise<number> {
31+
let curX = 0;
32+
const curY = 0;
33+
for (const testNode of testNodes) {
34+
if (typeof testNode === 'string') {
35+
const dimensions = await waitForTextDimensions(
36+
renderer.createTextNode({
37+
mount: 0.5,
38+
x: curX,
39+
y: SQUARE_SIZE / 2,
40+
text: testNode,
41+
parent: rowNode,
42+
}),
43+
);
44+
curX += dimensions.width + PADDING;
45+
} else {
46+
const container = renderer.createNode({
47+
parent: rowNode,
48+
color: 0xffffffff,
49+
width: SQUARE_SIZE,
50+
height: SQUARE_SIZE,
51+
clipping: true,
52+
x: curX,
53+
y: curY,
54+
});
55+
testNode.parent = container;
56+
curX += SQUARE_SIZE + PADDING;
57+
}
58+
}
59+
return curY + SQUARE_SIZE;
60+
}
File renamed without changes.

0 commit comments

Comments
 (0)