Einzelnen Beitrag anzeigen

Rollo62
Online

Registriert seit: 15. Mär 2007
4.095 Beiträge
 
Delphi 12 Athens
 
#2

AW: Scrollen zu einer absoluten Position innerhalb einer FMX.TScrollbox

  Alt 30. Aug 2022, 18:08
Ich hatte mir mal sowas gebastelt, ich weiss nicht ob das in Deinem Fall für dich auch funktioniert.
Man muss an allem möglichen Internas rumschrauben, auch sowas wie Targets und AniCalculations, aber das lief dann bei mir.

Delphi-Quellcode:
procedure TCustomScrollBox_Helper.Viewport_ScrollTo(const AX, AY: Single);
var
    LVp : TPointF;
    LTracking : TTouchTracking;
begin
    //04.03.21 Keep last Tracking
    LTracking := Self.AniCalculations.TouchTracking;

    // Make space for the VK-Board
    Self.AniCalculations.TouchTracking := [ ttVertical ];
    // Rx10: Stop Tracking Animation, since no Enable here ?

    LVp := Self.ViewportPosition;

    if ( AX < LVp.X )
       or ( AY < LVp.Y ) then
    begin // Scroll downwards, needs to clear the Min WORKAROUND
        Targets_Reset_Min( 0.0, 0.0 );
    end
    else
    if (AX > ( LVp.X + Self.Width ))
       or (AY > ( LVp.Y + Self.Height )) then
    begin // Scroll uüwards, needs to grow the Max WORKAROUND
        Targets_Reset_Max( AX, AY );
    end;


    Self.ViewportPosition := PointF( AX, AY ); //Self.ViewportPosition.X + AX,
    Self.AniCalculations.TouchTracking := [];

    Self.AniCalculations.TouchTracking := LTracking; // 04.03.21 Reset last tracking

end;

procedure TCustomScrollBox_Helper.Targets_Reset_Min(const AX, AY: Single);
var
    LTargets : array of TAniCalculations.TTarget;
    I : Integer;

begin

      // Make space
      SetLength(LTargets, Self.AniCalculations.TargetCount);
      Self.AniCalculations.GetTargets(LTargets);
      for I := 0 to Length(LTargets)-1 do
      begin
           if LTargets[I].TargetType = TAniCalculations.TTargetType.Min then
           begin // Force MinTarget to new min setting WORKAROUND SCROLLBOX
               LTargets[I].Point := PointF(AX, AY);
           end;
      end;
      Self.AniCalculations.SetTargets(LTargets); // Reset Targets

end;

procedure TCustomScrollBox_Helper.Targets_Reset_Max(const AX, AY: Single);
var
  LTargets: array of TAniCalculations.TTarget;
  LCnt : Integer;
  LTgt : TAniCalculations.TTargetType;
  LIdxMin : Integer;
  LIdxMax : Integer;
  I: Integer;

begin

      // Make space
      LCnt := Self.AniCalculations.TargetCount;
      if LCnt < 2 then
      begin //18.02.22 Need at Least Min/MaxTarget = 2
          LCnt := 2;
      end;

      SetLength(LTargets, LCnt );
      for I := 0 to Length( LTargets )-1 do
      begin
          LTargets[ I ].TargetType := TAniCalculations.TTargetType.Other; // Preset Array
      end;

      Self.AniCalculations.GetTargets( LTargets );

      //18.02.22 Check if Min/MaxTargets needs to be added
      LIdxMin := -1;
      LIdxMax := -1;
      for I := 0 to Length( LTargets )-1 do
      begin
          LTgt := LTargets[ I ].TargetType;

          if ( LTgt <> TAniCalculations.TTargetType.Other ) then
          begin
              if ( LTgt = TAniCalculations.TTargetType.Min ) then
              begin
                  LIdxMin := I;
              end;

              if ( LTgt = TAniCalculations.TTargetType.Max ) then
              begin
                  LIdxMax := I;
              end;

              Continue; //<== WAS ALREADY AVAILABLE ===============================
          end;

          if ( LIdxMax < 0 ) then
          begin
              LIdxMax := I; // First Max
              continue; //<== CONTINUE =====================================
          end;

          if ( LIdxMin < 0 ) then
          begin
              LIdxMin := I; // First Min
              continue; //<== CONTINUE =====================================
          end;

      end;

      if ( LIdxMin < 0 ) and ( LIdxMax < 0 ) then
      begin // Something wrong
      end
      else
      begin
          LTargets[ LIdxMin ].TargetType := TAniCalculations.TTargetType.Min;
          LTargets[ LIdxMin ].Point := PointF( 0.0, 0.0 );

          LTargets[ LIdxMax ].TargetType := TAniCalculations.TTargetType.Max;
          LTargets[ LIdxMax ].Point := PointF( AX, AY );
      end;

      Self.AniCalculations.SetTargets( LTargets ); // Reset Targets
end;

Geändert von Rollo62 (30. Aug 2022 um 18:14 Uhr)
  Mit Zitat antworten Zitat