Skip to content

Commit 8fe6f13

Browse files
committed
Merge branch 'master' of github.com:Immediate-Mode-UI/Nuklear into fix-hovered-unicode4
2 parents c2f210a + 242f35e commit 8fe6f13

4 files changed

Lines changed: 42 additions & 16 deletions

File tree

nuklear.h

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23500,7 +23500,8 @@ nk_widget_is_hovered(const struct nk_context *ctx)
2350023500
struct nk_rect bounds;
2350123501
NK_ASSERT(ctx);
2350223502
NK_ASSERT(ctx->current);
23503-
if (!ctx || !ctx->current || ctx->active != ctx->current)
23503+
NK_ASSERT(ctx->current->layout);
23504+
if (!ctx || !ctx->current || !ctx->current->layout || (ctx->active != ctx->current && !((int)ctx->current->layout->type & (int)NK_PANEL_SET_POPUP)))
2350423505
return 0;
2350523506

2350623507
c = ctx->current->layout->clip;
@@ -23522,7 +23523,8 @@ nk_widget_is_mouse_clicked(const struct nk_context *ctx, enum nk_buttons btn)
2352223523
struct nk_rect bounds;
2352323524
NK_ASSERT(ctx);
2352423525
NK_ASSERT(ctx->current);
23525-
if (!ctx || !ctx->current || ctx->active != ctx->current)
23526+
NK_ASSERT(ctx->current->layout);
23527+
if (!ctx || !ctx->current || !ctx->current->layout || (ctx->active != ctx->current && !((int)ctx->current->layout->type & (int)NK_PANEL_SET_POPUP)))
2352623528
return 0;
2352723529

2352823530
c = ctx->current->layout->clip;
@@ -23544,7 +23546,8 @@ nk_widget_has_mouse_click_down(const struct nk_context *ctx, enum nk_buttons btn
2354423546
struct nk_rect bounds;
2354523547
NK_ASSERT(ctx);
2354623548
NK_ASSERT(ctx->current);
23547-
if (!ctx || !ctx->current || ctx->active != ctx->current)
23549+
NK_ASSERT(ctx->current->layout);
23550+
if (!ctx || !ctx->current || !ctx->current->layout || (ctx->active != ctx->current && !((int)ctx->current->layout->type & (int)NK_PANEL_SET_POPUP)))
2354823551
return 0;
2354923552

2355023553
c = ctx->current->layout->clip;
@@ -23805,13 +23808,16 @@ nk_widget_text(struct nk_command_buffer *o, struct nk_rect b,
2380523808
if (!o || !t) return;
2380623809

2380723810
b.h = NK_MAX(b.h, 2 * t->padding.y);
23808-
label.x = 0; label.w = 0;
23809-
label.y = b.y + t->padding.y;
23810-
label.h = NK_MIN(f->height, b.h - 2 * t->padding.y);
2381123811

2381223812
text_width = f->width(f->userdata, f->height, (const char*)string, len);
2381323813
text_width += (2.0f * t->padding.x);
2381423814

23815+
/* use top-left alignment by default */
23816+
if (!(a & (NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_CENTERED | NK_TEXT_ALIGN_RIGHT)))
23817+
a |= NK_TEXT_ALIGN_LEFT;
23818+
if (!(a & (NK_TEXT_ALIGN_TOP | NK_TEXT_ALIGN_MIDDLE | NK_TEXT_ALIGN_BOTTOM)))
23819+
a |= NK_TEXT_ALIGN_TOP;
23820+
2381523821
/* align in x-axis */
2381623822
if (a & NK_TEXT_ALIGN_LEFT) {
2381723823
label.x = b.x + t->padding.x;
@@ -23825,16 +23831,20 @@ nk_widget_text(struct nk_command_buffer *o, struct nk_rect b,
2382523831
} else if (a & NK_TEXT_ALIGN_RIGHT) {
2382623832
label.x = NK_MAX(b.x + t->padding.x, (b.x + b.w) - (2 * t->padding.x + (float)text_width));
2382723833
label.w = (float)text_width + 2 * t->padding.x;
23828-
} else return;
23834+
}
2382923835

2383023836
/* align in y-axis */
23831-
if (a & NK_TEXT_ALIGN_MIDDLE) {
23837+
if (a & NK_TEXT_ALIGN_TOP) {
23838+
label.y = b.y + t->padding.y;
23839+
label.h = NK_MIN(f->height, b.h - 2 * t->padding.y);
23840+
} else if (a & NK_TEXT_ALIGN_MIDDLE) {
2383223841
label.y = b.y + b.h/2.0f - (float)f->height/2.0f;
2383323842
label.h = NK_MAX(b.h/2.0f, b.h - (b.h/2.0f + f->height/2.0f));
2383423843
} else if (a & NK_TEXT_ALIGN_BOTTOM) {
2383523844
label.y = b.y + b.h - f->height;
2383623845
label.h = f->height;
2383723846
}
23847+
2383823848
nk_draw_text(o, label, (const char*)string, len, f, t->background, t->text);
2383923849
}
2384023850
NK_LIB void
@@ -30716,6 +30726,9 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args)
3071630726
/// - [y]: Minor version with non-breaking API and library changes
3071730727
/// - [z]: Patch version with no direct changes to the API
3071830728
///
30729+
/// - 2025/10/08 (4.12.8) - Fix nk_widget_text to use NK_TEXT_ALIGN_LEFT by default,
30730+
/// instead of silently failing when no x-axis alignment is provided,
30731+
/// and refactor this function to keep the code style consistent
3071930732
/// - 2025/09/12 (4.12.8) - Fix nk_window_is_hovered to use current window flags
3072030733
- Fix nk_utf_decode length check (allow len == NK_UTF_SIZE)
3072130734
/// - 2025/04/06 (4.12.7) - Fix text input navigation and mouse scrolling

src/CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
/// - [y]: Minor version with non-breaking API and library changes
88
/// - [z]: Patch version with no direct changes to the API
99
///
10+
/// - 2025/10/08 (4.12.8) - Fix nk_widget_text to use NK_TEXT_ALIGN_LEFT by default,
11+
/// instead of silently failing when no x-axis alignment is provided,
12+
/// and refactor this function to keep the code style consistent
1013
/// - 2025/09/12 (4.12.8) - Fix nk_window_is_hovered to use current window flags
1114
- Fix nk_utf_decode length check (allow len == NK_UTF_SIZE)
1215
/// - 2025/04/06 (4.12.7) - Fix text input navigation and mouse scrolling

src/nuklear_text.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ nk_widget_text(struct nk_command_buffer *o, struct nk_rect b,
1919
if (!o || !t) return;
2020

2121
b.h = NK_MAX(b.h, 2 * t->padding.y);
22-
label.x = 0; label.w = 0;
23-
label.y = b.y + t->padding.y;
24-
label.h = NK_MIN(f->height, b.h - 2 * t->padding.y);
2522

2623
text_width = f->width(f->userdata, f->height, (const char*)string, len);
2724
text_width += (2.0f * t->padding.x);
2825

26+
/* use top-left alignment by default */
27+
if (!(a & (NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_CENTERED | NK_TEXT_ALIGN_RIGHT)))
28+
a |= NK_TEXT_ALIGN_LEFT;
29+
if (!(a & (NK_TEXT_ALIGN_TOP | NK_TEXT_ALIGN_MIDDLE | NK_TEXT_ALIGN_BOTTOM)))
30+
a |= NK_TEXT_ALIGN_TOP;
31+
2932
/* align in x-axis */
3033
if (a & NK_TEXT_ALIGN_LEFT) {
3134
label.x = b.x + t->padding.x;
@@ -39,16 +42,20 @@ nk_widget_text(struct nk_command_buffer *o, struct nk_rect b,
3942
} else if (a & NK_TEXT_ALIGN_RIGHT) {
4043
label.x = NK_MAX(b.x + t->padding.x, (b.x + b.w) - (2 * t->padding.x + (float)text_width));
4144
label.w = (float)text_width + 2 * t->padding.x;
42-
} else return;
45+
}
4346

4447
/* align in y-axis */
45-
if (a & NK_TEXT_ALIGN_MIDDLE) {
48+
if (a & NK_TEXT_ALIGN_TOP) {
49+
label.y = b.y + t->padding.y;
50+
label.h = NK_MIN(f->height, b.h - 2 * t->padding.y);
51+
} else if (a & NK_TEXT_ALIGN_MIDDLE) {
4652
label.y = b.y + b.h/2.0f - (float)f->height/2.0f;
4753
label.h = NK_MAX(b.h/2.0f, b.h - (b.h/2.0f + f->height/2.0f));
4854
} else if (a & NK_TEXT_ALIGN_BOTTOM) {
4955
label.y = b.y + b.h - f->height;
5056
label.h = f->height;
5157
}
58+
5259
nk_draw_text(o, label, (const char*)string, len, f, t->background, t->text);
5360
}
5461
NK_LIB void

src/nuklear_widget.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ nk_widget_is_hovered(const struct nk_context *ctx)
7272
struct nk_rect bounds;
7373
NK_ASSERT(ctx);
7474
NK_ASSERT(ctx->current);
75-
if (!ctx || !ctx->current || ctx->active != ctx->current)
75+
NK_ASSERT(ctx->current->layout);
76+
if (!ctx || !ctx->current || !ctx->current->layout || (ctx->active != ctx->current && !((int)ctx->current->layout->type & (int)NK_PANEL_SET_POPUP)))
7677
return 0;
7778

7879
c = ctx->current->layout->clip;
@@ -94,7 +95,8 @@ nk_widget_is_mouse_clicked(const struct nk_context *ctx, enum nk_buttons btn)
9495
struct nk_rect bounds;
9596
NK_ASSERT(ctx);
9697
NK_ASSERT(ctx->current);
97-
if (!ctx || !ctx->current || ctx->active != ctx->current)
98+
NK_ASSERT(ctx->current->layout);
99+
if (!ctx || !ctx->current || !ctx->current->layout || (ctx->active != ctx->current && !((int)ctx->current->layout->type & (int)NK_PANEL_SET_POPUP)))
98100
return 0;
99101

100102
c = ctx->current->layout->clip;
@@ -116,7 +118,8 @@ nk_widget_has_mouse_click_down(const struct nk_context *ctx, enum nk_buttons btn
116118
struct nk_rect bounds;
117119
NK_ASSERT(ctx);
118120
NK_ASSERT(ctx->current);
119-
if (!ctx || !ctx->current || ctx->active != ctx->current)
121+
NK_ASSERT(ctx->current->layout);
122+
if (!ctx || !ctx->current || !ctx->current->layout || (ctx->active != ctx->current && !((int)ctx->current->layout->type & (int)NK_PANEL_SET_POPUP)))
120123
return 0;
121124

122125
c = ctx->current->layout->clip;

0 commit comments

Comments
 (0)