mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-02 19:24:46 +01:00
TAChart: Add Margin and SymbolWidth properties to TChartLegend
git-svn-id: trunk@21890 -
This commit is contained in:
parent
50cc9941e0
commit
83a241e7ea
@ -7,6 +7,11 @@ interface
|
||||
uses
|
||||
Classes, Contnrs, SysUtils, Graphics, TAChartUtils, TATypes;
|
||||
|
||||
const
|
||||
DEF_LEGEND_SPACING = 4;
|
||||
DEF_LEGEND_MARGIN = 4;
|
||||
DEF_LEGEND_SYMBOL_WIDTH = 20;
|
||||
|
||||
type
|
||||
{ TLegendItem }
|
||||
|
||||
@ -57,12 +62,16 @@ type
|
||||
FAlignment: TLegendAlignment;
|
||||
FFont: TFont;
|
||||
FFrame: TChartPen;
|
||||
FMargin: TChartDistance;
|
||||
FSpacing: TChartDistance;
|
||||
FSymbolWidth: TChartDistance;
|
||||
|
||||
procedure SetAlignment(AValue: TLegendAlignment);
|
||||
procedure SetFont(AValue: TFont);
|
||||
procedure SetFrame(AValue: TChartPen);
|
||||
procedure SetSpacing(const AValue: TChartDistance);
|
||||
procedure SetMargin(AValue: TChartDistance);
|
||||
procedure SetSpacing(AValue: TChartDistance);
|
||||
procedure SetSymbolWidth(AValue: TChartDistance);
|
||||
public
|
||||
constructor Create(AOwner: TCustomChart);
|
||||
destructor Destroy; override;
|
||||
@ -76,7 +85,12 @@ type
|
||||
read FAlignment write SetAlignment default laRight;
|
||||
property Font: TFont read FFont write SetFont;
|
||||
property Frame: TChartPen read FFrame write SetFrame;
|
||||
property Spacing: TChartDistance read FSpacing write SetSpacing default 5;
|
||||
property Margin: TChartDistance
|
||||
read FMargin write SetMargin default DEF_LEGEND_MARGIN;
|
||||
property Spacing: TChartDistance
|
||||
read FSpacing write SetSpacing default DEF_LEGEND_SPACING;
|
||||
property SymbolWidth: TChartDistance
|
||||
read FSymbolWidth write SetSymbolWidth default DEF_LEGEND_SYMBOL_WIDTH;
|
||||
property Visible default false;
|
||||
end;
|
||||
|
||||
@ -86,9 +100,7 @@ uses
|
||||
FPCanvas, Math, Types;
|
||||
|
||||
const
|
||||
ICON_WIDTH = 17;
|
||||
ICON_SPACING = 3;
|
||||
MARGINS = 3;
|
||||
SYMBOL_TEXT_SPACING = 4;
|
||||
|
||||
{ TLegendItem }
|
||||
|
||||
@ -99,7 +111,7 @@ end;
|
||||
|
||||
procedure TLegendItem.Draw(ACanvas: TCanvas; const ARect: TRect);
|
||||
begin
|
||||
ACanvas.TextOut(ARect.Right + ICON_SPACING, ARect.Top, FText);
|
||||
ACanvas.TextOut(ARect.Right + SYMBOL_TEXT_SPACING, ARect.Top, FText);
|
||||
end;
|
||||
|
||||
{ TLegendItemLine }
|
||||
@ -166,7 +178,9 @@ constructor TChartLegend.Create(AOwner: TCustomChart);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FAlignment := laRight;
|
||||
FSpacing := 5;
|
||||
FMargin := DEF_LEGEND_MARGIN;
|
||||
FSpacing := DEF_LEGEND_SPACING;
|
||||
FSymbolWidth := DEF_LEGEND_SYMBOL_WIDTH;
|
||||
Visible := false;
|
||||
|
||||
InitHelper(TFPCanvasHelper(FFont), TFont);
|
||||
@ -199,11 +213,11 @@ begin
|
||||
for i := 0 to AItems.Count - 1 do
|
||||
with AItems[i] as TLegendItem do
|
||||
w := Max(ACanvas.TextWidth(FText), w);
|
||||
w += 2 * Spacing + ICON_WIDTH + ICON_SPACING;
|
||||
w += 2 * Spacing + SYMBOL_TEXT_SPACING + SymbolWidth;
|
||||
th := ACanvas.TextHeight('Iy');
|
||||
|
||||
AClipRect.Right -= w + 2 * MARGINS;
|
||||
x1 := AClipRect.Right + MARGINS;
|
||||
AClipRect.Right -= w + 2 * Margin;
|
||||
x1 := AClipRect.Right + Margin;
|
||||
y1 := AClipRect.Top;
|
||||
|
||||
// Border
|
||||
@ -212,7 +226,7 @@ begin
|
||||
ACanvas.Rectangle(Bounds(
|
||||
x1, y1, w, Spacing + AItems.Count * (th + Spacing)));
|
||||
|
||||
r := Bounds(x1 + Spacing, y1 + Spacing, ICON_WIDTH, th);
|
||||
r := Bounds(x1 + Spacing, y1 + Spacing, SymbolWidth, th);
|
||||
for i := 0 to AItems.Count - 1 do begin
|
||||
ACanvas.Brush.Color := clWhite;
|
||||
ACanvas.Pen.Assign(Frame);
|
||||
@ -243,12 +257,26 @@ begin
|
||||
StyleChanged(Self);
|
||||
end;
|
||||
|
||||
procedure TChartLegend.SetSpacing(const AValue: TChartDistance);
|
||||
procedure TChartLegend.SetMargin(AValue: TChartDistance);
|
||||
begin
|
||||
if FMargin = AValue then exit;
|
||||
FMargin := AValue;
|
||||
StyleChanged(Self);
|
||||
end;
|
||||
|
||||
procedure TChartLegend.SetSpacing(AValue: TChartDistance);
|
||||
begin
|
||||
if FSpacing = AValue then exit;
|
||||
FSpacing := AValue;
|
||||
StyleChanged(Self);
|
||||
end;
|
||||
|
||||
procedure TChartLegend.SetSymbolWidth(AValue: TChartDistance);
|
||||
begin
|
||||
if FSymbolWidth = AValue then exit;
|
||||
FSymbolWidth := AValue;
|
||||
StyleChanged(Self);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user