MainUnit.pas 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. unit MainUnit;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, Fresnel.Forms, Fresnel.DOM, Fresnel.Controls, DemoSlider,
  6. DemoCheckBox;
  7. type
  8. { TFresnelForm1 }
  9. TFresnelForm1 = class(TFresnelForm)
  10. procedure FresnelForm1Create(Sender: TObject);
  11. private
  12. procedure OnPropChange(Sender: TObject);
  13. procedure UpdateButton;
  14. public
  15. ButtonDiv: TDiv;
  16. ButtonLabel: TLabel;
  17. FontSizeSlider: TDemoSlider;
  18. PaddingVerticalSlider: TDemoSlider;
  19. BorderWidthSlider: TDemoSlider;
  20. BorderRadiusDiv: TDiv;
  21. BorderRadiusLabel: TLabel;
  22. BorderRadiusTopLeftChkBox: TDemoCheckBox;
  23. BorderRadiusTopRightChkBox: TDemoCheckBox;
  24. BorderRadiusBottomLeftChkBox: TDemoCheckBox;
  25. BorderRadiusBottomRightChkBox: TDemoCheckBox;
  26. BorderRadiusSlider: TDemoSlider;
  27. TextShadowChkBox: TDemoCheckBox;
  28. TextShadowVertPosSlider: TDemoSlider;
  29. TextShadowHorzPosSlider: TDemoSlider;
  30. TextShadowBlurRadiusSlider: TDemoSlider;
  31. end;
  32. var
  33. FresnelForm1: TFresnelForm1;
  34. implementation
  35. {$R *.lfm}
  36. { TFresnelForm1 }
  37. procedure TFresnelForm1.FresnelForm1Create(Sender: TObject);
  38. begin
  39. Stylesheet.Add(TDemoSlider.cStyle);
  40. Stylesheet.Add(TDemoCheckBox.cStyle);
  41. Stylesheet.Add('#ButtonDiv {'
  42. +'background:#44c767;'
  43. +'border:1px solid #18ab29;'
  44. +'border-radius:16px;'
  45. +'padding:16px 31px;'
  46. +'font-size:15px; font-family:Arial; font-weight:bold;'
  47. +'color:#fff;'
  48. +'text-shadow: 1px 1px 0px #2f6627;'
  49. +'}'
  50. +'.CheckBox {'+LineEnding
  51. +' margin: 6px;'+LineEnding
  52. +'}'+LineEnding
  53. +'.Slider {'+LineEnding
  54. +' margin: 6px;'+LineEnding
  55. +'}'+LineEnding
  56. );
  57. // font-size slider
  58. FontSizeSlider:=TDemoSlider.Create(Self);
  59. with FontSizeSlider do begin
  60. Name:='FontSizeSlider';
  61. Caption:='Font Size:';
  62. Style:='width: 150px';
  63. ValueFormat:='%.0fpx';
  64. MinPosition:=5;
  65. MaxPosition:=40;
  66. Position:=12;
  67. Parent:=Self;
  68. OnChange:=@OnPropChange;
  69. end;
  70. // padding vertical slider
  71. PaddingVerticalSlider:=TDemoSlider.Create(Self);
  72. with PaddingVerticalSlider do begin
  73. Name:='PaddingVerticalSlider';
  74. Caption:='Vertical Padding:';
  75. Style:='width: 150px';
  76. ValueFormat:='%.0fpx';
  77. MinPosition:=0;
  78. MaxPosition:=50;
  79. Position:=16;
  80. Parent:=Self;
  81. OnChange:=@OnPropChange;
  82. end;
  83. // border-width slider
  84. BorderWidthSlider:=TDemoSlider.Create(Self);
  85. with BorderWidthSlider do begin
  86. Name:='BorderWidthSlider';
  87. Caption:='Border Width:';
  88. Style:='width: 150px';
  89. ValueFormat:='%.0fpx';
  90. MinPosition:=0;
  91. MaxPosition:=10;
  92. Position:=1;
  93. Parent:=Self;
  94. OnChange:=@OnPropChange;
  95. end;
  96. // border-radius corners: four checkboxes
  97. BorderRadiusDiv:=TDiv.Create(Self);
  98. with BorderRadiusDiv do begin
  99. Name:='BorderRadiusDiv';
  100. Style:='margin: 6px;';
  101. Parent:=Self;
  102. end;
  103. BorderRadiusLabel:=TLabel.Create(Self);
  104. with BorderRadiusLabel do begin
  105. Name:='BorderRadiusLabel';
  106. Caption:='Border Corner Radius:';
  107. Parent:=BorderRadiusDiv;
  108. end;
  109. BorderRadiusTopLeftChkBox:=TDemoCheckBox.Create(Self);
  110. with BorderRadiusTopLeftChkBox do begin
  111. Name:='BorderRadiusTopLeftChkBox';
  112. Caption:='Top Left';
  113. Checked:=true;
  114. Parent:=BorderRadiusDiv;
  115. OnChange:=@OnPropChange;
  116. end;
  117. BorderRadiusTopRightChkBox:=TDemoCheckBox.Create(Self);
  118. with BorderRadiusTopRightChkBox do begin
  119. Name:='BorderRadiusTopRightChkBox';
  120. Caption:='Top Right';
  121. Checked:=true;
  122. Parent:=BorderRadiusDiv;
  123. OnChange:=@OnPropChange;
  124. end;
  125. BorderRadiusBottomLeftChkBox:=TDemoCheckBox.Create(Self);
  126. with BorderRadiusBottomLeftChkBox do begin
  127. Name:='BorderRadiusBottomLeftChkBox';
  128. Caption:='Bottom Left';
  129. Checked:=true;
  130. Parent:=BorderRadiusDiv;
  131. OnChange:=@OnPropChange;
  132. end;
  133. BorderRadiusBottomRightChkBox:=TDemoCheckBox.Create(Self);
  134. with BorderRadiusBottomRightChkBox do begin
  135. Name:='BorderRadiusBottomRightChkBox';
  136. Caption:='Bottom Right';
  137. Checked:=true;
  138. Parent:=BorderRadiusDiv;
  139. OnChange:=@OnPropChange;
  140. end;
  141. // slider for border radius
  142. BorderRadiusSlider:=TDemoSlider.Create(Self);
  143. with BorderRadiusSlider do begin
  144. Name:='BorderRadiusSlider';
  145. Caption:='Border Radius:';
  146. Style:='width: 150px';
  147. ValueFormat:='%.0fpx';
  148. MinPosition:=0;
  149. MaxPosition:=50;
  150. Position:=16;
  151. Parent:=Self;
  152. OnChange:=@OnPropChange;
  153. end;
  154. // text-shadow checkbox
  155. TextShadowChkBox:=TDemoCheckBox.Create(Self);
  156. with TextShadowChkBox do begin
  157. Name:='TextShadowChkBox';
  158. Caption:='Text Shadow';
  159. Checked:=true;
  160. Parent:=Self;
  161. OnChange:=@OnPropChange;
  162. end;
  163. // slider for text-shadow vertical position
  164. TextShadowVertPosSlider:=TDemoSlider.Create(Self);
  165. with TextShadowVertPosSlider do begin
  166. Name:='TextShadowVertPosSlider';
  167. Caption:='Vertical Position:';
  168. Style:='width: 150px';
  169. ValueFormat:='%.0fpx';
  170. MinPosition:=-30;
  171. MaxPosition:=30;
  172. Position:=1;
  173. Parent:=Self;
  174. OnChange:=@OnPropChange;
  175. end;
  176. // slider for text-shadow horizontal position
  177. TextShadowHorzPosSlider:=TDemoSlider.Create(Self);
  178. with TextShadowHorzPosSlider do begin
  179. Name:='TextShadowHorzPosSlider';
  180. Caption:='Horizontal Position:';
  181. Style:='width: 150px';
  182. ValueFormat:='%.0fpx';
  183. MinPosition:=-30;
  184. MaxPosition:=30;
  185. Position:=1;
  186. Parent:=Self;
  187. OnChange:=@OnPropChange;
  188. end;
  189. // slider for text-shadow horizontal position
  190. TextShadowBlurRadiusSlider:=TDemoSlider.Create(Self);
  191. with TextShadowBlurRadiusSlider do begin
  192. Name:='TextShadowBlurRadiusSlider';
  193. Caption:='Blur Radius:';
  194. Style:='width: 150px';
  195. ValueFormat:='%.0fpx';
  196. MinPosition:=0;
  197. MaxPosition:=30;
  198. Position:=0;
  199. Parent:=Self;
  200. OnChange:=@OnPropChange;
  201. end;
  202. // the Button
  203. ButtonDiv:=TDiv.Create(Self);
  204. with ButtonDiv do begin
  205. Name:='ButtonDiv';
  206. Parent:=Self;
  207. end;
  208. ButtonLabel:=TLabel.Create(Self);
  209. with ButtonLabel do begin
  210. Name:='ButtonLabel';
  211. Caption:='Button Text';
  212. Parent:=ButtonDiv;
  213. end;
  214. UpdateButton;
  215. end;
  216. procedure TFresnelForm1.OnPropChange(Sender: TObject);
  217. begin
  218. UpdateButton;
  219. end;
  220. procedure TFresnelForm1.UpdateButton;
  221. var
  222. s, NewStyle, Radius: String;
  223. begin
  224. if ButtonDiv=nil then exit;
  225. NewStyle:=
  226. 'font-size:'+FloatToStr(FontSizeSlider.Position)+'px;'
  227. +'padding: '+FloatToStr(PaddingVerticalSlider.Position)+'px 31px;'
  228. +'border-width:'+FloatToStr(BorderWidthSlider.Position)+'px;';
  229. Radius:=FloatToStr(BorderRadiusSlider.Position)+'px';
  230. s:='';
  231. if BorderRadiusTopLeftChkBox.Checked then
  232. s:=Radius
  233. else
  234. s:='0';
  235. if BorderRadiusTopRightChkBox.Checked then
  236. s+=' '+Radius
  237. else
  238. s+=' 0';
  239. if BorderRadiusBottomLeftChkBox.Checked then
  240. s+=' '+Radius
  241. else
  242. s+=' 0';
  243. if BorderRadiusBottomRightChkBox.Checked then
  244. s+=' '+Radius
  245. else
  246. s+=' 0';
  247. NewStyle+='border-radius:'+s+';';
  248. s:='';
  249. if TextShadowChkBox.Checked then
  250. begin
  251. s:=FloatToStr(TextShadowHorzPosSlider.Position)
  252. +' '+FloatToStr(TextShadowVertPosSlider.Position)
  253. +' '+FloatToStr(TextShadowBlurRadiusSlider.Position)
  254. +' #2f6627';
  255. end;
  256. NewStyle+='text-shadow:'+s+';';
  257. ButtonDiv.Style:=NewStyle;
  258. end;
  259. end.