Skip to content

Commit 912a52c

Browse files
committed
Fix error causing crash and only scroll if hovered
I could see text input being a special case of always eating scroll if you're active and have the visible cursor in there but I think it makes more sense to match other subpanels and that's especially true when the text box doesn't even have enough text to have a scrollbar; it's already a bit odd that it eats scroll when that's true if you *are* hovering but I think that's still understandable. Also remove dead line of code.
1 parent 31bad19 commit 912a52c

3 files changed

Lines changed: 6 additions & 8 deletions

File tree

nuklear.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27070,7 +27070,7 @@ nk_textedit_move_to_word_previous(struct nk_text_edit *state)
2707027070
int c = state->cursor - 1;
2707127071
if (c > 0) {
2707227072
if (nk_is_word_boundary(state, c)) {
27073-
while (c >= 0 && nk_is_word_boundary(state, --c));
27073+
while (c > 0 && nk_is_word_boundary(state, --c));
2707427074
}
2707527075
while (!nk_is_word_boundary(state, --c));
2707627076
c++;
@@ -28006,7 +28006,6 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
2800628006

2800728007
/* update edit state */
2800828008
prev_state = (char)edit->active;
28009-
is_hovered = (char)nk_input_is_mouse_hovering_rect(in, bounds);
2801028009
if (in && in->mouse.buttons[NK_BUTTON_LEFT].clicked && in->mouse.buttons[NK_BUTTON_LEFT].down) {
2801128010
edit->active = NK_INBOX(in->mouse.pos.x, in->mouse.pos.y,
2801228011
bounds.x, bounds.y, bounds.w, bounds.h);
@@ -28326,11 +28325,11 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
2832628325
scroll_step = scroll.h * 0.10f;
2832728326
scroll_inc = scroll.h * 0.01f;
2832828327
scroll_target = text_size.y;
28329-
edit->scrollbar.y = nk_do_scrollbarv(&ws, out, scroll, edit->active && in,
28328+
edit->scrollbar.y = nk_do_scrollbarv(&ws, out, scroll, is_hovered,
2833028329
scroll_offset, scroll_target, scroll_step, scroll_inc,
2833128330
&style->scrollbar, in, font);
2833228331
/* Eat mouse scroll if we're active */
28333-
if (edit->active && in && in->mouse.scroll_delta.y) {
28332+
if (is_hovered && in->mouse.scroll_delta.y) {
2833428333
in->mouse.scroll_delta.y = 0;
2833528334
}
2833628335
}

src/nuklear_edit.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
188188

189189
/* update edit state */
190190
prev_state = (char)edit->active;
191-
is_hovered = (char)nk_input_is_mouse_hovering_rect(in, bounds);
192191
if (in && in->mouse.buttons[NK_BUTTON_LEFT].clicked && in->mouse.buttons[NK_BUTTON_LEFT].down) {
193192
edit->active = NK_INBOX(in->mouse.pos.x, in->mouse.pos.y,
194193
bounds.x, bounds.y, bounds.w, bounds.h);
@@ -508,11 +507,11 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
508507
scroll_step = scroll.h * 0.10f;
509508
scroll_inc = scroll.h * 0.01f;
510509
scroll_target = text_size.y;
511-
edit->scrollbar.y = nk_do_scrollbarv(&ws, out, scroll, edit->active && in,
510+
edit->scrollbar.y = nk_do_scrollbarv(&ws, out, scroll, is_hovered,
512511
scroll_offset, scroll_target, scroll_step, scroll_inc,
513512
&style->scrollbar, in, font);
514513
/* Eat mouse scroll if we're active */
515-
if (edit->active && in && in->mouse.scroll_delta.y) {
514+
if (is_hovered && in->mouse.scroll_delta.y) {
516515
in->mouse.scroll_delta.y = 0;
517516
}
518517
}

src/nuklear_text_editor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ nk_textedit_move_to_word_previous(struct nk_text_edit *state)
292292
int c = state->cursor - 1;
293293
if (c > 0) {
294294
if (nk_is_word_boundary(state, c)) {
295-
while (c >= 0 && nk_is_word_boundary(state, --c));
295+
while (c > 0 && nk_is_word_boundary(state, --c));
296296
}
297297
while (!nk_is_word_boundary(state, --c));
298298
c++;

0 commit comments

Comments
 (0)