MainUnit.pas 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. unit MainUnit;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, Fresnel.Forms, Fresnel.DOM, Fresnel.Controls, Fresnel.Events,
  6. Fresnel.DemoRadioButton, Fresnel.DemoCombobox;
  7. type
  8. { TMainForm }
  9. TMainForm = class(TFresnelForm)
  10. procedure MainFormCreate(Sender: TObject);
  11. private
  12. procedure BorderStyleChange(Sender: TObject);
  13. public
  14. ExamplesDiv: TDiv;
  15. UserDiv: TDiv;
  16. BorderStyleCB: TDemoCombobox;
  17. UniformBorderDiv: TDiv;
  18. end;
  19. var
  20. MainForm: TMainForm;
  21. implementation
  22. const
  23. BorderStyles: array[0..9] of string = (
  24. 'none','hidden','dotted','dashed','solid','double','groove','ridge','inset','outset');
  25. {$R *.lfm}
  26. { TMainForm }
  27. procedure TMainForm.MainFormCreate(Sender: TObject);
  28. function AddDiv(aName: string; aParent: TFresnelElement; aStyle: string): TDiv;
  29. begin
  30. Result:=TDiv.Create(Self);
  31. Result.Name:=aName;
  32. Result.Parent:=aParent;
  33. Result.Style:=aStyle;
  34. end;
  35. function AddLabel(aName, aCaption: string; aParent: TFresnelElement): TLabel;
  36. begin
  37. Result:=TLabel.Create(Self);
  38. Result.Name:=aName;
  39. Result.Caption:=aCaption;
  40. Result.Parent:=aParent;
  41. end;
  42. function AddRadioButton(aName, aCaption: string; aParent: TFresnelElement;
  43. const OnClick: TFresnelEventHandler = nil): TDemoRadioButton;
  44. begin
  45. Result:=TDemoRadioButton.Create(Self);
  46. Result.Name:=aName;
  47. Result.Caption:=aCaption;
  48. Result.Parent:=aParent;
  49. Result.AddEventListener(evtClick,OnClick);
  50. end;
  51. function AddComboxBox(aName: string; aParent: TFresnelElement;
  52. const Items: TStrings; ItemIndex: integer;
  53. const OnChange: TNotifyEvent = nil): TDemoCombobox;
  54. var
  55. i: Integer;
  56. begin
  57. Result:=TDemoCombobox.Create(Self);
  58. Result.Name:=aName;
  59. for i:=0 to Items.Count-1 do
  60. Result.Items.Add(Items[i]);
  61. Result.ItemIndex:=ItemIndex;
  62. Result.Parent:=aParent;
  63. Result.OnChange:=OnChange;
  64. end;
  65. var
  66. s: TFresnelCSSSide;
  67. List: TStringList;
  68. i: Integer;
  69. begin
  70. Stylesheet.Text:=':root { font-size: 15px; }'+LineEnding
  71. +'div { margin: 3px; }'+LineEnding;
  72. // Examples - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  73. ExamplesDiv:=AddDiv('ExamplesDiv',Viewport,'position: absolute; left: 5px; top: 5px; width: 50px;');
  74. // uniform color and width
  75. AddDiv('Uniform1pxColorAndWidth',ExamplesDiv,'border: 1px solid red; width: 1px; height: 1px;');
  76. AddDiv('Uniform2pxColorAndWidth',ExamplesDiv,'border: 2px solid red; width: 1px; height: 1px;');
  77. AddDiv('UniformDot5pxColorAndWidth',ExamplesDiv,'border: .5px solid red; width: 2px; height: 2px;');
  78. // uniform color, one side no border
  79. for s in TFresnelCSSSide do
  80. AddDiv('UniformColorAndWidthOpen'+dbgs(s),ExamplesDiv,'border: 1px solid red; border-'+lowercase(dbgs(s))+'-width: 0px; width: 1px; height: 1px;');
  81. // 1px solid one side blue
  82. for s in TFresnelCSSSide do
  83. AddDiv('UniformWidth1pxAndColor'+dbgs(s),ExamplesDiv,'border: 1px solid red; border-'+lowercase(dbgs(s))+'-color: blue; width: 1px; height: 1px;');
  84. // 3px solid one side blue
  85. for s in TFresnelCSSSide do
  86. AddDiv('UniformWidth3pxAndColor'+dbgs(s),ExamplesDiv,'border: 3px solid red; border-'+lowercase(dbgs(s))+'-color: blue; width: 1px; height: 1px;');
  87. // 1px solid red, border-radius: 3px
  88. AddDiv('UniformColorAndWidth1pxAndRadius3px',ExamplesDiv,'border: 1px solid red; width: 5px; height: 5px; border-radius: 3px;');
  89. // 2px solid red, border-radius: 3px
  90. AddDiv('UniformColorAndWidth2pxAndRadius3px',ExamplesDiv,'border: 2px solid red; width: 5px; height: 5px; border-radius: 3px;');
  91. // User - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  92. UserDiv:=AddDiv('UserDiv',Viewport,'position: absolute; left: 60px; top: 5px; width: 200px;');
  93. List:=TStringList.Create;
  94. for i:=0 to high(BorderStyles) do
  95. List.Add('border-style: '+BorderStyles[i]);
  96. BorderStyleCB:=AddComboxBox('BorderStyleCB',UserDiv,List,4,@BorderStyleChange);
  97. UniformBorderDiv:=AddDiv('UniformBorderDiv',UserDiv,'padding: 5px; border: 1px solid black; height: 10px;');
  98. end;
  99. procedure TMainForm.BorderStyleChange(Sender: TObject);
  100. var
  101. s: String;
  102. begin
  103. if BorderStyleCB.ItemIndex>=0 then
  104. s:=BorderStyles[BorderStyleCB.ItemIndex]
  105. else
  106. s:='solid';
  107. s:='1px '+s+' black';
  108. UniformBorderDiv.SetStyleAttr('border',s);
  109. end;
  110. end.