Skip to content

Commit 8e89387

Browse files
Niels BrunekreefNiels Brunekreef
authored andcommitted
Merge branch 'fix_click' of https://github.com/Nielsbishere/Nuklear into fix_radio_buttons
2 parents 4ede715 + 31492dc commit 8e89387

17 files changed

+173
-137
lines changed

nuklear.h

Lines changed: 82 additions & 67 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
{
22
"name": "nuklear",
3-
"version": "4.01.4",
3+
"version": "4.01.5",
44
"repo": "vurtun/nuklear",
55
"description": "A small ANSI C gui toolkit",
6-
"keywords": ["gl", "ui", "toolkit"],
7-
"src": ["nuklear.h"]
6+
"keywords": [
7+
"gl",
8+
"ui",
9+
"toolkit"
10+
],
11+
"src": [
12+
"nuklear.h"
13+
]
814
}

src/nuklear.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4391,6 +4391,7 @@ struct nk_mouse {
43914391
unsigned char grab;
43924392
unsigned char grabbed;
43934393
unsigned char ungrab;
4394+
unsigned char clicked;
43944395
};
43954396

43964397
struct nk_key {

src/nuklear_button.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ nk_draw_symbol(struct nk_command_buffer *out, enum nk_symbol_type type,
6161
}
6262
NK_LIB int
6363
nk_button_behavior(nk_flags *state, struct nk_rect r,
64-
const struct nk_input *i, enum nk_button_behavior behavior)
64+
struct nk_input *i, enum nk_button_behavior behavior)
6565
{
6666
int ret = 0;
6767
nk_widget_state_reset(state);
@@ -78,6 +78,8 @@ nk_button_behavior(nk_flags *state, struct nk_rect r,
7878
#else
7979
nk_input_is_mouse_pressed(i, NK_BUTTON_LEFT);
8080
#endif
81+
if (ret)
82+
i->mouse.clicked = 1;
8183
}
8284
}
8385
if (*state & NK_WIDGET_STATE_HOVER && !nk_input_is_mouse_prev_hovering_rect(i, r))
@@ -108,7 +110,7 @@ nk_draw_button(struct nk_command_buffer *out,
108110
}
109111
NK_LIB int
110112
nk_do_button(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r,
111-
const struct nk_style_button *style, const struct nk_input *in,
113+
const struct nk_style_button *style, struct nk_input *in,
112114
enum nk_button_behavior behavior, struct nk_rect *content)
113115
{
114116
struct nk_rect bounds;
@@ -158,7 +160,7 @@ NK_LIB int
158160
nk_do_button_text(nk_flags *state,
159161
struct nk_command_buffer *out, struct nk_rect bounds,
160162
const char *string, int len, nk_flags align, enum nk_button_behavior behavior,
161-
const struct nk_style_button *style, const struct nk_input *in,
163+
const struct nk_style_button *style, struct nk_input *in,
162164
const struct nk_user_font *font)
163165
{
164166
struct nk_rect content;
@@ -204,7 +206,7 @@ NK_LIB int
204206
nk_do_button_symbol(nk_flags *state,
205207
struct nk_command_buffer *out, struct nk_rect bounds,
206208
enum nk_symbol_type symbol, enum nk_button_behavior behavior,
207-
const struct nk_style_button *style, const struct nk_input *in,
209+
const struct nk_style_button *style, struct nk_input *in,
208210
const struct nk_user_font *font)
209211
{
210212
int ret;
@@ -235,7 +237,7 @@ NK_LIB int
235237
nk_do_button_image(nk_flags *state,
236238
struct nk_command_buffer *out, struct nk_rect bounds,
237239
struct nk_image img, enum nk_button_behavior b,
238-
const struct nk_style_button *style, const struct nk_input *in)
240+
const struct nk_style_button *style, struct nk_input *in)
239241
{
240242
int ret;
241243
struct nk_rect content;
@@ -295,7 +297,7 @@ nk_do_button_text_symbol(nk_flags *state,
295297
struct nk_command_buffer *out, struct nk_rect bounds,
296298
enum nk_symbol_type symbol, const char *str, int len, nk_flags align,
297299
enum nk_button_behavior behavior, const struct nk_style_button *style,
298-
const struct nk_user_font *font, const struct nk_input *in)
300+
const struct nk_user_font *font, struct nk_input *in)
299301
{
300302
int ret;
301303
struct nk_rect tri = {0,0,0,0};
@@ -352,7 +354,7 @@ nk_do_button_text_image(nk_flags *state,
352354
struct nk_command_buffer *out, struct nk_rect bounds,
353355
struct nk_image img, const char* str, int len, nk_flags align,
354356
enum nk_button_behavior behavior, const struct nk_style_button *style,
355-
const struct nk_user_font *font, const struct nk_input *in)
357+
const struct nk_user_font *font, struct nk_input *in)
356358
{
357359
int ret;
358360
struct nk_rect icon;
@@ -434,7 +436,7 @@ nk_button_text_styled(struct nk_context *ctx,
434436
{
435437
struct nk_window *win;
436438
struct nk_panel *layout;
437-
const struct nk_input *in;
439+
struct nk_input *in;
438440

439441
struct nk_rect bounds;
440442
enum nk_widget_layout_states state;
@@ -476,7 +478,7 @@ nk_button_color(struct nk_context *ctx, struct nk_color color)
476478
{
477479
struct nk_window *win;
478480
struct nk_panel *layout;
479-
const struct nk_input *in;
481+
struct nk_input *in;
480482
struct nk_style_button button;
481483

482484
int ret = 0;
@@ -512,7 +514,7 @@ nk_button_symbol_styled(struct nk_context *ctx,
512514
{
513515
struct nk_window *win;
514516
struct nk_panel *layout;
515-
const struct nk_input *in;
517+
struct nk_input *in;
516518

517519
struct nk_rect bounds;
518520
enum nk_widget_layout_states state;
@@ -544,7 +546,7 @@ nk_button_image_styled(struct nk_context *ctx, const struct nk_style_button *sty
544546
{
545547
struct nk_window *win;
546548
struct nk_panel *layout;
547-
const struct nk_input *in;
549+
struct nk_input *in;
548550

549551
struct nk_rect bounds;
550552
enum nk_widget_layout_states state;
@@ -578,7 +580,7 @@ nk_button_symbol_text_styled(struct nk_context *ctx,
578580
{
579581
struct nk_window *win;
580582
struct nk_panel *layout;
581-
const struct nk_input *in;
583+
struct nk_input *in;
582584

583585
struct nk_rect bounds;
584586
enum nk_widget_layout_states state;
@@ -625,7 +627,7 @@ nk_button_image_text_styled(struct nk_context *ctx,
625627
{
626628
struct nk_window *win;
627629
struct nk_panel *layout;
628-
const struct nk_input *in;
630+
struct nk_input *in;
629631

630632
struct nk_rect bounds;
631633
enum nk_widget_layout_states state;

src/nuklear_chart.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ nk_chart_push_line(struct nk_context *ctx, struct nk_window *win,
107107
struct nk_chart *g, float value, int slot)
108108
{
109109
struct nk_panel *layout = win->layout;
110-
const struct nk_input *i = &ctx->input;
110+
struct nk_input *i = &ctx->input;
111111
struct nk_command_buffer *out = &win->buffer;
112112

113113
nk_flags ret = 0;

src/nuklear_color_picker.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ NK_LIB int
1010
nk_color_picker_behavior(nk_flags *state,
1111
const struct nk_rect *bounds, const struct nk_rect *matrix,
1212
const struct nk_rect *hue_bar, const struct nk_rect *alpha_bar,
13-
struct nk_colorf *color, const struct nk_input *in)
13+
struct nk_colorf *color, struct nk_input *in)
1414
{
1515
float hsva[4];
1616
int value_changed = 0;
@@ -121,7 +121,7 @@ NK_LIB int
121121
nk_do_color_picker(nk_flags *state,
122122
struct nk_command_buffer *out, struct nk_colorf *col,
123123
enum nk_color_format fmt, struct nk_rect bounds,
124-
struct nk_vec2 padding, const struct nk_input *in,
124+
struct nk_vec2 padding, struct nk_input *in,
125125
const struct nk_user_font *font)
126126
{
127127
int ret = 0;
@@ -170,7 +170,7 @@ nk_color_pick(struct nk_context * ctx, struct nk_colorf *color,
170170
struct nk_window *win;
171171
struct nk_panel *layout;
172172
const struct nk_style *config;
173-
const struct nk_input *in;
173+
struct nk_input *in;
174174

175175
enum nk_widget_layout_states state;
176176
struct nk_rect bounds;

src/nuklear_combo.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ NK_API int
4444
nk_combo_begin_text(struct nk_context *ctx, const char *selected, int len,
4545
struct nk_vec2 size)
4646
{
47-
const struct nk_input *in;
47+
struct nk_input *in;
4848
struct nk_window *win;
4949
struct nk_style *style;
5050

@@ -139,7 +139,7 @@ nk_combo_begin_color(struct nk_context *ctx, struct nk_color color, struct nk_ve
139139
{
140140
struct nk_window *win;
141141
struct nk_style *style;
142-
const struct nk_input *in;
142+
struct nk_input *in;
143143

144144
struct nk_rect header;
145145
int is_clicked = nk_false;
@@ -216,7 +216,7 @@ nk_combo_begin_symbol(struct nk_context *ctx, enum nk_symbol_type symbol, struct
216216
{
217217
struct nk_window *win;
218218
struct nk_style *style;
219-
const struct nk_input *in;
219+
struct nk_input *in;
220220

221221
struct nk_rect header;
222222
int is_clicked = nk_false;
@@ -399,7 +399,7 @@ nk_combo_begin_image(struct nk_context *ctx, struct nk_image img, struct nk_vec2
399399
{
400400
struct nk_window *win;
401401
struct nk_style *style;
402-
const struct nk_input *in;
402+
struct nk_input *in;
403403

404404
struct nk_rect header;
405405
int is_clicked = nk_false;

src/nuklear_contextual.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ nk_contextual_item_text(struct nk_context *ctx, const char *text, int len,
7070
nk_flags alignment)
7171
{
7272
struct nk_window *win;
73-
const struct nk_input *in;
73+
struct nk_input *in;
7474
const struct nk_style *style;
7575

7676
struct nk_rect bounds;
@@ -105,7 +105,7 @@ nk_contextual_item_image_text(struct nk_context *ctx, struct nk_image img,
105105
const char *text, int len, nk_flags align)
106106
{
107107
struct nk_window *win;
108-
const struct nk_input *in;
108+
struct nk_input *in;
109109
const struct nk_style *style;
110110

111111
struct nk_rect bounds;
@@ -141,7 +141,7 @@ nk_contextual_item_symbol_text(struct nk_context *ctx, enum nk_symbol_type symbo
141141
const char *text, int len, nk_flags align)
142142
{
143143
struct nk_window *win;
144-
const struct nk_input *in;
144+
struct nk_input *in;
145145
const struct nk_style *style;
146146

147147
struct nk_rect bounds;

src/nuklear_input.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ nk_input_begin(struct nk_context *ctx)
2323
in->mouse.prev.y = in->mouse.pos.y;
2424
in->mouse.delta.x = 0;
2525
in->mouse.delta.y = 0;
26+
27+
#if defined(NK_KEYSTATE_BASED_INPUT) || defined(NK_BUTTON_TRIGGER_ON_RELEASE)
28+
in->mouse.clicked = 0;
29+
#endif
30+
2631
for (i = 0; i < NK_KEY_MAX; i++)
2732
in->keyboard.keys[i].clicked = 0;
2833
}
@@ -79,6 +84,14 @@ nk_input_button(struct nk_context *ctx, enum nk_buttons id, int x, int y, int do
7984
if (in->mouse.buttons[id].down == down) return;
8085

8186
btn = &in->mouse.buttons[id];
87+
88+
#ifndef NK_BUTTON_TRIGGER_ON_RELEASE
89+
90+
if(id == NK_BUTTON_LEFT && !down)
91+
in->mouse.clicked = 0;
92+
93+
#endif
94+
8295
btn->clicked_pos.x = (float)x;
8396
btn->clicked_pos.y = (float)y;
8497
btn->down = down;
@@ -141,7 +154,7 @@ nk_input_has_mouse_click_in_rect(const struct nk_input *i, enum nk_buttons id,
141154
struct nk_rect b)
142155
{
143156
const struct nk_mouse_button *btn;
144-
if (!i) return nk_false;
157+
if (!i || i->mouse.clicked) return nk_false;
145158
btn = &i->mouse.buttons[id];
146159
if (!NK_INBOX(btn->clicked_pos.x,btn->clicked_pos.y,b.x,b.y,b.w,b.h))
147160
return nk_false;
@@ -215,15 +228,15 @@ nk_input_is_mouse_pressed(const struct nk_input *i, enum nk_buttons id)
215228
const struct nk_mouse_button *b;
216229
if (!i) return nk_false;
217230
b = &i->mouse.buttons[id];
218-
if (b->down && b->clicked)
231+
if (b->down && b->clicked && !i->mouse.clicked)
219232
return nk_true;
220233
return nk_false;
221234
}
222235
NK_API int
223236
nk_input_is_mouse_released(const struct nk_input *i, enum nk_buttons id)
224237
{
225238
if (!i) return nk_false;
226-
return (!i->mouse.buttons[id].down && i->mouse.buttons[id].clicked);
239+
return (!i->mouse.buttons[id].down && !(i->mouse.buttons[id].clicked && !i->mouse.clicked));
227240
}
228241
NK_API int
229242
nk_input_is_key_pressed(const struct nk_input *i, enum nk_keys key)

0 commit comments

Comments
 (0)