mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 09:39:09 +02:00
improved lcl autosizing: reduced overhead by preconsidering anchors
git-svn-id: trunk@7292 -
This commit is contained in:
parent
7bbed9755e
commit
5d05f5e62e
@ -665,6 +665,11 @@ var
|
|||||||
PreferredWidth: LongInt;
|
PreferredWidth: LongInt;
|
||||||
PreferredHeight: LongInt;
|
PreferredHeight: LongInt;
|
||||||
ChildBounds: TRect;
|
ChildBounds: TRect;
|
||||||
|
WidthIsFixed: boolean;
|
||||||
|
HeightIsFixed: boolean;
|
||||||
|
NewLeft: LongInt;
|
||||||
|
NewTop: LongInt;
|
||||||
|
CurAnchors: TAnchors;
|
||||||
begin
|
begin
|
||||||
//debugln('TWinControl.DoAutoSize ',DbgSName(Self));
|
//debugln('TWinControl.DoAutoSize ',DbgSName(Self));
|
||||||
If not AutoSizeCanStart then exit;
|
If not AutoSizeCanStart then exit;
|
||||||
@ -675,11 +680,17 @@ begin
|
|||||||
|
|
||||||
AutoSizing := True;
|
AutoSizing := True;
|
||||||
try
|
try
|
||||||
|
// test if resizing is possible
|
||||||
|
CurAnchors:=Anchors+AnchorAlign[Align];
|
||||||
|
WidthIsFixed:=(CurAnchors*[akLeft,akRight]=[akLeft,akRight]);
|
||||||
|
HeightIsFixed:=(CurAnchors*[akTop,akBottom]=[akTop,akBottom]);
|
||||||
|
|
||||||
// autosize control to preferred size
|
// autosize control to preferred size
|
||||||
|
if (not WidthIsFixed) or (not HeightIsFixed) then
|
||||||
GetPreferredSize(PreferredWidth,PreferredHeight,false);
|
GetPreferredSize(PreferredWidth,PreferredHeight,false);
|
||||||
if PreferredWidth<=0 then
|
if WidthIsFixed or (PreferredWidth<=0) then
|
||||||
PreferredWidth:=Constraints.MinMaxWidth(Width);
|
PreferredWidth:=Constraints.MinMaxWidth(Width);
|
||||||
if PreferredHeight<=0 then
|
if HeightIsFixed or (PreferredHeight<=0) then
|
||||||
PreferredHeight:=Constraints.MinMaxHeight(Height);
|
PreferredHeight:=Constraints.MinMaxHeight(Height);
|
||||||
|
|
||||||
// move childs tight to left and top (so no space left and above childs)
|
// move childs tight to left and top (so no space left and above childs)
|
||||||
@ -704,8 +715,15 @@ begin
|
|||||||
debugln('DoAutoSize A ',DbgSName(Self),' Cur=',dbgs(Width),'x',dbgs(Height),' Prefer=',dbgs(PreferredWidth),'x',dbgs(PreferredHeight),' WidgetClass=',WidgetSetClass.ClassName);
|
debugln('DoAutoSize A ',DbgSName(Self),' Cur=',dbgs(Width),'x',dbgs(Height),' Prefer=',dbgs(PreferredWidth),'x',dbgs(PreferredHeight),' WidgetClass=',WidgetSetClass.ClassName);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
if (PreferredWidth<>Width) or (PreferredHeight<>Height) then begin
|
if (PreferredWidth<>Width) or (PreferredHeight<>Height) then begin
|
||||||
|
// adjust Left/Top as well to reduce auto sizing overhead
|
||||||
|
NewLeft:=Left;
|
||||||
|
NewTop:=Top;
|
||||||
|
if akRight in CurAnchors then
|
||||||
|
dec(NewLeft,PreferredWidth-Width);
|
||||||
|
if akBottom in CurAnchors then
|
||||||
|
dec(NewTop,PreferredHeight-Height);
|
||||||
//debugln('DoAutoSize Resize ',DbgSName(Self),' W=',dbgs(PreferredWidth),' H=',dbgs(PreferredHeight));
|
//debugln('DoAutoSize Resize ',DbgSName(Self),' W=',dbgs(PreferredWidth),' H=',dbgs(PreferredHeight));
|
||||||
SetBoundsKeepBase(Left,Top,PreferredWidth,PreferredHeight,true);
|
SetBoundsKeepBase(NewLeft,NewTop,PreferredWidth,PreferredHeight,true);
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
AutoSizing := False;
|
AutoSizing := False;
|
||||||
@ -4517,6 +4535,9 @@ end;
|
|||||||
{ =============================================================================
|
{ =============================================================================
|
||||||
|
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.330 2005/06/28 22:56:32 mattias
|
||||||
|
improved lcl autosizing: reduced overhead by preconsidering anchors
|
||||||
|
|
||||||
Revision 1.329 2005/06/25 15:34:03 mattias
|
Revision 1.329 2005/06/25 15:34:03 mattias
|
||||||
fixed a few fpc over warnings from Andrew Haines
|
fixed a few fpc over warnings from Andrew Haines
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user