diff options
| author | Matthias Melcher <github@matthiasm.com> | 2025-12-06 00:16:00 +0100 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2025-12-06 00:16:04 +0100 |
| commit | b2746ad28693d61cecaa1e9fb57ab93c0050e3d3 (patch) | |
| tree | 2926036067991f88fef4ea29aa421468b754cff6 | |
| parent | 87160b6eb9143e044926827b82a2df021cff9c83 (diff) | |
Change arrow keys in log slider to even increments. #1232
| -rw-r--r-- | FL/Fl_Slider.H | 1 | ||||
| -rw-r--r-- | src/Fl_Slider.cxx | 22 |
2 files changed, 19 insertions, 4 deletions
diff --git a/FL/Fl_Slider.H b/FL/Fl_Slider.H index 8a70e4e85..ded8cde38 100644 --- a/FL/Fl_Slider.H +++ b/FL/Fl_Slider.H @@ -102,6 +102,7 @@ protected: void draw_ticks(const Fl_Rect& r, int S); double value_to_position(double val) const; double position_to_value(double pos) const; + double increment_lin_log(double v, int n, int range); public: 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; |
