Immediate-Mode-UI / Immediate-Mode-UI/Nuklear

Events not working with multiple Nuklear windows

Open
#626 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
11.4k
Forks
686
Avg merge
4d 1h
Merged PRs (30d)
3

Description

Hi, I have a problem with multiple Nuklear windows
When I add another window, the events on the first one are not handled correctly anymore
For example, hovers only work when I also left-click and mouse scroll not work

Everything work when I use only one window

Here is in pseudo-code how its done:
```C++
update_gui_events()
{
nk_input_begin(context);

// ...
// Calls to nk_input_*** to send inputs to Nuklear based on the current state
// I'm using NK_KEYSTATE_BASED_INPUT
// ...

nk_input_end(context);
}

generate_gui()
{
if (nk_begin_titled(context, "win1", ...)
{
// ... Window 1 content
}
nk_end(context);

if (nk_begin_titled(context, "win2", ...)
{
// ... Window 2 content
}
nk_end(context);

// Hack
// If I uncomment this line, the hover events seems to work on both windows
// but the scroll problem is still present
// nk_window_set_focus(context, "win1");
}

render_gui()
{
// ...
// Engine specific calls to init the render
// ...

nk_buffer_init_fixed(&vertices, ...);
nk_buffer_init_fixed(&elements, ...);
nk_convert(ctx, command_buffer, &vertices, &elements, ...);

nk_draw_foreach(cmd, ctx, command_buffer)
{
// ...
// Engine specific calls to draw the vertices
// ...
}

nk_clear(ctx);
nk_buffer_free(&vertices);
nk_buffer_free(&elements);

// ...
// Engine specific calls to end the render
// ...
}
```

Then on each frame

```C++
update_gui_events()
generate_gui()
render_gui();

```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the two-window case using the shown update_gui_events, generate_gui, and render_gui sequence with NK_KEYSTATE_BASED_INPUT. Inspect how nk_input_*, window focus, hover, and scroll state are handled around nk_window_set_focus; done means both windows receive hover and scroll events correctly without the focus hack.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
desktop, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.