简体   繁体   English

AIR - 将NativeWindow的大小设置为包括系统镶边

[英]AIR - set size of NativeWindow to include system chrome

How do you find out the size of the system chrome so that I can specify the window size to achieve the stage size I want? 你如何找出系统chrome的大小,以便我可以指定窗口大小来达到我想要的舞台大小?

If my main window is set at 800 x 600 (stage), and I create a second window as below, it will be smaller. 如果我的主窗口设置为800 x 600(阶段),并且我创建了如下的第二个窗口,它将更小。

public function Main():void 
{
    var windowOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
    windowOptions.systemChrome = NativeWindowSystemChrome.STANDARD;
    windowOptions.type = NativeWindowType.NORMAL;
    var newWindow:NativeWindow = new NativeWindow( windowOptions );
    newWindow.width = 800;
    newWindow.height = 600;
    newWindow.stage.scaleMode = StageScaleMode.NO_SCALE;
    newWindow.stage.align = StageAlign.TOP_LEFT;
    newWindow.activate();

}

I assume you increase both newWindow.width = 800; 我假设你增加newWindow.width = 800; and newWindow.height = 600; newWindow.height = 600; to account for the chrome, but how do you find this value? 考虑到铬,但你如何找到这个价值?

you can calculate the size of the chrome by substracting the windows size (that include the chrome) with the inner size (that exclude the chrome). 您可以通过减小内部大小(不包括镶边)的窗口大小(包括镶边)来计算镶边的大小。

From the width help of NativeWindows : 从NativeWindows的宽度帮助:

The dimensions reported for a native window include any system window chrome that is displayed. 为本机窗口报告的维度包括显示的任何系统窗口镶边。 The width of the usable display area inside a window is available from the Stage.stageWidth property. 窗口内可用显示区域的宽度可从Stage.stageWidth属性获得。

So the inner size can be obtained with stage object ( stage.stageWidth and stage.stageHeight: ) 因此可以使用stage对象获取内部大小(stage.stageWidth和stage.stageHeight:)

hence : 因此:

var chromeWidth=newWindow.width-newWindow.stage.stageWidth;
var chromeHeight=newWindow.height-newWindow.stage.stageHeight;

When creating ActionScript projects with NO_SCALE the stage.stageHeight and stage.stageWidth cannot be used to calculate chrome in the main application window as they do not resize to conform to the inner width. 使用NO_SCALE创建ActionScript项目时,stage.stageHeight和stage.stageWidth不能用于在主应用程序窗口中计算chrome,因为它们不会调整大小以符合内部宽度。 You must reference the main window stage. 您必须引用主窗口阶段。

To find the main windows inner stage height and width you can use the stage.nativeWindow.stage references stageHeight and stageWidth properties which gives inner width. 要查找主窗口内部舞台高度和宽度,可以使用stage.nativeWindow.stage引用stageHeight和stageWidth属性,它们提供内部宽度。

eg for a 1280x720 desired inner size: 例如,对于1280x720所需的内部尺寸:

// width stage.nativeWindow.width = 1280 + (stage.nativeWindow.width -
stage.nativeWindow.stage.stageWidth);

// height stage.nativeWindow.height = 720 + (stage.nativeWindow.height
- stage.nativeWindow.stage.stageHeight);

For reference, as I feel the other answers aren't clear enough. 作为参考,我觉得其他答案还不够清楚。 To set a new window to the desired dimensions: 要将新窗口设置为所需的尺寸:

// first set the desired window dimensions to set the (smaller) stage dimensions:
newWindow.width = 1024;
newWindow.height = 768;

// then reset the window dimensions and add chrome dimensions:
newWindow.width = 1024 + (1024 - newWindow.stage.stageWidth);
newWindow.height = 768 + (768 - newWindow.stage.stageHeight);   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM