blob: b7903f22dc903c2dd227b03dc91aac7a19415f37 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
{
fpGUI - Free Pascal GUI Library
Label class declarations
Copyright (C) 2000 - 2006 See the file AUTHORS.txt, included in this
distribution, for details of the copyright.
See the file COPYING.modifiedLGPL, included in this distribution,
for details about redistributing fpGUI.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
}
{%mainunit fpgui.pas}
{$IFDEF read_interface}
{ TFCustomLabel }
TFCustomLabel = class(TFWidget)
private
FFontColor: TColor;
procedure SetAlignment(AAlignment: TAlignment);
procedure SetFontColor(const AValue: TColor);
protected
FAlignment: TAlignment;
procedure Paint(Canvas: TFCanvas); override;
procedure CalcSizes; override;
property Alignment: TAlignment read FAlignment write SetAlignment;
property FontColor: TColor read FFontColor write SetFontColor;
public
constructor Create(const pText: string; pOwner: TComponent); overload;
end;
TFLabel = class(TFCustomLabel)
public
published
property CanExpandWidth;
property Enabled;
property FontColor;
property Text;
property Alignment default taLeftJustify;
end;
{$ENDIF read_interface}
{$IFDEF read_implementation}
// ===================================================================
// TFCustomLabel
// ===================================================================
procedure TFCustomLabel.Paint(Canvas: TFCanvas);
var
x: Integer;
begin
Canvas.SetColor(Style.GetUIColor(FFontColor));
// Canvas.SetColor(FFontColor);
case Alignment of
taLeftJustify: x := 0;
taCenter: x := (BoundsSize.cx - Canvas.TextWidth(Text)) div 2;
taRightJustify: x := BoundsSize.cx - Canvas.TextWidth(Text);
end;
Style.DrawText(Canvas, Point(x,
(BoundsSize.cy - Canvas.FontCellHeight) div 2), Text, WidgetState);
end;
procedure TFCustomLabel.CalcSizes;
begin
with FindForm.Wnd.Canvas do
FMinSize := gfxbase.Size(TextWidth(Text), FontCellHeight);
end;
constructor TFCustomLabel.Create(const pText: string; pOwner: TComponent);
begin
Create(pOwner);
Text := pText;
FFontColor := clWindowText;
end;
procedure TFCustomLabel.SetAlignment(AAlignment: TAlignment);
begin
if AAlignment <> Alignment then
begin
FAlignment := AAlignment;
Redraw;
end;
end;
procedure TFCustomLabel.SetFontColor(const AValue: TColor);
begin
if FFontColor = AValue then exit;
FFontColor := AValue;
end;
{$ENDIF read_implementation}
|