unit Vis2D_AxesSettings;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, VisCtl2D,
  TextEditor, ColorContainer, Vcl.StdCtrls, ScrollBoxEx, UxPanel, Vcl.ExtCtrls;

type
  TVis2D_AxesSettingsFrm = class(TDrawableOptionsFrm)
    pnToolbar: TUxClient;
    btnX: TUxButton;
    btnY: TUxButton;
    pnX: TPanel;
    pnY: TPanel;
    procedure FormCreate(Sender: TObject);
    procedure SetPage(Sender: TObject);
  strict private
    FPageButtons: TArray<TUxButton>;
    FX, FY: TDrawableOptionsFrm;
  public

  end;

implementation

uses
  Math, Vis2D_AxisSettings, Generics.Collections;

{$R *.dfm}

{ TVis2D_AxesSettingsFrm }

procedure TVis2D_AxesSettingsFrm.FormCreate(Sender: TObject);
var
  Axes: TAxes;
begin

  Axes := FDrawable as TAxes;

  btnX.Tag := NativeInt(pnX);
  btnY.Tag := NativeInt(pnY);
  FPageButtons := [btnX, btnY];

  SetPage(btnX);

  FX := TVis2D_AxisSettingsFrm.Create(Self, Axes.X);
  FX.Parent := pnX;
  FX.BorderStyle := bsNone;
  FX.Align := alClient;
  FX.Show;

  FY := TVis2D_AxisSettingsFrm.Create(Self, Axes.Y);
  FY.Parent := pnY;
  FY.BorderStyle := bsNone;
  FY.Align := alClient;
  FY.Show;

end;

procedure TVis2D_AxesSettingsFrm.SetPage(Sender: TObject);
var
  B: TUxButton;
  P: TPanel;
begin
  for B in FPageButtons do
  begin
    if B.Tag = 0 then
      Continue;
    P := TObject(B.Tag) as TPanel;
    P.Align := alClient;
    P.Visible := B = Sender;
    B.Down := B = Sender;
    if (B = Sender) and Visible and P.Visible and P.CanFocus then
      P.SetFocus;
  end;
end;

end.
