-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
bcmaterialfloatspinedit.pas
130 lines (113 loc) · 3.05 KB
/
bcmaterialfloatspinedit.pas
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
unit BCMaterialFloatSpinEdit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls, Spin;
type
{ TBCMaterialFloatSpinEdit }
TBCMaterialFloatSpinEdit = class(TCustomPanel)
private
FAccentColor: TColor;
FDisabledColor: TColor;
Flbl: TLabel;
Fedt: TFloatSpinEdit;
Ffocused: boolean;
FOnChange: TNotifyEvent;
FTexto: string;
procedure ChangeEdit(Sender: TObject);
procedure EnterEdit(Sender: TObject);
procedure ExitEdit(Sender: TObject);
procedure SetTexto(AValue: string);
protected
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
published
property Color;
property Text: string read FTexto write SetTexto;
property Edit: TFloatSpinEdit read Fedt;
property Title: TLabel read Flbl;
property DisabledColor: TColor read FDisabledColor write FDisabledColor;
property AccentColor: TColor read FAccentColor write FAccentColor;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('BGRA Controls', [TBCMaterialFloatSpinEdit]);
end;
{ TBCMaterialFloatSpinEdit }
procedure TBCMaterialFloatSpinEdit.EnterEdit(Sender: TObject);
begin
Ffocused := True;
Invalidate;
Flbl.Font.Color := AccentColor;
end;
procedure TBCMaterialFloatSpinEdit.ChangeEdit(Sender: TObject);
begin
if Assigned(FOnChange) then
FOnChange(Self);
end;
procedure TBCMaterialFloatSpinEdit.ExitEdit(Sender: TObject);
begin
Ffocused := False;
Invalidate;
Flbl.Font.Color := DisabledColor;
end;
procedure TBCMaterialFloatSpinEdit.SetTexto(AValue: string);
begin
if FTexto = AValue then
Exit;
FTexto := AValue;
Flbl.Caption := FTexto;
//Fedt.TextHint := FTexto;
end;
procedure TBCMaterialFloatSpinEdit.Paint;
begin
inherited Paint;
Canvas.Brush.Color := Color;
Canvas.Pen.Color := Color;
Canvas.Rectangle(0, 0, Width, Height);
if (fFocused) then
begin
Canvas.Pen.Color := AccentColor;
Canvas.Line(0, Height - 2, Width, Height - 2);
Canvas.Line(0, Height - 1, Width, Height - 1);
end
else
begin
Canvas.Pen.Color := DisabledColor;
Canvas.Line(0, Height - 1, Width, Height - 1);
end;
end;
constructor TBCMaterialFloatSpinEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Self.BevelOuter := bvNone;
Self.Color := clWhite;
AccentColor := clHighlight;
DisabledColor := $00B8AFA8;
Flbl := TLabel.Create(Self);
Flbl.Align := alTop;
Flbl.Caption := 'Buscar';
Flbl.BorderSpacing.Around := 4;
Flbl.Font.Style := [fsBold];
Flbl.Font.Color := $00B8AFA8;
Flbl.Parent := Self;
Fedt := TFloatSpinEdit.Create(Self);
Fedt.Color := Color;
Fedt.Font.Color := clBlack;
Fedt.OnEnter := @EnterEdit;
Fedt.OnExit := @ExitEdit;
Fedt.OnChange:=@ChangeEdit;
Fedt.Align := alClient;
Fedt.BorderStyle := bsNone;
//Fedt.TextHint := 'Buscar';
Fedt.BorderSpacing.Around := 4;
Fedt.Parent := Self;
Fedt.MinValue := 0;
Fedt.MaxValue := MaxInt;
end;
end.