EtheaDev / IconFontsImageList

Four advanced components to simplify use of Icon Fonts as images and ImageList: TIconFontImage, TIconFontsImageCollection, TIconFontsVirtualImageList, TIconFontsImageList (for VCL and FMX). Full support for High-DPI apps. Rendering optimized with GDI+
Apache License 2.0
217 stars 55 forks source link

TIconFontImageList + TIconFontImage VCL style support #51

Closed aehimself closed 1 year ago

aehimself commented 1 year ago

Is your feature request related to a problem? Please describe. I have a TIconFontImageList with a TIconFontImage linked to it. With the default Windows style all appears correctly but if a different VCL style is selected the background of the image stays white. This results a completely white image on dark themes as the font color is usually white as well.

Describe the solution you'd like TIconFontImage / TIconFontImageList would consider the background of the picture, allowing a "transparent" look (like on menu items, pagecontrol tabs, buttons, etc.)

Describe alternatives you've considered As a workaround, a normal image can be used:

 bmp := TBitMap.Create;
 Try
   bmp.Width := MyImage.ImageList.Width;
   bmp.Height := MyImage.ImageList.Height;
   If TStyleManager.ActiveStyle = TStyleManager.SystemStyle Then
     bmp.Canvas.Brush.Color := clWindow
   Else
     bmp.Canvas.Brush.Color := TStyleManager.ActiveStyle.GetStyleColor(scWindow);
   bmp.Canvas.FillRect(Rect(0, 0, bmp.Width, bmp.Height));
   MyImage.ImageList.GetBitmap(MyImage.ImageIndex, bmp);
 Finally
   FreeAndNil(bmp);
 End;

Additional context On the left is a TIconFontImage linked to a TIconFontImageList. On the right is a normal TImage with the above workaround:

System (no) theme: image

Carbon: image

carloBarazzetta commented 1 year ago

Which version of Delphi are you using? You can call UpdateIconFontsColorByStyle as explained in the Demo?

    TStyleManager.TrySetStyle(LStyleName);
    //Override default: use Windows 10 blue color for Windows and Windows10 Style
    if SameText(LStyleName,'Windows') or SameText(LStyleName,'Windows10') then
      IconFontsVirtualImageList.UpdateIconsAttributes(RGB(0, 120, 215), clBtnFace)
    else
      UpdateIconFontsColorByStyle(IconFontsVirtualImageList);
aehimself commented 1 year ago

Delphi 11.2. I did not call UpdateIconFontsColorByStyle, but calling it only turn the icons grey-ish (as it gets sfButtonTextNormal instead of sfWindowTextNormal, what my code is using):

image

carloBarazzetta commented 1 year ago

I don't understand in what context you are using the components. First of all I suggest you to use TVirtualImageList and TIconFontsImageCollection as explained in the wiki: only in this way your application can share a single collection of images and have multiple forms with different DPI (on different monitors). In the IconFontsImageListDemo Demo I don't have the problem you report, as you can see from this image. I don't understand what it depends on. image

aehimself commented 1 year ago

I attempted to create a minimal example to reproduce the behavior but failed to do so. The difference in my main application and the test is that in my main application the image is on a panel on a panel, and due to flickering issues during resizing the ParentBackground of said panels are set to False if any style (other than the system style) is selected.

As it turns out leaving ParentBackground on True solves the issue - which makes total sense.

I'll have to find a workaround for flickering, but the issue is NOT in any IconFonts component!

Thanks for the help!