unit FMXTee.Editor.Tools.CustomLegend;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.ListBox, FMX.TabControl, 
  FMX.Edit, FMX.Layouts, FMX.Memo, FMXTee.Tools.CustomLegend,
  FMXTee.Procs, FMXTee.Editor.Tools.Annotation;

type
  TCustomLegendToolEditor = class(TAnnotationToolEdit)
    TabGrid: TTabItem;
    Label20: TLabel;
    UDColCount: TSpinBox;
    Label18: TLabel;
    UDRowCount: TSpinBox;
    Label19: TLabel;
    UDFixedCols: TSpinBox;
    UDFixedRows: TSpinBox;
    Label21: TLabel;
    UDGridHeight: TSpinBox;
    UDGridWidth: TSpinBox;
    Label17: TLabel;
    Label22: TLabel;
    CBAllowDrag: TCheckBox;
    CBAllowResize: TCheckBox;
    procedure FormActivate(Sender: TObject);
    procedure UDColCountChange(Sender: TObject);
    procedure UDRowCountChange(Sender: TObject);
    procedure UDGridWidthChange(Sender: TObject);
    procedure UDGridHeightChange(Sender: TObject);
    procedure CBAllowDragChange(Sender: TObject);
    procedure CBAllowResizeChange(Sender: TObject);
  private
    { Private declarations }
    CustomLegend : TCustomLegendTool;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

procedure TCustomLegendToolEditor.CBAllowDragChange(Sender: TObject);
begin
  if Assigned(CustomLegend) then
     CustomLegend.AllowDrag:=CBAllowDrag.IsChecked;
end;

procedure TCustomLegendToolEditor.CBAllowResizeChange(Sender: TObject);
begin
  if Assigned(CustomLegend) then
     CustomLegend.AllowResize:=CBAllowResize.IsChecked;
end;

procedure TCustomLegendToolEditor.FormActivate(Sender: TObject);
begin
  inherited;

  if not Assigned(CustomLegend) then
  begin
    CustomLegend:=TCustomLegendTool(TagObject);

    if Assigned(CustomLegend) then
    With CustomLegend do
    begin
      CBallowDrag.IsChecked:=AllowDrag;
      CBAllowResize.IsChecked:=AllowResize;
      UDColCount.Value:=Grid.ColumnCount;
      UDRowCount.Value:=Grid.RowCount;
      //UDFixedCols.Value:=Grid.FixedCols;
      //UDFixedRows.Value:=Grid.FixedRows;
      UDGridWidth.Value:=Grid.Width;
      UDGridHeight.Value:=Grid.Height;
    end;
  end;
end;

procedure TCustomLegendToolEditor.UDGridHeightChange(Sender: TObject);
begin
  if Assigned(CustomLegend) then
   CustomLegend.Grid.Height:=UDHeight.Value;
end;

procedure TCustomLegendToolEditor.UDGridWidthChange(Sender: TObject);
begin
  if Assigned(CustomLegend) then
     CustomLegend.Grid.Width:=UDWidth.Value;
end;

procedure TCustomLegendToolEditor.UDColCountChange(Sender: TObject);
begin
  //if Assigned(CustomLegend) then
  //   CustomLegend.Grid.ColumnCount:=Round(UDColCount.Value);
end;

procedure TCustomLegendToolEditor.UDRowCountChange(Sender: TObject);
begin
  if Assigned(CustomLegend) then
     CustomLegend.Grid.RowCount:=Round(UDRowCount.Value);
end;

initialization
  RegisterSeriesEditor(TCustomLegendToolEditor);
end.
