IdentifiantMot de passe
Loading...
Mot de passe oubli� ?Je m'inscris ! (gratuit)

Vous �tes nouveau sur Developpez.com ? Cr�ez votre compte ou connectez-vous afin de pouvoir participer !

Vous devez avoir un compte Developpez.com et �tre connect� pour pouvoir participer aux discussions.

Vous n'avez pas encore de compte Developpez.com ? Cr�ez-en un en quelques instants, c'est enti�rement gratuit !

Si vous disposez d�j� d'un compte et qu'il est bien activ�, connectez-vous � l'aide du formulaire ci-dessous.

Identifiez-vous
Identifiant
Mot de passe
Mot de passe oubli� ?
Cr�er un compte

L'inscription est gratuite et ne vous prendra que quelques instants !

Je m'inscris !

[FMX] Des navigateurs de donn�es (TBindNavigator) en couleur
Un billet blog de SergioMaster

Le , par SergioMaster

0PARTAGES

Via ce billet, je vous propose d'�gayer le composant FMX TBindNavigator.
On pourrait penser que toucher au style permettrait ce genre de chose, mais cet �l�ment de style n'existe pas.
La couleur appliqu�e pour les glyphes est celle de la couleur d'un texte du style en cours. Pour les curieux le code d'obtention de cette couleur se trouve dans la proc�dure TBindNavButton.ApplyStyle de l'unit� FMX.Bind.Navigator.
En n'utilisant "aucun" style on obtient ceci



Alors qu'en VCL un navigator s'affiche ainsi



Bien qu'en FMX je ne suis pas un fervent utilisateur du composant TBindNavigator ou alors uniquement de la partie concernant la navigation, je me suis mis au d�fi de customiser ce composant. Avant de passer � de grands travaux, l'�criture d'un composant, j'ai voulu tester la faisabilit� via des Helpers.

Je vous propose donc cette unit�
Code : S�lectionner tout
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
unit ColoredBindNavigator; 
 
interface 
 
 uses System.Classes, System.UIConsts,System.UITypes, 
      FMX.Bind.Navigator, Data.Bind.Controls; 
 
/// range TNavigateButton in three groups 
const   NavigatorScrollings = [nbFirst, nbPrior, nbNext, nbLast,nbRefresh]; 
        NavigatorValidations = [nbInsert, nbDelete, nbEdit, nbPost, nbCancel, 
                                nbApplyUpdates]; 
        NavigatorCancelations = [nbDelete,nbCancel,nbCancelUpdates]; 
 
type 
 
  TNavigatorColors = record 
    scroll : TAlphacolor; 
    update : TAlphacolor; 
    cancel : TAlphacolor; 
    class operator initialize (out Dest: TNavigatorColors); 
    class operator finalize (var Dest: TNavigatorColors); 
  end; 
 
  TColorNavButton = class helper for TBindNavButton 
    /// set the color of the Tpath.fill.color property 
    procedure setcolor(c : TAlphaColor); 
    /// apply the custom colors corresponding to the TNavigateButton type 
    /// Three groups NavigatorScrollings,NavigatorValidations,NavigatorCancelations 
    /// see const part 
    procedure ApplyColorStyle(customcolors : TNavigatorColors); 
  end; 
 
  TColorBindNavigator = class helper for TCustomBindNavigator 
    /// initialize and apply custom colors 
    function customcolors(scrollcolor, Updatecolor, cancelcolor : TAlphaColor) : TNavigatorColors; overload; 
    function customcolors(colors : TNavigatorColors) : TNavigatorColors; overload; 
  end; 
 
implementation 
 
{ TColorNavButton } 
procedure TColorNavButton.ApplyColorStyle(customcolors : TNavigatorColors); 
var defaultstylecolor : TAlphaColor; 
begin 
inherited; 
with Self do 
  DefaultStylecolor:=FPath.Fill.Color; 
if (TNavigateButton(Self.index) in NavigatorScrollings) 
    AND (customcolors.scroll<>TAlphacolors.Alpha) 
// todo test    AND (customcolors.scroll<>DefaultStyleColor) 
 then Setcolor(customcolors.scroll); 
if (TNavigateButton(Self.index) in NavigatorValidations) 
    AND (customcolors.update<>TAlphacolors.Alpha) 
 then Setcolor(customcolors.update); 
if (TNavigateButton(Self.index) in NavigatorCancelations) 
    AND (customcolors.cancel<>TAlphacolors.Alpha) 
 then Setcolor(customcolors.cancel); 
end; 
 
procedure TColorNavButton.setcolor(c: TAlphaColor); 
begin 
with Self do 
   FPath.Fill.Color:=c; 
end; 
 
{ TNavigatorColors } 
class operator TNavigatorColors.finalize(var Dest: TNavigatorColors); 
begin 
// nothing to do 
end; 
 
class operator TNavigatorColors.initialize(out Dest: TNavigatorColors); 
begin 
Dest.scroll:=TAlphaColors.Alpha; 
Dest.update:=TAlphaColors.Alpha; 
Dest.cancel:=TAlphaColors.Alpha; 
end; 
 
 
{ TColorBindNavigator } 
function TColorBindNavigator.customcolors(scrollcolor, Updatecolor, 
  cancelcolor: TAlphaColor) : TNavigatorColors; 
begin 
result.scroll:=scrollcolor; 
result.update:=updatecolor; 
result.cancel:=cancelcolor; 
for var i := 0 to  self.ControlsCount-1 do 
      TBindNavButton(Self.Controls[i]).ApplyColorStyle(result); 
end; 
 
function TColorBindNavigator.customcolors( 
  colors: TNavigatorColors): TNavigatorColors; 
begin 
for var i := 0 to  self.ControlsCount-1 do 
      TBindNavButton(Self.Controls[i]).ApplyColorStyle(colors); 
end; 
 
end.
L'utilisation en est assez simple :
  1. Ajoutez l'unit� au projet.
  2. Dans la forme contenant le composant TBindNavigator que vous voulez "colorier", ajoutez l'unit� � la clause uses dans la partie interface.Vous obtiendrez alors quelque chose de ce genre :

Code : S�lectionner tout
1
2
3
4
5
6
7
8
9
10
11
12
13
 
interface 
 
uses 
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, 
  Data.Bind.Controls, FMX.Controls.Presentation, FMX.StdCtrls, FMX.Layouts, 
  Fmx.Bind.Navigator, FMX.Memo.Types, FMX.ScrollBox, FMX.Memo, FMX.Objects, 
  FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Param, 
  FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf, 
  FireDAC.Stan.StorageBin, Data.Bind.Components, Data.Bind.DBScope, Data.DB, 
  FireDAC.Comp.DataSet, FireDAC.Comp.Client, 
  ColoredBindNavigator;
  1. D�clarez une variable priv�e (� moins que vous ne vouliez la partager) au sein de votre forme.

Code : S�lectionner tout
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
type 
  TForm1 = class(TForm) 
    BindNavigator1: TBindNavigator; 
    btnDark: TButton; 
    Memo1: TMemo; 
    FDMemTable1: TFDMemTable; 
    BindSourceDB1: TBindSourceDB; 
    Label1: TLabel; 
    StyleBook1: TStyleBook; 
    Button1: TButton; 
    procedure btnDarkClick(Sender: TObject); 
    procedure FormCreate(Sender: TObject); 
    procedure Button1Click(Sender: TObject); 
  private 
    { D�clarations priv�es } 
     Colors : TNavigatorColors; 
  public 
    { D�clarations publiques } 
  end;
  1. Utilisez ensuite les diverses fonctions propos�es.

Deux exemples :
Code : S�lectionner tout
1
2
3
4
5
6
 
procedure TForm1.FormCreate(Sender: TObject); 
begin 
CustomColorsNavigator :=true; 
colors:=BindNavigator1.customcolors(Talphacolors.blue,Talphacolors.Green,Talphacolors.Red); 
end;
Code : S�lectionner tout
1
2
3
4
5
6
7
8
9
 
procedure TForm1.btnDarkClick(Sender: TObject); 
begin 
 colors.scroll:=Talphacolors.darkBlue; 
 colors.update:=Talphacolors.darkGreen; 
 colors.cancel:=TAlphacolors.darkRed; 
 for var i := 0 to  BindNavigator1.ControlsCount-1 do 
      TBindNavButton(BindNavigator1.Controls[i]).ApplyColorStyle(colors); 
end;
Vous pourrez ainsi obtenir ce navigateur, qui sans �tre totalement identique � celui propos� en VCL, la technique des TPath utilis�e emp�chant un remplissage autre que monochrome les boutons nbApplyUpdates et nbCancelUpdates sont donc un peu p�nalis�s.



[ATTACH]661512d1/a/a/a" /> contient les sources de mon programme test �crit en Delphi 12ֽ_1.
Note : L'utilisation d'un managed record limite aux versions sup�rieures ou �gales � 10_4.

Que reste t-il � contr�ler ? L'utilisation d'un style, mes essais m'ont impos� l'utilisation d'une variable et d'un �v�nement OnPainting (comment�s dans le source propos�), v�rifiez donc que les commentaires sur ce billet ne contienne pas un correctif car bien �videmment je ne veux pas rester sur cette constatation.
Vous avez lu gratuitement 0 articles depuis plus d'un an.
Soutenez le club developpez.com en souscrivant un abonnement pour que nous puissions continuer � vous proposer des publications.

Une erreur dans cette actualit� ? Signalez-nous-la !