Skip to content

Commit

Permalink
Add AutoSize property to TALLayout https://quality.embarcadero.com/br…
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeus64 committed Oct 13, 2023
1 parent 3bad90a commit 7cc471c
Show file tree
Hide file tree
Showing 7 changed files with 256 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
<Icon_MainIcon>$(BDS)\bin\delphi_PROJECTICON.ico</Icon_MainIcon>
<Icns_MainIcns>$(BDS)\bin\delphi_PROJECTICNS.icns</Icns_MainIcns>
<SanitizedProjectName>ALLiveVideoChatClient</SanitizedProjectName>
<DCC_UnitSearchPath>..\..\..\..\Embarcadero\Alexandria\fmx;..\..\..\..\Embarcadero\Alexandria\rtl\ios;..\..\..\Embarcadero\Alexandria\rtl\osx;..\..\..\..\Embarcadero\Alexandria\rtl\android;..\..\..\..\Source;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
<DCC_UnitSearchPath>..\..\..\..\Embarcadero\Alexandria\fmx;..\..\..\..\Embarcadero\Alexandria\rtl\ios;..\..\..\..\Embarcadero\Alexandria\rtl\osx;..\..\..\..\Embarcadero\Alexandria\rtl\android;..\..\..\..\Source;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
<OrientationPortrait>true</OrientationPortrait>
<OrientationPortraitUpsideDown>true</OrientationPortraitUpsideDown>
<DCC_CodePage>65001</DCC_CodePage>
Expand Down
28 changes: 19 additions & 9 deletions Embarcadero/Alexandria/Alexandria.patch
Original file line number Diff line number Diff line change
Expand Up @@ -286,23 +286,33 @@ diff --git a/Embarcadero/Alexandria/fmx/FMX.Controls.pas b/Embarcadero/Alexandri
end;

function TControl.GetLocked: Boolean;
@@ -4122,6 +4151,7 @@
@@ -3935,7 +3964,9 @@
begin
if not FNeedAlign then
Exit;
+ var LOriginalSize: TPointF := Size.Size; // https://quality.embarcadero.com/browse/RSP-15768
AlignObjects(Self, FPadding, FSize.Width, FSize.Height, FLastWidth, FLastHeight, FDisableAlign);
+ if not LOriginalSize.EqualsTo(Size.Size) then DoRealign; // https://quality.embarcadero.com/browse/RSP-15768
end;

procedure TControl.Realign;
@@ -4122,6 +4153,7 @@
ApplyTriggerEffect(Self, 'IsMouseOver');
if Assigned(FOnMouseEnter) then
FOnMouseEnter(Self);
+ if fparentControl <> nil then fparentControl.ChildrenMouseEnter(Self); // https://quality.embarcadero.com/browse/RSP-24397
end;

procedure TControl.DoMouseLeave;
@@ -4131,6 +4161,7 @@
@@ -4131,6 +4163,7 @@
ApplyTriggerEffect(Self, 'IsMouseOver');
if Assigned(FOnMouseLeave) then
FOnMouseLeave(Self);
+ if fparentControl <> nil then fparentControl.ChildrenMouseLeave(Self); // https://quality.embarcadero.com/browse/RSP-24397
end;

function TControl.GetCanFocus: Boolean;
@@ -4422,7 +4453,7 @@
@@ -4422,7 +4455,7 @@
end;

if not Handled and (FParent <> nil) and (EventInfo.GestureID <> sgiNoGesture) and Supports(Parent, IGestureControl, LGObj) then
Expand All @@ -311,31 +321,31 @@ diff --git a/Embarcadero/Alexandria/fmx/FMX.Controls.pas b/Embarcadero/Alexandri
end;

function TControl.ConvertLocalPointFrom(const AControl: TControl; const AControlLocalPoint: TPointF): TPointF;
@@ -4547,6 +4578,7 @@
@@ -4547,6 +4580,7 @@

if Assigned(FOnMouseDown) then
FOnMouseDown(Self, Button, Shift, X, Y);
+ if fparentControl <> nil then fparentControl.ChildrenMouseDown(Self, Button, Shift, X, Y); // https://quality.embarcadero.com/browse/RSP-24397
if FAutoCapture then
Capture;
if Button = TMouseButton.mbLeft then
@@ -4569,6 +4601,7 @@
@@ -4569,6 +4603,7 @@
begin
if Assigned(FOnMouseMove) then
FOnMouseMove(Self, Shift, X, Y);
+ if fparentControl <> nil then fparentControl.ChildrenMouseMove(Self, Shift, X, Y); // https://quality.embarcadero.com/browse/RSP-24397
end;

procedure TControl.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Single);
@@ -4577,6 +4610,7 @@
@@ -4577,6 +4612,7 @@

if Assigned(FOnMouseUp) then
FOnMouseUp(Self, Button, Shift, X, Y);
+ if fparentControl <> nil then fparentControl.ChildrenMouseUp(Self, Button, Shift, X, Y); // https://quality.embarcadero.com/browse/RSP-24397
if FPressed then
begin
FPressed := False;
@@ -4591,6 +4625,41 @@
@@ -4591,6 +4627,41 @@
FOnMouseWheel(Self, Shift, WheelDelta, Handled)
end;

Expand Down Expand Up @@ -377,7 +387,7 @@ diff --git a/Embarcadero/Alexandria/fmx/FMX.Controls.pas b/Embarcadero/Alexandri
procedure TControl.DragEnter(const Data: TDragObject; const Point: TPointF);
var
Operation: TDragOperation;
@@ -6013,7 +6082,7 @@
@@ -6013,7 +6084,7 @@
KillResourceLink;
if csLoading in ComponentState then
Exit;
Expand All @@ -386,7 +396,7 @@ diff --git a/Embarcadero/Alexandria/fmx/FMX.Controls.pas b/Embarcadero/Alexandri
end;

procedure TStyledControl.AdjustSize;
@@ -7171,7 +7240,7 @@
@@ -7171,7 +7242,7 @@
var
LFontColor: TAlphaColor;
begin
Expand Down
135 changes: 118 additions & 17 deletions Source/Alcinoe.FMX.Layouts.pas
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,18 @@ interface
{*************************}
[ComponentPlatforms($FFFF)]
TALLayout = class(TLayout)
private
FAutoSize: Boolean;
procedure SetAutoSize(const Value: Boolean);
protected
procedure DoRealign; override;
procedure AdjustSize; virtual;
public
constructor Create(AOwner: TComponent); override;
published
// Dynamically adjusts the dimensions to accommodate child controls,
// considering their sizes, positions, margins, and alignments.
property AutoSize: Boolean read FAutoSize write SetAutoSize default False;
end;

{*************************}
Expand Down Expand Up @@ -212,9 +222,7 @@ TALScrollBox = class(TALCustomScrollBox)
property OnPainting;
property OnPaint;
property OnResize;
{$IF CompilerVersion >= 32} // tokyo
property OnResized;
{$ENDIF}
{ Drag and Drop events }
property OnDragEnter;
property OnDragLeave;
Expand Down Expand Up @@ -282,9 +290,7 @@ TALVertScrollBox = class(TALCustomScrollBox)
property OnPainting;
property OnPaint;
property OnResize;
{$IF CompilerVersion >= 32} // tokyo
property OnResized;
{$ENDIF}
{ Drag and Drop events }
property OnDragEnter;
property OnDragLeave;
Expand Down Expand Up @@ -352,9 +358,7 @@ TALHorzScrollBox = class(TALCustomScrollBox)
property OnPainting;
property OnPaint;
property OnResize;
{$IF CompilerVersion >= 32} // tokyo
property OnResized;
{$ENDIF}
{ Drag and Drop events }
property OnDragEnter;
property OnDragLeave;
Expand Down Expand Up @@ -397,20 +401,117 @@ implementation
Alcinoe.FMX.Common,
Alcinoe.Common;

{*******************************************************************************************************}
// http://stackoverflow.com/questions/39317984/does-the-delphi-firemonkey-dorealign-implemented-correctly
// https://quality.embarcadero.com/browse/RSP-15768
// often we assign some event to some control onresize (like TText with autosize=True) to
// resize their parentcontrols to the same size as them. But in this way the problem is that if
// we resize the parentcontrol during it's dorealign process then it will not call again dorealign
{$IFNDEF ALCompilerVersionSupported}
{$MESSAGE WARN 'Check if https://quality.embarcadero.com/browse/RSP-15768 was not corrected and adjust the IFDEF'}
{$ENDIF}
{***********************************************}
constructor TALLayout.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FAutoSize := False;
end;

{****************************}
procedure TALLayout.DoRealign;
begin
var LOriginalSize: TPointF := Size.Size;
inherited DoRealign;
if not LOriginalSize.EqualsTo(Size.Size) then DoRealign;
AdjustSize;
end;

{*****************************}
procedure TALLayout.AdjustSize;
begin
if (not (csLoading in ComponentState)) and // loaded will call again AdjustSize
(not (csDestroying in ComponentState)) and // if csDestroying do not do autosize
(FAutoSize) then begin // if FAutoSize is false nothing to adjust

var LSize := TSizeF.Create(0,0);
for var Lcontrol in Controls do begin
case Lcontrol.Align of

//--
TAlignLayout.None,
TAlignLayout.Center:;

//--
TAlignLayout.Top,
TAlignLayout.MostTop,
TAlignLayout.Bottom,
TAlignLayout.MostBottom: begin
LSize.Width := Max(LSize.Width, Width);
LSize.height := Max(LSize.height, Lcontrol.Position.Y + Lcontrol.Height + Lcontrol.Margins.bottom + padding.bottom);
end;

//--
TAlignLayout.Left,
TAlignLayout.MostLeft,
TAlignLayout.Right,
TAlignLayout.MostRight: Begin
LSize.Width := Max(LSize.Width, Lcontrol.Position.X + Lcontrol.width + Lcontrol.Margins.right + padding.right);
LSize.height := Max(LSize.Height, Height);
End;

//--
TAlignLayout.Client,
TAlignLayout.Contents,
TAlignLayout.Scale,
TAlignLayout.Fit,
TAlignLayout.FitLeft,
TAlignLayout.FitRight: Begin
LSize.Width := Max(LSize.Width, Width);
LSize.height := Max(LSize.Height, Height);
End;

//--
TAlignLayout.Horizontal,
TAlignLayout.VertCenter: Begin
LSize.Width := Max(LSize.Width, Width);
End;

//--
TAlignLayout.Vertical,
TAlignLayout.HorzCenter: Begin
LSize.height := Max(LSize.Height, Height);
End;

end;
end;

// This to take care of the align constraint
if Align in [TAlignLayout.Client,
TAlignLayout.Contents,
TAlignLayout.Top,
TAlignLayout.Bottom,
TAlignLayout.MostTop,
TAlignLayout.MostBottom,
TAlignLayout.Horizontal,
TAlignLayout.VertCenter] then begin
LSize.Width := Width;
end;
if Align in [TAlignLayout.Client,
TAlignLayout.Contents,
TAlignLayout.Left,
TAlignLayout.Right,
TAlignLayout.MostLeft,
TAlignLayout.MostRight,
TAlignLayout.Vertical,
TAlignLayout.HorzCenter] then begin
LSize.height := height;
end;

if LSize.Width = 0 then LSize.Width := Width;
if LSize.Height = 0 then LSize.Height := Height;
SetBounds(Position.X, Position.Y, LSize.Width, LSize.Height);

end;
end;

{****************************************************}
procedure TALLayout.SetAutoSize(const Value: Boolean);
begin
if FAutoSize <> Value then
begin
FAutoSize := Value;
AdjustSize;
repaint;
end;
end;

{*********************************************************}
Expand Down
Loading

0 comments on commit 7cc471c

Please sign in to comment.