unit Vis2D_BarChartSettings;

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;

type
  TVis2D_BarChartSettingsFrm = class(TDrawableOptionsFrm)
    btnApply: TUxButton;
    ScrollBox1: TScrollBoxEx;
    Label9: TLabel;
    eBarWidth: TTextEditor;
    eBarSpacing: TTextEditor;
    Label7: TLabel;
    Label8: TLabel;
    eBarOffset: TTextEditor;
    procedure ScrollBox1Enter(Sender: TObject);
    procedure ScrollBox1Exit(Sender: TObject);
    procedure btnApplyClick(Sender: TObject);
    procedure CallUpdateDrawable(Sender: TObject);
  strict protected
    procedure Initialize; override;
    procedure UpdateDrawable; override;
  public

  end;

implementation

uses
  Math;

{$R *.dfm}

{ TVis2D_BarChartSettingsFrm }

procedure TVis2D_BarChartSettingsFrm.btnApplyClick(Sender: TObject);
begin
  UpdateDrawable;
end;

procedure TVis2D_BarChartSettingsFrm.CallUpdateDrawable(Sender: TObject);
begin
  UpdateDrawable;
end;

procedure TVis2D_BarChartSettingsFrm.Initialize;
var
  BarChart: TBarChart;
begin

  inherited;

  BarChart := FDrawable as TBarChart;

  eBarOffset.PlainText := BarChart.BarOffset.ToString;
  eBarWidth.PlainText := BarChart.BarWidth.ToString;
  eBarSpacing.PlainText := BarChart.BarSpacing.ToString;

end;

procedure TVis2D_BarChartSettingsFrm.ScrollBox1Enter(Sender: TObject);
begin
  btnApply.Default := True;
end;

procedure TVis2D_BarChartSettingsFrm.ScrollBox1Exit(Sender: TObject);
begin
  btnApply.Default := False;
end;

procedure TVis2D_BarChartSettingsFrm.UpdateDrawable;
var
  BarChart: TBarChart;
begin

  if not Initialized then
    Exit;

  BarChart := FDrawable as TBarChart;

  BarChart.BarOffset := StrToFloat(eBarOffset.PlainText);
  BarChart.BarWidth := StrToFloat(eBarWidth.PlainText);
  BarChart.BarSpacing := StrToFloat(eBarSpacing.PlainText);

  inherited;

end;

end.
