瀏覽代碼

label: publish Caption, load lfm resource

mattias 2 年之前
父節點
當前提交
0a251bc33a

+ 20 - 1
demo/LazDesignerForm/FloatLayoutUnit1.lfm

@@ -1,11 +1,30 @@
 object FresnelForm2: TFresnelForm2
   Caption = 'FresnelForm2'
-  FormHeight = 250
+  FormHeight = 255
   FormLeft = 450
   FormTop = 300
   FormWidth = 350
+  Stylesheet.Strings = (
+    'div {'
+    '  padding: 2px; '
+    '  border: 3px; '
+    '  margin: 6px;'
+    '}'
+  )
   object FresnelBody1: TFresnelBody
+    Style = 'border: 2px; border-color: blue;'
     object FresnelDiv1: TFresnelDiv
+      Style = 'background-color: blue; border-color: black; height:50px;'
+    end
+    object FresnelSpan1: TFresnelSpan
+      Style = 'width: 50px; height:70px; background-color: red; border: 3px; border-color: black; margin: 3px;'
+    end
+    object FresnelLabel1: TFresnelLabel
+      Style = 'background-color: green;'
+      Caption = 'Label1'
+    end
+    object FresnelDiv2: TFresnelDiv
+      Style = 'border-color: black; height:50px; position: absolute; left: 30px; top: 100px; width: 50px; height: 60px;'
     end
   end
 end

+ 3 - 0
demo/LazDesignerForm/FloatLayoutUnit1.pas

@@ -14,6 +14,9 @@ type
   TFresnelForm2 = class(TFresnelForm)
     FresnelBody1: TFresnelBody;
     FresnelDiv1: TFresnelDiv;
+    FresnelDiv2: TFresnelDiv;
+    FresnelLabel1: TFresnelLabel;
+    FresnelSpan1: TFresnelSpan;
   private
 
   public

+ 4 - 1
demo/LazDesignerForm/MainUnit.pas

@@ -31,8 +31,11 @@ implementation
 { TForm1 }
 
 procedure TForm1.ShowFloatLayoutButtonClick(Sender: TObject);
+var
+  Frm: TFresnelForm2;
 begin
-  FresnelForm1.Show;
+  Frm:=TFresnelForm2.Create(nil);
+  Frm.Show;
 end;
 
 end.

+ 20 - 13
src/fresnelcontrols.pas

@@ -56,9 +56,9 @@ type
     );
   TFresnelLabelStates = set of TFresnelLabelState;
 
-  { TFresnelLabel }
+  { TCustomFresnelLabel }
 
-  TFresnelLabel = class(TFresnelReplacedElement)
+  TCustomFresnelLabel = class(TFresnelReplacedElement)
   private
     class var FFresnelLabelTypeID: TCSSNumericalID;
     class constructor InitFresnelLabelClass;
@@ -86,6 +86,13 @@ type
     property RenderedCaption: String read FRenderedCaption write FRenderedCaption;
   end;
 
+  { TFresnelLabel }
+
+  TFresnelLabel = class(TCustomFresnelLabel)
+  published
+    property Caption;
+  end;
+
   { TFresnelBody }
 
   TFresnelBody = class(TFresnelElement)
@@ -268,14 +275,14 @@ begin
   FCSSAttributes[fcaPosition]:='absolute';
 end;
 
-{ TFresnelLabel }
+{ TCustomFresnelLabel }
 
-class constructor TFresnelLabel.InitFresnelLabelClass;
+class constructor TCustomFresnelLabel.InitFresnelLabelClass;
 begin
   FFresnelLabelTypeID:=RegisterCSSType(CSSTypeName);
 end;
 
-procedure TFresnelLabel.ComputeMinCaption;
+procedure TCustomFresnelLabel.ComputeMinCaption;
 // create FMinCaption from FCaption by putting every word on a line of its own
 var
   LineBreakLen, SrcP, l, StartP, WordLen, TargetP: Integer;
@@ -319,7 +326,7 @@ begin
   SetLength(FMinCaption,TargetP-1);
 end;
 
-procedure TFresnelLabel.SetCaption(const AValue: String);
+procedure TCustomFresnelLabel.SetCaption(const AValue: String);
 begin
   if FCaption=AValue then Exit;
   FCaption:=AValue;
@@ -327,7 +334,7 @@ begin
   FLabelStates:=FLabelStates-[flsMinCaptionValid,flsMinWidthValid,flsSizeValid];
 end;
 
-function TFresnelLabel.GetMinWidthIntrinsicContentBox: TFresnelLength;
+function TCustomFresnelLabel.GetMinWidthIntrinsicContentBox: TFresnelLength;
 var
   p: TFresnelPoint;
 begin
@@ -344,7 +351,7 @@ begin
   Result:=FMinWidth;
 end;
 
-function TFresnelLabel.GetPreferredContentBox_MaxWidth(MaxWidth: TFresnelLength
+function TCustomFresnelLabel.GetPreferredContentBox_MaxWidth(MaxWidth: TFresnelLength
   ): TFresnelPoint;
 begin
   if not (flsSizeValid in FLabelStates) then
@@ -358,7 +365,7 @@ begin
     Result:=Font.TextSizeMaxWidth(FCaption,MaxWidth);
 end;
 
-function TFresnelLabel.GetCSSInitialAttribute(const AttrID: TCSSNumericalID
+function TCustomFresnelLabel.GetCSSInitialAttribute(const AttrID: TCSSNumericalID
   ): TCSSString;
 var
   Attr: TFresnelCSSAttribute;
@@ -373,24 +380,24 @@ begin
   end;
 end;
 
-procedure TFresnelLabel.ClearCSSValues;
+procedure TCustomFresnelLabel.ClearCSSValues;
 begin
   inherited ClearCSSValues;
   FCSSAttributes[fcaDisplayOutside]:='inline';
 end;
 
-procedure TFresnelLabel.UpdateRenderedAttributes;
+procedure TCustomFresnelLabel.UpdateRenderedAttributes;
 begin
   inherited UpdateRenderedAttributes;
   FRenderedCaption:=Caption;
 end;
 
-class function TFresnelLabel.CSSTypeID: TCSSNumericalID;
+class function TCustomFresnelLabel.CSSTypeID: TCSSNumericalID;
 begin
   Result:=FFresnelLabelTypeID;
 end;
 
-class function TFresnelLabel.CSSTypeName: TCSSString;
+class function TCustomFresnelLabel.CSSTypeName: TCSSString;
 begin
   Result:='label';
 end;

+ 35 - 1
src/fresnellclcontrols.pas

@@ -7,7 +7,7 @@ interface
 uses
   Classes, SysUtils, Types, Math, FPImage, FresnelDOM, FresnelLayouter,
   FresnelControls, FresnelRenderer, AvgLvlTree, Laz_AVL_Tree, LazLoggerBase,
-  Graphics, Controls, LCLIntf, Forms;
+  Graphics, Controls, LCLIntf, Forms, LCLStrConsts, LResources;
 
 type
   TFresnelLCLFontEngine = class;
@@ -208,13 +208,17 @@ type
     procedure Notification(AComponent: TComponent; Operation: TOperation);
       override;
     procedure OnQueuedLayout({%H-}Data: PtrInt); virtual;
+    procedure ProcessResource; virtual;
     procedure SetName(const NewName: TComponentName); override;
     procedure SetHeight({%H-}AValue: TFresnelLength); override;
     procedure SetWidth({%H-}AValue: TFresnelLength); override;
   public
     constructor Create(AOwner: TComponent); override;
+    constructor CreateNew(AOwner: TComponent); virtual;
     destructor Destroy; override;
     procedure DomChanged; override;
+    procedure Show; virtual;
+    function ShowModal: TModalResult; virtual;
     property AllowDropFiles: Boolean read GetAllowDropFiles write SetAllowDropFiles default false;
     property AlphaBlend: Boolean read GetAlphaBlend write SetAlphaBlend default false;
     property AlphaBlendValue: Byte read GetAlphaBlendValue write SetAlphaBlendValue default 255;
@@ -335,6 +339,16 @@ begin
   LayoutQueued:=true;
 end;
 
+procedure TCustomFresnelForm.Show;
+begin
+  Form.Show;
+end;
+
+function TCustomFresnelForm.ShowModal: TModalResult;
+begin
+  Result:=Form.ShowModal;
+end;
+
 procedure TCustomFresnelForm.OnQueuedLayout(Data: PtrInt);
 begin
   ApplyCSS;
@@ -346,6 +360,12 @@ begin
     Form.Invalidate;
 end;
 
+procedure TCustomFresnelForm.ProcessResource;
+begin
+  if not InitResourceComponent(Self, TFresnelForm) then
+    raise EResNotFound.CreateFmt(rsFormResourceSNotFoundForResourcelessFormsCreateNew, [ClassName]);
+end;
+
 procedure TCustomFresnelForm.FormPaint(Sender: TObject);
 begin
   if Designer<>nil then exit;
@@ -642,6 +662,20 @@ begin
 end;
 
 constructor TCustomFresnelForm.Create(AOwner: TComponent);
+begin
+  GlobalNameSpace.BeginWrite;
+  try
+    CreateNew(AOwner);
+    if (ClassType <> TFresnelForm) and not (csDesigning in ComponentState) then
+    begin
+      ProcessResource;
+    end;
+  finally
+    GlobalNameSpace.EndWrite;
+  end;
+end;
+
+constructor TCustomFresnelForm.CreateNew(AOwner: TComponent);
 begin
   inherited Create(AOwner);
   FForm:=TCustomForm.CreateNew(nil);

+ 2 - 2
src/fresnelrenderer.pas

@@ -139,9 +139,9 @@ begin
         Line(aBorderColorFP,aBorderBox.Left,aBorderBox.Bottom-i,aBorderBox.Right,aBorderBox.Bottom-i);
     end;
 
-    if El is TFresnelLabel then
+    if El is TCustomFresnelLabel then
     begin
-      aCaption:=TFresnelLabel(El).RenderedCaption;
+      aCaption:=TCustomFresnelLabel(El).RenderedCaption;
       if aCaption<>'' then
       begin
         TextOut(aContentBox.Left,aContentBox.Top,El.Font,colBlack,aCaption);