unit MainUnit; {$mode objfpc}{$H+} interface uses Classes, SysUtils, Fresnel.Forms, Fresnel.DOM, Fresnel.Controls, Fresnel.Events, FCL.Events, Fresnel.DemoRadioButton; type { TMainForm } TMainForm = class(TFresnelForm) procedure MainFormCreate(Sender: TObject); private procedure OnTextAlignClick(Event: TAbstractEvent); public TextAlignRadiogroup: TDiv; TextAlignLeftRadioButton: TDemoRadioButton; TextAlignCenterRadioButton: TDemoRadioButton; TextAlignJustifyRadioButton: TDemoRadioButton; TextAlignRightRadioButton: TDemoRadioButton; TextDiv: TDiv; Label1, Label2, Label3, Label4, Label5: TLabel; end; var MainForm: TMainForm; implementation {$R *.lfm} { TMainForm } procedure TMainForm.MainFormCreate(Sender: TObject); function AddDiv(aName: string; aParent: TFresnelElement): TDiv; begin Result:=TDiv.Create(Self); Result.Name:=aName; Result.Parent:=aParent; end; function AddLabel(aName, aCaption: string; aParent: TFresnelElement): TLabel; begin Result:=TLabel.Create(Self); Result.Name:=aName; Result.Caption:=aCaption; Result.Parent:=aParent; end; function AddRadioButton(aName, aCaption: string; aParent: TFresnelElement; const OnClick: TFresnelEventHandler = nil): TDemoRadioButton; begin Result:=TDemoRadioButton.Create(Self); Result.Name:=aName; Result.Caption:=aCaption; Result.Parent:=aParent; Result.AddEventListener(evtClick,OnClick); end; begin Style:='font-size: 15px;'; Stylesheet.Text:=':root { font-size: 15px; }'+LineEnding +'#TextDiv { font-size: 30px; }'+LineEnding +'#TextDiv>label { margin-right: .5em; }'; TextAlignRadiogroup:=AddDiv('TextAlignRadiogroup',Self); TextAlignRadiogroup.Style:='padding: 1em;'; TextAlignLeftRadioButton:=AddRadioButton('TextAlignLeftRadioButton','Left', TextAlignRadiogroup,@OnTextAlignClick); TextAlignLeftRadioButton.Checked:=true; TextAlignCenterRadioButton:=AddRadioButton('TextAlignCenterRadioButton','Center', TextAlignRadiogroup,@OnTextAlignClick); TextAlignJustifyRadioButton:=AddRadioButton('TextAlignJustifyRadioButton','Justify (last line: left)', TextAlignRadiogroup,@OnTextAlignClick); TextAlignRightRadioButton:=AddRadioButton('TextAlignRightRadioButton','Right', TextAlignRadiogroup,@OnTextAlignClick); TextDiv:=AddDiv('TextDiv',Self); TextDiv.Style:='padding: 1em;'; Label1:=AddLabel('Label1','Fresnel',TextDiv); Label1.Style:='color: #800;'; Label2:=AddLabel('Label2','demonstration',TextDiv); Label2.Style:='color: #080;'; Label3:=AddLabel('Label3','of',TextDiv); Label3.Style:='color: #080;'; Label4:=AddLabel('Label4','Text',TextDiv); Label4.Style:='color: #080;'; Label5:=AddLabel('Label5','Align',TextDiv); Label5.Style:='color: #008;'; end; procedure TMainForm.OnTextAlignClick(Event: TAbstractEvent); begin if Event.Sender=TextAlignLeftRadioButton then TextDiv.SetStyleAttr('text-align','left') else if Event.Sender=TextAlignCenterRadioButton then TextDiv.SetStyleAttr('text-align','center') else if Event.Sender=TextAlignJustifyRadioButton then TextDiv.SetStyleAttr('text-align','justify') else if Event.Sender=TextAlignRightRadioButton then TextDiv.SetStyleAttr('text-align','right'); end; end.