Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal: Allow changing the roundf() method #714

Closed
wants to merge 2 commits into from
Closed
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
9 changes: 7 additions & 2 deletions nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -6158,6 +6158,9 @@ NK_LIB float nk_atan(float x);
#ifndef NK_ATAN2
NK_LIB float nk_atan2(float y, float x);
#endif
#ifndef NK_ROUNDF
NK_LIB float nk_roundf(float x);
#endif
NK_LIB nk_uint nk_round_up_pow2(nk_uint v);
NK_LIB struct nk_rect nk_shrink_rect(struct nk_rect r, float amount);
NK_LIB struct nk_rect nk_pad_rect(struct nk_rect r, struct nk_vec2 pad);
Expand All @@ -6167,7 +6170,6 @@ 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};
Expand Down Expand Up @@ -6624,11 +6626,14 @@ nk_log10(double n)
if (neg) exp = -exp;
return exp;
}
#ifndef NK_ROUNDF
#define NK_ROUNDF nk_roundf
NK_LIB float
nk_roundf(float x)
{
return (x >= 0.0f) ? (float)nk_ifloorf(x + 0.5f) : (float)nk_iceilf(x - 0.5f);
}
#endif
NK_API struct nk_rect
nk_get_null_rect(void)
{
Expand Down Expand Up @@ -22587,7 +22592,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)nk_roundf(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: {
Expand Down
4 changes: 3 additions & 1 deletion src/nuklear_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ NK_LIB float nk_atan(float x);
#ifndef NK_ATAN2
NK_LIB float nk_atan2(float y, float x);
#endif
#ifndef NK_ROUNDF
NK_LIB float nk_roundf(float x);
#endif
NK_LIB nk_uint nk_round_up_pow2(nk_uint v);
NK_LIB struct nk_rect nk_shrink_rect(struct nk_rect r, float amount);
NK_LIB struct nk_rect nk_pad_rect(struct nk_rect r, struct nk_vec2 pad);
Expand All @@ -118,7 +121,6 @@ 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};
Expand Down
2 changes: 1 addition & 1 deletion src/nuklear_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)nk_roundf(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: {
Expand Down
3 changes: 3 additions & 0 deletions src/nuklear_math.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,14 @@ nk_log10(double n)
if (neg) exp = -exp;
return exp;
}
#ifndef NK_ROUNDF
#define NK_ROUNDF nk_roundf
NK_LIB float
nk_roundf(float x)
{
return (x >= 0.0f) ? (float)nk_ifloorf(x + 0.5f) : (float)nk_iceilf(x - 0.5f);
}
#endif
NK_API struct nk_rect
nk_get_null_rect(void)
{
Expand Down