nuklear icon indicating copy to clipboard operation
nuklear copied to clipboard

Update on input using SDL_WaitEvent

Open KenthJohan opened this issue 6 years ago • 0 comments

In nuklear.h#L997 comments it says:

/// If you actually only update on input make sure to update the UI two times each /// frame and call nk_clear directly after the first pass and only draw in /// the second pass.

void gui (struct nk_context * ctx)
{
	/* GUI */
	static int value = 0;
	if (nk_begin(ctx, "Demo", nk_rect (50, 50, 500, 600), NK_WINDOW_TITLE))
	{
		nk_layout_row_static (ctx, 25, 400, 1);
		nk_property_int (ctx, "Value:", 0, &value, 100, 10, 1);
	}
	nk_end (ctx);
}
while (running)
{
	SDL_Event evt;
	nk_input_begin (ctx);
	//while (SDL_PollEvent (&evt))
	if (SDL_WaitEvent (&evt))
	{
		if (evt.type == SDL_QUIT) {goto cleanup;}
		nk_sdl_handle_event (&evt);
	}
	nk_input_end (ctx);

	gui (ctx);
	//nk_clear (ctx);
	//gui (ctx);

	SDL_GetWindowSize (win, &win_width, &win_height);
	glViewport (0, 0, win_width, win_height);
	glClear (GL_COLOR_BUFFER_BIT);
	glClearColor (bg.r, bg.g, bg.b, bg.a);
	nk_sdl_render (NK_ANTI_ALIASING_ON, MAX_VERTEX_MEMORY, MAX_ELEMENT_MEMORY);
	SDL_GL_SwapWindow (win);
}

This works ok! However the two UI updates is commented out because updating the UI two times over makes the nk_property_int increment value two times when a user click increment once.

So am I misunderstanding something here because why should I do what the nuklear.h#L997 says?

Updating the ui only once is working ok, updating twice is not working as it should.

KenthJohan avatar Apr 01 '19 09:04 KenthJohan