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
| procedure TFormPrestaStocks.GrilleDrawColumnHeader(Sender: TObject;
const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF);
var TL : TTextLayout;
rf : TRectF;
StyleBrush : TBrush;
ABackColor,ATextColor : TAlphaColor;
function GetHeaderColors(Sender: TObject; var BackGroundColor,TextColor : TAlphaColor) : TBrush;
var Header : THeader;
HeaderItem : THeaderItem;
aFMXObj : TFMXObject;
begin
// valeurs par défaut fournies avant l'appel
BackGroundColor:=0;
TextColor:=TAlphaColors.Black;
// recherche dans les styles
Header:=THeader((Sender as TStringGrid).FindStyleResource('header'));
if Assigned(Header) then
begin
// obtention d'un élément
HeaderItem := Header.Items[1];
// accès au style du texte
AFMXObj:=THeaderItem(HeaderItem).FindStyleResource('Text');
TextColor:=TText(AFMXObj).TextSettings.FontColor;
// accès au style du fond
AFMXObj:=THeaderItem(HeaderItem).FindStyleResource('background');
Result:=TRectangle(AFMXObj).Fill;
if Assigned(result) then
begin
if (Result.Kind=TBrushKind.Gradient)
then begin
BackGroundColor:=Result.Gradient.InterpolateColor(50);
// de horizontal à vertical ? (Pas concluant)
Result.Gradient.StartPosition.X:=1;
Result.Gradient.StartPosition.Y:=1;
end
else BackGroundColor:=Result.Color;
end;
end;
end;
begin
if Column.Index<>0 then
begin
// aBackColor:=TAlphaColors.Lightgray;
// ATextColor:=TAlphaColors.Black;
Stylebrush:= GetHeaderColors(Sender,aBackColor,aTextColor);
tl := TTextLayoutManager.DefaultTextLayout.Create;
try
tl.BeginUpdate;
try
rf:=Bounds;
InflateRect(rf,-1,-1);
canvas.ClearRect(rf,ABackColor);
tl.TopLeft := Bounds.TopLeft;
tl.MaxSize := PointF(Column.Width, Column.Height);
tl.Font.Size := 15;
tl.Text := Column.Header; // Value
tl.HorizontalAlign := TTextAlign.Center;
finally
tl.EndUpdate;
end;
tl.RenderLayout(Canvas);
finally
tl.Free;
end;
end;
end; |
Partager