|
@@ -44,8 +44,6 @@ unit Fresnel.Layouter;
|
|
{$WARN 6060 off} // Case statement does not handle all possible cases
|
|
{$WARN 6060 off} // Case statement does not handle all possible cases
|
|
{$ENDIF}
|
|
{$ENDIF}
|
|
|
|
|
|
-{$DEFINE VerboseFlexBox}
|
|
|
|
-
|
|
|
|
interface
|
|
interface
|
|
|
|
|
|
uses
|
|
uses
|
|
@@ -534,7 +532,9 @@ begin
|
|
|
|
|
|
DeductUsedLengths(NoChildren);
|
|
DeductUsedLengths(NoChildren);
|
|
|
|
|
|
- //writeln('TUsedLayoutNode.ComputeUsedLengths ',Element.GetPath,' NoChildren=',NoChildren,' Width=',FloatToCSSStr(Width),' Height=',FloatToCSSStr(Height),' MinWidth=',FloatToCSSStr(MinWidth),' MaxWidth=',FloatToCSSStr(MaxWidth));
|
|
|
|
|
|
+ {$IFDEF VerboseFresnelPlacing}
|
|
|
|
+ writeln('TUsedLayoutNode.ComputeUsedLengths ',Element.GetPath,' NoChildren=',NoChildren,' Width=',FloatToCSSStr(Width),' Height=',FloatToCSSStr(Height),' MinWidth=',FloatToCSSStr(MinWidth),' MaxWidth=',FloatToCSSStr(MaxWidth));
|
|
|
|
+ {$ENDIF}
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TUsedLayoutNode.DeductUsedLengths(NoChildren: boolean);
|
|
procedure TUsedLayoutNode.DeductUsedLengths(NoChildren: boolean);
|
|
@@ -998,13 +998,6 @@ begin
|
|
EndLine(Commit);
|
|
EndLine(Commit);
|
|
|
|
|
|
Result.Y:=Max(Result.Y,FLastLineBorderBoxBottom+FLastLineMarginBottom);
|
|
Result.Y:=Max(Result.Y,FLastLineBorderBoxBottom+FLastLineMarginBottom);
|
|
- if Commit then
|
|
|
|
- begin
|
|
|
|
- if IsNan(Node.Width) then
|
|
|
|
- Node.Width:=Node.FitWidth(Result.X);
|
|
|
|
- if IsNan(Node.Height) then
|
|
|
|
- Node.Height:=Node.FitHeight(Result.Y);
|
|
|
|
- end;
|
|
|
|
end;
|
|
end;
|
|
|
|
|
|
{ TFLGridLayouter }
|
|
{ TFLGridLayouter }
|
|
@@ -1059,7 +1052,9 @@ var
|
|
Item:=TFlexItem(FLineItems[i]);
|
|
Item:=TFlexItem(FLineItems[i]);
|
|
CurMainSize:=CurMainSize+Item.MainFrameLT+Item.MainContentSize+Item.MainFrameRB;
|
|
CurMainSize:=CurMainSize+Item.MainFrameLT+Item.MainContentSize+Item.MainFrameRB;
|
|
end;
|
|
end;
|
|
- if not IsNan(MaxMainSize) then
|
|
|
|
|
|
+ if IsNan(MaxMainSize) then
|
|
|
|
+ aSpace:=0
|
|
|
|
+ else
|
|
aSpace:=MaxMainSize-CurMainSize;
|
|
aSpace:=MaxMainSize-CurMainSize;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -1095,92 +1090,90 @@ begin
|
|
Item.MainContentSize:=Item.Basis;
|
|
Item.MainContentSize:=Item.Basis;
|
|
end;
|
|
end;
|
|
|
|
|
|
- if IsNan(MaxMainSize) then
|
|
|
|
- begin
|
|
|
|
- // computing min-content or max-content
|
|
|
|
- CalcMainSize;
|
|
|
|
- AdjustMainContentSize(CurMainSize);
|
|
|
|
- end else begin
|
|
|
|
- // shrink or grow
|
|
|
|
- repeat
|
|
|
|
- // compute difference between current size and max size
|
|
|
|
|
|
+ CalcMainSize;
|
|
|
|
+ // shrink or grow
|
|
|
|
+ repeat
|
|
|
|
+ // compute difference between current size and max size
|
|
|
|
+ if aSpace>MinAdjust then
|
|
|
|
+ begin
|
|
|
|
+ // try to grow
|
|
|
|
+ // collect grow factors of all items able to grow
|
|
|
|
+ SumGrow:=0;
|
|
|
|
+ for i:=0 to FLineItems.Count-1 do
|
|
|
|
+ begin
|
|
|
|
+ Item:=TFlexItem(FLineItems[i]);
|
|
|
|
+ if Item.Grow<MinAdjust then continue;
|
|
|
|
+ ItemNode:=Item.Node;
|
|
|
|
+ if (not IsNan(ItemNode.MaxWidth))
|
|
|
|
+ and (Item.MainContentSize>ItemNode.MaxWidth-MinAdjust) then continue;
|
|
|
|
+ SumGrow:=SumGrow+Item.Grow;
|
|
|
|
+ end;
|
|
|
|
+ if SumGrow=0 then
|
|
|
|
+ break; // can not grow
|
|
|
|
+ // grow
|
|
|
|
+ for i:=0 to FLineItems.Count-1 do
|
|
|
|
+ begin
|
|
|
|
+ Item:=TFlexItem(FLineItems[i]);
|
|
|
|
+ if Item.Grow<MinAdjust then continue;
|
|
|
|
+ ItemNode:=Item.Node;
|
|
|
|
+ if (not IsNan(ItemNode.MaxWidth))
|
|
|
|
+ and (Item.MainContentSize>ItemNode.MaxWidth-MinAdjust) then continue;
|
|
|
|
+ Item.MainContentSize:=Item.MainContentSize+(Item.Grow/SumGrow)*aSpace;
|
|
|
|
+ if (not IsNan(ItemNode.MaxWidth))
|
|
|
|
+ and (Item.MainContentSize>ItemNode.MaxWidth-MinAdjust) then
|
|
|
|
+ Item.MainContentSize:=ItemNode.MaxWidth;
|
|
|
|
+ end;
|
|
CalcMainSize;
|
|
CalcMainSize;
|
|
- if aSpace>MinAdjust then
|
|
|
|
|
|
+ end else if aSpace<-MinAdjust then begin
|
|
|
|
+ // try to shrink
|
|
|
|
+ // collect shrink factors of all items able to shrink
|
|
|
|
+ SumShrink:=0;
|
|
|
|
+ for i:=0 to FLineItems.Count-1 do
|
|
begin
|
|
begin
|
|
- // try to grow
|
|
|
|
- // collect grow factors of all items able to grow
|
|
|
|
- SumGrow:=0;
|
|
|
|
- for i:=0 to FLineItems.Count-1 do
|
|
|
|
- begin
|
|
|
|
- Item:=TFlexItem(FLineItems[i]);
|
|
|
|
- if Item.Grow<MinAdjust then continue;
|
|
|
|
- ItemNode:=Item.Node;
|
|
|
|
- if (not IsNan(ItemNode.MaxWidth))
|
|
|
|
- and (Item.MainContentSize>ItemNode.MaxWidth-MinAdjust) then continue;
|
|
|
|
- SumGrow:=SumGrow+Item.Grow;
|
|
|
|
- end;
|
|
|
|
- if SumGrow=0 then
|
|
|
|
- break; // can not grow
|
|
|
|
- // grow
|
|
|
|
- for i:=0 to FLineItems.Count-1 do
|
|
|
|
- begin
|
|
|
|
- Item:=TFlexItem(FLineItems[i]);
|
|
|
|
- if Item.Grow<MinAdjust then continue;
|
|
|
|
- ItemNode:=Item.Node;
|
|
|
|
- if (not IsNan(ItemNode.MaxWidth))
|
|
|
|
- and (Item.MainContentSize>ItemNode.MaxWidth-MinAdjust) then continue;
|
|
|
|
- Item.MainContentSize:=Item.MainContentSize+(Item.Grow/SumGrow)*aSpace;
|
|
|
|
- if (not IsNan(ItemNode.MaxWidth))
|
|
|
|
- and (Item.MainContentSize>ItemNode.MaxWidth-MinAdjust) then
|
|
|
|
- Item.MainContentSize:=ItemNode.MaxWidth;
|
|
|
|
- end;
|
|
|
|
- end else if aSpace<-MinAdjust then begin
|
|
|
|
- // try to shrink
|
|
|
|
- // collect shrink factors of all items able to shrink
|
|
|
|
- SumShrink:=0;
|
|
|
|
- for i:=0 to FLineItems.Count-1 do
|
|
|
|
- begin
|
|
|
|
- Item:=TFlexItem(FLineItems[i]);
|
|
|
|
- if Item.Shrink<MinAdjust then continue;
|
|
|
|
- if Item.MainContentSize<MinAdjust then continue;
|
|
|
|
- ItemNode:=Item.Node;
|
|
|
|
- if (not IsNan(ItemNode.MinWidth))
|
|
|
|
- and (Item.MainContentSize<ItemNode.MinWidth+MinAdjust) then continue;
|
|
|
|
- SumShrink:=SumShrink+Item.Shrink;
|
|
|
|
- end;
|
|
|
|
- if SumShrink=0 then
|
|
|
|
- break; // can not shrink
|
|
|
|
- // shrink
|
|
|
|
- for i:=0 to FLineItems.Count-1 do
|
|
|
|
- begin
|
|
|
|
- Item:=TFlexItem(FLineItems[i]);
|
|
|
|
- if Item.Shrink<MinAdjust then continue;
|
|
|
|
- if Item.MainContentSize<MinAdjust then continue;
|
|
|
|
- ItemNode:=Item.Node;
|
|
|
|
- if (not IsNan(ItemNode.MinWidth))
|
|
|
|
- and (Item.MainContentSize<ItemNode.MinWidth+MinAdjust) then continue;
|
|
|
|
- Item.MainContentSize:=Max(0,Item.MainContentSize+(Item.Shrink/SumShrink)*aSpace);
|
|
|
|
- if (not IsNan(ItemNode.MinWidth))
|
|
|
|
- and (Item.MainContentSize<ItemNode.MinWidth+MinAdjust) then
|
|
|
|
- Item.MainContentSize:=ItemNode.MinWidth;
|
|
|
|
- end;
|
|
|
|
- end else
|
|
|
|
- break;
|
|
|
|
- until false;
|
|
|
|
|
|
+ Item:=TFlexItem(FLineItems[i]);
|
|
|
|
+ if Item.Shrink<MinAdjust then continue;
|
|
|
|
+ if Item.MainContentSize<MinAdjust then continue;
|
|
|
|
+ ItemNode:=Item.Node;
|
|
|
|
+ if (not IsNan(ItemNode.MinWidth))
|
|
|
|
+ and (Item.MainContentSize<ItemNode.MinWidth+MinAdjust) then continue;
|
|
|
|
+ SumShrink:=SumShrink+Item.Shrink;
|
|
|
|
+ end;
|
|
|
|
+ if SumShrink=0 then
|
|
|
|
+ break; // can not shrink
|
|
|
|
+ // shrink
|
|
|
|
+ for i:=0 to FLineItems.Count-1 do
|
|
|
|
+ begin
|
|
|
|
+ Item:=TFlexItem(FLineItems[i]);
|
|
|
|
+ if Item.Shrink<MinAdjust then continue;
|
|
|
|
+ if Item.MainContentSize<MinAdjust then continue;
|
|
|
|
+ ItemNode:=Item.Node;
|
|
|
|
+ if (not IsNan(ItemNode.MinWidth))
|
|
|
|
+ and (Item.MainContentSize<ItemNode.MinWidth+MinAdjust) then continue;
|
|
|
|
+ Item.MainContentSize:=Max(0,Item.MainContentSize+(Item.Shrink/SumShrink)*aSpace);
|
|
|
|
+ if (not IsNan(ItemNode.MinWidth))
|
|
|
|
+ and (Item.MainContentSize<ItemNode.MinWidth+MinAdjust) then
|
|
|
|
+ Item.MainContentSize:=ItemNode.MinWidth;
|
|
|
|
+ end;
|
|
|
|
+ CalcMainSize;
|
|
|
|
+ end else
|
|
|
|
+ break;
|
|
|
|
+ until false;
|
|
|
|
|
|
- // justify-content:
|
|
|
|
- // todo safe, unsafe: ?
|
|
|
|
|
|
+ // justify-content:
|
|
|
|
+ // todo safe, unsafe: ?
|
|
|
|
|
|
- CalcMainSize;
|
|
|
|
- if Commit then
|
|
|
|
- begin
|
|
|
|
- if JustifyContent in [CSSRegistry.kwLeft,CSSRegistry.kwStart,CSSRegistry.kwFlexStart] then
|
|
|
|
- AdjustMainContentSize(CurMainSize)
|
|
|
|
- else
|
|
|
|
- AdjustMainContentSize(MaxMainSize);
|
|
|
|
- end else
|
|
|
|
- AdjustMainContentSize(CurMainSize);
|
|
|
|
|
|
+ if Commit then
|
|
|
|
+ begin
|
|
|
|
+ if IsNan(MaxMainSize)
|
|
|
|
+ or (JustifyContent in [CSSRegistry.kwLeft,CSSRegistry.kwStart,CSSRegistry.kwFlexStart]) then
|
|
|
|
+ AdjustMainContentSize(CurMainSize)
|
|
|
|
+ else
|
|
|
|
+ AdjustMainContentSize(MaxMainSize);
|
|
|
|
+ end else
|
|
|
|
+ AdjustMainContentSize(CurMainSize);
|
|
|
|
|
|
|
|
+ if Commit then
|
|
|
|
+ begin
|
|
p:=0;
|
|
p:=0;
|
|
aSpaceItem:=0;
|
|
aSpaceItem:=0;
|
|
case JustifyContent of
|
|
case JustifyContent of
|
|
@@ -1225,7 +1218,7 @@ begin
|
|
if FlexDirection in [CSSRegistry.kwRow,CSSRegistry.kwColumn] then
|
|
if FlexDirection in [CSSRegistry.kwRow,CSSRegistry.kwColumn] then
|
|
begin
|
|
begin
|
|
if i>0 then p:=p+MainGap;
|
|
if i>0 then p:=p+MainGap;
|
|
- if FlexDirection=CSSRegistry.kwRow then
|
|
|
|
|
|
+ if MainIsRow then
|
|
Item.StaticLeft:=p
|
|
Item.StaticLeft:=p
|
|
else
|
|
else
|
|
Item.StaticTop:=p;
|
|
Item.StaticTop:=p;
|
|
@@ -1233,11 +1226,15 @@ begin
|
|
end else begin
|
|
end else begin
|
|
if i>0 then p:=p-MainGap;
|
|
if i>0 then p:=p-MainGap;
|
|
p:=p-(Item.MainFrameLT+Item.MainContentSize+Item.MainFrameRB);
|
|
p:=p-(Item.MainFrameLT+Item.MainContentSize+Item.MainFrameRB);
|
|
- if FlexDirection=CSSRegistry.kwRow then
|
|
|
|
|
|
+ if MainIsRow then
|
|
Item.StaticLeft:=p
|
|
Item.StaticLeft:=p
|
|
else
|
|
else
|
|
Item.StaticTop:=p;
|
|
Item.StaticTop:=p;
|
|
end;
|
|
end;
|
|
|
|
+ if MainIsRow then
|
|
|
|
+ Item.ContentBoxWidth:=Item.MainContentSize
|
|
|
|
+ else
|
|
|
|
+ Item.ContentBoxHeight:=Item.MainContentSize;
|
|
|
|
|
|
case JustifyContent of
|
|
case JustifyContent of
|
|
CSSRegistry.kwSpaceAround:
|
|
CSSRegistry.kwSpaceAround:
|
|
@@ -1463,8 +1460,6 @@ begin
|
|
MaxMainSize:=aMaxHeight;
|
|
MaxMainSize:=aMaxHeight;
|
|
MainGap:=GetComputedGap(false);
|
|
MainGap:=GetComputedGap(false);
|
|
end;
|
|
end;
|
|
- if IsNan(MaxMainSize) then
|
|
|
|
- raise EFresnelLayout.Create('20240908163359');
|
|
|
|
|
|
|
|
CurMainSize:=0;
|
|
CurMainSize:=0;
|
|
|
|
|
|
@@ -1496,6 +1491,7 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
Item:=TFlexItem.Create;
|
|
Item:=TFlexItem.Create;
|
|
|
|
+ Item.Node:=ChildNode;
|
|
ItemAdded:=false;
|
|
ItemAdded:=false;
|
|
ComputeChildAttributes(Item,ChildEl);
|
|
ComputeChildAttributes(Item,ChildEl);
|
|
|
|
|
|
@@ -1585,7 +1581,9 @@ begin
|
|
r.Bottom:=r.Top+Item.ContentBoxHeight;
|
|
r.Bottom:=r.Top+Item.ContentBoxHeight;
|
|
ChildEl.UsedContentBox:=r;
|
|
ChildEl.UsedContentBox:=r;
|
|
|
|
|
|
- //writeln('TFLFlowLayouter.PlaceLineItems '+ChildEl.GetPath+' BorderBox='+ChildEl.UsedBorderBox.ToString);
|
|
|
|
|
|
+ {$IFDEF VerboseFresnelPlacing}
|
|
|
|
+ writeln('TFLFlowLayouter.PlaceLineItems '+ChildEl.GetPath+' BorderBox='+ChildEl.UsedBorderBox.ToString);
|
|
|
|
+ {$ENDIF}
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -1708,9 +1706,11 @@ begin
|
|
r.Bottom:=R.Top+NewHeight;
|
|
r.Bottom:=R.Top+NewHeight;
|
|
ChildEl.UsedContentBox:=r;
|
|
ChildEl.UsedContentBox:=r;
|
|
|
|
|
|
- //writeln('TFLFlowLayouter.PlaceAbsoluteItem '+ChildEl.GetPath+' BorderBox='+ChildEl.UsedBorderBox.ToString);
|
|
|
|
|
|
+ {$IFDEF VerboseFresnelPlacing}
|
|
|
|
+ writeln('TFLFlowLayouter.PlaceAbsoluteItem '+ChildEl.GetPath+' BorderBox='+ChildEl.UsedBorderBox.ToString);
|
|
//if ChildEl.Name='Div1' then
|
|
//if ChildEl.Name='Div1' then
|
|
- // writeln('TFLFlowLayouter.PlaceAbsoluteItem ',ChildEl.GetPath,' ',aMode,' Commit Left=',FloatToCSSStr(ChildNode.Left),',Top=',FloatToCSSStr(ChildNode.Top),',Right=',FloatToCSSStr(ChildNode.Right),',Bottom=',FloatToCSSStr(ChildNode.Bottom),' Width=',FloatToCSSStr(ChildNode.Width),' Height=',FloatToCSSStr(ChildNode.Height));
|
|
|
|
|
|
+ //writeln('TFLFlowLayouter.PlaceAbsoluteItem ',ChildEl.GetPath,' ',aMode,' Commit Left=',FloatToCSSStr(ChildNode.Left),',Top=',FloatToCSSStr(ChildNode.Top),',Right=',FloatToCSSStr(ChildNode.Right),',Bottom=',FloatToCSSStr(ChildNode.Bottom),' Width=',FloatToCSSStr(ChildNode.Width),' Height=',FloatToCSSStr(ChildNode.Height));
|
|
|
|
+ {$ENDIF}
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|