nk_style_window rounding
Has anyone had any luck with the rounding parameter of the nk_style_window struct? I am having a bit of trouble getting whole windows to become round. Button rounding is working just fine.
I've done a bit more digging and I can confirm that setting the rounding parameter in nk_style_window does not effect the rounding parameter in NK_COMMAND_RECT or NK_COMMAND_RECT_FILLED when using the default values for nk_style. The rounding parameter is always set to 0. Again setting the rounding parameter on nk_style_button does actually pass a non zero rounding parameter to NK_COMMAND_RECT or NK_COMMAND_RECT_FILLED.
@vurtun if you could take a look at this that would be great!
Another update, I noticed that I did not have the latest nuklear header file when running these tests. I have updated to the latest file and I can still confirm the following: setting the "rounding" variable in the nk_style_window does not set the rounding parameter on any NK_COMMAND_RECT or NK_COMMAND_RECT_FILLED commands.
Is this expected behavior? Has anyone else had any luck getting windows to have rounded corners? I have also tried adjusting the padding and the border sizes with no luck.
Hi all, I am still working on this issue. This is literally the only reference to rounding windows in nuklear on the whole planet: https://www.thecodingfox.com/nuklear-usage-guide-lwjgl#styling-the-window. But it seems to be related to lwjgl for java. Does anyone know anything about rounding windows in nuklear please!!
It might sound rude, but it's the standard, that one needs to read source code of single-header libraries (maybe except sqlite). This is not different for Nuklear.
$ grep -Ein round nuklear.h | grep -v background
1457: NK_WINDOW_BACKGROUND = NK_FLAG(8),
1615:/// Do not keep the returned panel pointer around, it is only valid until `nk_end`
1707:/// Do not keep the returned command buffer pointer around it is only valid until `nk_end`
1963:/// All layouting methods in this library are based around the concept of a row.
4364: unsigned short rounding;
4373: unsigned short rounding;
4483: struct nk_color foreground;
4507:NK_API void nk_stroke_rect(struct nk_command_buffer*, struct nk_rect, float rounding, float line_thickness, struct nk_color);
4515:NK_API void nk_fill_rect(struct nk_command_buffer*, struct nk_rect, float rounding, struct nk_color);
4705:NK_API void nk_draw_list_path_rect_to(struct nk_draw_list*, struct nk_vec2 a, struct nk_vec2 b, float rounding);
4712:NK_API void nk_draw_list_stroke_rect(struct nk_draw_list*, struct nk_rect rect, struct nk_color, float rounding, float thickness);
4719:NK_API void nk_draw_list_fill_rect(struct nk_draw_list*, struct nk_rect rect, struct nk_color, float rounding);
4775: float rounding;
4840: float rounding;
4871: float rounding;
4904: float rounding;
4907: float cursor_rounding;
4931: float rounding;
4933: float rounding_cursor;
4976: float rounding;
5001: float rounding;
5023: float rounding;
5052: float rounding;
5074: float rounding;
5132: float rounding;
5738:NK_LIB nk_uint nk_round_up_pow2(nk_uint v);
6036:nk_round_up_pow2(nk_uint v)
8100: capacity = NK_MAX(capacity, nk_round_up_pow2((nk_uint)(b->allocated + size)));
8792: float rounding, float line_thickness, struct nk_color c)
8805: cmd->rounding = (unsigned short)rounding;
8815: float rounding, struct nk_color c)
8829: cmd->rounding = (unsigned short)rounding;
9136: cmd->foreground = fg;
9984: This allows us to rotate the coordinates around the
10011: struct nk_vec2 b, float rounding)
10016: r = rounding;
10098: struct nk_color col, float rounding)
10105: nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding);
10108: nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding);
10113: struct nk_color col, float rounding, float thickness)
10119: nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding);
10122: nk_vec2(rect.x + rect.w, rect.y + rect.h), rounding);
10367: r->color, (float)r->rounding, r->line_thickness);
10372: r->color, (float)r->rounding);
10446: t->string, t->length, t->height, t->foreground);
11175: nk_int mid = low + ((high-low) >> 1); /* rounds down, so low <= mid < high */
11346: /* where we can start, and we need to save some state for when we wraparound. */
11931: /* swap it to the beginning so it won't move around */
12770: *height = (int)nk_round_up_pow2((nk_uint)*height);
14248: button->rounding = 4.0f;
14268: button->rounding = 0.0f;
14288: button->rounding = 1.0f;
14349: select->rounding = 0.0f;
14374: slider->rounding = 0;
14393: button->rounding = 0.0f;
14411: prog->rounding = 0;
14413: prog->cursor_rounding = 0;
14435: scroll->rounding = 0;
14437: scroll->rounding_cursor = 0;
14457: button->rounding = 0.0f;
14488: edit->rounding = 0;
14505: property->rounding = 10;
14525: button->rounding = 0.0f;
14551: edit->rounding = 0;
14562: chart->rounding = 0;
14580: combo->rounding = 0;
14598: button->rounding = 0.0f;
14613: tab->rounding = 0;
14631: button->rounding = 0.0f;
14652: button->rounding = 0.0f;
14689: button->rounding = 0.0f;
14709: button->rounding = 0.0f;
14725: win->rounding = 0.0f;
16227: if (flags & NK_WINDOW_BACKGROUND)
16319: if (iter && !(win->flags & NK_WINDOW_ROM) && (win->flags & NK_WINDOW_BACKGROUND)) {
16323: if (!(iter->flags & NK_WINDOW_BACKGROUND)) {
16331: if (!(win->flags & NK_WINDOW_BACKGROUND)) {
16340: if (ctx->end != win && !(win->flags & NK_WINDOW_BACKGROUND))
17532: /* if one of these triggers you forgot to add an `if` condition around either
18961: /* if one of these triggers you forgot to add an `if` condition around either
19513: text.text = foreground;
19522: nk_fill_rect(out, content, 0, foreground);
19526: nk_fill_circle(out, content, foreground);
19542: points[2].x, points[2].y, foreground);
19592: nk_stroke_rect(out, *bounds, style->rounding, style->border, style->border_color);
19609: content->x = r.x + style->padding.x + style->border + style->rounding;
19610: content->y = r.y + style->padding.y + style->border + style->rounding;
19611: content->w = r.w - (2 * style->padding.x + style->border + style->rounding*2);
19612: content->h = r.h - (2 * style->padding.y + style->border + style->rounding*2);
20896: nk_stroke_rect(out, *bounds, style->rounding, style->border, style->border_color);
20900: nk_fill_rect(out, bar, style->rounding, bar_color);
20901: nk_fill_rect(out, fill, style->rounding, style->bar_filled);
21118: nk_stroke_rect(out, *bounds, style->rounding, style->border, style->border_color);
21123: nk_fill_rect(out, *scursor, style->rounding, cursor->data.color);
21124: nk_stroke_rect(out, *scursor, style->rounding, style->border, style->border_color);
21304: nk_stroke_rect(out, *bounds, style->rounding, style->border, style->border_color);
21311: nk_fill_rect(out, *scroll, style->rounding_cursor, cursor->data.color);
21312: nk_stroke_rect(out, *scroll, style->rounding_cursor, style->border_cursor, style->cursor_border_color);
21381: /* calculate empty space around cursor */
21469: /* calculate empty space around cursor */
22599: struct nk_color foreground, int is_selected)
22618: txt.text = foreground;
22853: nk_stroke_rect(out, bounds, style->rounding, style->border, style->border_color);
23888: nk_fill_rect(&win->buffer, bounds, style->rounding, style->border_color);
24438: nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color);
24523: nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color);
24609: nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color);
24698: nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color);
24783: nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color);
24867: nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, style->combo.border_color);
25344:/// - 2017/03/25 (1.35.2) - Fixed popup overlapping for `NK_WINDOW_BACKGROUND` windows
25524:/// - 2016/08/03 (1.04.1)- Fixed `NK_WINDOW_BACKGROUND` behavior
25529:/// - 2016/08/03 (1.04.0) - Added `NK_WINDOW_BACKGROUND` flag to force a window
Okay I think I perhaps see the issue. take a look at this:
/* draw header background */
header.h += 1.0f;
if (background->type == NK_STYLE_ITEM_IMAGE) {
text.background = nk_rgba(0,0,0,0);
nk_draw_image(&win->buffer, header, &background->data.image, nk_white);
} else {
text.background = background->data.color;
nk_fill_rect(out, header, 0, background->data.color);
}
/* draw window background */
if (!(layout->flags & NK_WINDOW_MINIMIZED) && !(layout->flags & NK_WINDOW_DYNAMIC)) {
struct nk_rect body;
body.x = win->bounds.x;
body.w = win->bounds.w;
body.y = (win->bounds.y + layout->header_height);
body.h = (win->bounds.h - layout->header_height);
if (style->window.fixed_background.type == NK_STYLE_ITEM_IMAGE)
nk_draw_image(out, body, &style->window.fixed_background.data.image, nk_white);
else nk_fill_rect(out, body, 0, style->window.fixed_background.data.color);
}
Looks like zero is being passed in for the rounding parameter when the windows are being drawn...
@dumblob am I missing something else? It seems like it might be a bug in nuklear. Does window rounding work on your instance of nuklear?
I'll keep digging here...
Okay setting this line:
15748: nk_fill_rect(out, body, 0, style->window.fixed_background.data.color);
to
15748: nk_fill_rect(out, body, style->window.rounding, style->window.fixed_background.data.color);
causes the core part of the window to be rounded. (so excluding the header).
@dumblob since you're the only one who seems to be listening to me could you try and confirm the same just to confirm I am not going crazy here
That might be the case - I didn't try on my setup, but try to change it, recompile all demos and take a look, whether it works in all of them and report back. I'll try to find some time to look at it if it works in all these cases for you :wink:.
@dumblob Okay I just compiled all the demos and it seems to work just fine! What is the next step here?
A pull request :wink:.
Don't forget to change sources in src/ and then automatically generate the single header file using src/paq.sh). Also bump version according to Semver.