Skip to content

Commit

Permalink
Support TTrackBar
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeroen Wiert Pluimers committed Oct 19, 2015
1 parent 47429ce commit a22929a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Knockoff.Binding.Components.pas
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface
Classes,
Rtti,
StdCtrls,
ComCtrls,
SysUtils,
Knockoff.Observable;

Expand Down Expand Up @@ -87,6 +88,13 @@ TCheckBoxBinding = class(TBinding<TCheckBox>)
procedure InitTarget; override;
end;

TTrackBarBinding = class(TBinding<TTrackBar>)
protected
procedure HandleChange(Sender: TObject);
function InitGetValue(const observable: IObservable): TFunc<TValue>; override;
procedure InitTarget; override;
end;

function GetBindingClass(const target: TObject; const expression: string): TBindingClass;

implementation
Expand All @@ -107,6 +115,8 @@ function GetBindingClass(const target: TObject; const expression: string): TBind
Result := TButtonBinding
else if (target is TCheckBox) and SameText(expression, 'Checked') then
Result := TCheckBoxBinding
else if (target is TTrackBar) and SameText(expression, 'Position') then
Result := TTrackBarBinding
else
Result := nil;
end;
Expand Down Expand Up @@ -357,4 +367,28 @@ function TCheckBoxBinding.InitGetValue(
{$ENDREGION}


{$REGION 'TTrackBarBinding'}

procedure TTrackBarBinding.HandleChange(Sender: TObject);
begin
Source.Value := Target.Position;
end;

procedure TTrackBarBinding.InitTarget;
begin
Target.OnChange := HandleChange;
end;

function TTrackBarBinding.InitGetValue(const observable: IObservable): TFunc<TValue>;
begin
Result :=
function: TValue
begin
Target.Position := observable.Value.ToType<Integer>;
end;
end;

{$ENDREGION}


end.

0 comments on commit a22929a

Please sign in to comment.