Bladeren bron

layout: flow: position absolute behind a block

mattias 11 maanden geleden
bovenliggende
commit
7337435646
3 gewijzigde bestanden met toevoegingen van 28 en 13 verwijderingen
  1. 1 1
      demo/Combobox/DemoCombobox.pas
  2. 0 3
      demo/Combobox/MainUnit.pas
  3. 27 9
      src/base/fresnel.layouter.pas

+ 1 - 1
demo/Combobox/DemoCombobox.pas

@@ -48,7 +48,7 @@ type
         +'}'+LineEnding
         +'.ComboboxMenu {'+LineEnding
         +'  position: absolute;'+LineEnding
-        +'  padding-top: 5px;'+LineEnding
+        +'  padding-top: 2px;'+LineEnding
         +'  border-radius: 5px;'+LineEnding
         +'  border: 1px solid #5080e0;'+LineEnding
         +'  background-color: #b6d6f0;'+LineEnding

+ 0 - 3
demo/Combobox/MainUnit.pas

@@ -81,9 +81,6 @@ begin
     +'  font-size:15px; font-family:Arial; font-weight:bold;'
     +'  text-shadow: 0 1 1 #333;'
     +'  color:#fff;'
-    +'}'
-    +'#Div1:hover {'
-    +'  background:#88bb22;'
     +'};');
   Div1.Style:='';
 

+ 27 - 9
src/base/fresnel.layouter.pas

@@ -673,7 +673,7 @@ end;
 
 procedure TFLFlowLayouter.EndLine(Commit: boolean);
 var
-  Item: TLineItem;
+  AbsItem: TLineItem;
   El: TFresnelElement;
   IsInline: Boolean;
 begin
@@ -691,11 +691,16 @@ begin
       // set default top position of absolute blocks below line
       while FLineFirstAbsoluteIndex<FAbsoluteItems.Count do
       begin
-        Item:=TLineItem(FAbsoluteItems[FLineFirstAbsoluteIndex]);
-        El:=Item.Node.Element;
+        AbsItem:=TLineItem(FAbsoluteItems[FLineFirstAbsoluteIndex]);
+        El:=AbsItem.Node.Element;
         IsInline:=El.ComputedDisplayOutside=CSSRegistry.kwInline;
         if not IsInline then
-          Item.StaticTop:=FLineBorderBoxBottom+FLineMarginBottom;
+        begin
+          AbsItem.StaticTop:=FLineBorderBoxBottom+FLineMarginBottom;
+          {$IFDEF VerboseFresnelPlacing}
+          writeln('TFLFlowLayouter.EndLine SetAbsBlockDefaultPos ',El.GetPath,' StaticLeft=',FloatToCSSStr(AbsItem.StaticLeft),' StaticTop=',FloatToCSSStr(AbsItem.StaticTop));
+          {$ENDIF}
+        end;
         inc(FLineFirstAbsoluteIndex);
       end;
     end;
@@ -831,12 +836,23 @@ begin
       if Commit then
       begin
         AbsItem:=AddAbsoluteItem(ChildNode,TLineItem);
-        if IsInline then
-          AbsItem.StaticLeft:=FLineBorderBoxRight+FLineMarginRight
-        else begin
+        if (FLineItems=nil) or (FLineItems.Count=0) then
+        begin
+          // first item after a block
+          AbsItem.StaticTop:=FLineBorderBoxBottom-FLineMarginBottom;
+          AbsItem.StaticLeft:=0;
+        end else if IsInline then
+        begin
+          // right behind an inline element
           AbsItem.StaticTop:=FLineBorderBoxTop-FLineMarginTop;
+          AbsItem.StaticLeft:=FLineBorderBoxRight+FLineMarginRight;
+        end else begin
+          // below an inline element
           AbsItem.StaticLeft:=0;
         end;
+        {$IFDEF VerboseFresnelPlacing}
+        writeln('TFLFlowLayouter.ComputeLayoutContent SetAbsBlockDefaultPos ',ChildEl.GetPath,' StaticLeft=',FloatToCSSStr(AbsItem.StaticLeft),' StaticTop=',FloatToCSSStr(AbsItem.StaticTop));
+        {$ENDIF}
       end;
       continue;
     end;
@@ -1622,8 +1638,10 @@ begin
 
   ChildEl:=ChildNode.Element;
 
+  { $IFDEF VerboseFresnelPlacing}
   //if ChildEl.Name='Div1' then
     writeln('TFLFlowLayouter.PlaceAbsoluteItem ',ChildEl.GetPath,' ',aMode,' Commit=',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),' Default=',FloatToCSSStr(DefaultPos.X),',',FloatToCSSStr(DefaultPos.Y));
+  { $ENDIF}
   NewLeft:=ChildNode.Left;
   NewTop:=ChildNode.Top;
   NewRight:=ChildNode.Right;
@@ -1733,11 +1751,11 @@ begin
     r.Bottom:=R.Top+NewHeight;
     ChildEl.UsedContentBox:=r;
 
-    {$IFDEF VerboseFresnelPlacing}
+    { $IFDEF VerboseFresnelPlacing}
     writeln('TFLFlowLayouter.PlaceAbsoluteItem '+ChildEl.GetPath+' BorderBox='+ChildEl.UsedBorderBox.ToString);
     //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));
-    {$ENDIF}
+    { $ENDIF}
   end;
 end;