Recent

Author Topic: TDrawGrid excessive mouse wheel speed, and my solution.  (Read 2649 times)

Manlio

  • Full Member
  • ***
  • Posts: 125
  • Pascal dev
TDrawGrid excessive mouse wheel speed, and my solution.
« on: July 17, 2021, 06:26:52 pm »
I find that when using a mouse wheel to scroll through a long list implemented with TDrawStringGrid, the scrolling speed is so high that it makes borderline unusable. A tiny movement on the wheel translates in more than a pageful of items - it's more than annoying, it's just unusable, very quickly one gives up and goes to use the scrollbar instead.

Today, after yet another complaint from a user, I decided to find a solution, and I came up with the following approach: an Integer property WheelBrakes which slows down the scrolling speed as follows.

Code: Pascal  [Select][+][-]
  1.     TMyDrawGrid = class (TDrawGrid)
  2.     private
  3.       fWheelCount: integer;
  4.       fWheelDelta: integer;
  5.       fWheelBrakes: integer;
  6.     protected
  7.       procedure GridMouseWheel(shift: TShiftState; Delta: Integer); override;
  8.     published
  9.       property WheelBrakes: integer read fWheelBrakes write fWheelBrakes;
  10.     end;
  11.  

Implementation:

Code: Pascal  [Select][+][-]
  1.     procedure TMyDrawGrid.GridMouseWheel(shift: TShiftState; Delta: Integer);
  2.     begin
  3.       if WheelBrakes > 0 then begin
  4.         if fWheelDelta <> Delta then begin
  5.           fWheelDelta := delta;
  6.           fWheelCount := 0;
  7.         end;
  8.         inc(fWheelCount);
  9.         if fWheelCount <= fWheelBrakes then exit;
  10.         fWheelCount := 0;
  11.       end;
  12.       inherited GridMouseWheel(shift, Delta);
  13.     end;
  14.  

Basically, if WheelBrakes > 0, a corresponding number of scroll commands are skipped, and the scrolling becomes correspondingly slower. I find that WheelBrakes = 4 is about right for my purposes.

I hope this may be useful to someone.

Best regards to all!
manlio mazzon gmail

jamie

  • Hero Member
  • *****
  • Posts: 4838
Re: TDrawGrid excessive mouse wheel speed, and my solution.
« Reply #1 on: July 17, 2021, 06:30:51 pm »
What widget are you on because I seem to remember some widgets did not act the same across the board with mouse wheels.

Bad implementation of the mouse scroll, it shouldn't be flying off the map like that.
The only true wisdom is knowing you know nothing

Manlio

  • Full Member
  • ***
  • Posts: 125
  • Pascal dev
Re: TDrawGrid excessive mouse wheel speed, and my solution.
« Reply #2 on: July 26, 2021, 04:57:19 pm »
What widget are you on

I tested the above on Windows and MacOS (cocoa). In both cases the mouse wheel is much faster than desired, and in both cases my code works at making it more usable. And in both cases the same value of WheelBrakes seems to bring similar results in terms of scrolling speed, which to me it means that mouse wheel actions in Windows and MacOS are probably implemented in the same way.

(Sorry for the slow reply)
manlio mazzon gmail

jamie

  • Hero Member
  • *****
  • Posts: 4838
Re: TDrawGrid excessive mouse wheel speed, and my solution.
« Reply #3 on: July 26, 2021, 11:52:30 pm »
if it works for you then go with it..

Delta for the most part of 120 in value for each click of the mouse wheel. This was done by MS because finer mouse wheels can  be used which then give you lower values per wheel click.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018