From b6e261b508537e60a93ead8802f2b2d25d5990d9 Mon Sep 17 00:00:00 2001 From: ryuukk Date: Sat, 28 Sep 2024 21:44:42 +0200 Subject: [PATCH] Round layout widget position to nearest 0 --- src/nuklear_internal.h | 1 + src/nuklear_layout.c | 2 +- src/nuklear_math.c | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/nuklear_internal.h b/src/nuklear_internal.h index e945d74..51eef47 100644 --- a/src/nuklear_internal.h +++ b/src/nuklear_internal.h @@ -118,6 +118,7 @@ NK_LIB int nk_ifloord(double x); NK_LIB int nk_ifloorf(float x); NK_LIB int nk_iceilf(float x); NK_LIB int nk_log10(double n); +NK_LIB float nk_roundf(float x); /* util */ enum {NK_DO_NOT_STOP_ON_NEW_LINE, NK_STOP_ON_NEW_LINE}; diff --git a/src/nuklear_layout.c b/src/nuklear_layout.c index 0229bd0..e2f3af6 100644 --- a/src/nuklear_layout.c +++ b/src/nuklear_layout.c @@ -601,7 +601,7 @@ nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx, panel_space = nk_layout_row_calculate_usable_space(&ctx->style, layout->type, layout->bounds.w, layout->row.columns); - #define NK_FRAC(x) (x - (float)(int)x) /* will be used to remove fookin gaps */ + #define NK_FRAC(x) (x - (float)(int)nk_roundf(x)) /* will be used to remove fookin gaps */ /* calculate the width of one item inside the current layout space */ switch (layout->row.type) { case NK_LAYOUT_DYNAMIC_FIXED: { diff --git a/src/nuklear_math.c b/src/nuklear_math.c index d9b981e..565f6af 100644 --- a/src/nuklear_math.c +++ b/src/nuklear_math.c @@ -197,6 +197,11 @@ nk_log10(double n) if (neg) exp = -exp; return exp; } +NK_LIB float +nk_roundf(float x) +{ + return (x >= 0.0) ? nk_ifloorf(x + 0.5) : nk_iceilf(x - 0.5); +} NK_API struct nk_rect nk_get_null_rect(void) {