shithub: microui

Download patch

ref: d7bf4e0f786812f864938ebed211140836aa6058
parent: ae610b9d4c0fff7227cd9d4ea94122167eb23cf6
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sat Jan 4 18:39:15 EST 2020

left/right to move slider

--- a/demo/plan9.c
+++ b/demo/plan9.c
@@ -110,6 +110,8 @@
 			case Kbs: nkey = MU_KEY_BACKSPACE; break;
 			case '\n': nkey = MU_KEY_RETURN; break;
 			case Knack: nkey = MU_KEY_NACK; break;
+			case Kleft: nkey = MU_KEY_LEFT; break;
+			case Kright: nkey = MU_KEY_RIGHT; break;
 			case Kesc: mu_set_focus(ctx, 0); break;
 			default:
 				if (key < 0xf000 || key > 0xffff) {
--- a/src/microui.c
+++ b/src/microui.c
@@ -868,10 +868,21 @@
   mu_update_control(ctx, id, base, opt);
 
   /* handle input */
-  if (ctx->focus == id && ctx->mouse_down == MU_MOUSE_LEFT) {
-    v = low + ((mu_Real) (ctx->mouse_pos.x - base.x) / base.w) * (high - low);
-    if (step) { v = ((long) ((v + step/2) / step)) * step; }
+  if (ctx->focus == id) {
+    if (ctx->mouse_down == MU_MOUSE_LEFT) {
+      v = low + ((mu_Real) (ctx->mouse_pos.x - base.x) / base.w) * (high - low);
+    }
+  } else if (ctx->hover == id) {
+    if ((ctx->key_pressed & (MU_KEY_LEFT | MU_KEY_RIGHT)) == MU_KEY_LEFT) {
+      v -= step ? step : 1;
+      if (v < low) v = low;
+    } else if ((ctx->key_pressed & (MU_KEY_LEFT | MU_KEY_RIGHT)) == MU_KEY_RIGHT) {
+      v += step ? step : 1;
+      if (v > high) v = high;
+    }
   }
+
+  if (step) { v = ((long) ((v + step/2) / step)) * step; }
   /* clamp and store value, update res */
   *value = v = mu_clamp(v, low, high);
   if (last != v) { res |= MU_RES_CHANGE; }
--- a/src/microui.h
+++ b/src/microui.h
@@ -112,6 +112,8 @@
   MU_KEY_BACKSPACE    = (1 << 3),
   MU_KEY_RETURN       = (1 << 4),
   MU_KEY_NACK         = (1 << 5),
+  MU_KEY_LEFT         = (1 << 6),
+  MU_KEY_RIGHT        = (1 << 7),
 };