mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-05 13:36:17 +02:00
TAChart: Add wordwrapping feature to chart title and footer.
git-svn-id: trunk@64804 -
This commit is contained in:
parent
3289f2c7f1
commit
6b6de2da43
@ -135,12 +135,18 @@ type
|
|||||||
FMargin: TChartDistance;
|
FMargin: TChartDistance;
|
||||||
FPolygon: TPointArray;
|
FPolygon: TPointArray;
|
||||||
FText: TStrings;
|
FText: TStrings;
|
||||||
|
FWordWrap: Boolean;
|
||||||
|
FWrappedCaption: String;
|
||||||
|
|
||||||
|
function GetRealCaption: String;
|
||||||
|
function IsWordwrapped: Boolean;
|
||||||
procedure SetBrush(AValue: TBrush);
|
procedure SetBrush(AValue: TBrush);
|
||||||
procedure SetFont(AValue: TFont);
|
procedure SetFont(AValue: TFont);
|
||||||
procedure SetFrame(AValue: TChartTitleFramePen);
|
procedure SetFrame(AValue: TChartTitleFramePen);
|
||||||
procedure SetMargin(AValue: TChartDistance);
|
procedure SetMargin(AValue: TChartDistance);
|
||||||
procedure SetText(AValue: TStrings);
|
procedure SetText(AValue: TStrings);
|
||||||
|
procedure SetWordwrap(AValue: Boolean);
|
||||||
|
procedure WordWrapCaption(ADrawer: IChartDrawer; AMaxWidth: Integer);
|
||||||
strict protected
|
strict protected
|
||||||
function GetFrame: TChartPen; override;
|
function GetFrame: TChartPen; override;
|
||||||
function GetLabelBrush: TBrush; override;
|
function GetLabelBrush: TBrush; override;
|
||||||
@ -167,6 +173,7 @@ type
|
|||||||
property Text: TStrings read FText write SetText;
|
property Text: TStrings read FText write SetText;
|
||||||
property TextFormat;
|
property TextFormat;
|
||||||
property Visible default false;
|
property Visible default false;
|
||||||
|
property Wordwrap: Boolean read FWordwrap write SetWordwrap default false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TChartMarkAttachment = (maDefault, maEdge, maCenter);
|
TChartMarkAttachment = (maDefault, maEdge, maCenter);
|
||||||
@ -613,7 +620,7 @@ end;
|
|||||||
procedure TChartTitle.Draw(ADrawer: IChartDrawer);
|
procedure TChartTitle.Draw(ADrawer: IChartDrawer);
|
||||||
begin
|
begin
|
||||||
if not Visible or (Text.Count = 0) then exit;
|
if not Visible or (Text.Count = 0) then exit;
|
||||||
DrawLabel(ADrawer, FCenter, FCenter, Text.Text, FPolygon);
|
DrawLabel(ADrawer, FCenter, FCenter, GetRealCaption, FPolygon);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TChartTitle.GetFrame: TChartPen;
|
function TChartTitle.GetFrame: TChartPen;
|
||||||
@ -631,18 +638,35 @@ begin
|
|||||||
Result := Font;
|
Result := Font;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TChartTitle.GetRealCaption: String;
|
||||||
|
begin
|
||||||
|
if IsWordWrapped then
|
||||||
|
Result := FWrappedCaption
|
||||||
|
else
|
||||||
|
Result := Text.Text;
|
||||||
|
end;
|
||||||
|
|
||||||
function TChartTitle.IsPointInBounds(APoint: TPoint): Boolean;
|
function TChartTitle.IsPointInBounds(APoint: TPoint): Boolean;
|
||||||
begin
|
begin
|
||||||
Result := IsPointInPolygon(APoint, FPolygon);
|
Result := IsPointInPolygon(APoint, FPolygon);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TChartTitle.IsWordWrapped: Boolean;
|
||||||
|
begin
|
||||||
|
Result := FWordWrap and (Font.Orientation = 0);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TChartTitle.Measure(ADrawer: IChartDrawer;
|
procedure TChartTitle.Measure(ADrawer: IChartDrawer;
|
||||||
ADir, ALeft, ARight: Integer; var AY: Integer);
|
ADir, ALeft, ARight: Integer; var AY: Integer);
|
||||||
var
|
var
|
||||||
ptSize: TPoint;
|
ptSize: TPoint;
|
||||||
begin
|
begin
|
||||||
if not Visible or (Text.Count = 0) then exit;
|
if not Visible or (Text.Count = 0) then exit;
|
||||||
ptSize := MeasureLabel(ADrawer, Text.Text);
|
|
||||||
|
if IsWordWrapped then
|
||||||
|
WordwrapCaption(ADrawer, ARight - ALeft);
|
||||||
|
|
||||||
|
ptSize := MeasureLabel(ADrawer, GetRealCaption);
|
||||||
case Alignment of
|
case Alignment of
|
||||||
taLeftJustify: FCenter.X := ALeft + ptSize.X div 2;
|
taLeftJustify: FCenter.X := ALeft + ptSize.X div 2;
|
||||||
taRightJustify: FCenter.X := ARight - ptSize.X div 2;
|
taRightJustify: FCenter.X := ARight - ptSize.X div 2;
|
||||||
@ -683,6 +707,13 @@ begin
|
|||||||
StyleChanged(Self);
|
StyleChanged(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TChartTitle.SetWordWrap(AValue: Boolean);
|
||||||
|
begin
|
||||||
|
if FWordwrap = AValue then exit;
|
||||||
|
FWordwrap := AValue;
|
||||||
|
StyleChanged(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TChartTitle.UpdateBidiMode;
|
procedure TChartTitle.UpdateBidiMode;
|
||||||
begin
|
begin
|
||||||
case Alignment of
|
case Alignment of
|
||||||
@ -691,6 +722,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TChartTitle.WordwrapCaption(ADrawer: IChartDrawer; AMaxWidth: Integer);
|
||||||
|
begin
|
||||||
|
ADrawer.Font := Font;
|
||||||
|
FWrappedCaption := TADrawUtils.Wordwrap(Text.Text, ADrawer, AMaxWidth, TextFormat);
|
||||||
|
end;
|
||||||
|
|
||||||
{ TGenericChartMarks }
|
{ TGenericChartMarks }
|
||||||
|
|
||||||
procedure TGenericChartMarks.ApplyLabelFont(ADrawer: IChartDrawer);
|
procedure TGenericChartMarks.ApplyLabelFont(ADrawer: IChartDrawer);
|
||||||
|
Loading…
Reference in New Issue
Block a user