How to center NeutralinoJS screen

225 views Asked by At

Using NeutralinoJS, how can start the app right in the center of the screen?

It should look like the splashscreen of any app. Unlike ElectronJS, Neutralino's window options doesn't seem to have a center() method.

1

There are 1 answers

0
Ashutosh Jha On BEST ANSWER

I made a simple javascript function by using native API of neutralionJS. Used Neutralino.computer.getDisplays() to height & width of the screen along with Neutralino.window.getSize() to height & width of the window and Neutralino.window.move(x,y) to center it. Note: x,y is the coordinates of the top right corner of the window. For a better explaination I have also attested a img demostrating it.

async function centerWindow(){
    
    let display  = await Neutralino.computer.getDisplays();
    const displayHeight = display[0].resolution.height;
    const displayWidth = display[0].resolution.width;

    let window = await Neutralino.window.getSize();
    const windowHeight = window.height;
    const windowWidth = window.width;

    const x = (displayWidth - windowWidth) / 2;
    const y = (displayHeight - windowHeight) / 2;

    Neutralino.window.move(x,y);

}

centerWindow();

Image link

The black dot is actual center of screen, red dot is where Neutralino.window.move(x,y) takes you too.