vurtun / nuklear

A single-header ANSI C gui library
13.68k stars 1.1k forks source link

Clipping issue with buttons inside a window #813

Closed tanis2000 closed 5 years ago

tanis2000 commented 5 years ago

I can't understand why a simple button is overflowing the content of a window.

The code can be summed up by pretty much the following:

  if (nk_begin(ctx, "Operators", nk_rect(0, 30, 220, 220),
               NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {

    nk_layout_row_begin(ctx, NK_STATIC, CELL_HEIGHT, MAX_OPERATORS_COLS);
    for (int y = 0 ; y < MAX_OPERATORS_ROWS ; y++) {
      nk_layout_row_push(ctx, CELL_WIDTH);
      for (int x = 0 ; x < MAX_OPERATORS_COLS ; x++) {
        struct op_node_t *n = &op_edit->op_node_buf[y * MAX_OPERATORS_COLS + x];
        if (n != NULL && n->op != NULL) {
          nk_button_label(ctx, n->label);
        } else {
          nk_button_label(ctx, "[empty]");
        }
      }
    }
    nk_layout_row_end(ctx);
  }
  nk_end(ctx);

But the result is that some buttons are overflowing the window instead of clipping:

nuklear button issue

tanis2000 commented 5 years ago

I solved this. I completely forgot to apply the scissor during the rendering of nuklear’s commands.