Nuklear
Nuklear copied to clipboard
Scrollbars Appear when content fills area that scrollbar would appear in
When content fills and area (even partially) that a scrollbar would be drawn in, the scrollbars automatically appear, even if the content is not larger than the window/container.
Platform: Linux: x86_64 Rendering Info: GLFW, GLAD, OpenGL 3.3
Example 1 (Default scrollbar is 10px, scrollbar appears):
if (nk_begin(ctx, "Demo", nk_rect(0, 0, 800, 600), (nk_flags)NULL))
{
ctx->style.window.padding = {0,0};
ctx->style.window.spacing = {0,0};
ctx->style.button.padding = {0,0};
nk_layout_row_static(ctx, 591, 791, 1);
if (nk_button_label(ctx, "button"))
fprintf(stdout, "button pressed\n");
}
nk_end(ctx);
Example 2 (Settings scrollbar to 5px, scrollbar still appears):
if (nk_begin(ctx, "Demo", nk_rect(0, 0, 800, 600), (nk_flags)NULL))
{
ctx->style.window.padding = {0,0};
ctx->style.window.spacing = {0,0};
ctx->style.button.padding = {0,0};
ctx->style.window.scrollbar_size = {5,5};
nk_layout_row_static(ctx, 596, 796, 1);
if (nk_button_label(ctx, "button"))
fprintf(stdout, "button pressed\n");
}
nk_end(ctx);
I did not try this but I have some questions:
a) is it really nk_layout_row_static(ctx, 591, 791, 1); and not nk_layout_row_static(ctx, 791, 591, 1);?
b) Scrollbar appears to contribute to the dimensions of the content even in this very special case of having content smaller than the scrollable area. Admittedly this does not make much sense but I did not take a look at the source so feel free to make a PR :wink:.
Regarding question a), I thought this looked weird too, but the function signature for nk_layout_row_static is void nk_layout_row_static(struct nk_context *ctx, float height, int item_width, int cols); while the signature for nk_rect is nk_rect(float x, float y, float w, float h), so they are actually swapped compared to each other.
Regarding b), I'll take a look at the code and see if I can figure it out