async function newWindowButton_click()

in archived/LineDisplay/js/js/scenario3-usingWindows.js [105:175]


    async function newWindowButton_click() {
        if (SdkSample.Scenario3.windowList.length >= maxWindows) {
            WinJS.log(`Too many windows created. The line display only supports ${maxWindows} windows.`, "sample", "error");
            return;
        }

        var viewportBounds = {
            x: SdkSample.parseIntWithFallback(viewportBoundsXTextbox, -1),
            y: SdkSample.parseIntWithFallback(viewportBoundsYTextbox, -1),
            width: SdkSample.parseIntWithFallback(viewportBoundsWidthTextbox, 0),
            height: SdkSample.parseIntWithFallback(viewportBoundsHeightTextbox, 0)
        };

        if ((viewportBounds.width <= 0) || (viewportBounds.height <= 0)) {
            WinJS.log("Viewport size must be be positive.", "sample", "error");
            return;
        }

        // Viewport cannot extend beyond the screen.
        var screenSizeInCharacters = lineDisplay.getAttributes().screenSizeInCharacters;
        if ((viewportBounds.x < 0) || (viewportBounds.y < 0) ||
            (viewportBounds.x + viewportBounds.width > screenSizeInCharacters.width) ||
            (viewportBounds.y + viewportBounds.height > screenSizeInCharacters.height)) {
            WinJS.log("Viewport cannot extend beyond the screen.", "sample", "error");
            return;
        }

        var windowSize = {
            width: SdkSample.parseIntWithFallback(windowWidthTextbox, 0),
            height: SdkSample.parseIntWithFallback(windowHeightTextbox, 0)
        };

        if ((windowSize.width <= 0) || (windowSize.height <= 0)) {
            WinJS.log("Window size must be be positive.", "sample", "error");
            return;
        }

        // Windows must be at least as large as their viewports.
        if ((viewportBounds.width > windowSize.width) || (viewportBounds.height > windowSize.height)) {
            WinJS.log("Window must be at least as large as viewport.", "sample", "error");
            return;
        }

        // Window taller than viewport requires IsVerticalMarqueeSupported.
        if ((windowSize.height > viewportBounds.height) && !lineDisplay.capabilities.isVerticalMarqueeSupported) {
            WinJS.log("Window cannot be taller than viewport on this line display.", "sample", "error");
            return;
        }

        // Window wider than viewport requires IsHorizontalMarqueeSupported.
        if ((windowSize.width > viewportBounds.width) && !lineDisplay.capabilities.isHorizontalMarqueeSupported) {
            WinJS.log("Window cannot be wider than viewport on this line display.", "sample", "error");
            return;
        }

        // Window cannot be larger than viewport in both directions.
        // (Two-dimensional scrolling is not supported.)
        if ((windowSize.width > viewportBounds.width) && (windowSize.height > viewportBounds.height)) {
            WinJS.log("Window cannot be larger than viewport in both dimensions.", "sample", "error");
            return;
        }

        var displayWindow = await lineDisplay.tryCreateWindowAsync(viewportBounds, windowSize);
        if (displayWindow) {
            var newWindowInfo = addWindowToList(displayWindow);
            WinJS.log(`Created window ${newWindowInfo.id}.`, "sample", "status");
        } else {
            // We probably lost our claim.
            WinJS.log("Failed to create a new window.", "sample", "error");
        }
    }