rxi / microui

A tiny immediate-mode UI library
MIT License
3.29k stars 239 forks source link

How can you resize microui window dynamically? #32

Closed tomaszte closed 4 years ago

tomaszte commented 4 years ago

Hi, I want to resize microui window when whole SDL2 window is resized.

basically I'd expect code below to work, but microui window size stays the same. SDL_GetWindowSize(window, &width, &height); if (mu_begin_window(mu, MAIN_WINDOW_NAME, mu_rect(0, 0, width, height)))

Am I doing it wrong? How can I resize microui window?

rxi commented 4 years ago

The rect passed to mu_begin_window is only used for the window's initial state. You can do the following before the mu_begin_window call to set its size explicitly each frame; the rect passed to mu_begin_window will never be used in this case:

  mu_Container *win = mu_get_container(ctx, MAIN_WINDOW_NAME);
  win->rect = mu_rect(0, 0, width, height);

Note you might want to use mu_begin_window_ex instead and pass the MU_OPT_NOTITLE option so that it doesn't draw a title bar

tomaszte commented 4 years ago

Thank you!