diff options
Diffstat (limited to 'gui/label.inc')
-rw-r--r-- | gui/label.inc | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/gui/label.inc b/gui/label.inc new file mode 100644 index 00000000..e9a948aa --- /dev/null +++ b/gui/label.inc @@ -0,0 +1,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} + |