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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
| unit GrilleFrame;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
System.Generics.Collections,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
System.Rtti, FMX.Grid.Style, FMX.Grid, FMX.Controls.Presentation,
FMX.ScrollBox, FMX.Header;
type
TFrame5 = class(TFrame)
Grid1: TGrid;
Column1: TColumn;
Column2: TColumn;
Column3: TColumn;
Column4: TColumn;
Label1: TLabel;
procedure Grid1DrawColumnHeader(Sender: TObject; const Canvas: TCanvas;
const Column: TColumn; const Bounds: TRectF);
private
FSortList: TDictionary<TColumn,smallint>;
FColumnSortedList: TList<TColumn>;
Fgridheaderheight: Integer;
procedure Setgridheaderheight(const Value: Integer);
{ Déclarations privées }
function DrawSVGInHeader(aColumn : TColumn; TriType : integer;
ColorBar:String ='"#00A1A7"';
CircleColor : String='red') : String;
public
Constructor Create(AOwner:TComponent);Override;
Destructor Destroy; Override;
property SortList : TDictionary<TColumn,smallint> read FSortList;
property gridheaderheight : Integer read Fgridheaderheight write Setgridheaderheight;
procedure AddToSort(aColumn : TColumn);
procedure RemoveFromSort(aColumn : TColumn);
procedure SetColumnSortable(AColumn : TColumn; SortType : integer =0 ; Sorted : Boolean = True);
procedure ChangeColumnSort(AColumn : TColumn);
end;
implementation
{$R *.fmx}
uses System.Skia, FMX.Skia;
const
svgsort = '''
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 511.993 511.993"
xml:space="preserve" fill="#000000">
<g color="#00A1A7">
<rect x="0.000" y="$T1" fill="currentColor" width="100.000" height="73.038"></rect>
<rect x="0.000" y="$T2" fill="currentColor" width="150.000" height="73.038"></rect>
<rect x="0.000" y="$T3" fill="currentColor" width="250.000" height="73.038"></rect>
<rect x="0.000" y="$T4" fill="currentColor" width="300.000" height="73.038"></rect>
</g>
<circle cx="400" cy="$CPOS" r="100" style="stroke:none; fill:$CFIL" />
<text x="370" y="$TPOS" style="font-family: Times New Roman;
font-size : 150;
fill : white;">$TRI</text>
<g>
</g>
</svg>
''';
{ TFrame5 }
procedure TFrame5.AddToSort(aColumn : TColumn);
begin
if not FSortList.ContainsKey(aColumn) then FSortList.Add(aColumn,0);
end;
procedure TFrame5.ChangeColumnSort(AColumn : TColumn);
begin
end;
constructor TFrame5.Create(AOwner: TComponent);
var
I: Integer;
begin
inherited;
FSortList:=TDictionary<TColumn,smallint>.Create;
FColumnSortedList:= TList<TColumn>.Create();
gridheaderheight:=40;
end;
destructor TFrame5.Destroy;
begin
FSortList.Free;
FColumnSortedList.Free;
inherited;
end;
function TFrame5.DrawSVGInHeader(aColumn: TColumn; TriType : integer; ColorBar:String ='"#00A1A7"'; CircleColor : String='red'): String;
begin
result := svgsort;
if tritype = 0 then
begin
result := StringReplace(result, '$T1', '146.444', []);
result := StringReplace(result, '$T2', '0.362', []);
result := StringReplace(result, '$T3', '438.594', []);
result := StringReplace(result, '$T4', '292.519', []);
result := StringReplace(result, 'g color="#00A1A7"', 'g color="silver"',
[rfreplaceall]);
result := StringReplace(result, '$CFIL', 'none', []);
result := StringReplace(result, '$TRI', '', []);
end
else
begin
if tritype > 0 then
begin
// type de tri Descendant
result := StringReplace(result, 'g color="#00A1A7"', 'g color='+ColorBar,[]);
result := StringReplace(result, '$T1', '0.362', []);
result := StringReplace(result, '$T2', '146.444', []);
result := StringReplace(result, '$T3', '292.519', []);
result := StringReplace(result, '$T4', '438.594', []);
result := StringReplace(result, '$CFIL', circlecolor, []);
result := StringReplace(result, '$CPOS', '100', []);
result := StringReplace(result, '$TPOS', '150', []);
result := StringReplace(result, '$TRI', tritype.ToString, []);
end
else
begin
// type de tri Ascendant
result := StringReplace(result, 'g color="#00A1A7"', 'g color='+ColorBar,[]);
result := StringReplace(result, '$T1', '438.594', []);
result := StringReplace(result, '$T2', '292.519', []);
result := StringReplace(result, '$T3', '146.444', []);
result := StringReplace(result, '$T4', '0.362', []);
result := StringReplace(result, '$CFIL', CircleColor, []);
result := StringReplace(result, '$CPOS', '400', []);
result := StringReplace(result, '$TRI', Abs(tritype).ToString, []);
result := StringReplace(result, '$TPOS', '450', []);
end;
end;
end;
//procedure TFrame5.DrawSGVInHeader(aColumn: TColumn) : String;
//begin
//end;
procedure TFrame5.Grid1DrawColumnHeader(Sender: TObject; const Canvas: TCanvas;
const Column: TColumn; const Bounds: TRectF);
var Header : THeader;
aSVG : TSKSVG;
sortvalue : smallint;
begin
Header:=THeader(Grid1.FindStyleResource('header'));
if Header.Height<>Fgridheaderheight then Header.Height:=Fgridheaderheight;
// dessin SVG
if FColumnSortedList.Contains(Column) then
begin
if not FSortList.TryGetValue(Column,sortvalue) then sortvalue:=0;
var HeaderItem := Header.Items[Column.index];
aSVG:=nil;
for var aFMXObj in HeaderItem.Children do
if (aFMXObj is TSkSvg) then
begin
aSVG:=TSKSVG(aFMXObj);
break;
end;
if not assigned(aSVG) then
begin
aSVG:=TSkSvg.Create(HeaderItem);
with aSVG do
begin
Margins.Right := 2;
Margins.Top := 1;
Margins.Bottom := 1;
height := Header.height - 2;
width := height;
Align := TalignLayout.Right;
Parent := HeaderItem;
HitTest := true;
HeaderItem.TextSettings.HorzAlign := TTextAlign.Leading;
svg.Source := DrawSVGInHeader(Column,Sortvalue);
aSvg.InvalidateRect(TRectF.Create(0,0,height,width));
// OnClick := ClickSort;
end;
end;
end;
end;
procedure TFrame5.RemoveFromSort(aColumn : TColumn);
begin
FSortList.Remove(aColumn);
end;
procedure TFrame5.SetColumnSortable(AColumn : TColumn; SortType : integer =0 ; Sorted : Boolean = True);
begin
if Sorted then
begin
if not FColumnSortedList.Contains(aColumn) then FColumnSortedList.Add(AColumn);
if SortType<>0 then FSortList.AddOrSetValue(aColumn,sorttype);
DrawSVGInHeader(AColumn,SortType);
Grid1.NeedStyleLookup;
end
else
begin
if FSortList.ContainsKey(aColumn) then Fsortlist.Remove(aColumn);
if FColumnSortedList.Contains(aColumn) then FColumnSortedList.Remove(aColumn);
end;
end;
procedure TFrame5.Setgridheaderheight(const Value: Integer);
var Header : THeader;
begin
Fgridheaderheight := Value;
end;
end. |
Partager