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
| unit ColoredBindNavigator;
interface
uses System.Classes, System.UIConsts,System.UITypes,System.Types,System.SysUtils,
FMX.Bind.Navigator, FMX.Graphics, FMX.Forms, FMX.Types,
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)
// AND (customcolors.scroll<>DefaultStyleColor) // todo test
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;
var colors : TNavigatorColors;
begin
Colors.scroll:=scrollcolor;
Colors.update:=updatecolor;
Colors.cancel:=cancelcolor;
customcolors(Colors);
Result:=Colors;
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. |
Partager