Immediate-Mode-UI / Immediate-Mode-UI/Nuklear
Closing the last window resets all of the other windows
- Dominant language
- C
- Stars
- 11.4k
- Forks
- 686
- Avg merge
- 4d 1h
- Merged PRs (30d)
- 3
Description
I have encountered a strange behavior while rendering 2 or more windows and trying to close the last one. When I try to close it, every other window resets itself.
Consider the following code and the examples below it:
```cpp
const auto flags = NK_WINDOW_BACKGROUND | NK_WINDOW_CLOSABLE | NK_WINDOW_BORDER | NK_WINDOW_MOVABLE;
// First window
if (nk_window_is_closed(ctx.get(), "Window 1")) {
std::cout << "window 1 closed" << std::endl;
}
if (nk_begin(ctx.get(), "Window 1", nk_rect(50.0f, 50.0f, 200.0f, 200.0f), flags)) {
nk_layout_row_dynamic(ctx.get(), 0.0f, 1);
nk_label(ctx.get(), "Hello World!", NK_TEXT_ALIGN_LEFT);
}
nk_end(ctx.get());
// Second window
if (nk_window_is_closed(ctx.get(), "Window 2")) {
std::cout << "window 2 closed" << std::endl;
}
if (nk_begin(ctx.get(), "Window 2", nk_rect(250.0f, 50.0f, 200.0f, 200.0f), flags)) {
nk_layout_row_dynamic(ctx.get(), 0.0f, 1);
nk_label(ctx.get(), "Hello World!", NK_TEXT_ALIGN_LEFT);
}
nk_end(ctx.get());
// Third window
if (nk_window_is_closed(ctx.get(), "Window 3")) {
std::cout << "window 3 closed" << std::endl;
}
if (nk_begin(ctx.get(), "Window 3", nk_rect(450.0f, 50.0f, 200.0f, 200.0f), flags)) {
nk_layout_row_dynamic(ctx.get(), 0.0f, 1);
nk_label(ctx.get(), "Hello World!", NK_TEXT_ALIGN_LEFT);
}
nk_end(ctx.get());
```
**First example:**
Now, when I close all of the windows in this order: 1, 2, 3 I will get this:
* Close window 1, window 1 is no longer visible, nothing gets printed out (because `nk_window_is_closed` returned `0` for window 1, but it was expected to return `1`).
* Close window 2, window 2 is no longer visible, nothing gets printed out (because `nk_window_is_closed` returned `0` for window 2, but it was expected to return `1`).
* Close window 3, window 1 and 2 reset position and are visible, `nk_window_is_closed` returns `1` for **all** of the windows -> `std::cout` is called 3 times.
What I would expect is that when I close window 1 or 2 the `nk_window_is_closed` for those windows would return non zero value, but it doesn't. It returns `1` for all of the windows.
**Another example:**
* Move window 1
* Move window 2
* Close window 3, then window 1 and 2 will reset their position, window 3 stays visible.
I have expected window 1 and 2 to stay on their position after moved, and window 3 to stay hidden/closed.
So there are two problems in here. Closing the last window resets all of the other windows positions and also shows them, but they should stay hidden.
**Workaround for nk_window_is_closed:**
Checking for `nk_window_is_hidden` instead of `nk_window_is_closed` works (but only after `nk_end` for that particular window being checked, which is fine).
**Workaround for window reset after closing the last one:**
No idea.
**Additional info:**
* Switching from `nk_begin` to `nk_begin_titled` has no different result.
* Adding more windows has the same effect.
* I am using the latest version (sha d9ddd1810f8e43911c06f4f86eab3053db757adc)
Contributor guide
Research direction
Reproduce the behavior using the supplied calls to nk_begin, nk_end, nk_window_is_closed, and nk_window_is_hidden with three windows. Trace how closing the final window affects window state, visibility, and stored positions. Done means each closed window is reported independently, other windows retain their positions and visibility, and the documented workarounds are no longer required.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100