Products
Technologies

Developer resources

How to keep the application contents dimensions the same on OS with different window chrome

Avg. Rating 4.0

Problem

You have an application with a window having a fixed width. You design the interface with great care only to see that on another operations system than the one you used for development the application has scrolls all over the window

Solution

You have to determine at run time the margin between the application window and the NativeWindow.stage dimensions. That's the space lost for the window chrome

Detailed explanation

In an AIR application the stage is supposed to take all the space in the window.

Apparently everything else that takes up space out of the NativeWindow's bounds is the window's chrome. (Or alsmost everything)

Here's a short code that'll help you keep the size of your window consistent in windows with different chrome.

            resizeWindowTo(200,200);
           
            function resizeWindowTo(initWidth, initHeight){
                //hide the window
                window.nativeWindow.visible = false;
               
                //give some margin to windows
                if (air.Capabilities.os.match(/windows/))
                    initHeight += 5;
               
                //set the window dimensions
                window.nativeWindow.width = initWidth;
                window.nativeWindow.height = initHeight;
               
                //now resize the window to dimensinos to fit the chrome
                window.nativeWindow.height = initHeight + (window.nativeWindow.height - window.nativeWindow.stage.stageHeight);
                window.nativeWindow.width = initWidth + (window.nativeWindow.width - window.nativeWindow.stage.stageWidth);
               
                //show the window
                window.nativeWindow.visible = true;
            }

You might prefer to set your application to open it's window invisible at first and then run the resizeWindowTo function to resize it and show it.

As you can see there's a not very elegant solution which adds 5px margin on Windows, well .. after some testing it seems that there are few pixels coming from something which is not the chrome or the stage on Windows ... 5px will keep you safe on Windows XP default theme, which is (in my humble opinion) the biggest chrome an OS should have at all.

If you find a better solution for the Windows issue - please post it online


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes