shithub: neindaw

Download patch

ref: af6b3f2488b4bb5f6650c24b941dbe75184a8fe9
parent: 72598d67523d58bc2894edbb8d2e3bccb27653b5
author: Sigrid Haflínudóttir <[email protected]>
date: Mon Jan 13 18:41:46 EST 2020

cfg: fix button state on press/release, fixes gate not working

--- a/cfg/cfg.c
+++ b/cfg/cfg.c
@@ -193,6 +193,7 @@
 {
 	UI *c, *slider;
 	double v;
+	mu_Id id;
 	int i, state, n, widths[32], maxwidth, x;
 	char tmp[256];
 
@@ -214,17 +215,21 @@
 				process_ui(c);
 			break;
 		case UIButton:
-			if ((state = mu_button(c->label)) != !!c->value) {
-				if (write(c->ctl, state ? "1" : "0", 1) > 0)
-					c->value = state;
+			if (mu_button(c->label) & MU_RES_SUBMIT) {
+				if (write(c->ctl, "1", 1) > 0)
+					c->value = 1;
+			} else if (c->value) {
+				id = mu_get_id(c->label, strlen(c->label));
+				if (mu_ctx.focus != id || mu_ctx.mouse_down != MU_MOUSE_LEFT) {
+					if (write(c->ctl, "0", 1) > 0)
+						c->value = 0;
+				}
 			}
 			break;
 		case UICheckBox:
 			state = !!c->value;
-			if (mu_checkbox(&state, c->label) & MU_RES_CHANGE) {
-				if (write(c->ctl, state ? "1" : "0", 1) > 0)
-					c->value = state;
-			}
+			if ((mu_checkbox(&state, c->label) & MU_RES_CHANGE) != 0 && write(c->ctl, state ? "1" : "0", 1) > 0)
+				c->value = state;
 			break;
 		case UIVSlider: /* FIXME no vslider in µui yet */
 		case UIHSlider: