|
| 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 | +} |
0 commit comments