summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-03-12 08:43:17 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-03-12 08:43:17 +0000
commitfd0f20fe11c9d3d9865ff714c19bcfe0f6bab946 (patch)
tree29bd95ac4f8f306f5d7bfc87e5d19d9c29e58778 /src
parenteac0307cf013ed2e8a726c447ee454a3ee3055fd (diff)
downloadfpGUI-fd0f20fe11c9d3d9865ff714c19bcfe0f6bab946.tar.xz
* Applied patch [ 1911897 ] label bug fix patch - from Jean-Marc.
* Added some extra bug fixes. Wordwrap resized the component even thought AutoSize = False. * Resizing the TfpgLabel component doesn't re-wordwrap the text if Wordwrap = True.
Diffstat (limited to 'src')
-rw-r--r--src/gui/gui_label.pas79
1 files changed, 52 insertions, 27 deletions
diff --git a/src/gui/gui_label.pas b/src/gui/gui_label.pas
index 3ced6c06..9b6940c9 100644
--- a/src/gui/gui_label.pas
+++ b/src/gui/gui_label.pas
@@ -51,6 +51,7 @@ type
protected
FText: string;
FFont: TfpgFont;
+ procedure HandleResize(awidth, aheight: TfpgCoord); override;
procedure HandlePaint; override;
property WrapText: boolean read FWrapText write SetWrapText default False;
property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
@@ -121,31 +122,42 @@ end;
{ TfpgCustomLabel }
procedure TfpgCustomLabel.Wrap(MaxLength: integer; AText: string);
+var
+ l: integer;
begin
FWrappedText.Clear;
+ l := 0;
repeat
- if UTF8Pos(' ', AText) > 0 then
- begin
- if Font.TextWidth(UTF8Copy(AText, 1, UTF8Pos(' ', AText))) < MaxLength then
+ if UTF8Pos(' ', AText) > 0 then
begin
- if FWrappedText.Count > 0 then
- if (Font.TextWidth(FWrappedText[Pred(FWrappedText.Count)] + ' ' +
- UTF8Copy(AText, 1, UTF8Pos(' ', AText)))) < MaxLength then
- FWrappedText[Pred(FWrappedText.Count)] := FWrappedText[Pred(FWrappedText.Count)] + ' '
- + UTF8Copy(AText, 1, Pred(UTF8Pos(' ', AText)))
+ if Font.TextWidth(UTF8Copy(AText, 1, UTF8Pos(' ', AText))) < MaxLength then
+ begin
+ if FWrappedText.Count > 0 then
+ if (Font.TextWidth(FWrappedText[Pred(FWrappedText.Count)] + ' ' +
+ UTF8Copy(AText, 1, UTF8Pos(' ', AText)))) < MaxLength then
+ FWrappedText[Pred(FWrappedText.Count)] := FWrappedText[Pred(FWrappedText.Count)] + ' '
+ + UTF8Copy(AText, 1, Pred(UTF8Pos(' ', AText)))
+ else
+ FWrappedText.Add(UTF8Copy(AText, 1, Pred(UTF8Pos(' ', AText))))
else
- FWrappedText.Add(UTF8Copy(AText, 1, Pred(UTF8Pos(' ', AText))))
+ FWrappedText.Add(UTF8Copy(AText, 1, Pred(UTF8Pos(' ', AText))));
+ AText := UTF8Copy(AText, Succ(UTF8Pos(' ', AText)), UTF8Length(AText) - Pred(UTF8Pos(' ', AText)));
+ end
else
+ begin
FWrappedText.Add(UTF8Copy(AText, 1, Pred(UTF8Pos(' ', AText))));
- AText := UTF8Copy(AText, Succ(UTF8Pos(' ', AText)), UTF8Length(AText) - Pred(UTF8Pos(' ', AText)));
- end;
- end
- else
- begin
- FWrappedText.Add(AText);
- AText:= '';
- end;
+ if l < Font.TextWidth(UTF8Copy(AText, 1, UTF8Pos(' ', AText))) then
+ l := Font.TextWidth(UTF8Copy(AText, 1, UTF8Pos(' ', AText)));
+ AText := UTF8Copy(AText, Succ(UTF8Pos(' ', AText)), UTF8Length(AText) - Pred(UTF8Pos(' ', AText)));
+ end; { if/else }
+ end
+ else
+ begin
+ FWrappedText.Add(AText);
+ AText := '';
+ end; { if/else }
until UTF8Pos(' ', AText) = 0;
+
if FWrappedText.Count > 0 then
begin
if (Font.TextWidth(FWrappedText[Pred(FWrappedText.Count)] + ' ' + AText)) < MaxLength then
@@ -153,16 +165,25 @@ begin
else
FWrappedText.Add(AText);
end;
- if Height < FWrappedText.Count * (Font.Height + 2) then
- Height := FWrappedText.Count * (Font.Height + 2);
+
+ if AutoSize then
+ begin
+ if Height < FWrappedText.Count * (Font.Height + 2) then
+ Height := FWrappedText.Count * (Font.Height + 2);
+ if Width < l then // adjust the length to the longest word
+ Width := l;
+ end;
end;
procedure TfpgCustomLabel.SetWrapText(const AValue: boolean);
begin
- FWrapText := AValue;
- if FWrapText then
- Wrap(Width, FText);
- RePaint;
+ if FWrapText <> AValue then
+ begin
+ FWrapText := AValue;
+ if FWrapText then
+ Wrap(Width, FText);
+ RePaint;
+ end;
end;
procedure TfpgCustomLabel.SetAlignment(const AValue: TAlignment);
@@ -216,9 +237,7 @@ end;
procedure TfpgCustomLabel.ResizeLabel;
begin
if FAutoSize then
- begin
- Width := FFont.TextWidth(FText);
- end
+ Width := FFont.TextWidth(FText)
else if FWrapText then
Wrap(Width, FText);
@@ -226,6 +245,13 @@ begin
RePaint;
end;
+procedure TfpgCustomLabel.HandleResize(awidth, aheight: TfpgCoord);
+begin
+ inherited HandleResize(awidth, aheight);
+ if FWrapText then
+ Wrap(Width, FText);
+end;
+
constructor TfpgCustomLabel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
@@ -236,7 +262,6 @@ begin
FTextColor := Parent.TextColor;
FBackgroundColor := Parent.BackgroundColor;
FAutoSize := False;
-
FLayout := tlTop;
FAlignment := taLeftJustify;
FWrapText := False;