mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 19:59:31 +02:00
LCL: customflowpanel refactoring AlignControls
git-svn-id: trunk@50533 -
This commit is contained in:
parent
598f55c1b6
commit
8c9af59666
@ -155,56 +155,56 @@ end;
|
|||||||
procedure TCustomFlowPanel.AlignControls(AControl: TControl;
|
procedure TCustomFlowPanel.AlignControls(AControl: TControl;
|
||||||
var RemainingClientRect: TRect);
|
var RemainingClientRect: TRect);
|
||||||
const
|
const
|
||||||
XIncDir: array[TFlowStyle] of Integer = (1, -1, 1, -1, 1, 1, -1, -1);
|
cXIncDir: array[TFlowStyle] of Integer = (1, -1, 1, -1, 1, 1, -1, -1);
|
||||||
YIncDir: array[TFlowStyle] of Integer = (1, 1, -1, -1, 1, -1, 1, -1);
|
cYIncDir: array[TFlowStyle] of Integer = (1, 1, -1, -1, 1, -1, 1, -1);
|
||||||
YDeltaConst: array[TFlowStyle] of Integer = (0, 0, -1, -1, 0, 0, 0, 0);
|
cYDeltaConst: array[TFlowStyle] of Integer = (0, 0, -1, -1, 0, 0, 0, 0);
|
||||||
XDeltaConst: array[TFlowStyle] of Integer = (0, 0, 0, 0, 0, 0, -1, -1);
|
cXDeltaConst: array[TFlowStyle] of Integer = (0, 0, 0, 0, 0, 0, -1, -1);
|
||||||
var
|
var
|
||||||
I, L: Integer;
|
I, L: Integer;
|
||||||
MaxHeight, MaxWidth: Integer;
|
xMaxHeight, xMaxWidth: Integer;
|
||||||
YDelta, XDelta: Integer;
|
xPosition: TPoint;
|
||||||
Position: TPoint;
|
xSize, xGroupSize: TSize;
|
||||||
Size, GroupSize: TSize;
|
xControl: TControl;
|
||||||
Control: TControl;
|
xConBS: TControlBorderSpacing;
|
||||||
ConBS: TControlBorderSpacing;
|
xForceWrap, xForbidWrap: Boolean;
|
||||||
ForceWrap, ForbidWrap: Boolean;
|
|
||||||
begin
|
begin
|
||||||
|
if ControlCount = 0 then
|
||||||
|
Exit;
|
||||||
|
|
||||||
DisableAlign;
|
DisableAlign;
|
||||||
try
|
try
|
||||||
if ControlCount > 0 then
|
xMaxHeight := 0;
|
||||||
begin
|
xMaxWidth := 0;
|
||||||
MaxHeight := 0;
|
|
||||||
MaxWidth := 0;
|
|
||||||
AdjustClientRect(RemainingClientRect);
|
AdjustClientRect(RemainingClientRect);
|
||||||
case FFlowStyle of
|
case FFlowStyle of
|
||||||
fsLeftRightTopBottom,
|
fsLeftRightTopBottom,
|
||||||
fsTopBottomLeftRight:
|
fsTopBottomLeftRight:
|
||||||
Position := RemainingClientRect.TopLeft;
|
xPosition := RemainingClientRect.TopLeft;
|
||||||
fsRightLeftTopBottom,
|
fsRightLeftTopBottom,
|
||||||
fsTopBottomRightLeft:
|
fsTopBottomRightLeft:
|
||||||
Position := Point(RemainingClientRect.Right, RemainingClientRect.Top);
|
xPosition := Point(RemainingClientRect.Right, RemainingClientRect.Top);
|
||||||
fsLeftRightBottomTop,
|
fsLeftRightBottomTop,
|
||||||
fsBottomTopLeftRight:
|
fsBottomTopLeftRight:
|
||||||
Position := Point(RemainingClientRect.Left, RemainingClientRect.Bottom);
|
xPosition := Point(RemainingClientRect.Left, RemainingClientRect.Bottom);
|
||||||
fsRightLeftBottomTop,
|
fsRightLeftBottomTop,
|
||||||
fsBottomTopRightLeft:
|
fsBottomTopRightLeft:
|
||||||
Position := RemainingClientRect.BottomRight;
|
xPosition := RemainingClientRect.BottomRight;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
for I := 0 to FControlList.Count - 1 do
|
for I := 0 to FControlList.Count - 1 do
|
||||||
begin
|
begin
|
||||||
Control := FControlList[I].Control;
|
xControl := FControlList[I].Control;
|
||||||
ConBS := Control.BorderSpacing;
|
xConBS := xControl.BorderSpacing;
|
||||||
if not Control.Visible and not (csDesigning in ComponentState) then
|
if not xControl.Visible and not (csDesigning in ComponentState) then
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Size.cx := ConBS.ControlWidth;
|
xSize.cx := xConBS.ControlWidth;
|
||||||
Size.cy := ConBS.ControlHeight;
|
xSize.cy := xConBS.ControlHeight;
|
||||||
GroupSize := Size;
|
xGroupSize := xSize;
|
||||||
|
|
||||||
ForceWrap := (I > 0) and (FControlList[I-1].WrapAfter = waForce);
|
xForceWrap := (I > 0) and (FControlList[I-1].WrapAfter = waForce);
|
||||||
ForbidWrap := (I > 0) and (FControlList[I-1].WrapAfter = waForbid);
|
xForbidWrap := (I > 0) and (FControlList[I-1].WrapAfter = waForbid);
|
||||||
if not ForceWrap
|
if not xForceWrap
|
||||||
and ((I = 0) or not(FControlList[I-1].WrapAfter in [waAvoid, waForbid])) then
|
and ((I = 0) or not(FControlList[I-1].WrapAfter in [waAvoid, waForbid])) then
|
||||||
begin
|
begin
|
||||||
for L := I to FControlList.Count-2 do
|
for L := I to FControlList.Count-2 do
|
||||||
@ -213,9 +213,9 @@ begin
|
|||||||
begin
|
begin
|
||||||
case FFlowStyle of
|
case FFlowStyle of
|
||||||
fsLeftRightTopBottom, fsLeftRightBottomTop, fsRightLeftTopBottom, fsRightLeftBottomTop:
|
fsLeftRightTopBottom, fsLeftRightBottomTop, fsRightLeftTopBottom, fsRightLeftBottomTop:
|
||||||
Inc(GroupSize.cx, FControlList[L+1].Control.BorderSpacing.ControlWidth);
|
Inc(xGroupSize.cx, FControlList[L+1].Control.BorderSpacing.ControlWidth);
|
||||||
fsTopBottomLeftRight, fsTopBottomRightLeft, fsBottomTopLeftRight, fsBottomTopRightLeft:
|
fsTopBottomLeftRight, fsTopBottomRightLeft, fsBottomTopLeftRight, fsBottomTopRightLeft:
|
||||||
Inc(GroupSize.cy, FControlList[L+1].Control.BorderSpacing.ControlHeight);
|
Inc(xGroupSize.cy, FControlList[L+1].Control.BorderSpacing.ControlHeight);
|
||||||
end;
|
end;
|
||||||
end else
|
end else
|
||||||
break;
|
break;
|
||||||
@ -224,64 +224,61 @@ begin
|
|||||||
case FFlowStyle of
|
case FFlowStyle of
|
||||||
fsLeftRightTopBottom,
|
fsLeftRightTopBottom,
|
||||||
fsLeftRightBottomTop:
|
fsLeftRightBottomTop:
|
||||||
if (MaxHeight > 0) and FAutoWrap and not ForbidWrap
|
if (xMaxHeight > 0) and FAutoWrap and not xForbidWrap
|
||||||
and (ForceWrap or (Position.X + GroupSize.cx >= RemainingClientRect.Right)) then
|
and (xForceWrap or (xPosition.X + xGroupSize.cx >= RemainingClientRect.Right)) then
|
||||||
begin
|
begin
|
||||||
Inc(Position.Y, MaxHeight * YIncDir[FFlowStyle]);
|
Inc(xPosition.Y, xMaxHeight * cYIncDir[FFlowStyle]);
|
||||||
MaxHeight := 0;
|
xMaxHeight := 0;
|
||||||
Position.X := RemainingClientRect.Left;
|
xPosition.X := RemainingClientRect.Left;
|
||||||
end;
|
end;
|
||||||
fsRightLeftTopBottom,
|
fsRightLeftTopBottom,
|
||||||
fsRightLeftBottomTop:
|
fsRightLeftBottomTop:
|
||||||
begin
|
begin
|
||||||
Dec(Position.X, GroupSize.cx);
|
Dec(xPosition.X, xGroupSize.cx);
|
||||||
if (MaxHeight > 0) and FAutoWrap and not ForbidWrap
|
if (xMaxHeight > 0) and FAutoWrap and not xForbidWrap
|
||||||
and (ForceWrap or (Position.X <= 0)) then
|
and (xForceWrap or (xPosition.X <= 0)) then
|
||||||
begin
|
begin
|
||||||
Inc(Position.Y, MaxHeight * YIncDir[FFlowStyle]);
|
Inc(xPosition.Y, xMaxHeight * cYIncDir[FFlowStyle]);
|
||||||
MaxHeight := 0;
|
xMaxHeight := 0;
|
||||||
Position.X := RemainingClientRect.Right - Size.cx;
|
xPosition.X := RemainingClientRect.Right - xSize.cx;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
fsTopBottomLeftRight,
|
fsTopBottomLeftRight,
|
||||||
fsTopBottomRightLeft:
|
fsTopBottomRightLeft:
|
||||||
if (MaxWidth > 0) and FAutoWrap and not ForbidWrap
|
if (xMaxWidth > 0) and FAutoWrap and not xForbidWrap
|
||||||
and (ForceWrap or (Position.Y + GroupSize.cy >= RemainingClientRect.Bottom)) then
|
and (xForceWrap or (xPosition.Y + xGroupSize.cy >= RemainingClientRect.Bottom)) then
|
||||||
begin
|
begin
|
||||||
Inc(Position.X, MaxWidth * XIncDir[FFlowStyle]);
|
Inc(xPosition.X, xMaxWidth * cXIncDir[FFlowStyle]);
|
||||||
MaxWidth := 0;
|
xMaxWidth := 0;
|
||||||
Position.Y := RemainingClientRect.Top;
|
xPosition.Y := RemainingClientRect.Top;
|
||||||
end;
|
end;
|
||||||
fsBottomTopLeftRight,
|
fsBottomTopLeftRight,
|
||||||
fsBottomTopRightLeft:
|
fsBottomTopRightLeft:
|
||||||
begin
|
begin
|
||||||
Dec(Position.Y, GroupSize.cy);
|
Dec(xPosition.Y, xGroupSize.cy);
|
||||||
if (MaxWidth > 0) and FAutoWrap and not ForbidWrap
|
if (xMaxWidth > 0) and FAutoWrap and not xForbidWrap
|
||||||
and (ForceWrap or (Position.Y <= 0)) then
|
and (xForceWrap or (xPosition.Y <= 0)) then
|
||||||
begin
|
begin
|
||||||
Inc(Position.X, MaxWidth * XIncDir[FFlowStyle]);
|
Inc(xPosition.X, xMaxWidth * cXIncDir[FFlowStyle]);
|
||||||
MaxWidth := 0;
|
xMaxWidth := 0;
|
||||||
Position.Y := RemainingClientRect.Bottom - Size.cy;
|
xPosition.Y := RemainingClientRect.Bottom - xSize.cy;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
YDelta := YDeltaConst[FFlowStyle] * Size.cy;
|
if xSize.cy > xMaxHeight then
|
||||||
XDelta := XDeltaConst[FFlowStyle] * Size.cx;
|
xMaxHeight := xSize.cy;
|
||||||
if Size.cy > MaxHeight then
|
if xSize.cx > xMaxWidth then
|
||||||
MaxHeight := Size.cy;
|
xMaxWidth := xSize.cx;
|
||||||
if Size.cx > MaxWidth then
|
xControl.SetBounds(
|
||||||
MaxWidth := Size.cx;
|
xPosition.X + xConBS.Left + xConBS.Around + cXDeltaConst[FFlowStyle] * xSize.cx,
|
||||||
Control.SetBounds(
|
xPosition.Y + xConBS.Top + xConBS.Around + cYDeltaConst[FFlowStyle] * xSize.cy,
|
||||||
Position.X + ConBS.Left + ConBS.Around + XDelta,
|
xSize.cx - (xConBS.Left + xConBS.Right + xConBS.Around*2),
|
||||||
Position.Y + ConBS.Top + ConBS.Around + YDelta,
|
xSize.cy - (xConBS.Top + xConBS.Bottom + xConBS.Around*2));
|
||||||
Size.cx - (ConBS.Left + ConBS.Right + ConBS.Around*2),
|
|
||||||
Size.cy - (ConBS.Top + ConBS.Bottom + ConBS.Around*2));
|
|
||||||
if FFlowStyle in [fsLeftRightTopBottom, fsLeftRightBottomTop] then
|
if FFlowStyle in [fsLeftRightTopBottom, fsLeftRightBottomTop] then
|
||||||
Inc(Position.X, Size.cx * XIncDir[FFlowStyle])
|
Inc(xPosition.X, xSize.cx * cXIncDir[FFlowStyle])
|
||||||
else if FFlowStyle in [fsTopBottomLeftRight, fsTopBottomRightLeft] then
|
else if FFlowStyle in [fsTopBottomLeftRight, fsTopBottomRightLeft] then
|
||||||
Inc(Position.Y, Size.cy + YIncDir[FFlowStyle]);
|
Inc(xPosition.Y, xSize.cy + cYIncDir[FFlowStyle]);
|
||||||
end;
|
end;
|
||||||
end;
|
|
||||||
finally
|
finally
|
||||||
EnableAlign;
|
EnableAlign;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user