Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to set position to the center of the screen? #317

Open
Aukstkalnis opened this issue Jan 23, 2024 · 4 comments
Open

Question: How to set position to the center of the screen? #317

Aukstkalnis opened this issue Jan 23, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@Aukstkalnis
Copy link

Hi. I want to set window to the center of my screen. How do I do it? There is no current method to get total of the current screen and there is no method to set in directly to the center. I only have SetPosition method.

I am using Go programing language and fedora 39 OS.

@jinzhongjia
Copy link
Contributor

jinzhongjia commented Jan 23, 2024

mayebe you can use js api screen.width screen.height or screen.availWidth or screen.availHeight to get screent size
then you can get browser size
Then we can get x and y after a small amount of calculations
This is just a solution I proposed, I have not tested whether it is feasible

@AlbertShown
Copy link
Contributor

Try this:

function centerWindow() {
    const screenWidth = screen.width;
    const screenHeight = screen.height;
    const width = window.outerWidth;
    const height = window.outerHeight;
    const centerX = (screenWidth - width) / 2;
    const centerY = (screenHeight - height) / 2;
    window.moveTo(centerX, centerY);
}

centerWindow();

@Aukstkalnis
Copy link
Author

It kinda works but I can see the change in position. I guess we can close this issue, but can be feature for the future to implement functions get position, monitor size, mult-imonitor positioning. etc.. Anyway, thanks :)

@AlbertShown
Copy link
Contributor

webui is not like the other GUI libraries, a webui window is a web browser window, so just let the browser handle the size and position. If you still want to to get the current window info just use JavaScript, example run JS from your backend:

"return window.outerWidth;"
"return window.outerHeight;"

@hassandraga hassandraga added the enhancement New feature or request label May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants