为什么 win.setPosition('center') 将 window 移到左上角?

Why does win.setPosition('center') move the window to top-left?

我有这段代码,我在将全屏从全屏切换回 windowed 模式后执行:

win.setPosition('center');

window 一直出现在屏幕的左上角 -- 而不是中间。

http://docs.nwjs.io/en/latest/References/Window/#winsetpositionposition 处的手册声明:

position {String} the position of the window. There are three valid positions: null or center or mouse Move window to specified position. Currently only center is supported on all platforms, which will put window in the middle of the screen.

我尝试了引用和未引用的“center”,甚至尝试了“center”,以防它是手册中的错字。

郑重声明,“鼠标”值(我没有 want/need)也不起作用;它似乎把 window 放在一个随机或半随机的地方,远离光标。

Windows10.nwjs-v0.61.0-win-x64.

确保您正在创建如下所示的 win 变量:

<script>
const win = nw.Window.get();

// Move window to top left of screen
win.moveTo(0, 0);

// Move window to middle of screen
win.setPosition('center');

// Manually move window to middle of screen
const screen = nw.Screens.screen[0].bounds;
const x = Math.floor((screen.width - win.width) / 2);
const y = Math.floor((screen.height - win.height) / 2);
win.moveTo(x, y);
</script>

如果您想将显示器移动到其他位置,可以使用 nw.Screen.screens 查看所有显示器的尺寸。