Immediate-Mode-UI / Nuklear

A single-header ANSI C immediate mode cross-platform GUI library
https://immediate-mode-ui.github.io/Nuklear/doc/index.html
Other
9.06k stars 542 forks source link

dragging the pointer inside the RGBA fields may cause the cursor to disappear #556

Open Ryder17z opened 1 year ago

Ryder17z commented 1 year ago

This is happening using SDL_renderer.h Not sure if it happens on other backends or if it's related to #512 It might also be a specific thing just on on Windows. (10)

dan-oak commented 1 year ago

not only on Windows, i reproduced on Linux, although in virtual box. also SDL renderer, in the demo app

it seems to me like there is some funky business here: https://github.com/Immediate-Mode-UI/Nuklear/blob/ca49016428aace2b19c30b87f8d2418bdfc755ca/demo/sdl_renderer/nuklear_sdl_renderer.h#L272C1-L281

because with commenting out of this block, i'm unable to reproduce it

Ryder17z commented 1 year ago

I have had issues reproducing the issue, so I'm happy see some more information on this since I haven't found a reliable way to trigger it, using both windows and linux.

diegzumillo commented 1 year ago

I just encountered this behavior here. It's very hard to reproduce indeed, even in the same program sometimes it doesn't happen. I'm not even sure if the issue is on the SDL side or Nuklear. I'll try to track down the cause with the debugger.

jacknicklenson commented 9 months ago

I have the same issue by using nuklear_sdl_renderer.h here is the video:

https://github.com/Immediate-Mode-UI/Nuklear/assets/90291236/76219c03-1f7c-4177-ac01-0d0820147429

here is the code:

#define SDL_MAIN_HANDLED
#include "SDL2/SDL.h"
#include <stdio.h>
#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_STANDARD_VARARGS
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_DEFAULT_FONT
#define NK_IMPLEMENTATION
#define NK_SDL_RENDERER_IMPLEMENTATION
#include "nuklear.h"
#include "nuklear_sdl_renderer.h"

#ifdef _MSC_VER
#pragma comment(linker, "/ENTRY:mainCRTStartup")
#endif

int
main(int argc, char **argv) {
  (void)argc;
  (void)argv;

  if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
    fprintf(stderr, "SDL_Init Error: %s\n", SDL_GetError());
    return EXIT_FAILURE;
  }

  SDL_Window *win =
      SDL_CreateWindow("demo", 100, 100, 620, 400, SDL_WINDOW_SHOWN);
  if (win == NULL) {
    fprintf(stderr, "SDL_CreateWindow Error: %s\n", SDL_GetError());
    return EXIT_FAILURE;
  }
  SDL_SetWindowResizable(win, SDL_TRUE);

  SDL_Renderer *ren = SDL_CreateRenderer(
      win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
  if (ren == NULL) {
    fprintf(stderr, "SDL_CreateRenderer Error: %s\n", SDL_GetError());
    SDL_DestroyWindow(win);
    SDL_Quit();
    return EXIT_FAILURE;
  }

  struct nk_context *nkctx = nk_sdl_init(win, ren);
  {
    struct nk_font_atlas *atlas;
    struct nk_font_config config = nk_font_config(0);
    struct nk_font *font;

    /* set up the font atlas and add desired font; note that font sizes are
     * multiplied by font_scale to produce better results at higher DPIs */
    nk_sdl_font_stash_begin(&atlas);
    font = nk_font_atlas_add_default(atlas, 13 * 1.0f, &config);
    nk_sdl_font_stash_end();

    /* this hack makes the font appear to be scaled down to the desired
     * size and is only necessary when font_scale > 1 */
    /* font->handle.height /= font_scale; */
    /*nk_style_load_all_cursors(ctx, atlas->cursors);*/
    nk_style_set_font(nkctx, &font->handle);
  }

  SDL_Event e;
  _Bool is_quit = 1;
  struct nk_color bg = {255, 0, 0, 255};
  struct nk_colorf bgf = {0};
  while (is_quit) {
    nk_input_begin(nkctx);
    while (SDL_PollEvent(&e)) {
      switch (e.type) {
      case SDL_QUIT:
        is_quit = 0;
        break;
      case SDL_KEYDOWN:
        switch (e.key.keysym.sym) {
        case SDLK_ESCAPE:
          is_quit = 0;
          break;
        default:
          break;
        }
        break;
      default:
        break;
      }
      nk_sdl_handle_event(&e);
    }
    nk_input_end(nkctx);
    /* GUI */
    if (nk_begin(nkctx, "Demo", nk_rect(50, 50, 230, 250),
                 NK_WINDOW_BORDER | NK_WINDOW_MOVABLE | NK_WINDOW_SCALABLE |
                     NK_WINDOW_MINIMIZABLE | NK_WINDOW_TITLE)) {
      enum { EASY, HARD };
      static int op = EASY;
      static int property = 20;

      nk_layout_row_static(nkctx, 30, 80, 1);
      if (nk_button_label(nkctx, "button"))
        fprintf(stdout, "button pressed\n");
      nk_layout_row_dynamic(nkctx, 30, 2);
      if (nk_option_label(nkctx, "easy", op == EASY))
        op = EASY;
      if (nk_option_label(nkctx, "hard", op == HARD))
        op = HARD;
      nk_layout_row_dynamic(nkctx, 25, 1);
      nk_property_int(nkctx, "Compression:", 0, &property, 100, 10, 1);

      nk_layout_row_dynamic(nkctx, 20, 1);
      nk_label(nkctx, "background:", NK_TEXT_LEFT);
      nk_layout_row_dynamic(nkctx, 25, 1);
      if (nk_combo_begin_color(nkctx, bg,
                               nk_vec2(nk_widget_width(nkctx), 500))) {
        nk_layout_row_dynamic(nkctx, 120, 1);
        bgf = nk_color_picker(nkctx, bgf, NK_RGBA);
        nk_layout_row_dynamic(nkctx, 25, 1);
        bg.r = (nk_byte)nk_propertyi(nkctx, "#R:", 0, bg.r, 255, 1, 2.f);
        bg.g = (nk_byte)nk_propertyi(nkctx, "#G:", 0, bg.g, 255, 1, 2.f);
        bg.b = (nk_byte)nk_propertyi(nkctx, "#B:", 0, bg.b, 255, 1, 2.f);
        bg.a = (nk_byte)nk_propertyi(nkctx, "#A:", 0, bg.a, 255, 1, 2.f);
        nk_combo_end(nkctx);
      }
    }
    nk_end(nkctx);

    SDL_SetRenderDrawColor(ren, 0, 0, 0, 255);
    SDL_RenderClear(ren);
    nk_sdl_render(NK_ANTI_ALIASING_ON);
    SDL_RenderPresent(ren);
    SDL_Delay(10);
  }

  nk_sdl_shutdown();
  SDL_DestroyRenderer(ren);
  SDL_DestroyWindow(win);
  SDL_Quit();

  return 0;
}

BTW, this happens on both windows 11 & Linux machine, i have tried.

jacknicklenson commented 9 months ago

not only on Windows, i reproduced on Linux, although in virtual box. also SDL renderer, in the demo app

it seems to me like there is some funky business here: https://github.com/Immediate-Mode-UI/Nuklear/blob/ca49016428aace2b19c30b87f8d2418bdfc755ca/demo/sdl_renderer/nuklear_sdl_renderer.h#L272C1-L281

because with commenting out of this block, i'm unable to reproduce it

Confirming, caused by this piece of code. Commenting it out or removing solves issue.

Ryder17z commented 9 months ago

does that affect any other functionality ?

jacknicklenson commented 9 months ago

i dont think so, at least for my observation. It can be omiitted.

zoogies commented 8 months ago

Was wondering why this behavior was occurring (and so inconsistently). Glad I stumbled upon this issue, commenting out the below lines in nuklear_sdl_renderer.h completely fixed it for me as well. (I am running natively on linux).

not only on Windows, i reproduced on Linux, although in virtual box. also SDL renderer, in the demo app

it seems to me like there is some funky business here: https://github.com/Immediate-Mode-UI/Nuklear/blob/ca49016428aace2b19c30b87f8d2418bdfc755ca/demo/sdl_renderer/nuklear_sdl_renderer.h#L272C1-L281

because with commenting out of this block, i'm unable to reproduce it