Skip to content

Commit 7cc471c

Browse files
committed
Add AutoSize property to TALLayout https://quality.embarcadero.com/browse/RSP-42427
1 parent 3bad90a commit 7cc471c

File tree

7 files changed

+256
-49
lines changed

7 files changed

+256
-49
lines changed

Demos/ALLiveVideoChat/Client/_Source/ALLiveVideoChatClient.dproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
<Icon_MainIcon>$(BDS)\bin\delphi_PROJECTICON.ico</Icon_MainIcon>
183183
<Icns_MainIcns>$(BDS)\bin\delphi_PROJECTICNS.icns</Icns_MainIcns>
184184
<SanitizedProjectName>ALLiveVideoChatClient</SanitizedProjectName>
185-
<DCC_UnitSearchPath>..\..\..\..\Embarcadero\Alexandria\fmx;..\..\..\..\Embarcadero\Alexandria\rtl\ios;..\..\..\Embarcadero\Alexandria\rtl\osx;..\..\..\..\Embarcadero\Alexandria\rtl\android;..\..\..\..\Source;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
185+
<DCC_UnitSearchPath>..\..\..\..\Embarcadero\Alexandria\fmx;..\..\..\..\Embarcadero\Alexandria\rtl\ios;..\..\..\..\Embarcadero\Alexandria\rtl\osx;..\..\..\..\Embarcadero\Alexandria\rtl\android;..\..\..\..\Source;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
186186
<OrientationPortrait>true</OrientationPortrait>
187187
<OrientationPortraitUpsideDown>true</OrientationPortraitUpsideDown>
188188
<DCC_CodePage>65001</DCC_CodePage>

Embarcadero/Alexandria/Alexandria.patch

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -286,23 +286,33 @@ diff --git a/Embarcadero/Alexandria/fmx/FMX.Controls.pas b/Embarcadero/Alexandri
286286
end;
287287

288288
function TControl.GetLocked: Boolean;
289-
@@ -4122,6 +4151,7 @@
289+
@@ -3935,7 +3964,9 @@
290+
begin
291+
if not FNeedAlign then
292+
Exit;
293+
+ var LOriginalSize: TPointF := Size.Size; // https://quality.embarcadero.com/browse/RSP-15768
294+
AlignObjects(Self, FPadding, FSize.Width, FSize.Height, FLastWidth, FLastHeight, FDisableAlign);
295+
+ if not LOriginalSize.EqualsTo(Size.Size) then DoRealign; // https://quality.embarcadero.com/browse/RSP-15768
296+
end;
297+
298+
procedure TControl.Realign;
299+
@@ -4122,6 +4153,7 @@
290300
ApplyTriggerEffect(Self, 'IsMouseOver');
291301
if Assigned(FOnMouseEnter) then
292302
FOnMouseEnter(Self);
293303
+ if fparentControl <> nil then fparentControl.ChildrenMouseEnter(Self); // https://quality.embarcadero.com/browse/RSP-24397
294304
end;
295305

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

304314
function TControl.GetCanFocus: Boolean;
305-
@@ -4422,7 +4453,7 @@
315+
@@ -4422,7 +4455,7 @@
306316
end;
307317

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

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

316326
if Assigned(FOnMouseDown) then
317327
FOnMouseDown(Self, Button, Shift, X, Y);
318328
+ if fparentControl <> nil then fparentControl.ChildrenMouseDown(Self, Button, Shift, X, Y); // https://quality.embarcadero.com/browse/RSP-24397
319329
if FAutoCapture then
320330
Capture;
321331
if Button = TMouseButton.mbLeft then
322-
@@ -4569,6 +4601,7 @@
332+
@@ -4569,6 +4603,7 @@
323333
begin
324334
if Assigned(FOnMouseMove) then
325335
FOnMouseMove(Self, Shift, X, Y);
326336
+ if fparentControl <> nil then fparentControl.ChildrenMouseMove(Self, Shift, X, Y); // https://quality.embarcadero.com/browse/RSP-24397
327337
end;
328338

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

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

@@ -377,7 +387,7 @@ diff --git a/Embarcadero/Alexandria/fmx/FMX.Controls.pas b/Embarcadero/Alexandri
377387
procedure TControl.DragEnter(const Data: TDragObject; const Point: TPointF);
378388
var
379389
Operation: TDragOperation;
380-
@@ -6013,7 +6082,7 @@
390+
@@ -6013,7 +6084,7 @@
381391
KillResourceLink;
382392
if csLoading in ComponentState then
383393
Exit;
@@ -386,7 +396,7 @@ diff --git a/Embarcadero/Alexandria/fmx/FMX.Controls.pas b/Embarcadero/Alexandri
386396
end;
387397

388398
procedure TStyledControl.AdjustSize;
389-
@@ -7171,7 +7240,7 @@
399+
@@ -7171,7 +7242,7 @@
390400
var
391401
LFontColor: TAlphaColor;
392402
begin

Source/Alcinoe.FMX.Layouts.pas

Lines changed: 118 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,18 @@ interface
2525
{*************************}
2626
[ComponentPlatforms($FFFF)]
2727
TALLayout = class(TLayout)
28+
private
29+
FAutoSize: Boolean;
30+
procedure SetAutoSize(const Value: Boolean);
2831
protected
2932
procedure DoRealign; override;
33+
procedure AdjustSize; virtual;
34+
public
35+
constructor Create(AOwner: TComponent); override;
36+
published
37+
// Dynamically adjusts the dimensions to accommodate child controls,
38+
// considering their sizes, positions, margins, and alignments.
39+
property AutoSize: Boolean read FAutoSize write SetAutoSize default False;
3040
end;
3141

3242
{*************************}
@@ -212,9 +222,7 @@ TALScrollBox = class(TALCustomScrollBox)
212222
property OnPainting;
213223
property OnPaint;
214224
property OnResize;
215-
{$IF CompilerVersion >= 32} // tokyo
216225
property OnResized;
217-
{$ENDIF}
218226
{ Drag and Drop events }
219227
property OnDragEnter;
220228
property OnDragLeave;
@@ -282,9 +290,7 @@ TALVertScrollBox = class(TALCustomScrollBox)
282290
property OnPainting;
283291
property OnPaint;
284292
property OnResize;
285-
{$IF CompilerVersion >= 32} // tokyo
286293
property OnResized;
287-
{$ENDIF}
288294
{ Drag and Drop events }
289295
property OnDragEnter;
290296
property OnDragLeave;
@@ -352,9 +358,7 @@ TALHorzScrollBox = class(TALCustomScrollBox)
352358
property OnPainting;
353359
property OnPaint;
354360
property OnResize;
355-
{$IF CompilerVersion >= 32} // tokyo
356361
property OnResized;
357-
{$ENDIF}
358362
{ Drag and Drop events }
359363
property OnDragEnter;
360364
property OnDragLeave;
@@ -397,20 +401,117 @@ implementation
397401
Alcinoe.FMX.Common,
398402
Alcinoe.Common;
399403

400-
{*******************************************************************************************************}
401-
// http://stackoverflow.com/questions/39317984/does-the-delphi-firemonkey-dorealign-implemented-correctly
402-
// https://quality.embarcadero.com/browse/RSP-15768
403-
// often we assign some event to some control onresize (like TText with autosize=True) to
404-
// resize their parentcontrols to the same size as them. But in this way the problem is that if
405-
// we resize the parentcontrol during it's dorealign process then it will not call again dorealign
406-
{$IFNDEF ALCompilerVersionSupported}
407-
{$MESSAGE WARN 'Check if https://quality.embarcadero.com/browse/RSP-15768 was not corrected and adjust the IFDEF'}
408-
{$ENDIF}
404+
{***********************************************}
405+
constructor TALLayout.Create(AOwner: TComponent);
406+
begin
407+
inherited Create(AOwner);
408+
FAutoSize := False;
409+
end;
410+
411+
{****************************}
409412
procedure TALLayout.DoRealign;
410413
begin
411-
var LOriginalSize: TPointF := Size.Size;
412414
inherited DoRealign;
413-
if not LOriginalSize.EqualsTo(Size.Size) then DoRealign;
415+
AdjustSize;
416+
end;
417+
418+
{*****************************}
419+
procedure TALLayout.AdjustSize;
420+
begin
421+
if (not (csLoading in ComponentState)) and // loaded will call again AdjustSize
422+
(not (csDestroying in ComponentState)) and // if csDestroying do not do autosize
423+
(FAutoSize) then begin // if FAutoSize is false nothing to adjust
424+
425+
var LSize := TSizeF.Create(0,0);
426+
for var Lcontrol in Controls do begin
427+
case Lcontrol.Align of
428+
429+
//--
430+
TAlignLayout.None,
431+
TAlignLayout.Center:;
432+
433+
//--
434+
TAlignLayout.Top,
435+
TAlignLayout.MostTop,
436+
TAlignLayout.Bottom,
437+
TAlignLayout.MostBottom: begin
438+
LSize.Width := Max(LSize.Width, Width);
439+
LSize.height := Max(LSize.height, Lcontrol.Position.Y + Lcontrol.Height + Lcontrol.Margins.bottom + padding.bottom);
440+
end;
441+
442+
//--
443+
TAlignLayout.Left,
444+
TAlignLayout.MostLeft,
445+
TAlignLayout.Right,
446+
TAlignLayout.MostRight: Begin
447+
LSize.Width := Max(LSize.Width, Lcontrol.Position.X + Lcontrol.width + Lcontrol.Margins.right + padding.right);
448+
LSize.height := Max(LSize.Height, Height);
449+
End;
450+
451+
//--
452+
TAlignLayout.Client,
453+
TAlignLayout.Contents,
454+
TAlignLayout.Scale,
455+
TAlignLayout.Fit,
456+
TAlignLayout.FitLeft,
457+
TAlignLayout.FitRight: Begin
458+
LSize.Width := Max(LSize.Width, Width);
459+
LSize.height := Max(LSize.Height, Height);
460+
End;
461+
462+
//--
463+
TAlignLayout.Horizontal,
464+
TAlignLayout.VertCenter: Begin
465+
LSize.Width := Max(LSize.Width, Width);
466+
End;
467+
468+
//--
469+
TAlignLayout.Vertical,
470+
TAlignLayout.HorzCenter: Begin
471+
LSize.height := Max(LSize.Height, Height);
472+
End;
473+
474+
end;
475+
end;
476+
477+
// This to take care of the align constraint
478+
if Align in [TAlignLayout.Client,
479+
TAlignLayout.Contents,
480+
TAlignLayout.Top,
481+
TAlignLayout.Bottom,
482+
TAlignLayout.MostTop,
483+
TAlignLayout.MostBottom,
484+
TAlignLayout.Horizontal,
485+
TAlignLayout.VertCenter] then begin
486+
LSize.Width := Width;
487+
end;
488+
if Align in [TAlignLayout.Client,
489+
TAlignLayout.Contents,
490+
TAlignLayout.Left,
491+
TAlignLayout.Right,
492+
TAlignLayout.MostLeft,
493+
TAlignLayout.MostRight,
494+
TAlignLayout.Vertical,
495+
TAlignLayout.HorzCenter] then begin
496+
LSize.height := height;
497+
end;
498+
499+
if LSize.Width = 0 then LSize.Width := Width;
500+
if LSize.Height = 0 then LSize.Height := Height;
501+
SetBounds(Position.X, Position.Y, LSize.Width, LSize.Height);
502+
503+
end;
504+
end;
505+
506+
{****************************************************}
507+
procedure TALLayout.SetAutoSize(const Value: Boolean);
508+
begin
509+
if FAutoSize <> Value then
510+
begin
511+
FAutoSize := Value;
512+
AdjustSize;
513+
repaint;
514+
end;
414515
end;
415516

416517
{*********************************************************}

0 commit comments

Comments
 (0)