1

In Delphi 11, using the FMX framework, I am trying to achieve a smooth resize of a TForm, but each time I change the Left and Width of a TForm simultaneously, the form appears to jitter. As if first the Left position is changed, the form updated, then the Width. Same problem when using SetBounds.

In the VCL framework, there is the option to use DoubleBuffered, but this is absent in FMX.

I have tried several possible solutions, like nesting the code inside a BeginUpdate/EndUpdate, to no avail.

The shortest piece of code to more or less illustrate this is:

unit JitteryResizeTestUnit;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls;

type
  TForm1 = class(TForm)
    tmr1: TTimer;
    procedure tmr1Timer(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.tmr1Timer(Sender: TObject);
begin
  if Left < 50 then tmr1.Enabled := False;
  Left := Left - 10;
  Width := Width + 10
end;

end.

With, for instance, a timer Interval of 50.

Domus
  • 1,263
  • 7
  • 23
  • Setting Left and Width separately can indeed have this effect, but replaced by a single SetBounds call should avoid that. Perhaps hardware related, but I cannot reproduce it here even with your code. – Uwe Raabe Aug 01 '23 at 12:11
  • Here the window visibly moves to the left followed by getting wider by the same amount as separate steps so the right border is jittery. – Brian Aug 01 '23 at 12:17
  • @UweRaabe I mentioned in my question that SetBounds doesn't solve anything. – Domus Aug 01 '23 at 12:19
  • There is indeed some jitter here when Width changes after Left, but only for part of the events. Even that can be solved by wrapping both commands in a BeginUpdate/EndUpdate, jut like SetBounds avoids the jitter, too. In the moment I cannot see the effect you describe. – Uwe Raabe Aug 01 '23 at 12:34
  • @UweRaabe As I wrote in the question, I tried SetBounds AND putting it all in-between BeginUpdate/EndUpdate. Here is a video of the result. https://youtu.be/G5oK64olWfk I put a rectangle in there to better show the jittering. The capture is not perfect and much of the jittering is not shown because of low fps, but it does the trick. – Domus Aug 01 '23 at 13:36
  • 1
    Yes, this is a classic problem. In Windows, it is difficult to smoothly expand a window to the left (or upwards). To the right (or downwards) is no problem, though. (The same problem exists in the VCL.) Here's more info: https://stackoverflow.com/questions/48825519/flicker-free-expansion-resize-of-a-window-to-the-left – Andreas Rejbrand Aug 01 '23 at 16:08
  • @AndreasRejbrand Aha! Thanks a lot! Yes, it only occurs when expanding to the left and upwards. I have abandoned my OCD about this issue and am attempting to move on. :) – Domus Aug 01 '23 at 20:24

0 Answers0