ideintf/graphpropedits: Scale images in TImageIndexPropertyEditor dropdown to line height. Issue #35807.

(cherry picked from commit ce4661f5ec)
This commit is contained in:
wp_xyz 2021-12-18 23:10:31 +01:00 committed by Maxim Ganetsky
parent 8a72f0f832
commit e95ced47e4

View File

@ -18,7 +18,7 @@ interface
uses uses
Classes, TypInfo, SysUtils, Math, Classes, TypInfo, SysUtils, Math,
// LCL // LCL
LCLType, Forms, Graphics, Buttons, Menus, Dialogs, Grids, ImgList, EditBtn, LCLIntf, LCLType, Forms, Graphics, Buttons, Menus, Dialogs, Grids, ImgList, EditBtn,
// LazUtils // LazUtils
GraphType, UITypes, LazFileUtils, GraphType, UITypes, LazFileUtils,
// IdeIntf // IdeIntf
@ -744,29 +744,36 @@ end;
procedure TImageIndexPropertyEditor.ListMeasureHeight(const AValue: ansistring; procedure TImageIndexPropertyEditor.ListMeasureHeight(const AValue: ansistring;
Index: integer; ACanvas: TCanvas; var AHeight: Integer); Index: integer; ACanvas: TCanvas; var AHeight: Integer);
var
Images: TCustomImageList;
begin begin
AHeight := ACanvas.TextHeight('1'); AHeight := ACanvas.TextHeight('1');
Images := GetImageList;
if Assigned(Images) then
AHeight := Max(AHeight, Images.Height + 2);
end; end;
procedure TImageIndexPropertyEditor.ListDrawValue(const CurValue: ansistring; procedure TImageIndexPropertyEditor.ListDrawValue(const CurValue: ansistring;
Index: integer; ACanvas: TCanvas; const ARect: TRect; AState: TPropEditDrawState); Index: integer; ACanvas: TCanvas; const ARect: TRect; AState: TPropEditDrawState);
var var
Images: TCustomImageList; Images: TCustomImageList;
R: TRect; R, RImg: TRect;
dh: Integer; dh: Integer;
wimg, himg: Integer;
begin begin
if GetDefaultOrdValue <> NoDefaultValue then if GetDefaultOrdValue <> NoDefaultValue then
Dec(Index); Dec(Index);
Images := GetImageList; Images := GetImageList;
R := ARect; R := ARect;
dh := R.Bottom - R.Top; // Rect height. dh := R.Bottom - R.Top;
if Assigned(Images) then if Assigned(Images) then
begin begin
if Images.Height <= dh - 2 then
begin
himg := Images.Height;
wimg := Images.Width;
end else
begin
himg := dh - 2;
wimg := round(hImg * Images.Width/Images.Height);
end;
RImg := Rect(0, 0, wimg, himg);
OffsetRect(RImg, R.Left + 1, (R.Top + R.Bottom - himg) div 2);
if (pedsInComboList in AState) and not (pedsInEdit in AState) then if (pedsInComboList in AState) and not (pedsInEdit in AState) then
begin begin
if pedsSelected in AState then if pedsSelected in AState then
@ -775,10 +782,8 @@ begin
ACanvas.Brush.Color := clWhite; ACanvas.Brush.Color := clWhite;
ACanvas.FillRect(R); ACanvas.FillRect(R);
end; end;
Images.Draw(ACanvas, R.Left + 1, R.Top + 1, Index); Images.StretchDraw(ACanvas, Index, RImg, true);
Inc(R.Left, Images.Width + 2); R.Left := RImg.Right + 2;
// The numeric value in list goes too low without an adjustment. Why?
Dec(R.Top, (dh - ACanvas.TextHeight(CurValue)) div 2);
end; end;
inherited ListDrawValue(CurValue, Index, ACanvas, R, AState); inherited ListDrawValue(CurValue, Index, ACanvas, R, AState);
end; end;