aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dc/dc.c16
-rw-r--r--teensy/teensy_ui.c2
2 files changed, 5 insertions, 13 deletions
diff --git a/dc/dc.c b/dc/dc.c
index 01915a6..93fa220 100644
--- a/dc/dc.c
+++ b/dc/dc.c
@@ -82,26 +82,16 @@ void tick(void)
if (tyui_button("press me"))
toggled = !toggled;
- tyui_layout((float[]){0.1, 0.2, 0.5, 0.1, 0});
+ tyui_layout((float[]){0.1, 0.2, 0});
static float xvalue = 10;
tyui_text("x");
tyui_text("%g", xvalue);
- tyui_slider(0, 100, 1, &xvalue);
- if (tyui_button("^"))
- xvalue++;
- if (tyui_button("v"))
- xvalue--;
- xvalue = floor(xvalue);
+ tyui_slider(0, 100, 5, &xvalue);
static float yvalue = 50;
tyui_text("y");
tyui_text("%g", yvalue);
- tyui_slider(0, 100, 1, &yvalue);
- if (tyui_button("^"))
- yvalue++;
- if (tyui_button("v"))
- yvalue--;
- yvalue = floor(yvalue);
+ tyui_slider(0, 100, 5, &yvalue);
tyui_layout(NULL);
tyui_end_window();
diff --git a/teensy/teensy_ui.c b/teensy/teensy_ui.c
index e8d71eb..918d203 100644
--- a/teensy/teensy_ui.c
+++ b/teensy/teensy_ui.c
@@ -1,6 +1,7 @@
#include "teensy_ui.h"
#include <assert.h>
+#include <math.h>
#include <stdarg.h>
#include "teensy_list.h"
@@ -417,6 +418,7 @@ void tyui_slider(float min, float max, float step, float *value)
if (hovered && ty_button_down(TY_BTN_DB_LMB)) {
float new_val = (float)(mouse_pos.x - bar_rect.x) / bar_rect.w * (max - min) + min;
+ new_val = round(new_val / step) * step;
*value = new_val;
}
}