@@ -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+ { ****************************}
409412procedure TALLayout.DoRealign ;
410413begin
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 ;
414515end ;
415516
416517{ *********************************************************}
0 commit comments