Browse Source

* Simpler createcontrols

Michaël Van Canneyt 1 year ago
parent
commit
edde2e6eac
2 changed files with 25 additions and 58 deletions
  1. 2 3
      demo/StyleSheet/mainunit.lfm
  2. 23 55
      demo/StyleSheet/mainunit.pas

+ 2 - 3
demo/StyleSheet/mainunit.lfm

@@ -3,13 +3,11 @@ object MainForm: TMainForm
   Height = 508
   Top = 260
   Width = 620
-  Caption = 'FresnelLCLControl'
+  Caption = 'Style sheet demo'
   ClientHeight = 508
   ClientWidth = 620
   LCLVersion = '3.99.0.0'
-  OnActivate = FormActivate
   OnCreate = FormCreate
-  OnShow = FormShow
   object Panel1: TPanel
     Left = 0
     Height = 50
@@ -19,6 +17,7 @@ object MainForm: TMainForm
     ClientHeight = 50
     ClientWidth = 620
     TabOrder = 0
+    Visible = False
     object FECSS: TFileNameEdit
       Left = 136
       Height = 28

+ 23 - 55
demo/StyleSheet/mainunit.pas

@@ -17,19 +17,16 @@ type
     FECSS: TFileNameEdit;
     LblStyleSheet: StdCtrls.TLabel;
     Panel1: TPanel;
-    procedure CGEventsItemClick(Sender: TObject; {%H-}Index: integer);
     procedure FECSSEditingDone(Sender: TObject);
-    procedure FormActivate(Sender: TObject);
     procedure FormCreate(Sender: TObject);
-    procedure FormShow(Sender: TObject);
   private
     Body1: TBody;
     Div1, Div2: TDiv;
     Img1 : TImage;
-    ViewPort: TFresnelViewport;
     Span1: TSpan;
     Fresnel1: TFresnelLCLControl;
     label1 : Fresnel.controls.TLabel;
+    procedure CreateControls(ViewPort: TFresnelViewport);
   public
 
   end;
@@ -61,59 +58,34 @@ begin
   begin
     Name:='Fresnel1';
     Align:=alClient;
-    Viewport.Stylesheet.LoadFromFile('style2.css');
+    Viewport.Stylesheet.LoadFromFile('style1.css');
     Parent:=Self;
   end;
-  ViewPort:=Fresnel1.Viewport;
+  CreateControls(Fresnel1.Viewport);
+end;
 
-  Body1:=TBody.Create(Self);
-  with Body1 do begin
-    Name:='Body1';
-    Parent:=ViewPort;
-  end;
+Procedure TMainForm.CreateControls(ViewPort : TFresnelViewport);
 
-  Div1:=TDiv.Create(Self);
-  with Div1 do begin
-    Name:='Div1';
-    Parent:=Body1;
-  end;
-
-  Span1:=TSpan.Create(Self);
-  with Span1 do begin
-    Name:='Span1';
-    Parent:=Body1;
-  end;
-
-  label1:=TLabel.Create(Self);
-  with label1 do
+  Function CreateControl(aClass : TFresnelElementClass;
+                         aName : String;
+                         aParent : TFresnelElement = nil) : TFresnelElement;
   begin
-    Name:='Label1';
-    Caption:='Label1Caption';
-    Parent:=Body1;
-  end;
-
-  Div2:=TDiv.Create(Self);
-  with Div2 do begin
-    Name:='Div2';
-    Parent:=Body1;
-  end;
-
-  Img1:=TImage.Create(Self);
-  with Img1 do begin
-    Name:='Img1';
-    Parent:=Body1;
-    Image.LoadFromFile('image.png');
+    if aParent=Nil then
+      aparent:=Body1;
+    Result:=aClass.Create(Self);
+    Result.Name:=aName;
+    Result.parent:=aParent;
   end;
 
-end;
-
-procedure TMainForm.FormShow(Sender: TObject);
-
-begin
-end;
-
-procedure TMainForm.CGEventsItemClick(Sender: TObject; Index: integer);
 begin
+  Body1:=TBody(CreateControl(TBody,'Body1',ViewPort));
+  Div1:=TDiv(CreateControl(TDiv,'Div1'));
+  Span1:=TSpan(CreateControl(TSpan,'Span1'));
+  label1:=TLabel(CreateControl(TLabel,'Label1'));
+  Label1.Caption:='Label1Caption';
+  Div2:=TDiv(CreateControl(TDiv,'Div2'));
+  Img1:=TImage(CreateControl(TImage,'Img1'));
+  Img1.Image.LoadFromFile('image.png');
 end;
 
 procedure TMainForm.FECSSEditingDone(Sender: TObject);
@@ -126,16 +98,12 @@ begin
     begin
     L:=TstringList.Create;
     L.LoadFromFile(FECSS.FileName);
-    ViewPort.Stylesheet:=L;
-    ViewPort.ApplyCSS;
+    Fresnel1.ViewPort.Stylesheet:=L;
     L.Free;
-    Fresnel1.Repaint;
+    Fresnel1.ViewPort.ApplyCSS;
     end;
 end;
 
-procedure TMainForm.FormActivate(Sender: TObject);
-begin
-end;