Skip to content

Commit

Permalink
Fixed vurtun#145 scrollbar mouse grabbing behavior
Browse files Browse the repository at this point in the history
While mouse grabbing already works in x-direction for vertical and
in y-direction for horizontal scrollbars moving over scrollbar
boundries in the other direction would fail. The problem is now fixed
and scrollbar should work as expected. Note: interestingly slider
already work correctly even though I did not do anything to make it
work correctly.
  • Loading branch information
vurtun committed May 20, 2016
1 parent eb500b0 commit 2e975a3
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -12442,20 +12442,19 @@ nk_scrollbar_behavior(nk_flags *state, struct nk_input *in,
float pixel, delta;
*state = NK_WIDGET_STATE_ACTIVE;
if (o == NK_VERTICAL) {
float cursor_y;
pixel = in->mouse.delta.y;
delta = (pixel / scroll.h) * target;
scroll_offset = NK_CLAMP(0, scroll_offset + delta, target - scroll.h);
/* This is probably one of my most disgusting hacks I have ever done.
* This basically changes the mouse clicked position with the moving
* cursor. This allows for better scroll behavior but resulted into me
* having to remove const correctness for input. But in the end I believe
* it is worth it. */
in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.y += in->mouse.delta.y;
cursor_y = scroll.y + ((scroll_offset/target) * scroll.h);
in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.y = cursor_y + cursor.h/2.0f;
} else {
float cursor_x;
pixel = in->mouse.delta.x;
delta = (pixel / scroll.w) * target;
scroll_offset = NK_CLAMP(0, scroll_offset + delta, target - scroll.w);
in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.x += in->mouse.delta.x;
cursor_x = scroll.x + ((scroll_offset/target) * scroll.w);
in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.x = cursor_x + cursor.w/2.0f;
}
} else if (has_scrolling && ((in->mouse.scroll_delta<0) ||
(in->mouse.scroll_delta>0))) {
Expand Down Expand Up @@ -15288,7 +15287,7 @@ nk_window_is_any_hovered(struct nk_context *ctx)
} else if (nk_input_is_mouse_hovering_rect(&ctx->input, iter->bounds)) {
return 1;
}
/* check if window popup is being hovered */
/* check if window is being hovered */
if (iter->popup.active && nk_input_is_mouse_hovering_rect(&ctx->input, iter->popup.win->bounds))
return 1;
iter = iter->next;
Expand Down

0 comments on commit 2e975a3

Please sign in to comment.