os-gui icon indicating copy to clipboard operation
os-gui copied to clipboard

setting window position

Open 909oce opened this issue 1 year ago • 4 comments

hi, im having some trouble and hoping someone more knowledge might be able to help.

i know that we have center(); to set a window to be centered, however im trying to set a window to be next to another one on creation.

using css left: 500 during creation doesnt work as that doesnt take the browser size into account and causes varying results.

is there some way to do this that im not seeing? thanks

909oce avatar Mar 20 '24 18:03 909oce

I'd be happy to help, but I need more details.

  • What does your code look like?
  • What exactly are you trying to achieve overall?
  • How do you want to take the browser size into account, and what is happening instead?

Screenshots/mockups might help to explain.

1j01 avatar Mar 30 '24 23:03 1j01

Could you send me a message on Discord? I think it would be easier to screenshare my project and explain it rather than write it all out here.

Discord: 909oce

909oce avatar Apr 01 '24 21:04 909oce

Hello, how did you get window positioning to work? Like you stated, using position: absolute and left: 500px in the style tags do not cause the windows to spawn in that position, still spawning in the center.

JoshDoesStuff avatar May 09 '24 22:05 JoshDoesStuff

@JoshDoesStuff There's no API specifically for positioning windows currently.

The way to do it right now is to use jQuery's .css() method, or otherwise setting inline styles. For example:

$win.css({ left: 500, top: 200 });

Styles defined in a stylesheet will not apply (without !important) as inline styles will override them, and the windows have inline styles by default for left and top.

This topic definitely deserves documentation, regardless of whether there's an API for it or not, and a helper method might be nice.

Also, note that the $Window API is returning a jQuery object extended with additional methods and properties. This was a really bad decision I made 10 years ago when I was a kid, and didn't know about the benefits of composition over inheritance (or that jQuery would become less useful over time). I have already converted the $MenuBar class into a MenuBar class, removing the dependency on jQuery, and I plan to do the same for $Window, although I won't be able to name it Window, as that's a built-in DOM API. I'll probably add a prefix.

1j01 avatar May 17 '24 20:05 1j01

I added a section to the docs about positioning windows.

1j01 avatar May 29 '24 20:05 1j01