Browse Source

material edit, material spin edit, material float spin edit

Leandro Diaz 4 years ago
parent
commit
31d0f25ece

+ 128 - 0
bcmaterialedit.pas

@@ -0,0 +1,128 @@
+unit BCMaterialEdit;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls,
+  StdCtrls;
+
+type
+
+  { TBCMaterialEdit }
+
+  TBCMaterialEdit = class(TCustomPanel)
+  private
+    FAccentColor: TColor;
+    FDisabledColor: TColor;
+    Flbl: TLabel;
+    Fedt: TEdit;
+    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: TEdit 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', [TBCMaterialEdit]);
+end;
+
+{ TBCMaterialEdit }
+
+procedure TBCMaterialEdit.EnterEdit(Sender: TObject);
+begin
+  Ffocused := True;
+  Invalidate;
+  Flbl.Font.Color := accentColor;
+end;
+
+procedure TBCMaterialEdit.ChangeEdit(Sender: TObject);
+begin
+  if Assigned(FOnChange) then
+    FOnChange(Self);
+end;
+
+procedure TBCMaterialEdit.ExitEdit(Sender: TObject);
+begin
+  Ffocused := False;
+  Invalidate;
+  Flbl.Font.Color := DisabledColor;
+end;
+
+procedure TBCMaterialEdit.SetTexto(AValue: string);
+begin
+  if FTexto = AValue then
+    Exit;
+  FTexto := AValue;
+  Flbl.Caption := FTexto;
+  //Fedt.TextHint := FTexto;
+end;
+
+procedure TBCMaterialEdit.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 TBCMaterialEdit.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 := TEdit.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;
+end;
+
+end.

+ 130 - 0
bcmaterialfloatspinedit.pas

@@ -0,0 +1,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.

+ 130 - 0
bcmaterialspinedit.pas

@@ -0,0 +1,130 @@
+unit BCMaterialSpinEdit;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls,
+  StdCtrls, Spin;
+
+type
+
+  { TBCMaterialSpinEdit }
+
+  TBCMaterialSpinEdit = class(TCustomPanel)
+  private
+    FAccentColor: TColor;
+    FDisabledColor: TColor;
+    Flbl: TLabel;
+    Fedt: TSpinEdit;
+    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: TSpinEdit 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', [TBCMaterialSpinEdit]);
+end;
+
+{ TBCMaterialSpinEdit }
+
+procedure TBCMaterialSpinEdit.EnterEdit(Sender: TObject);
+begin
+  Ffocused := True;
+  Invalidate;
+  Flbl.Font.Color := AccentColor;
+end;
+
+procedure TBCMaterialSpinEdit.ChangeEdit(Sender: TObject);
+begin
+  if Assigned(FOnChange) then
+    FOnChange(Self);
+end;
+
+procedure TBCMaterialSpinEdit.ExitEdit(Sender: TObject);
+begin
+  Ffocused := False;
+  Invalidate;
+  Flbl.Font.Color := DisabledColor;
+end;
+
+procedure TBCMaterialSpinEdit.SetTexto(AValue: string);
+begin
+  if FTexto = AValue then
+    Exit;
+  FTexto := AValue;
+  Flbl.Caption := FTexto;
+  //Fedt.TextHint := FTexto;
+end;
+
+procedure TBCMaterialSpinEdit.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 TBCMaterialSpinEdit.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 := TSpinEdit.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.

+ 16 - 1
bgracontrols.lpk

@@ -29,7 +29,7 @@
     <Description Value="BGRA Controls is a set of graphical UI elements that you can use with Lazarus LCL applications."/>
     <License Value="Modified LGPL"/>
     <Version Major="7" Minor="3"/>
-    <Files Count="63">
+    <Files Count="66">
       <Item1>
         <Filename Value="atshapelinebgra.pas"/>
         <HasRegisterProc Value="True"/>
@@ -335,6 +335,21 @@
         <Filename Value="bgrasvgimagelistform/bgrasvgimagelistform.pas"/>
         <UnitName Value="bgrasvgimagelistform"/>
       </Item63>
+      <Item64>
+        <Filename Value="bcmaterialedit.pas"/>
+        <HasRegisterProc Value="True"/>
+        <UnitName Value="POSBerryLiteMaterialEdit"/>
+      </Item64>
+      <Item65>
+        <Filename Value="bcmaterialfloatspinedit.pas"/>
+        <HasRegisterProc Value="True"/>
+        <UnitName Value="POSBerryLiteMaterialFloatSpinEdit"/>
+      </Item65>
+      <Item66>
+        <Filename Value="bcmaterialspinedit.pas"/>
+        <HasRegisterProc Value="True"/>
+        <UnitName Value="POSBerryLiteMaterialSpinEdit"/>
+      </Item66>
     </Files>
     <LazDoc Paths="fpdoc"/>
     <RequiredPkgs Count="2">

+ 5 - 1
bgracontrols.pas

@@ -20,7 +20,8 @@ uses
   BGRAThemeCheckBox, BGRAThemeRadioButton, BGRAVirtualScreen, 
   ColorSpeedButton, DTAnalogClock, DTAnalogCommon, DTAnalogGauge, 
   dtthemedclock, dtthemedgauge, MaterialColors, BCListBoxEx, BGRASVGTheme, 
-  BGRASVGImageList, bgrasvgimagelistform, LazarusPackageIntf;
+  BGRASVGImageList, bgrasvgimagelistform, bcmaterialedit, 
+  bcmaterialfloatspinedit, bcmaterialspinedit, LazarusPackageIntf;
 
 implementation
 
@@ -68,6 +69,9 @@ begin
   RegisterUnit('dtthemedgauge', @dtthemedgauge.Register);
   RegisterUnit('BGRASVGTheme', @BGRASVGTheme.Register);
   RegisterUnit('BGRASVGImageList', @BGRASVGImageList.Register);
+  RegisterUnit('bcmaterialedit', @bcmaterialedit.Register);
+  RegisterUnit('bcmaterialfloatspinedit', @bcmaterialfloatspinedit.Register);
+  RegisterUnit('bcmaterialspinedit', @bcmaterialspinedit.Register);
 end;
 
 initialization

BIN
test/test_material_edit/project1.ico


+ 83 - 0
test/test_material_edit/project1.lpi

@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CONFIG>
+  <ProjectOptions>
+    <Version Value="11"/>
+    <PathDelim Value="\"/>
+    <General>
+      <SessionStorage Value="InProjectDir"/>
+      <MainUnit Value="0"/>
+      <Title Value="project1"/>
+      <Scaled Value="True"/>
+      <ResourceType Value="res"/>
+      <UseXPManifest Value="True"/>
+      <XPManifest>
+        <DpiAware Value="True"/>
+      </XPManifest>
+      <Icon Value="0"/>
+    </General>
+    <BuildModes Count="1">
+      <Item1 Name="Default" Default="True"/>
+    </BuildModes>
+    <PublishOptions>
+      <Version Value="2"/>
+      <UseFileFilters Value="True"/>
+    </PublishOptions>
+    <RunParams>
+      <FormatVersion Value="2"/>
+      <Modes Count="0"/>
+    </RunParams>
+    <RequiredPackages Count="2">
+      <Item1>
+        <PackageName Value="bgracontrols"/>
+      </Item1>
+      <Item2>
+        <PackageName Value="LCL"/>
+      </Item2>
+    </RequiredPackages>
+    <Units Count="2">
+      <Unit0>
+        <Filename Value="project1.lpr"/>
+        <IsPartOfProject Value="True"/>
+      </Unit0>
+      <Unit1>
+        <Filename Value="unit1.pas"/>
+        <IsPartOfProject Value="True"/>
+        <ComponentName Value="Form1"/>
+        <HasResources Value="True"/>
+        <ResourceBaseClass Value="Form"/>
+        <UnitName Value="Unit1"/>
+      </Unit1>
+    </Units>
+  </ProjectOptions>
+  <CompilerOptions>
+    <Version Value="11"/>
+    <PathDelim Value="\"/>
+    <Target>
+      <Filename Value="project1"/>
+    </Target>
+    <SearchPaths>
+      <IncludeFiles Value="$(ProjOutDir)"/>
+      <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
+    </SearchPaths>
+    <Linking>
+      <Options>
+        <Win32>
+          <GraphicApplication Value="True"/>
+        </Win32>
+      </Options>
+    </Linking>
+  </CompilerOptions>
+  <Debugging>
+    <Exceptions Count="3">
+      <Item1>
+        <Name Value="EAbort"/>
+      </Item1>
+      <Item2>
+        <Name Value="ECodetoolError"/>
+      </Item2>
+      <Item3>
+        <Name Value="EFOpenError"/>
+      </Item3>
+    </Exceptions>
+  </Debugging>
+</CONFIG>

+ 22 - 0
test/test_material_edit/project1.lpr

@@ -0,0 +1,22 @@
+program project1;
+
+{$mode objfpc}{$H+}
+
+uses
+  {$IFDEF UNIX}{$IFDEF UseCThreads}
+  cthreads,
+  {$ENDIF}{$ENDIF}
+  Interfaces, // this includes the LCL widgetset
+  Forms, Unit1
+  { you can add units after this };
+
+{$R *.res}
+
+begin
+  RequireDerivedFormResource:=True;
+  Application.Scaled:=True;
+  Application.Initialize;
+  Application.CreateForm(TForm1, Form1);
+  Application.Run;
+end.
+

+ 77 - 0
test/test_material_edit/unit1.lfm

@@ -0,0 +1,77 @@
+object Form1: TForm1
+  Left = 164
+  Height = 240
+  Top = 250
+  Width = 320
+  Caption = 'Form1'
+  ClientHeight = 240
+  ClientWidth = 320
+  Color = clWhite
+  LCLVersion = '2.0.12.0'
+  object BCMaterialEdit1: TBCMaterialEdit
+    Left = 8
+    Height = 50
+    Top = 8
+    Width = 170
+    Color = clWhite
+    Text = 'Text'
+    DisabledColor = 12103592
+    AccentColor = clHighlight
+    OnChange = BCMaterialEdit1Change
+  end
+  object BCMaterialFloatSpinEdit1: TBCMaterialFloatSpinEdit
+    Left = 8
+    Height = 50
+    Top = 64
+    Width = 170
+    Color = clWhite
+    Text = 'Float'
+    DisabledColor = 12103592
+    AccentColor = clMoneyGreen
+    OnChange = BCMaterialFloatSpinEdit1Change
+  end
+  object BCMaterialSpinEdit1: TBCMaterialSpinEdit
+    Left = 8
+    Height = 50
+    Top = 120
+    Width = 170
+    Color = clWhite
+    Text = 'Integer'
+    DisabledColor = 12103592
+    AccentColor = clRed
+    OnChange = BCMaterialSpinEdit1Change
+  end
+  object Label1: TLabel
+    Left = 184
+    Height = 16
+    Top = 8
+    Width = 33
+    Caption = 'Label1'
+    ParentColor = False
+  end
+  object Label2: TLabel
+    Left = 184
+    Height = 16
+    Top = 64
+    Width = 33
+    Caption = 'Label2'
+    ParentColor = False
+  end
+  object Label3: TLabel
+    Left = 184
+    Height = 16
+    Top = 120
+    Width = 33
+    Caption = 'Label3'
+    ParentColor = False
+  end
+  object Button1: TButton
+    Left = 240
+    Height = 25
+    Top = 208
+    Width = 75
+    Caption = 'Dark'
+    OnClick = Button1Click
+    TabOrder = 3
+  end
+end

+ 82 - 0
test/test_material_edit/unit1.pas

@@ -0,0 +1,82 @@
+unit Unit1;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
+  BCMaterialEdit, BCMaterialFloatSpinEdit, BCMaterialSpinEdit;
+
+type
+
+  { TForm1 }
+
+  TForm1 = class(TForm)
+    BCMaterialEdit1: TBCMaterialEdit;
+    BCMaterialFloatSpinEdit1: TBCMaterialFloatSpinEdit;
+    BCMaterialSpinEdit1: TBCMaterialSpinEdit;
+    Button1: TButton;
+    Label1: TLabel;
+    Label2: TLabel;
+    Label3: TLabel;
+    procedure BCMaterialEdit1Change(Sender: TObject);
+    procedure BCMaterialFloatSpinEdit1Change(Sender: TObject);
+    procedure BCMaterialSpinEdit1Change(Sender: TObject);
+    procedure Button1Click(Sender: TObject);
+  private
+
+  public
+
+  end;
+
+var
+  Form1: TForm1;
+
+implementation
+
+{$R *.lfm}
+
+{ TForm1 }
+
+procedure TForm1.BCMaterialEdit1Change(Sender: TObject);
+begin
+  Label1.Caption := BCMaterialEdit1.Edit.Text;
+end;
+
+procedure TForm1.BCMaterialFloatSpinEdit1Change(Sender: TObject);
+begin
+  Label2.Caption := BCMaterialFloatSpinEdit1.Edit.Text;
+end;
+
+procedure TForm1.BCMaterialSpinEdit1Change(Sender: TObject);
+begin
+  Label3.Caption := BCMaterialSpinEdit1.Edit.Text;
+end;
+
+procedure TForm1.Button1Click(Sender: TObject);
+begin
+  Self.Color := clBlack;
+
+  Label1.Font.Color := clWhite;
+  Label2.Font.Color := clWhite;
+  Label3.Font.Color := clWhite;
+
+  BCMaterialEdit1.Color := clBlack;
+  BCMaterialEdit1.Edit.Color := clBlack;
+  BCMaterialEdit1.Edit.Font.Color := clWhite;
+  BCMaterialEdit1.Font.Color := clWhite;
+
+  BCMaterialFloatSpinEdit1.Color := clBlack;
+  BCMaterialFloatSpinEdit1.Edit.Color := clBlack;
+  BCMaterialFloatSpinEdit1.Edit.Font.Color := clWhite;
+  BCMaterialFloatSpinEdit1.Font.Color := clWhite;
+
+  BCMaterialSpinEdit1.Color := clBlack;
+  BCMaterialSpinEdit1.Edit.Color := clBlack;
+  BCMaterialSpinEdit1.Edit.Font.Color := clWhite;
+  BCMaterialSpinEdit1.Font.Color := clWhite;
+end;
+
+end.
+