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

Is there a way to resize a window? #590

Open
Wertzui123 opened this issue Dec 8, 2021 · 10 comments
Open

Is there a way to resize a window? #590

Wertzui123 opened this issue Dec 8, 2021 · 10 comments

Comments

@Wertzui123
Copy link
Contributor

Hello,
I've noticed that it is possible to specify a size when a window is created, but I can't find a function to change it later.
Have I missed something or is this currently not possible?

@floooh
Copy link
Owner

floooh commented Dec 8, 2021

Nope that's currently not possible, mainly because this doesn't make sense in browsers and on mobile platforms.

I had started to add more window functions in a WIP multiwindow-branch (which stalled because of various problems on macOS), but it might make sense to move at least those functions over into the main branch (with the setter functions being empty stubs on platforms where programmatic resizing doesn't make sense).

sokol/sokol_app.h

Lines 1497 to 1521 in 57688eb

/* set client rect size in logical 'window system pixels' */
SOKOL_APP_API_DECL void sapp_set_client_size(int width, int height);
/* same as sapp_set_client_size(), but with float parameters */
SOKOL_APP_API_DECL void sapp_set_client_sizef(float width, float height);
/* get client rect width in logical 'window system pixels' */
SOKOL_APP_API_DECL int sapp_client_width(void);
/* same as sapp_client_width() but returns float */
SOKOL_APP_API_DECL float sapp_client_widthf(void);
/* get client rect height in logical 'window system pixels' */
SOKOL_APP_API_DECL int sapp_client_height(void);
/* same as sapp_client_height() but returns float */
SOKOL_APP_API_DECL float sapp_client_heightf(void);
/* set client rect position in logical 'window system pixels' */
SOKOL_APP_API_DECL void sapp_set_client_pos(int x, int y);
/* same as sapp_set_client_pos(), but with float parameters */
SOKOL_APP_API_DECL void sapp_set_client_posf(float x, float y);
/* get client rect horizontal position in logical 'window system pixels' */
SOKOL_APP_API_DECL int sapp_client_posx(void);
/* same as sapp_client_posx(), but returns float */
SOKOL_APP_API_DECL float sapp_client_posxf(void);
/* get client rect vertical position in logical 'window system pixels' */
SOKOL_APP_API_DECL int sapp_client_posy(void);
/* same as sapp_client_posy(), but returns float */
SOKOL_APP_API_DECL float sapp_client_posyf(void);

@Wertzui123
Copy link
Contributor Author

I'd love to see this in the main branch.

Do you plan to continue the multiwindow branch in the near future? This is something I'm really looking forward to.

And by the way, thanks for this awesome library.

@floooh
Copy link
Owner

floooh commented Dec 8, 2021

Do you plan to continue the multiwindow branch in the near future?

I don't know yet, on macOS I was hitting a wall that the whole application is blocked for around a second if one window becomes obscured. A workaround would probably require to run each window in its own thread. The next big feature will probably be finishing the WebGPU support in sokol_gfx.h and sokol_app.h.

@Wertzui123
Copy link
Contributor Author

A workaround would probably require to run each window in its own thread

I think this would make sense anyway.

The next big feature will probably be finishing the WebGPU support in sokol_gfx.h and sokol_app.h.

Sounds interesting!

@meshula
Copy link

meshula commented Dec 23, 2021

fwiw, this pr ocornut/imgui#4821 claims to address an issue in dear imgui that involves imgui suspending when a window is obscured on mac. wonder if there's any clues in there that might help here.

"✅ Fix a performance / hang issue when a window is completely occluded, which resulted in nextDrawable hanging for about 1 second, causing ImGui to become unresponsive"

exactly the same maybe?

@floooh
Copy link
Owner

floooh commented Dec 23, 2021

Oh, interesting. Yes this sounds like exactly the same issue I've been seeing. Thanks for pinging me!

@stuartcarnie
Copy link

@floooh if the CAMetalLayer is completely occluded by another window, nextDrawable hangs. I resolved it by the following:

https://github.com/ocornut/imgui/blob/b685b625c302c0cb1844e0155e0a4fbb4b3d967b/backends/imgui_impl_metal.mm#L246-L253

@floooh
Copy link
Owner

floooh commented Dec 24, 2021

Thanks @stuartcarnie, I need to try this :) IFIR I had checked the occlusionState member before but found that this triggers too late, but maybe I did something wrong there.

@edubart
Copy link
Contributor

edubart commented Sep 18, 2023

+1 for window resize method

mainly because this doesn't make sense in browsers and on mobile platforms.

Actually I was needing such feature in the browser, that is, to change the canvas size at runtime, so I think it makes sense in the browser. My workaround at the moment is to resize canvas using JS code.

@lou256
Copy link

lou256 commented Nov 28, 2023

Has anyone developed a branch with this functionality? theres working code here for mac os:
> https://github.com/floooh/sokol/blob/57688eb0c5d09f6149ae6a612c5b53a56e94c328/sokol_app.h#L1497-L1521

I've been trying to hack it in for windows but its kind of finicky

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants