summaryrefslogtreecommitdiff
path: root/gui/label.inc
blob: e9a948aa795d15e5ef97a6bc934efd5a41aaa8d4 (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
111
112
113
{
    fpGUI  -  Free Pascal Graphical User Interface
    Copyright (C) 2000 - 2001 by
      Areca Systems GmbH / Sebastian Guenther
    Copyright (C) 2006 by Graeme Geldenhuys 
      member of the fpGUI development team.

    Label class declarations

    See the file COPYING.fpGUI, included in this distribution,
    for details about the copyright.

    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.pp}

{$IFDEF read_interface}


  { TCustomLabel }

  TCustomLabel = class(TWidget)
  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;
  

  TLabel = class(TCustomLabel)
  public
  published
    property CanExpandWidth;
    property Enabled;
    property FontColor;
    property Text;
    property Alignment default taLeftJustify;
  end;

{$ENDIF read_interface}



{$IFDEF read_implementation}


// ===================================================================
//   TCustomLabel
// ===================================================================

procedure TCustomLabel.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 TCustomLabel.CalcSizes;
begin
  with FindForm.Wnd.Canvas do
    FMinSize := gfxbase.Size(TextWidth(Text), FontCellHeight);
end;


constructor TCustomLabel.Create(const pText: string; pOwner: TComponent);
begin
  Create(pOwner);
  Text := pText;
  FFontColor := clWindowText;
end;


procedure TCustomLabel.SetAlignment(AAlignment: TAlignment);
begin
  if AAlignment <> Alignment then
  begin
    FAlignment := AAlignment;
    Redraw;
  end;
end;


procedure TCustomLabel.SetFontColor(const AValue: TColor);
begin
  if FFontColor = AValue then exit;
  FFontColor := AValue;
end;


{$ENDIF read_implementation}