Jump to content

Mousewheel - scroll distance


Recommended Posts

I have noticed that when using the mousewheel the contents are always scrolled to the size of the scroll box client height - in other words it is basically like a snap to page result.

 

I would like to only scroll a small distance but I cannot find a good way to do it.

 

I can change the code in smartcl.scroll - but obviously not a good long term solution :)

 

procedure TW3ScrollController.HandleMouseWheel(Sender: TObject;
  Shift: TShiftState; WheelDelta: integer;
  const MousePos: TPoint; var Handled: boolean);
begin
  if FDirection in [mdVertical,mdAll] then
  begin
    var dy := FContentTop + (Sign(WheelDelta) * 100);//FScrollControl.ClientHeight);
    MomentumScrollTo(FContentLeft, dy);
    Handled := true;
  end;
end;

Any suggestions for setting the value of FScrollControl.ClientHeight to smaller than the actual component height? 

Link to post
Share on other sites
  • Moderators

you could write a class helper unit for the scrollcontroller with a modified HandleMouseWheel procedure which does what you want 

In Delphi, class helper functions take precedence over the actual class type. 

The absence/presence of this unit in uses clauses then modifies behaviour, and without making changes to rtl production code

Have not tried this in SMS, but might work

 

at least such a unit compiles ok

unit Unit2;

interface

uses 
  System.Types,
  System.Types.Convert,
  SmartCL.System, SmartCL.Scroll, smartcl.components, system.types.graphics;

type
 TW3ScrollControllerHelper = Class helper for TW3ScrollController
    procedure   HandleMouseWheel(Sender: TObject; Shift: TShiftState;
                WheelDelta: integer;
                const MousePos: TPoint;
                var Handled: boolean);
end;

implementation

procedure TW3ScrollControllerHelper.HandleMouseWheel(Sender: TObject;
  Shift: TShiftState; WheelDelta: integer;
  const MousePos: TPoint; var Handled: boolean);
begin
  if FDirection in [mdVertical,mdAll] then
  begin
    var dy := FContentTop + (Sign(WheelDelta) * 100);
    MomentumScrollTo(FContentLeft, dy);
    Handled := true;
  end;
end;

end.
Link to post
Share on other sites
  • Moderators

Making methods virtual is definitely the easiest way to be able to override them

 

Testing whether or not the idea of overriding methods through helper functions works in SMS as expected, that seems to work ok

 

The unit below overrides the SetBorderRadius procedure in the TW3CustomControl class (just adds an alert)

Adding a TW3CustomControl descendant (TW3Panel) to a Form and setting the borderradius 

  Panel.BorderRadius := 2;

does indeed produce the alert box

 

unit Unit2;

interface

uses
  System.Types,
  System.Types.Convert,
  SmartCL.System, SmartCL.Components, SmartCL.Controls.Panel;

type
 TW3CustomControlHelper = Class helper for TW3CustomControl
    procedure SetBorderRadius(aNewRadius: integer);
    property BorderRadius: integer write SetBorderRadius;
end;

implementation

procedure TW3CustomControlHelper.SetBorderRadius(aNewRadius: integer);
begin
  asm window.alert('setborderradius to ' + @aNewRadius); end;
  inherited SetBorderRadius(aNewRadius);
end;

end.

 

Link to post
Share on other sites
  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...