So, recently I playing with Snap API to display package icons in ListView, and the result is kinda mess.
The first method is I populate the items first get Icons later.
The code:
procedure TAppCentreForm.FormShow(Sender: TObject);
var
i: integer;
item: TListItem;
begin
IconIndex := 0;
PackageIcons.Clear;
AddDefaultIcon;
for i := 0 to SnapPackages.PackageList.Count -1 do
begin
item := LvPackages.Items.Add;
item.Caption := SnapPackages.PackageList[i].title;
end;
if SnapPackages.PackageList.Count > 0 then
GetPackageIcon;
end;
And the result is in the first attachment, kinda messy.
Second, I try to add default icon first, then set ImageIndex with real icons later. I also shortened the item caption because it does makes the item height inconsistent.
procedure TAppCentreForm.FormShow(Sender: TObject);
var
i: integer;
item: TListItem;
begin
IconIndex := 0;
PackageIcons.Clear;
AddDefaultIcon;
for i := 0 to SnapPackages.PackageList.Count -1 do
begin
item := LvPackages.Items.Add;
item.Caption := SnapPackages.PackageList[i].title;
// set default icon first here
item.ImageIndex := 0;
end;
if SnapPackages.PackageList.Count > 0 then
GetPackageIcon;
end;
The result is quite good but I the item width is not aligned. (in second attachment)