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
8.89k stars 533 forks source link

center window title at the middle #565

Closed azc5OQ closed 10 months ago

azc5OQ commented 1 year ago

I want to align window title to the center of the window bar, window title is rendered on the left side by default Can somebody please point me to the right location?

with this code

if (nk_begin(ctx_nuklear, "menu", nk_rect(menu__position_x, menu__position_y, 750, 400), NK_WINDOW_MOVABLE | NK_WINDOW_BORDER))

Is there some way to add NK_TEXT_CENTEREDto it?

thank you

dosshell commented 11 months ago

I changed the defaults to center the title with the following patch to master:

@@ -19727,9 +19727,8 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan
         label.x += style->window.header.label_padding.x;
         label.y = header.y + style->window.header.label_padding.y;
         label.h = font->height + 2 * style->window.header.label_padding.y;
-        label.w = t + 2 * style->window.header.spacing.x;
-        label.w = NK_CLAMP(0, label.w, header.x + header.w - label.x);
-        nk_widget_text(out, label, (const char*)title, text_len, &text, NK_TEXT_LEFT, font);}
+        label.w = header.w - 2 * (style->window.header.padding.x + style->window.header.label_padding.x);
+        nk_widget_text(out, label, (const char*)title, text_len, &text, NK_TEXT_CENTERED, font);}
     }

The text widget should also have the correct size after this (the clamp max value was a missing the padding), right alignment should also work now.

azc5OQ commented 10 months ago

worked, thank you