瀏覽代碼

demo: radiogroup

mattias 4 月之前
父節點
當前提交
b4007687ca

+ 2 - 0
demo/RadioGroup/.gitignore

@@ -0,0 +1,2 @@
+RadioGroupDemo1
+RadioGroupLCLDemo1

+ 22 - 0
demo/RadioGroup/MainUnit.lfm

@@ -0,0 +1,22 @@
+object MainForm: TMainForm
+  Caption = 'MainForm'
+  FormLeft = 450
+  FormTop = 300
+  FormWidth = 350
+  FormHeight = 255
+  Stylesheet.Strings = (
+    '#Div1 {'
+    '  padding: 5px; '
+    '  border: 2px solid black; '
+    '  margin: 8px;'
+    '}'
+  )
+  OnCreate = MainFormCreate
+  Visible = true
+  object Body1: TBody
+    Style = 'border: 2px solid blue;'#10
+    object Div1: TDiv
+      Style = 'background-color: blue;'#10'border-color: black;'#10'min-height:50px;'
+    end
+  end
+end

+ 54 - 0
demo/RadioGroup/MainUnit.pas

@@ -0,0 +1,54 @@
+unit MainUnit;
+
+{$mode ObjFPC}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils, Fresnel.Forms, Fresnel.Controls, Fresnel.Events,
+  FCL.Events, Fresnel.DemoRadioButton;
+
+type
+
+  { TMainForm }
+
+  TMainForm = class(TFresnelForm)
+    Body1: TBody;
+    Div1: TDiv;
+    procedure MainFormCreate(Sender: TObject);
+  private
+  public
+    RadioButton1: TDemoRadioButton;
+    RadioButton2: TDemoRadioButton;
+  end;
+
+var
+  MainForm: TMainForm;
+
+implementation
+
+{$R *.lfm}
+
+{ TMainForm }
+
+procedure TMainForm.MainFormCreate(Sender: TObject);
+begin
+  Div1.Style:='min-width: 200px; min-height: 50px; font-size: 15px;';
+
+  RadioButton1:=TDemoRadioButton.Create(Self);
+  with RadioButton1 do begin
+    Name:='RadioButton1';
+    Caption:='First';
+    Parent:=Div1;
+  end;
+
+  RadioButton2:=TDemoRadioButton.Create(Self);
+  with RadioButton2 do begin
+    Name:='RadioButton2';
+    Caption:='Second';
+    Parent:=Div1;
+  end;
+end;
+
+end.
+

+ 78 - 0
demo/RadioGroup/RadioGroupDemo1.lpi

@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CONFIG>
+  <ProjectOptions>
+    <Version Value="12"/>
+    <General>
+      <Flags>
+        <MainUnitHasCreateFormStatements Value="False"/>
+        <MainUnitHasTitleStatement Value="False"/>
+        <MainUnitHasScaledStatement Value="False"/>
+      </Flags>
+      <SessionStorage Value="InProjectDir"/>
+      <Title Value="RadioGroupDemo1"/>
+      <UseAppBundle Value="False"/>
+      <ResourceType Value="res"/>
+    </General>
+    <BuildModes>
+      <Item Name="Default" Default="True"/>
+    </BuildModes>
+    <PublishOptions>
+      <Version Value="2"/>
+      <UseFileFilters Value="True"/>
+    </PublishOptions>
+    <RunParams>
+      <FormatVersion Value="2"/>
+    </RunParams>
+    <RequiredPackages>
+      <Item>
+        <PackageName Value="FresnelDemoComps"/>
+      </Item>
+      <Item>
+        <PackageName Value="Fresnel"/>
+        <DefaultFilename Value="../../src/fresnel.lpk" Prefer="True"/>
+      </Item>
+    </RequiredPackages>
+    <Units>
+      <Unit>
+        <Filename Value="RadioGroupDemo1.lpr"/>
+        <IsPartOfProject Value="True"/>
+      </Unit>
+      <Unit>
+        <Filename Value="MainUnit.pas"/>
+        <IsPartOfProject Value="True"/>
+        <ComponentName Value="MainForm"/>
+        <HasResources Value="True"/>
+        <ResourceBaseClass Value="Other"/>
+        <ResourceBaseClassname Value="TFresnelForm"/>
+      </Unit>
+    </Units>
+  </ProjectOptions>
+  <CompilerOptions>
+    <Version Value="11"/>
+    <Target>
+      <Filename Value="RadioGroupDemo1"/>
+    </Target>
+    <SearchPaths>
+      <IncludeFiles Value="$(ProjOutDir)"/>
+      <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
+    </SearchPaths>
+    <Linking>
+      <Debugging>
+        <DebugInfoType Value="dsDwarf2"/>
+      </Debugging>
+    </Linking>
+  </CompilerOptions>
+  <Debugging>
+    <Exceptions>
+      <Item>
+        <Name Value="EAbort"/>
+      </Item>
+      <Item>
+        <Name Value="ECodetoolError"/>
+      </Item>
+      <Item>
+        <Name Value="EFOpenError"/>
+      </Item>
+    </Exceptions>
+  </Debugging>
+</CONFIG>

+ 16 - 0
demo/RadioGroup/RadioGroupDemo1.lpr

@@ -0,0 +1,16 @@
+program RadioGroupDemo1;
+
+uses
+  {$IFDEF Unix}
+  cthreads,
+  {$ENDIF}
+  Fresnel, // initializes the widgetset
+  Fresnel.App, MainUnit;
+
+begin
+  FresnelApplication.HookFresnelLog:=true;
+  FresnelApplication.Initialize;
+  FresnelApplication.CreateForm(TMainForm,MainForm);
+  FresnelApplication.Run;
+end.
+

二進制
demo/RadioGroup/RadioGroupDemoLCL1


+ 83 - 0
demo/RadioGroup/RadioGroupDemoLCL1.lpi

@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CONFIG>
+  <ProjectOptions>
+    <Version Value="12"/>
+    <General>
+      <SessionStorage Value="InProjectDir"/>
+      <Title Value="LCLButton"/>
+      <Scaled Value="True"/>
+      <ResourceType Value="res"/>
+      <UseXPManifest Value="True"/>
+      <XPManifest>
+        <DpiAware Value="True"/>
+      </XPManifest>
+    </General>
+    <BuildModes>
+      <Item Name="Default" Default="True"/>
+      <SharedMatrixOptions Count="1">
+        <Item1 ID="000962466024" Type="IDEMacro" MacroName="FresnelLCLRenderer" Value="skia"/>
+      </SharedMatrixOptions>
+    </BuildModes>
+    <PublishOptions>
+      <Version Value="2"/>
+      <UseFileFilters Value="True"/>
+    </PublishOptions>
+    <RunParams>
+      <FormatVersion Value="2"/>
+    </RunParams>
+    <RequiredPackages>
+      <Item>
+        <PackageName Value="FresnelDemoComps"/>
+      </Item>
+      <Item>
+        <PackageName Value="FresnelLCL"/>
+        <DefaultFilename Value="../../../src/lcl/fresnellcl.lpk" Prefer="True"/>
+      </Item>
+      <Item>
+        <PackageName Value="LCL"/>
+      </Item>
+    </RequiredPackages>
+    <Units>
+      <Unit>
+        <Filename Value="RadioGroupDemoLCL1.lpr"/>
+        <IsPartOfProject Value="True"/>
+      </Unit>
+      <Unit>
+        <Filename Value="MainUnit.pas"/>
+        <IsPartOfProject Value="True"/>
+        <ComponentName Value="MainForm"/>
+        <ResourceBaseClass Value="Form"/>
+      </Unit>
+    </Units>
+  </ProjectOptions>
+  <CompilerOptions>
+    <Version Value="11"/>
+    <SearchPaths>
+      <IncludeFiles Value="$(ProjOutDir)"/>
+      <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
+    </SearchPaths>
+    <Linking>
+      <Debugging>
+        <DebugInfoType Value="dsDwarf2"/>
+      </Debugging>
+      <Options>
+        <Win32>
+          <GraphicApplication Value="True"/>
+        </Win32>
+      </Options>
+    </Linking>
+  </CompilerOptions>
+  <Debugging>
+    <Exceptions>
+      <Item>
+        <Name Value="EAbort"/>
+      </Item>
+      <Item>
+        <Name Value="ECodetoolError"/>
+      </Item>
+      <Item>
+        <Name Value="EFOpenError"/>
+      </Item>
+    </Exceptions>
+  </Debugging>
+</CONFIG>

+ 23 - 0
demo/RadioGroup/RadioGroupDemoLCL1.lpr

@@ -0,0 +1,23 @@
+program RadioGroupDemoLCL1;
+
+{$mode objfpc}{$H+}
+
+uses
+  {$IFDEF UNIX}
+  cthreads,
+  {$ENDIF}
+  Interfaces, // this includes the LCL widgetset
+  Fresnel, // this includes the Fresnel-LCL widgetset
+  Forms, MainUnit;
+
+{$R *.res}
+
+begin
+  RequireDerivedFormResource:=True;
+  Application.Title:='LCLButton';
+  Application.Scaled:=True;
+  Application.Initialize;
+  Application.CreateForm(TMainForm, MainForm);
+  Application.Run;
+end.
+

二進制
demo/RadioGroup/RadioGroupDemoLCL1.res


+ 136 - 0
demo/democomps/fresnel.demoradiobutton.pas

@@ -0,0 +1,136 @@
+unit Fresnel.DemoRadioButton;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils,
+  Fresnel.DOM, Fresnel.Controls, Fresnel.Classes,
+  FCL.Events, Fresnel.Events, fpCSSTree;
+
+type
+
+  { TDemoRadioButton }
+
+  TDemoRadioButton = class(TDiv)
+  private
+    FChecked: boolean;
+    FOnChange: TNotifyEvent;
+    function GetCaption: TFresnelCaption;
+    function GetChecked: boolean;
+  protected
+    procedure OnBoxClickEvent(Event: TAbstractEvent); virtual;
+    procedure SetCaption(const AValue: TFresnelCaption); virtual;
+    procedure SetChecked(AValue: boolean); virtual;
+    procedure UncheckOthers; virtual;
+  public
+    // default styles
+    const
+      cStyle = ''
+        +'.RadioButton {'+LineEnding
+        +'}'+LineEnding
+        +'.RadioButtonBox {'+LineEnding
+        +'  width: 0.9em;'+LineEnding
+        +'  height: 0.9em;'+LineEnding
+        +'  border-radius: 50%;'+LineEnding
+        +'}'+LineEnding
+        +'.RadioButtonLabel {'+LineEnding
+        +'  cursor: pointer;'+LineEnding
+        +'  padding: 0.2em 0.3em;'+LineEnding
+        +'  margin-bottom: 0;'+LineEnding
+        +'}'+LineEnding;
+    cCheckedStyle = 'background: #68f; border: 2px solid #333;';
+    cUncheckedStyle = 'background: white; border: 2px solid #333;';
+  public
+    Box: TSpan;
+    CaptionLabel: TLabel;
+    constructor Create(AOwner: TComponent); override;
+    class function GetCSSTypeStyle: TCSSString; override;
+    property Caption: TFresnelCaption read GetCaption write SetCaption;
+    property Checked: boolean read GetChecked write SetChecked;
+    property OnChange: TNotifyEvent read FOnChange write FOnChange;
+  end;
+
+implementation
+
+{ TDemoRadioButton }
+
+function TDemoRadioButton.GetCaption: TFresnelCaption;
+begin
+  Result:=CaptionLabel.Caption;
+end;
+
+function TDemoRadioButton.GetChecked: boolean;
+begin
+  Result:=FChecked;
+end;
+
+procedure TDemoRadioButton.OnBoxClickEvent(Event: TAbstractEvent);
+begin
+  if Event=nil then ;
+  Checked:=true;
+  if Assigned(OnChange) then OnChange(Self);
+end;
+
+procedure TDemoRadioButton.SetCaption(const AValue: TFresnelCaption);
+begin
+  CaptionLabel.Caption:=AValue;
+end;
+
+procedure TDemoRadioButton.SetChecked(AValue: boolean);
+begin
+  if Checked=AValue then exit;
+  FChecked:=AValue;
+  if Checked then
+  begin
+    Box.Style:=cCheckedStyle;
+    UncheckOthers;
+  end else begin
+    Box.Style:=cUncheckedStyle;
+  end;
+end;
+
+procedure TDemoRadioButton.UncheckOthers;
+var
+  i: Integer;
+  El: TFresnelElement;
+begin
+  for i:=0 to Parent.NodeCount-1 do
+  begin
+    El:=Parent.Nodes[i];
+    if (El<>Self) and (El is TDemoRadioButton) then
+      TDemoRadioButton(El).Checked:=false;
+  end;
+end;
+
+constructor TDemoRadioButton.Create(AOwner: TComponent);
+begin
+  inherited Create(AOwner);
+
+  CSSClasses.Add('RadioButton');
+
+  Box:=TSpan.Create(Self);
+  with Box do begin
+    Name:='Box';
+    CSSClasses.Add('RadioButtonBox');
+    AddEventListener(evtClick,@OnBoxClickEvent);
+    Style:=cUncheckedStyle;
+    Parent:=Self;
+  end;
+
+  CaptionLabel:=TLabel.Create(Self);
+  with CaptionLabel do begin
+    Name:='CaptionLabel';
+    CSSClasses.Add('RadioButtonLabel');
+    Parent:=Self;
+  end;
+end;
+
+class function TDemoRadioButton.GetCSSTypeStyle: TCSSString;
+begin
+  Result:=cStyle;
+end;
+
+end.
+

+ 4 - 0
demo/democomps/fresneldemocomps.lpk

@@ -38,6 +38,10 @@
         <Filename Value="DemoButtonGenerator.pas"/>
         <UnitName Value="DemoButtonGenerator"/>
       </Item>
+      <Item>
+        <Filename Value="fresnel.demoradiobutton.pas"/>
+        <UnitName Value="fresnel.demoradiobutton"/>
+      </Item>
     </Files>
     <RequiredPkgs>
       <Item>

+ 2 - 2
demo/democomps/fresneldemocomps.pas

@@ -8,8 +8,8 @@ unit FresnelDemoComps;
 interface
 
 uses
-  Fresnel.DemoCombobox, Fresnel.DemoCheckbox, Fresnel.DemoSlider, DemoButtonGenerator, 
-  LazarusPackageIntf;
+  Fresnel.DemoCombobox, Fresnel.DemoCheckbox, Fresnel.DemoSlider, 
+  DemoButtonGenerator, Fresnel.DemoRadioButton, LazarusPackageIntf;
 
 implementation