bgracontrols
bgracontrols copied to clipboard
Set the color of svg icons in the PopulateImageList method
There is no way to set the color of svg icons in the PopulateImageList method. Useful for creating light and dark app theme
Hi, is not that easy I think, at least you must iterate each color in the XML of the svg image, and apply a function into it to make it darker or lighter.
I can see 4 ways to do it:
- iterate through the XML (not practical indeed)
- iterate through the SVG elements (I've just added an IterateElements method to do that). Here is a sample callback function:
procedure TForm1.ChangeFill(AElement: TSVGElement; AData: pointer;
var ARecursive: boolean);
begin
if AElement is TSVGDefine then
ARecursive:= false
else
begin
if not AElement.isFillNone then AElement.fillColor := CSSSkyBlue;
if not AElement.isStrokeNone then AElement.strokeColor := CSSOrange;
end;
end;
// used like this:
svg.IterateElements(@ChangeFill, nil, true);
- to use the currentColor variable in the SVG and to define it at the top level when drawing the SVG (I've just added a Color property to TBGRASVG class)
- render the SVG in a temporary image and apply a filter to change its color (as done in TBGRASVGTheme)