ListView support for multi-resolution image lists
Original Reporter info from Mantis: zpeterson @boramis
-
Reporter name: Zoë Peterson
Original Reporter info from Mantis: zpeterson @boramis
- Reporter name: Zoë Peterson
Description:
On Cocoa, when a TListView is associated with a TImageList that includes multiple resolutions, it always uses the base imagelist size. The attached patch adds support for including all of the image resolutions in the associated NSImage so the list view will dynamically switch to the appropriate one when switching between HiDPI and standard displays.
Since the existing Cocoa code didn't rely on TWSCustomListView.SetImageList, this doesn't either, and just always includes all of the available resolutions. It has the benefit of working automatically thanks to Cocoa's built-in switching, and keeps the patch size small and limited to LCL/Interfaces/Cocoa. The alternative would be to update TCustomListView.SetImageListWS to take GetCanvasScaleFactor into account, but there isn't currently an LCL level notification when the scaling factor changes (which is available through NSWindowDelegate.windowDidChangeBackingProperties)
Steps to reproduce:
The attached sample project has a list view and a multi-resolution image list. To demonstrate the behavior more the image list's 16x16 and 32x32 images are slightly different. If you run it on a system with a 96dpi display attached, it will use the 16x16 icons. If you run it on a high DPI/retina display, it will use the 32x32 icons. If you have both types of monitors attached to one computer it will switch dynamically when the window is dragged between them. Setting the ListView's SmallImagesWidth works correctly.
Additional information:
TCocoaWSMenuItem would benefit from similar behavior and should probably use multi-resolution NSImages even if ListView becomes backingScaleFactor aware in the future. Since Mac menus don't generally have images, and the current menu item code is completely different, I haven't looked into that further.
Mantis conversion info:
- Mantis ID: 35029
- Version: 2.0
- Monitored by: » @onpok (Ondrej Pokorny)