{*********************************************}
{  TeeChart Charting Library for FireMonkey   }
{  Copyright (c) 2012-2020 by Steema Software }
{  All Rights Reserved                        }
{*********************************************}
unit FMXTee.Editor.Margins;
{$I TeeDefs.inc}

interface

uses
  SysUtils, Types, Classes, Variants, FMX.Types, FMX.Controls, FMX.Forms,
  {$IFNDEF UPTOXE3}
  FMX.StdCtrls,
  {$ENDIF}
  {$IFDEF D21}
  FMX.SpinBox,
  {$ENDIF}
  FMX.Edit, FMX.Dialogs, FMXTee.Engine, FMXTee.RadioGroup;

type
  TMarginsEditor = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    UDLeft: TSpinBox;
    UDTop: TSpinBox;
    UDRight: TSpinBox;
    UDBottom: TSpinBox;
    RGUnits: TRadioGroup;
    procedure RGUnitsChange(Sender: TObject);
    procedure UDLeftChange(Sender: TObject);
    procedure UDTopChange(Sender: TObject);
    procedure UDRightChange(Sender: TObject);
    procedure UDBottomChange(Sender: TObject);
  private
   { Private declarations }
    FMargins : TMargins;
  public
   { Public declarations }
    class function CreateEditor(const AOwner:TComponent; const AMargins:TMargins):TMarginsEditor;
    procedure RefreshMargins(const AMargins:TMargins);
  end;

implementation

{$R *.fmx}

procedure TMarginsEditor.RGUnitsChange(Sender: TObject);
begin
  FMargins.Units:=TMarginUnits(RGUnits.ItemIndex);
end;

procedure TMarginsEditor.UDBottomChange(Sender: TObject);
begin
  FMargins.Bottom:=Round(UDBottom.Value);
end;

procedure TMarginsEditor.UDLeftChange(Sender: TObject);
begin
  FMargins.Left:=Round(UDLeft.Value);
end;

procedure TMarginsEditor.UDRightChange(Sender: TObject);
begin
  FMargins.Right:=Round(UDRight.Value);
end;

procedure TMarginsEditor.UDTopChange(Sender: TObject);
begin
  FMargins.Top:=Round(UDTop.Value);
end;

procedure TMarginsEditor.RefreshMargins(const AMargins:TMargins);
begin
  FMargins:=AMargins;

  RGUnits.ItemIndex:=Ord(AMargins.Units);
  UDLeft.Value:=AMargins.Left;
  UDTop.Value:=AMargins.Top;
  UDRight.Value:=AMargins.Right;
  UDBottom.Value:=AMargins.Bottom;
end;

class function TMarginsEditor.CreateEditor(const AOwner: TComponent;
  const AMargins: TMargins): TMarginsEditor;
begin
  result:=TMarginsEditor.Create(AOwner);
  TMarginsEditor(result).RefreshMargins(AMargins);
end;

end.
