Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clib.json
Original file line number Diff line number Diff line change
@@ -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"],
Expand Down
20 changes: 15 additions & 5 deletions nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this line because label.x and label.w is always set inside of every x-axis branch, and now none of these branches can be missed, so this line has no effect.

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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions src/nuklear_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down