Skip to content

Commit

Permalink
Fix most warnings. Weird bug in allegro backend dissapeared
Browse files Browse the repository at this point in the history
  • Loading branch information
Hejsil committed Apr 13, 2020
1 parent 0b4676a commit e0d96bf
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 83 deletions.
2 changes: 1 addition & 1 deletion demo/allegro5/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
BIN = demo

# Flags
CFLAGS += -std=c99 -pedantic -ggdb -Wall -Wextra -Werror
CFLAGS += -std=c99 -pedantic -O2

SRC = main.c
OBJ = $(SRC:.c=.o)
Expand Down
53 changes: 12 additions & 41 deletions nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -3053,7 +3053,7 @@ enum nk_widget_states {
NK_WIDGET_STATE_ACTIVE = NK_WIDGET_STATE_ACTIVED|NK_WIDGET_STATE_MODIFIED /* widget is currently activated */
};
NK_API enum nk_widget_layout_states nk_widget(struct nk_rect*, const struct nk_context*);
NK_API enum nk_widget_layout_states nk_widget_fitting(struct nk_rect*, struct nk_context*, struct nk_vec2);
NK_API enum nk_widget_layout_states nk_widget_fitting(struct nk_rect*, struct nk_context*);
NK_API struct nk_rect nk_widget_bounds(struct nk_context*);
NK_API struct nk_vec2 nk_widget_position(struct nk_context*);
NK_API struct nk_vec2 nk_widget_size(struct nk_context*);
Expand Down Expand Up @@ -5640,7 +5640,7 @@ template<typename T> struct nk_alignof{struct Big {T x; char c;}; enum {
#endif

#ifndef STBTT_malloc
static nk_handle fictional_handle = {0};
static const nk_handle fictional_handle = {0};

#define STBTT_malloc(x,u) nk_malloc( fictional_handle, 0, x )
#define STBTT_free(x,u) nk_mfree( fictional_handle , x)
Expand Down Expand Up @@ -5871,7 +5871,7 @@ NK_LIB int nk_panel_begin(struct nk_context *ctx, struct nk_slice title, enum nk
NK_LIB void nk_panel_end(struct nk_context *ctx);

/* layout */
NK_LIB float nk_layout_row_calculate_usable_space(const struct nk_style *style, enum nk_panel_type type, float total_space, int columns);
NK_LIB float nk_layout_row_calculate_usable_space(const struct nk_style *style, float total_space, int columns);
NK_LIB void nk_panel_layout(const struct nk_context *ctx, struct nk_window *win, float height, int cols);
NK_LIB void nk_row_layout(struct nk_context *ctx, enum nk_layout_format fmt, float height, int cols, int width);
NK_LIB void nk_panel_alloc_row(const struct nk_context *ctx, struct nk_window *win);
Expand Down Expand Up @@ -8318,7 +8318,7 @@ nk_str_append_str_char(struct nk_str *s, struct nk_slice str)
NK_API int
nk_str_append_str_runes(struct nk_str *str, const nk_rune *text, nk_size len)
{
int i = 0;
nk_size i = 0;
int byte_len = 0;
nk_glyph glyph;

Expand Down Expand Up @@ -20111,7 +20111,6 @@ nk_item_is_any_active(struct nk_context *ctx)
NK_API int
nk_window_is_collapsed(struct nk_context *ctx, struct nk_slice name)
{
int title_len;
nk_hash title_hash;
struct nk_window *win;
NK_ASSERT(ctx);
Expand All @@ -20125,7 +20124,6 @@ nk_window_is_collapsed(struct nk_context *ctx, struct nk_slice name)
NK_API int
nk_window_is_closed(struct nk_context *ctx, struct nk_slice name)
{
int title_len;
nk_hash title_hash;
struct nk_window *win;
NK_ASSERT(ctx);
Expand All @@ -20139,7 +20137,6 @@ nk_window_is_closed(struct nk_context *ctx, struct nk_slice name)
NK_API int
nk_window_is_hidden(struct nk_context *ctx, struct nk_slice name)
{
int title_len;
nk_hash title_hash;
struct nk_window *win;
NK_ASSERT(ctx);
Expand All @@ -20153,7 +20150,6 @@ nk_window_is_hidden(struct nk_context *ctx, struct nk_slice name)
NK_API int
nk_window_is_active(struct nk_context *ctx, struct nk_slice name)
{
int title_len;
nk_hash title_hash;
struct nk_window *win;
NK_ASSERT(ctx);
Expand All @@ -20167,7 +20163,6 @@ nk_window_is_active(struct nk_context *ctx, struct nk_slice name)
NK_API struct nk_window*
nk_window_find(struct nk_context *ctx, struct nk_slice name)
{
int title_len;
nk_hash title_hash;
title_hash = nk_murmur_hash(name, NK_WINDOW_TITLE);
return nk_find_window(ctx, title_hash, name);
Expand Down Expand Up @@ -20231,7 +20226,6 @@ NK_API void
nk_window_collapse(struct nk_context *ctx, struct nk_slice name,
enum nk_collapse_states c)
{
int title_len;
nk_hash title_hash;
struct nk_window *win;
NK_ASSERT(ctx);
Expand All @@ -20255,7 +20249,6 @@ nk_window_collapse_if(struct nk_context *ctx, struct nk_slice name,
NK_API void
nk_window_show(struct nk_context *ctx, struct nk_slice name, enum nk_show_states s)
{
int title_len;
nk_hash title_hash;
struct nk_window *win;
NK_ASSERT(ctx);
Expand All @@ -20280,7 +20273,6 @@ nk_window_show_if(struct nk_context *ctx, struct nk_slice name,
NK_API void
nk_window_set_focus(struct nk_context *ctx, struct nk_slice name)
{
int title_len;
nk_hash title_hash;
struct nk_window *win;
NK_ASSERT(ctx);
Expand Down Expand Up @@ -20311,7 +20303,6 @@ nk_popup_begin(struct nk_context *ctx, enum nk_popup_type type,
struct nk_window *win;
struct nk_panel *panel;

int title_len;
nk_hash title_hash;
nk_size allocated;

Expand Down Expand Up @@ -20644,7 +20635,7 @@ nk_contextual_item_label(struct nk_context *ctx, struct nk_slice text,

win = ctx->current;
style = &ctx->style;
state = nk_widget_fitting(&bounds, ctx, style->contextual_button.padding);
state = nk_widget_fitting(&bounds, ctx);
if (!state) return nk_false;

in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input;
Expand Down Expand Up @@ -20674,7 +20665,7 @@ nk_contextual_item_image_label(struct nk_context *ctx, struct nk_image img,

win = ctx->current;
style = &ctx->style;
state = nk_widget_fitting(&bounds, ctx, style->contextual_button.padding);
state = nk_widget_fitting(&bounds, ctx);
if (!state) return nk_false;

in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input;
Expand Down Expand Up @@ -20704,7 +20695,7 @@ nk_contextual_item_symbol_label(struct nk_context *ctx, enum nk_symbol_type symb

win = ctx->current;
style = &ctx->style;
state = nk_widget_fitting(&bounds, ctx, style->contextual_button.padding);
state = nk_widget_fitting(&bounds, ctx);
if (!state) return nk_false;

in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input;
Expand Down Expand Up @@ -21069,13 +21060,11 @@ nk_layout_reset_min_row_height(struct nk_context *ctx)
layout->row.min_height += ctx->style.window.min_row_height_padding*2;
}
NK_LIB float
nk_layout_row_calculate_usable_space(const struct nk_style *style, enum nk_panel_type type,
nk_layout_row_calculate_usable_space(const struct nk_style *style,
float total_space, int columns)
{
float panel_padding;
float panel_spacing;
float panel_space;

struct nk_vec2 spacing;

spacing = style->window.spacing;
Expand Down Expand Up @@ -21417,7 +21406,7 @@ nk_layout_row_template_end(struct nk_context *ctx)
}
}
if (variable_count) {
float space = nk_layout_row_calculate_usable_space(&ctx->style, layout->type,
float space = nk_layout_row_calculate_usable_space(&ctx->style,
layout->bounds.w, layout->row.columns);
float var_width = (NK_MAX(space-min_fixed_width,0.0f)) / (float)variable_count;
int enough_space = var_width >= max_variable_width;
Expand Down Expand Up @@ -21607,7 +21596,6 @@ nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx,
const struct nk_style *style;

struct nk_vec2 spacing;
struct nk_vec2 padding;

float item_offset = 0;
float item_width = 0;
Expand All @@ -21626,7 +21614,7 @@ nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx,
NK_ASSERT(bounds);

spacing = style->window.spacing;
panel_space = nk_layout_row_calculate_usable_space(&ctx->style, layout->type,
panel_space = nk_layout_row_calculate_usable_space(&ctx->style,
layout->bounds.w, layout->row.columns);

#define NK_FRAC(x) (x - (int)x) /* will be used to remove fookin gaps */
Expand Down Expand Up @@ -21910,7 +21898,6 @@ nk_tree_base(struct nk_context *ctx, enum nk_tree_type type,
struct nk_slice hash, int line)
{
struct nk_window *win = ctx->current;
int title_len = 0;
nk_hash tree_hash = 0;
nk_uint *state = 0;

Expand Down Expand Up @@ -21990,13 +21977,11 @@ nk_tree_element_image_push_hashed_base(struct nk_context *ctx, enum nk_tree_type
float row_height;
struct nk_vec2 padding;

int text_len;
float text_width;

struct nk_vec2 item_spacing;
struct nk_rect header = {0,0,0,0};
struct nk_rect sym = {0,0,0,0};
struct nk_text text;

nk_flags ws = 0;
enum nk_widget_layout_states widget_state;
Expand Down Expand Up @@ -22026,14 +22011,12 @@ nk_tree_element_image_push_hashed_base(struct nk_context *ctx, enum nk_tree_type
const struct nk_style_item *background = &style->tab.background;
if (background->type == NK_STYLE_ITEM_IMAGE) {
nk_draw_image(out, header, &background->data.image, nk_white);
text.background = nk_rgba(0,0,0,0);
} else {
text.background = background->data.color;
nk_fill_rect(out, header, 0, style->tab.border_color);
nk_fill_rect(out, nk_shrink_rect(header, style->tab.border),
style->tab.rounding, background->data.color);
}
} else text.background = style->window.background;
}

in = (!(layout->flags & NK_WINDOW_ROM)) ? &ctx->input: 0;
in = (in && widget_state == NK_WIDGET_VALID) ? &ctx->input : 0;
Expand Down Expand Up @@ -22091,7 +22074,6 @@ nk_tree_element_base(struct nk_context *ctx, enum nk_tree_type type,
int *selected, struct nk_slice hash, int line)
{
struct nk_window *win = ctx->current;
int title_len = 0;
nk_hash tree_hash = 0;
nk_uint *state = 0;

Expand Down Expand Up @@ -22256,7 +22238,6 @@ NK_API int
nk_group_begin_titled(struct nk_context *ctx, struct nk_slice id,
struct nk_slice title, nk_flags flags)
{
int id_len;
nk_hash id_hash;
struct nk_window *win;
nk_uint *x_offset;
Expand Down Expand Up @@ -22297,7 +22278,6 @@ nk_group_end(struct nk_context *ctx)
NK_API void
nk_group_get_scroll(struct nk_context *ctx, struct nk_slice id, nk_uint *x_offset, nk_uint *y_offset)
{
int id_len;
nk_hash id_hash;
struct nk_window *win;
nk_uint *x_offset_ptr;
Expand Down Expand Up @@ -22372,7 +22352,6 @@ NK_API int
nk_list_view_begin(struct nk_context *ctx, struct nk_list_view *view,
struct nk_slice title, nk_flags flags, int row_height, int row_count)
{
int title_len;
nk_hash title_hash;
nk_uint *x_offset;
nk_uint *y_offset;
Expand Down Expand Up @@ -22624,25 +22603,17 @@ nk_widget(struct nk_rect *bounds, const struct nk_context *ctx)
return NK_WIDGET_VALID;
}
NK_API enum nk_widget_layout_states
nk_widget_fitting(struct nk_rect *bounds, struct nk_context *ctx,
struct nk_vec2 item_padding)
nk_widget_fitting(struct nk_rect *bounds, struct nk_context *ctx)
{
/* update the bounds to stand without padding */
struct nk_window *win;
struct nk_style *style;
struct nk_panel *layout;
enum nk_widget_layout_states state;
struct nk_vec2 panel_padding;

NK_ASSERT(ctx);
NK_ASSERT(ctx->current);
NK_ASSERT(ctx->current->layout);
if (!ctx || !ctx->current || !ctx->current->layout)
return NK_WIDGET_INVALID;

win = ctx->current;
style = &ctx->style;
layout = win->layout;
state = nk_widget(bounds, ctx);
return state;
}
Expand Down
4 changes: 2 additions & 2 deletions src/nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -2834,7 +2834,7 @@ enum nk_widget_states {
NK_WIDGET_STATE_ACTIVE = NK_WIDGET_STATE_ACTIVED|NK_WIDGET_STATE_MODIFIED /* widget is currently activated */
};
NK_API enum nk_widget_layout_states nk_widget(struct nk_rect*, const struct nk_context*);
NK_API enum nk_widget_layout_states nk_widget_fitting(struct nk_rect*, struct nk_context*, struct nk_vec2);
NK_API enum nk_widget_layout_states nk_widget_fitting(struct nk_rect*, struct nk_context*);
NK_API struct nk_rect nk_widget_bounds(struct nk_context*);
NK_API struct nk_vec2 nk_widget_position(struct nk_context*);
NK_API struct nk_vec2 nk_widget_size(struct nk_context*);
Expand Down Expand Up @@ -5421,7 +5421,7 @@ template<typename T> struct nk_alignof{struct Big {T x; char c;}; enum {
#endif

#ifndef STBTT_malloc
static nk_handle fictional_handle = {0};
static const nk_handle fictional_handle = {0};

#define STBTT_malloc(x,u) nk_malloc( fictional_handle, 0, x )
#define STBTT_free(x,u) nk_mfree( fictional_handle , x)
Expand Down
6 changes: 3 additions & 3 deletions src/nuklear_contextual.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ nk_contextual_item_label(struct nk_context *ctx, struct nk_slice text,

win = ctx->current;
style = &ctx->style;
state = nk_widget_fitting(&bounds, ctx, style->contextual_button.padding);
state = nk_widget_fitting(&bounds, ctx);
if (!state) return nk_false;

in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input;
Expand Down Expand Up @@ -114,7 +114,7 @@ nk_contextual_item_image_label(struct nk_context *ctx, struct nk_image img,

win = ctx->current;
style = &ctx->style;
state = nk_widget_fitting(&bounds, ctx, style->contextual_button.padding);
state = nk_widget_fitting(&bounds, ctx);
if (!state) return nk_false;

in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input;
Expand Down Expand Up @@ -144,7 +144,7 @@ nk_contextual_item_symbol_label(struct nk_context *ctx, enum nk_symbol_type symb

win = ctx->current;
style = &ctx->style;
state = nk_widget_fitting(&bounds, ctx, style->contextual_button.padding);
state = nk_widget_fitting(&bounds, ctx);
if (!state) return nk_false;

in = (state == NK_WIDGET_ROM || win->layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input;
Expand Down
2 changes: 0 additions & 2 deletions src/nuklear_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ NK_API int
nk_group_begin_titled(struct nk_context *ctx, struct nk_slice id,
struct nk_slice title, nk_flags flags)
{
int id_len;
nk_hash id_hash;
struct nk_window *win;
nk_uint *x_offset;
Expand Down Expand Up @@ -168,7 +167,6 @@ nk_group_end(struct nk_context *ctx)
NK_API void
nk_group_get_scroll(struct nk_context *ctx, struct nk_slice id, nk_uint *x_offset, nk_uint *y_offset)
{
int id_len;
nk_hash id_hash;
struct nk_window *win;
nk_uint *x_offset_ptr;
Expand Down
2 changes: 1 addition & 1 deletion src/nuklear_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ NK_LIB int nk_panel_begin(struct nk_context *ctx, struct nk_slice title, enum nk
NK_LIB void nk_panel_end(struct nk_context *ctx);

/* layout */
NK_LIB float nk_layout_row_calculate_usable_space(const struct nk_style *style, enum nk_panel_type type, float total_space, int columns);
NK_LIB float nk_layout_row_calculate_usable_space(const struct nk_style *style, float total_space, int columns);
NK_LIB void nk_panel_layout(const struct nk_context *ctx, struct nk_window *win, float height, int cols);
NK_LIB void nk_row_layout(struct nk_context *ctx, enum nk_layout_format fmt, float height, int cols, int width);
NK_LIB void nk_panel_alloc_row(const struct nk_context *ctx, struct nk_window *win);
Expand Down
9 changes: 3 additions & 6 deletions src/nuklear_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ nk_layout_reset_min_row_height(struct nk_context *ctx)
layout->row.min_height += ctx->style.window.min_row_height_padding*2;
}
NK_LIB float
nk_layout_row_calculate_usable_space(const struct nk_style *style, enum nk_panel_type type,
nk_layout_row_calculate_usable_space(const struct nk_style *style,
float total_space, int columns)
{
float panel_padding;
float panel_spacing;
float panel_space;

struct nk_vec2 spacing;

spacing = style->window.spacing;
Expand Down Expand Up @@ -389,7 +387,7 @@ nk_layout_row_template_end(struct nk_context *ctx)
}
}
if (variable_count) {
float space = nk_layout_row_calculate_usable_space(&ctx->style, layout->type,
float space = nk_layout_row_calculate_usable_space(&ctx->style,
layout->bounds.w, layout->row.columns);
float var_width = (NK_MAX(space-min_fixed_width,0.0f)) / (float)variable_count;
int enough_space = var_width >= max_variable_width;
Expand Down Expand Up @@ -579,7 +577,6 @@ nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx,
const struct nk_style *style;

struct nk_vec2 spacing;
struct nk_vec2 padding;

float item_offset = 0;
float item_width = 0;
Expand All @@ -598,7 +595,7 @@ nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx,
NK_ASSERT(bounds);

spacing = style->window.spacing;
panel_space = nk_layout_row_calculate_usable_space(&ctx->style, layout->type,
panel_space = nk_layout_row_calculate_usable_space(&ctx->style,
layout->bounds.w, layout->row.columns);

#define NK_FRAC(x) (x - (int)x) /* will be used to remove fookin gaps */
Expand Down
Loading

0 comments on commit e0d96bf

Please sign in to comment.