mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-06 15:41:45 +02:00
Gtk3: proper calculate item width of listview vsIcon and vsSmallIcon
This commit is contained in:
parent
f6ceb6980a
commit
96d378e919
@ -660,6 +660,7 @@ type
|
||||
const AIsSet: Boolean);
|
||||
function ItemGetState(const AIndex: Integer; const {%H-}AItem: TListItem; const AState: TListItemState;
|
||||
out AIsSet: Boolean): Boolean;
|
||||
procedure setItemWidth(const AImageListWidth: integer=0); //calculates width of vsIcon item. Param aWidth is imageList.Width
|
||||
procedure ScrollToRow(const ARow: integer);
|
||||
procedure UpdateImageCellsSize;
|
||||
|
||||
@ -6815,6 +6816,32 @@ end;
|
||||
type
|
||||
TCustomListViewHack = class(TCustomListView);
|
||||
|
||||
procedure TGtk3ListView.setItemWidth(const AImageListWidth: integer);
|
||||
var
|
||||
aImgWidth, aBorders: gint;
|
||||
AListView: TCustomListViewHack;
|
||||
aIconView: PGtkIconView;
|
||||
begin
|
||||
aImgWidth := AImageListWidth;
|
||||
aListView := TCustomListViewHack(LCLObject);
|
||||
if not (AListView.ViewStyle in [vsSmallIcon, vsIcon]) then
|
||||
exit;
|
||||
if not Gtk3IsWidget(getContainerWidget) then
|
||||
exit;
|
||||
if aImgWidth <= 0 then
|
||||
begin
|
||||
if AListView.ViewStyle = vsIcon then
|
||||
gtk_icon_size_lookup(Ord(GTK_ICON_SIZE_DIALOG), @aImgWidth, @aBorders)
|
||||
else
|
||||
gtk_icon_size_lookup(Ord(GTK_ICON_SIZE_LARGE_TOOLBAR), @aImgWidth, @aBorders);
|
||||
end;
|
||||
aIconView := PGtkIconView(GetContainerWidget);
|
||||
aBorders := aIconView^.get_margin_start + aIconView^.get_margin_end +
|
||||
(aIconView^.get_border_width * 2) + aIconView^.get_column_spacing +
|
||||
(aIconView^.get_spacing * 2);
|
||||
aIconView^.set_item_width(aImgWidth + aBorders);
|
||||
end;
|
||||
|
||||
function TGtk3ListView.CreateWidget(const Params: TCreateParams): PGtkWidget;
|
||||
var
|
||||
AListView: TCustomListViewHack;
|
||||
|
@ -367,6 +367,12 @@ end;
|
||||
|
||||
{ TGtk3WSCustomListView }
|
||||
|
||||
type
|
||||
TLVHack = class(TCustomListView)
|
||||
end;
|
||||
TLVItemHack = class(TListItem)
|
||||
end;
|
||||
|
||||
class function TGtk3WSCustomListView.CreateHandle(
|
||||
const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle;
|
||||
var
|
||||
@ -374,16 +380,23 @@ var
|
||||
begin
|
||||
// DebugLn('TGtk3WSCustomListView.CreateHandle');
|
||||
AListView := TGtk3ListView.Create(AWinControl, AParams);
|
||||
if TLVHack(AWinControl).ViewStyle = vsSmallIcon then
|
||||
begin
|
||||
if Assigned(TLVHack(AWinControl).SmallImages) then
|
||||
AListView.setItemWidth(TLVHack(AWinControl).SmallImages.Width)
|
||||
else
|
||||
AListView.setItemWidth(0);
|
||||
end else
|
||||
if TLVHack(AWinControl).ViewStyle = vsIcon then
|
||||
begin
|
||||
if Assigned(TLVHack(AWinControl).LargeImages) then
|
||||
AListView.setItemWidth(TLVHack(AWinControl).LargeImages.Width)
|
||||
else
|
||||
AListView.setItemWidth(0);
|
||||
end;
|
||||
Result := TLCLHandle(AListView);
|
||||
end;
|
||||
|
||||
type
|
||||
TLVHack = class(TCustomListView)
|
||||
end;
|
||||
TLVItemHack = class(TListItem)
|
||||
end;
|
||||
|
||||
|
||||
procedure Gtk3_ItemCheckedChanged(renderer: PGtkCellRendererToggle; PathStr: Pgchar; aData: gPointer);cdecl;
|
||||
var
|
||||
LV: TLVHack;
|
||||
@ -1127,7 +1140,8 @@ begin
|
||||
PixRenderer^.set_fixed_size(AValue.Width + 2, AValue.Height + 2);
|
||||
AColumn^.queue_resize;
|
||||
end;
|
||||
|
||||
if TLVHack(ALV).ViewStyle in [vsSmallIcon, vsIcon] then
|
||||
TGtk3ListView(ALV.Handle).setItemWidth(AValue.Width);
|
||||
for i := 0 to AValue.Count-1 do
|
||||
begin
|
||||
pixbuf := nil;
|
||||
|
Loading…
Reference in New Issue
Block a user