summaryrefslogtreecommitdiff
path: root/src/Fl_Slider.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2025-12-06 00:16:00 +0100
committerMatthias Melcher <github@matthiasm.com>2025-12-06 00:16:04 +0100
commitb2746ad28693d61cecaa1e9fb57ab93c0050e3d3 (patch)
tree2926036067991f88fef4ea29aa421468b754cff6 /src/Fl_Slider.cxx
parent87160b6eb9143e044926827b82a2df021cff9c83 (diff)
Change arrow keys in log slider to even increments. #1232
Diffstat (limited to 'src/Fl_Slider.cxx')
-rw-r--r--src/Fl_Slider.cxx22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/Fl_Slider.cxx b/src/Fl_Slider.cxx
index 74fe98644..f1d0444ac 100644
--- a/src/Fl_Slider.cxx
+++ b/src/Fl_Slider.cxx
@@ -247,6 +247,20 @@ void Fl_Slider::draw_ticks(const Fl_Rect& r, int /*S*/ /*, int min_spacing*/)
}
}
+/**
+ Adds a sensible step value to the passed value.
+ The step size is not useful in logarithmic scales.
+ */
+double Fl_Slider::increment_lin_log(double v, int n, int range) {
+ if (scale() == Scale_Type::LOG_SCALE) {
+ double pos = value_to_position(v);
+ pos = pos + (n*4/(double)range);
+ return position_to_value(pos);
+ } else {
+ return increment(v, n);
+ }
+}
+
int Fl_Slider::handle(int event, int X, int Y, int W, int H) {
// Fl_Widget_Tracker wp(this);
@@ -330,7 +344,7 @@ int Fl_Slider::handle(int event, int X, int Y, int W, int H) {
if (horizontal()) return 0;
handle_push();
if (wp.deleted()) return 1;
- handle_drag(clamp(increment(value(),-1)));
+ handle_drag(clamp(increment_lin_log(value(), -1, H)));
if (wp.deleted()) return 1;
handle_release();
return 1;
@@ -338,7 +352,7 @@ int Fl_Slider::handle(int event, int X, int Y, int W, int H) {
if (horizontal()) return 0;
handle_push();
if (wp.deleted()) return 1;
- handle_drag(clamp(increment(value(),1)));
+ handle_drag(clamp(increment_lin_log(value(), 1, H)));
if (wp.deleted()) return 1;
handle_release();
return 1;
@@ -346,7 +360,7 @@ int Fl_Slider::handle(int event, int X, int Y, int W, int H) {
if (!horizontal()) return 0;
handle_push();
if (wp.deleted()) return 1;
- handle_drag(clamp(increment(value(),-1)));
+ handle_drag(clamp(increment_lin_log(value(), -1, W)));
if (wp.deleted()) return 1;
handle_release();
return 1;
@@ -354,7 +368,7 @@ int Fl_Slider::handle(int event, int X, int Y, int W, int H) {
if (!horizontal()) return 0;
handle_push();
if (wp.deleted()) return 1;
- handle_drag(clamp(increment(value(),1)));
+ handle_drag(clamp(increment_lin_log(value(), 1, W)));
if (wp.deleted()) return 1;
handle_release();
return 1;