Browse Source

demo: checkbox: use resource for image

mattias 1 year ago
parent
commit
20176c350b
2 changed files with 19 additions and 4 deletions
  1. 19 4
      demo/CheckBox/DemoCheckBox.pas
  2. BIN
      demo/CheckBox/DemoCheckBox.res

+ 19 - 4
demo/CheckBox/DemoCheckBox.pas

@@ -49,13 +49,16 @@ type
     // default styles
     // default styles
     const
     const
       cStyle = ''
       cStyle = ''
+        +'.CheckBox {'+LineEnding
+        +'  position: relative;'+LineEnding
+        +'}'+LineEnding
         +'.CheckBoxButton {'+LineEnding
         +'.CheckBoxButton {'+LineEnding
         +'  margin: 0 2px 0 0;'+LineEnding
         +'  margin: 0 2px 0 0;'+LineEnding
         +'}'+LineEnding
         +'}'+LineEnding
         +'.CheckBoxLabel {'+LineEnding
         +'.CheckBoxLabel {'+LineEnding
         +'  cursor: pointer;'+LineEnding
         +'  cursor: pointer;'+LineEnding
-        +'  font-size: 12px;'+LineEnding
-        +'  padding: 4px 3px;'+LineEnding
+        +'  font-size: 11px;'+LineEnding
+        +'  padding: 2px 3px;'+LineEnding
         +'  margin-bottom: 0;'+LineEnding
         +'  margin-bottom: 0;'+LineEnding
         +'}'+LineEnding;
         +'}'+LineEnding;
   public
   public
@@ -68,6 +71,8 @@ type
 
 
 implementation
 implementation
 
 
+{$R *.res}
+
 { TDemoCheckBoxButton }
 { TDemoCheckBoxButton }
 
 
 procedure TDemoCheckBoxButton.OnClickEvent(Event: TAbstractEvent);
 procedure TDemoCheckBoxButton.OnClickEvent(Event: TAbstractEvent);
@@ -89,6 +94,8 @@ begin
 end;
 end;
 
 
 constructor TDemoCheckBoxButton.Create(AOwner: TComponent);
 constructor TDemoCheckBoxButton.Create(AOwner: TComponent);
+var
+  aStream: TResourceStream;
 begin
 begin
   inherited Create(AOwner);
   inherited Create(AOwner);
 
 
@@ -96,7 +103,13 @@ begin
   UncheckedStyle:=cUncheckedStyle;
   UncheckedStyle:=cUncheckedStyle;
 
 
   Style:=UncheckedStyle;
   Style:=UncheckedStyle;
-  Image.LoadFromFile('Check.png');
+
+  aStream := TResourceStream.Create(HINSTANCE, 'Check', RT_RCDATA);
+  try
+    Image.LoadFromStream(aStream);
+  finally
+    aStream.Free;
+  end;
 
 
   AddEventListener(evtClick,@OnClickEvent);
   AddEventListener(evtClick,@OnClickEvent);
 end;
 end;
@@ -127,6 +140,8 @@ constructor TDemoCheckBox.Create(AOwner: TComponent);
 begin
 begin
   inherited Create(AOwner);
   inherited Create(AOwner);
 
 
+  CSSClasses.Add('CheckBox');
+
   Box:=TDemoCheckBoxButton.Create(Self);
   Box:=TDemoCheckBoxButton.Create(Self);
   with Box do begin
   with Box do begin
     Name:='Box';
     Name:='Box';
@@ -137,7 +152,7 @@ begin
   CaptionLabel:=TLabel.Create(Self);
   CaptionLabel:=TLabel.Create(Self);
   with CaptionLabel do begin
   with CaptionLabel do begin
     Name:='CaptionLabel';
     Name:='CaptionLabel';
-    CSSClasses.Add('CheckBoxCaption');
+    CSSClasses.Add('CheckBoxLabel');
     Parent:=Self;
     Parent:=Self;
   end;
   end;
 end;
 end;

BIN
demo/CheckBox/DemoCheckBox.res