electron子窗口相对于父窗口垂直水平居中

652 阅读1分钟
  之前一直认为electron父子窗口坐标位置是用getPosition()获取,后来发现不是的.

踩坑代码来源于csdn上的一个博客,好歹给了思路,我就不方便贴地址了。直接上代码吧。
`
//封装一个方法实现  electron中有一个getBounds获取窗口属性的方法,需要传入父子窗口对象
getCenterPosition(parentWin,sonWin){
    let {x:topX,y:topY,width:topWidth,height:topHeight}=parentWin.getBounds();
    let {width:sonWidth,height:sonHeight}=sonWin.getBounds();
    let x=topX +(topWidth-sonWidth) / 2 ;
    let y=topY +(topHeight-sonHeight) / 2;
    //设置位置这里electron是setPosition()设置的
    sonWin.setPosition(parseInt(x),parseInt(y),false)
    sonWin.show();
}

`