diff --git a/clib.json b/clib.json index a3b05f86..e704fda7 100644 --- a/clib.json +++ b/clib.json @@ -1,6 +1,6 @@ { "name": "nuklear", - "version": "4.12.7", + "version": "4.12.8", "repo": "Immediate-Mode-UI/Nuklear", "description": "A small ANSI C gui toolkit", "keywords": ["gl", "ui", "toolkit"], diff --git a/nuklear.h b/nuklear.h index 71b55a24..b17cf9c3 100644 --- a/nuklear.h +++ b/nuklear.h @@ -23805,13 +23805,16 @@ nk_widget_text(struct nk_command_buffer *o, struct nk_rect b, if (!o || !t) return; b.h = NK_MAX(b.h, 2 * t->padding.y); - label.x = 0; label.w = 0; - label.y = b.y + t->padding.y; - label.h = NK_MIN(f->height, b.h - 2 * t->padding.y); text_width = f->width(f->userdata, f->height, (const char*)string, len); text_width += (2.0f * t->padding.x); + /* use top-left alignment by default */ + if (!(a & (NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_CENTERED | NK_TEXT_ALIGN_RIGHT))) + a |= NK_TEXT_ALIGN_LEFT; + if (!(a & (NK_TEXT_ALIGN_TOP | NK_TEXT_ALIGN_MIDDLE | NK_TEXT_ALIGN_BOTTOM))) + a |= NK_TEXT_ALIGN_TOP; + /* align in x-axis */ if (a & NK_TEXT_ALIGN_LEFT) { label.x = b.x + t->padding.x; @@ -23825,16 +23828,20 @@ nk_widget_text(struct nk_command_buffer *o, struct nk_rect b, } else if (a & NK_TEXT_ALIGN_RIGHT) { label.x = NK_MAX(b.x + t->padding.x, (b.x + b.w) - (2 * t->padding.x + (float)text_width)); label.w = (float)text_width + 2 * t->padding.x; - } else return; + } /* align in y-axis */ - if (a & NK_TEXT_ALIGN_MIDDLE) { + if (a & NK_TEXT_ALIGN_TOP) { + label.y = b.y + t->padding.y; + label.h = NK_MIN(f->height, b.h - 2 * t->padding.y); + } else if (a & NK_TEXT_ALIGN_MIDDLE) { label.y = b.y + b.h/2.0f - (float)f->height/2.0f; label.h = NK_MAX(b.h/2.0f, b.h - (b.h/2.0f + f->height/2.0f)); } else if (a & NK_TEXT_ALIGN_BOTTOM) { label.y = b.y + b.h - f->height; label.h = f->height; } + nk_draw_text(o, label, (const char*)string, len, f, t->background, t->text); } NK_LIB void @@ -30716,6 +30723,9 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2025/10/08 (4.12.8) - Fix nk_widget_text to use NK_TEXT_ALIGN_LEFT by default, +/// instead of silently failing when no x-axis alignment is provided, +/// and refactor this function to keep the code style consistent /// - 2025/04/06 (4.12.7) - Fix text input navigation and mouse scrolling /// - 2025/03/29 (4.12.6) - Fix unitialized data in nk_input_char /// - 2025/03/05 (4.12.5) - Fix scrolling knob also scrolling parent window, remove dead code diff --git a/src/CHANGELOG b/src/CHANGELOG index 300c3d40..513b4a90 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -7,6 +7,9 @@ /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2025/10/08 (4.12.8) - Fix nk_widget_text to use NK_TEXT_ALIGN_LEFT by default, +/// instead of silently failing when no x-axis alignment is provided, +/// and refactor this function to keep the code style consistent /// - 2025/04/06 (4.12.7) - Fix text input navigation and mouse scrolling /// - 2025/03/29 (4.12.6) - Fix unitialized data in nk_input_char /// - 2025/03/05 (4.12.5) - Fix scrolling knob also scrolling parent window, remove dead code diff --git a/src/nuklear_text.c b/src/nuklear_text.c index 3df91498..4e3233f1 100644 --- a/src/nuklear_text.c +++ b/src/nuklear_text.c @@ -19,13 +19,16 @@ nk_widget_text(struct nk_command_buffer *o, struct nk_rect b, if (!o || !t) return; b.h = NK_MAX(b.h, 2 * t->padding.y); - label.x = 0; label.w = 0; - label.y = b.y + t->padding.y; - label.h = NK_MIN(f->height, b.h - 2 * t->padding.y); text_width = f->width(f->userdata, f->height, (const char*)string, len); text_width += (2.0f * t->padding.x); + /* use top-left alignment by default */ + if (!(a & (NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_CENTERED | NK_TEXT_ALIGN_RIGHT))) + a |= NK_TEXT_ALIGN_LEFT; + if (!(a & (NK_TEXT_ALIGN_TOP | NK_TEXT_ALIGN_MIDDLE | NK_TEXT_ALIGN_BOTTOM))) + a |= NK_TEXT_ALIGN_TOP; + /* align in x-axis */ if (a & NK_TEXT_ALIGN_LEFT) { label.x = b.x + t->padding.x; @@ -39,16 +42,20 @@ nk_widget_text(struct nk_command_buffer *o, struct nk_rect b, } else if (a & NK_TEXT_ALIGN_RIGHT) { label.x = NK_MAX(b.x + t->padding.x, (b.x + b.w) - (2 * t->padding.x + (float)text_width)); label.w = (float)text_width + 2 * t->padding.x; - } else return; + } /* align in y-axis */ - if (a & NK_TEXT_ALIGN_MIDDLE) { + if (a & NK_TEXT_ALIGN_TOP) { + label.y = b.y + t->padding.y; + label.h = NK_MIN(f->height, b.h - 2 * t->padding.y); + } else if (a & NK_TEXT_ALIGN_MIDDLE) { label.y = b.y + b.h/2.0f - (float)f->height/2.0f; label.h = NK_MAX(b.h/2.0f, b.h - (b.h/2.0f + f->height/2.0f)); } else if (a & NK_TEXT_ALIGN_BOTTOM) { label.y = b.y + b.h - f->height; label.h = f->height; } + nk_draw_text(o, label, (const char*)string, len, f, t->background, t->text); } NK_LIB void