{"size": 1375, "ext": "js", "max_stars_repo_path": "src/platform/lumin-runtime/elements/builders/layout-builder.js", "max_stars_repo_name": "magic-script/magic-script-components-lumin", "max_stars_repo_stars_event_min_datetime": "2019-09-11T06:03:52.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-11T13:35:29.000Z", "max_issues_repo_path": "src/platform/lumin-runtime/elements/builders/layout-builder.js", "max_issues_repo_name": "magic-script/magic-script-components-lumin", "max_issues_repo_issues_event_min_datetime": "2019-09-13T08:07:18.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-09T12:48:13.000Z", "max_forks_repo_path": "src/platform/lumin-runtime/elements/builders/layout-builder.js", "max_forks_repo_name": "magic-script/magic-script-components-lumin", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 35, "max_forks_count": null, "avg_line_length": 29.2553191489, "max_line_length": 74, "alphanum_fraction": 0.616}
// Copyright (c) 2019 Magic Leap, Inc. All Rights Reserved

import { UiNodeBuilder } from './ui-node-builder.js';
import { PropertyDescriptor } from '../properties/property-descriptor.js';

export class LayoutBuilder extends UiNodeBuilder {

    update(element, oldProperties, newProperties) {
        super.update(element, oldProperties, newProperties);

        this._validateSize(newProperties);
        this._setSize(element, newProperties);
    }

    validate(element, oldProperties, newProperties) {
        super.validate(element, oldProperties, newProperties);

        this._validateSize(newProperties);
    }

    _validateSize(properties) {
        PropertyDescriptor.throwIfNotTypeOf(properties.height, 'number');
        PropertyDescriptor.throwIfNotTypeOf(properties.width, 'number');
    }

    _setSize(element, properties) {
        let { height, width } = properties;

        if (width || height) {
            if (width === undefined) {
                width = this._callNodeFunction(element, 'getSize')[0];
            }

            if (height === undefined) {
                height = this._callNodeFunction(element, 'getSize')[1];
            }

            this._callNodeAction(element, 'setSize', [width, height]);
        }
    }

    extraTypeScript() {
        return  '    width?: number;\n' +
                '    height?: number;\n';
    }

}