|
@@ -0,0 +1,206 @@
|
|
|
+unit DemoSlider;
|
|
|
+
|
|
|
+{$mode ObjFPC}{$H+}
|
|
|
+
|
|
|
+interface
|
|
|
+
|
|
|
+uses
|
|
|
+ Classes, SysUtils, math, Fresnel.DOM, Fresnel.Controls, Fresnel.Classes;
|
|
|
+
|
|
|
+type
|
|
|
+
|
|
|
+ { TDemoSlider }
|
|
|
+
|
|
|
+ TDemoSlider = class(TDiv)
|
|
|
+ private
|
|
|
+ FMaxPosition: TFresnelLength;
|
|
|
+ FMinPosition: TFresnelLength;
|
|
|
+ FPosition: TFresnelLength;
|
|
|
+ FValueFormat: string;
|
|
|
+ function GetCaption: TFresnelCaption;
|
|
|
+ procedure SetCaption(const AValue: TFresnelCaption);
|
|
|
+ procedure SetMaxPosition(const AValue: TFresnelLength);
|
|
|
+ procedure SetMinPosition(const AValue: TFresnelLength);
|
|
|
+ procedure SetPosition(AValue: TFresnelLength);
|
|
|
+ procedure SetValueFormat(const AValue: string);
|
|
|
+ procedure UpdateValueLabel;
|
|
|
+ procedure UpdatePosition;
|
|
|
+ public
|
|
|
+ const
|
|
|
+ cStyle = ''
|
|
|
+ +'.SliderCaptionDiv {'
|
|
|
+ +' margin-bottom: 4px;'
|
|
|
+ +' font-size: 12px;'
|
|
|
+ +' width: 100%;'
|
|
|
+ +'}'
|
|
|
+ +'.SliderLabel {'
|
|
|
+ +'}'
|
|
|
+ +'.SliderValue {'
|
|
|
+ +' margin-left: 5px;'
|
|
|
+ +' font-size: 13px;'
|
|
|
+ +' font-weight: 700;'
|
|
|
+ +' color: #f66020;'
|
|
|
+ +'}'
|
|
|
+ +'.SliderDiv {'
|
|
|
+ +' margin: 7px 0 5px;'
|
|
|
+ +' position: relative;'
|
|
|
+ +' border: 1px solid #5080e0;'
|
|
|
+ +' background-color: #b6d6f0;'
|
|
|
+ +' height: 9px;'
|
|
|
+ +' border-radius: 6px;'
|
|
|
+ +' width: 100%;'
|
|
|
+ +'}'
|
|
|
+ +'.SliderRange {'
|
|
|
+ +' display: block;'
|
|
|
+ +' position: absolute;'
|
|
|
+ +' z-index: 1;'
|
|
|
+ +' font-size: .7em;'
|
|
|
+ +' border: 0;'
|
|
|
+ +' background-color: #5ca0cc;'
|
|
|
+ +' top: 0;'
|
|
|
+ +' height: 100%;'
|
|
|
+ +'}'
|
|
|
+ +'.SliderPoint {'
|
|
|
+ +' position: absolute;'
|
|
|
+ +' z-index: 2;'
|
|
|
+ +' width: 15px;'
|
|
|
+ +' height: 15px;'
|
|
|
+ +' border: 1px solid #385590;'
|
|
|
+ +' background-color: #fff;'
|
|
|
+ +' border-radius: 50%;'
|
|
|
+ +' cursor: pointer;'
|
|
|
+ +' top: -.3em;'
|
|
|
+ +' margin-left: -.6em;'
|
|
|
+ +'}';
|
|
|
+ var
|
|
|
+ CaptionDiv: TDiv;
|
|
|
+ SliderLabel: TLabel; // inside CaptionDiv
|
|
|
+ SliderValue: TLabel; // inside CaptionDiv
|
|
|
+ SliderDiv: TDiv;
|
|
|
+ SliderRange: TDiv; // inside SliderDiv
|
|
|
+ SliderPoint: TDiv; // inside SliderDiv
|
|
|
+ constructor Create(AOwner: TComponent); override;
|
|
|
+ property MinPosition: TFresnelLength read FMinPosition write SetMinPosition;
|
|
|
+ property MaxPosition: TFresnelLength read FMaxPosition write SetMaxPosition;
|
|
|
+ property Position: TFresnelLength read FPosition write SetPosition;
|
|
|
+ property Caption: TFresnelCaption read GetCaption write SetCaption;
|
|
|
+ property ValueFormat: string read FValueFormat write SetValueFormat;
|
|
|
+ end;
|
|
|
+
|
|
|
+implementation
|
|
|
+
|
|
|
+{ TDemoSlider }
|
|
|
+
|
|
|
+function TDemoSlider.GetCaption: TFresnelCaption;
|
|
|
+begin
|
|
|
+ Result:=SliderLabel.Caption;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TDemoSlider.SetCaption(const AValue: TFresnelCaption);
|
|
|
+begin
|
|
|
+ SliderLabel.Caption:=AValue;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TDemoSlider.SetMaxPosition(const AValue: TFresnelLength);
|
|
|
+begin
|
|
|
+ if FMaxPosition=AValue then Exit;
|
|
|
+ FMaxPosition:=AValue;
|
|
|
+ FMinPosition:=Min(MinPosition,MaxPosition);
|
|
|
+ FPosition:=Min(MaxPosition,Max(MinPosition,Position));
|
|
|
+ UpdatePosition;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TDemoSlider.SetMinPosition(const AValue: TFresnelLength);
|
|
|
+begin
|
|
|
+ if FMinPosition=AValue then Exit;
|
|
|
+ FMinPosition:=AValue;
|
|
|
+ FMaxPosition:=Max(MinPosition,MaxPosition);
|
|
|
+ FPosition:=Min(MaxPosition,Max(MinPosition,Position));
|
|
|
+ UpdatePosition;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TDemoSlider.SetPosition(AValue: TFresnelLength);
|
|
|
+begin
|
|
|
+ AValue:=Min(MaxPosition,Max(MinPosition,AValue));
|
|
|
+ if AValue=FPosition then exit;
|
|
|
+ FPosition:=AValue;
|
|
|
+ UpdatePosition;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TDemoSlider.SetValueFormat(const AValue: string);
|
|
|
+begin
|
|
|
+ if FValueFormat=AValue then Exit;
|
|
|
+ FValueFormat:=AValue;
|
|
|
+ UpdateValueLabel;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TDemoSlider.UpdateValueLabel;
|
|
|
+var
|
|
|
+ s: String;
|
|
|
+begin
|
|
|
+ s:=Format(ValueFormat,[Position]);
|
|
|
+ writeln('AAA1 TDemoSlider.UpdateValueLabel ',Position,' ',s);
|
|
|
+ SliderValue.Caption:=s;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TDemoSlider.UpdatePosition;
|
|
|
+var
|
|
|
+ p: TFresnelLength;
|
|
|
+ s: String;
|
|
|
+begin
|
|
|
+ p:=(Position-MinPosition)/(MaxPosition-MinPosition);
|
|
|
+ s:=FloatToStr(p)+'%';
|
|
|
+ SliderRange.Style:='width: '+s;
|
|
|
+ SliderPoint.Style:='left: '+s;
|
|
|
+ UpdateValueLabel;
|
|
|
+end;
|
|
|
+
|
|
|
+constructor TDemoSlider.Create(AOwner: TComponent);
|
|
|
+begin
|
|
|
+ inherited Create(AOwner);
|
|
|
+ FMinPosition:=0;
|
|
|
+ FMaxPosition:=100;
|
|
|
+ FValueFormat:='%fpx';
|
|
|
+
|
|
|
+ CaptionDiv:=TDiv.Create(Self);
|
|
|
+ with CaptionDiv do begin
|
|
|
+ Name:='CaptionDiv';
|
|
|
+ CSSClasses.Add('SliderCaptionDiv');
|
|
|
+ Parent:=Self;
|
|
|
+ end;
|
|
|
+ SliderLabel:=TLabel.Create(Self);
|
|
|
+ with SliderLabel do begin
|
|
|
+ Name:='SliderLabel';
|
|
|
+ CSSClasses.Add('SliderLabel');
|
|
|
+ Caption:='Position';
|
|
|
+ Parent:=CaptionDiv;
|
|
|
+ end;
|
|
|
+ SliderValue:=TLabel.Create(Self);
|
|
|
+ with SliderValue do begin
|
|
|
+ Name:='ValueLabel';
|
|
|
+ CSSClasses.Add('SliderValue');
|
|
|
+ Parent:=CaptionDiv;
|
|
|
+ end;
|
|
|
+
|
|
|
+ SliderDiv:=TDiv.Create(Self);
|
|
|
+ with SliderDiv do begin
|
|
|
+ Name:='SliderDiv';
|
|
|
+ CSSClasses.Add('SliderDiv');
|
|
|
+ Parent:=Self;
|
|
|
+ end;
|
|
|
+ SliderRange:=TDiv.Create(Self);
|
|
|
+ with SliderRange do begin
|
|
|
+ Name:='SliderRangeDiv';
|
|
|
+ CSSClasses.Add('SliderRange');
|
|
|
+ Parent:=SliderDiv;
|
|
|
+ end;
|
|
|
+ SliderPoint:=TDiv.Create(Self);
|
|
|
+ with SliderPoint do begin
|
|
|
+ Name:='SliderPointDiv';
|
|
|
+ CSSClasses.Add('SliderPoint');
|
|
|
+ Parent:=SliderDiv;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+end.
|
|
|
+
|