Procházet zdrojové kódy

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.
Robert Winkler před 6 měsíci
rodič
revize
912a52c391
3 změnil soubory, kde provedl 6 přidání a 8 odebrání
  1. 3 4
      nuklear.h
  2. 2 3
      src/nuklear_edit.c
  3. 1 1
      src/nuklear_text_editor.c

+ 3 - 4
nuklear.h

@@ -27070,7 +27070,7 @@ nk_textedit_move_to_word_previous(struct nk_text_edit *state)
    int c = state->cursor - 1;
    int c = state->cursor - 1;
    if (c > 0) {
    if (c > 0) {
       if (nk_is_word_boundary(state, c)) {
       if (nk_is_word_boundary(state, c)) {
-         while (c >= 0 && nk_is_word_boundary(state, --c));
+         while (c > 0 && nk_is_word_boundary(state, --c));
       }
       }
       while (!nk_is_word_boundary(state, --c));
       while (!nk_is_word_boundary(state, --c));
       c++;
       c++;
@@ -28006,7 +28006,6 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
 
 
     /* update edit state */
     /* update edit state */
     prev_state = (char)edit->active;
     prev_state = (char)edit->active;
-    is_hovered = (char)nk_input_is_mouse_hovering_rect(in, bounds);
     if (in && in->mouse.buttons[NK_BUTTON_LEFT].clicked && in->mouse.buttons[NK_BUTTON_LEFT].down) {
     if (in && in->mouse.buttons[NK_BUTTON_LEFT].clicked && in->mouse.buttons[NK_BUTTON_LEFT].down) {
         edit->active = NK_INBOX(in->mouse.pos.x, in->mouse.pos.y,
         edit->active = NK_INBOX(in->mouse.pos.x, in->mouse.pos.y,
                                 bounds.x, bounds.y, bounds.w, bounds.h);
                                 bounds.x, bounds.y, bounds.w, bounds.h);
@@ -28326,11 +28325,11 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
                 scroll_step = scroll.h * 0.10f;
                 scroll_step = scroll.h * 0.10f;
                 scroll_inc = scroll.h * 0.01f;
                 scroll_inc = scroll.h * 0.01f;
                 scroll_target = text_size.y;
                 scroll_target = text_size.y;
-                edit->scrollbar.y = nk_do_scrollbarv(&ws, out, scroll, edit->active && in,
+                edit->scrollbar.y = nk_do_scrollbarv(&ws, out, scroll, is_hovered,
                         scroll_offset, scroll_target, scroll_step, scroll_inc,
                         scroll_offset, scroll_target, scroll_step, scroll_inc,
                         &style->scrollbar, in, font);
                         &style->scrollbar, in, font);
                 /* Eat mouse scroll if we're active */
                 /* Eat mouse scroll if we're active */
-                if (edit->active && in && in->mouse.scroll_delta.y) {
+                if (is_hovered && in->mouse.scroll_delta.y) {
                     in->mouse.scroll_delta.y = 0;
                     in->mouse.scroll_delta.y = 0;
                 }
                 }
             }
             }

+ 2 - 3
src/nuklear_edit.c

@@ -188,7 +188,6 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
 
 
     /* update edit state */
     /* update edit state */
     prev_state = (char)edit->active;
     prev_state = (char)edit->active;
-    is_hovered = (char)nk_input_is_mouse_hovering_rect(in, bounds);
     if (in && in->mouse.buttons[NK_BUTTON_LEFT].clicked && in->mouse.buttons[NK_BUTTON_LEFT].down) {
     if (in && in->mouse.buttons[NK_BUTTON_LEFT].clicked && in->mouse.buttons[NK_BUTTON_LEFT].down) {
         edit->active = NK_INBOX(in->mouse.pos.x, in->mouse.pos.y,
         edit->active = NK_INBOX(in->mouse.pos.x, in->mouse.pos.y,
                                 bounds.x, bounds.y, bounds.w, bounds.h);
                                 bounds.x, bounds.y, bounds.w, bounds.h);
@@ -508,11 +507,11 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
                 scroll_step = scroll.h * 0.10f;
                 scroll_step = scroll.h * 0.10f;
                 scroll_inc = scroll.h * 0.01f;
                 scroll_inc = scroll.h * 0.01f;
                 scroll_target = text_size.y;
                 scroll_target = text_size.y;
-                edit->scrollbar.y = nk_do_scrollbarv(&ws, out, scroll, edit->active && in,
+                edit->scrollbar.y = nk_do_scrollbarv(&ws, out, scroll, is_hovered,
                         scroll_offset, scroll_target, scroll_step, scroll_inc,
                         scroll_offset, scroll_target, scroll_step, scroll_inc,
                         &style->scrollbar, in, font);
                         &style->scrollbar, in, font);
                 /* Eat mouse scroll if we're active */
                 /* Eat mouse scroll if we're active */
-                if (edit->active && in && in->mouse.scroll_delta.y) {
+                if (is_hovered && in->mouse.scroll_delta.y) {
                     in->mouse.scroll_delta.y = 0;
                     in->mouse.scroll_delta.y = 0;
                 }
                 }
             }
             }

+ 1 - 1
src/nuklear_text_editor.c

@@ -292,7 +292,7 @@ nk_textedit_move_to_word_previous(struct nk_text_edit *state)
    int c = state->cursor - 1;
    int c = state->cursor - 1;
    if (c > 0) {
    if (c > 0) {
       if (nk_is_word_boundary(state, c)) {
       if (nk_is_word_boundary(state, c)) {
-         while (c >= 0 && nk_is_word_boundary(state, --c));
+         while (c > 0 && nk_is_word_boundary(state, --c));
       }
       }
       while (!nk_is_word_boundary(state, --c));
       while (!nk_is_word_boundary(state, --c));
       c++;
       c++;