shithub: microui

Download patch

ref: 71dc0b6cfdf0e63dfc7e9c8a13d064db8c446f53
parent: f451aa33dd2b30fbf75887b6a4f6936533b4abba
author: rxi <rxi@users.noreply.github.com>
date: Thu Apr 18 15:07:10 EDT 2019

Replaced mu_input_mousewheel() with mu_input_scroll()

--- a/demo/main.c
+++ b/demo/main.c
@@ -277,7 +277,7 @@
       switch (e.type) {
         case SDL_QUIT: exit(EXIT_SUCCESS); break;
         case SDL_MOUSEMOTION: mu_input_mousemove(ctx, e.motion.x, e.motion.y); break;
-        case SDL_MOUSEWHEEL: mu_input_mousewheel(ctx, e.wheel.y); break;
+        case SDL_MOUSEWHEEL: mu_input_scroll(ctx, 0, e.wheel.y * -30); break;
         case SDL_TEXTINPUT: mu_input_text(ctx, e.text.text); break;
 
         case SDL_MOUSEBUTTONDOWN:
--- a/src/microui.c
+++ b/src/microui.c
@@ -177,9 +177,10 @@
   expect(ctx->id_stack.idx        == 0);
   expect(ctx->layout_stack.idx    == 0);
 
-  /* handle mouse wheel scrolling */
-  if (ctx->scroll_target && ctx->mouse_wheel) {
-    ctx->scroll_target->scroll.y -= ctx->mouse_wheel * 30;
+  /* handle scroll input */
+  if (ctx->scroll_target) {
+    ctx->scroll_target->scroll.x += ctx->scroll_delta.x;
+    ctx->scroll_target->scroll.y += ctx->scroll_delta.y;
   }
 
   /* unset focus if focus id was not touched this frame */
@@ -197,7 +198,7 @@
   ctx->key_pressed = 0;
   ctx->text_input[0] = '\0';
   ctx->mouse_pressed = 0;
-  ctx->mouse_wheel = 0;
+  ctx->scroll_delta = mu_vec2(0, 0);
   ctx->last_mouse_pos = ctx->mouse_pos;
 
   /* sort root containers by zindex */
@@ -363,8 +364,9 @@
 }
 
 
-void mu_input_mousewheel(mu_Context *ctx, int y) {
-  ctx->mouse_wheel += y;
+void mu_input_scroll(mu_Context *ctx, int x, int y) {
+  ctx->scroll_delta.x += x;
+  ctx->scroll_delta.y += y;
 }
 
 
--- a/src/microui.h
+++ b/src/microui.h
@@ -203,7 +203,7 @@
   mu_Vec2 mouse_pos;
   mu_Vec2 last_mouse_pos;
   mu_Vec2 mouse_delta;
-  int mouse_wheel;
+  mu_Vec2 scroll_delta;
   int mouse_down;
   int mouse_pressed;
   int key_down;
@@ -234,7 +234,7 @@
 void mu_input_mousemove(mu_Context *ctx, int x, int y);
 void mu_input_mousedown(mu_Context *ctx, int x, int y, int btn);
 void mu_input_mouseup(mu_Context *ctx, int x, int y, int btn);
-void mu_input_mousewheel(mu_Context *ctx, int y);
+void mu_input_scroll(mu_Context *ctx, int x, int y);
 void mu_input_keydown(mu_Context *ctx, int key);
 void mu_input_keyup(mu_Context *ctx, int key);
 void mu_input_text(mu_Context *ctx, const char *text);