Ver Fonte

flex: use content size as default

mattias há 11 meses atrás
pai
commit
adb04c288d
2 ficheiros alterados com 29 adições e 4 exclusões
  1. 13 0
      demo/Combobox/DemoCombobox.pas
  2. 16 4
      src/base/fresnel.layouter.pas

+ 13 - 0
demo/Combobox/DemoCombobox.pas

@@ -23,6 +23,7 @@ type
     procedure SetItemIndex(const AValue: integer);
     procedure SetItems(const AValue: TStrings);
   protected
+    procedure SetName(const NewName: TComponentName); override;
     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
     Procedure FPOObservedChanged(ASender: TObject; {%H-}Operation: TFPObservedOperation; {%H-}Data: Pointer); override;
   public
@@ -94,6 +95,16 @@ begin
   UpdateItems;
 end;
 
+procedure TDemoCombobox.SetName(const NewName: TComponentName);
+var
+  WasCaption: Boolean;
+begin
+  WasCaption:=Caption=Name;
+  inherited SetName(NewName);
+  if WasCaption then
+    Caption:=NewName;
+end;
+
 procedure TDemoCombobox.Notification(AComponent: TComponent; Operation: TOperation);
 begin
   inherited Notification(AComponent, Operation);
@@ -148,6 +159,7 @@ begin
     Menu.SetStyleAttr('display','')
   else
     Menu.SetStyleAttr('display','none');
+  writeln('TDemoCombobox.CaptionDivMouseDown ',Name,' "',Menu.Style,'"');
 end;
 
 procedure TDemoCombobox.SetCaption(const AValue: string);
@@ -176,6 +188,7 @@ begin
   CaptionLabel:=TLabel.Create(Self);
   with CaptionLabel do begin
     Name:='CaptionLabel';
+    Caption:=Self.Name;
     CSSClasses.Add('ComboboxCaptionLabel');
     Parent:=CaptionDiv;
   end;

+ 16 - 4
src/base/fresnel.layouter.pas

@@ -923,7 +923,7 @@ begin
         CurSpace:=ChildWidth;
       end;
       ChildPrefSize:=ChildEl.GetIntrinsicContentSize(aMode,CurSpace,NaN);
-      //if ChildEl.Name='ButtonLabel' then
+      //if ChildEl.Name='CaptionLabel' then
       //  writeln('TFLFlowLayouter.ComputeLayoutContent ',ChildEl.GetPath,' MaxWidth=',CurSpace,' Preferred=',ChildPrefSize.ToString,' ChildPadBorderX=',ChildPadBorderX,' ChildPadBorderY=',ChildPadBorderY);
       // apply min, max
       if IsNan(ChildWidth) then
@@ -1204,8 +1204,9 @@ begin
 
   if Commit then
   begin
-    if IsNan(MaxMainSize)
-        or (JustifyContent in [CSSRegistry.kwLeft,CSSRegistry.kwStart,CSSRegistry.kwFlexStart]) then
+    if IsNan(MaxMainSize) then
+      MaxMainSize:=CurMainSize;
+    if (JustifyContent in [CSSRegistry.kwLeft,CSSRegistry.kwStart,CSSRegistry.kwFlexStart]) then
       AdjustMainContentSize(CurMainSize)
     else
       AdjustMainContentSize(MaxMainSize);
@@ -1376,7 +1377,6 @@ end;
 
 procedure TFLFlexLayouter.PlaceLineItems;
 begin
-
   inherited;
 end;
 
@@ -1442,6 +1442,10 @@ begin
   end;
   if IsNan(FlexItem.Grow) then FlexItem.Grow:=0;
   if IsNan(FlexItem.Shrink) then FlexItem.Shrink:=1;
+
+  {$IFDEF VerboseFlexLayout}
+  writeln('TFLFlexLayouter.ComputeChildAttributes ',ItemNode.Element.GetPath,' Basis=',FloatToCSSStr(FlexItem.Basis),' Grow=',FloatToCSSStr(FlexItem.Grow),' Shrink=',FloatToCSSStr(FlexItem.Shrink),' AlignSelf=',CSSRegistry.Keywords[FlexItem.AlignSelf],' CrossSize=',FloatToCSSStr(FlexItem.CrossContentSize));
+  {$ENDIF}
 end;
 
 procedure TFLFlexLayouter.Init;
@@ -1582,6 +1586,14 @@ begin
 
     NewLeft:=Item.StaticLeft;
     NewTop:=Item.StaticTop;
+    if IsNan(NewLeft) then
+      raise EFresnelLayout.Create('20241001111913');
+    if IsNan(NewTop) then
+      raise EFresnelLayout.Create('20241001111913');
+    if IsNan(Item.ContentBoxWidth) then
+      raise EFresnelLayout.Create('20241001111941');
+    if IsNan(Item.ContentBoxHeight) then
+      raise EFresnelLayout.Create('20241001111949');
 
     if ChildEl.ComputedPosition in [CSSRegistry.kwRelative,CSSRegistry.kwSticky] then
     begin