SF symbol canvas difference between Intel / M1

Hi everybody,

maybe it’s a bug, or i have not the best way to do that.

i try to put some SFSymbol in canvas, but with build, some graphics difference between intel version and M1 version (build as universal).

If anyone have an idea ?

Intel Version

M1 version

and the project file
https://www.delimard.fr/xojo/SFSymbolM1.zip

I recommend that you draw the resulting pictures in the canvases as opposed to setting them as a backdrop. This way you can draw them at the size you require.

g.drawpicture clientIcon, 0, 0, 16, 16, 0, 0, clientIcon.width, clientIcon.height

My guess after looking at the function “SystemImage”, is that it’s losing the DPI meta data of the image for Intel, there’s several unneeded conversions of the image data in this code (which will also make it slow).

Hi, I too use the MacOSLib module you are using in your project.

For canvases I rely on their paint event (the canvas is subclassed in order to deal with mousedown etc. events, but I have temporarely commented it for you to quickly test it).
BTW, this particular canvas is 20x20 px.

Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint
dim c as color = color.TextColor

//if mpressed then
//c = new ColorGroup(color.Teal, color.Green)
//end if

dim p as picture = SystemImage(“book”,13.0,SystemImageWeights.Medium, SymbolScale.Large,c)

g.DrawPicture p,1,0

#Pragma Unused areas
End Sub

Thank you @Sam_Rowlands and @Carlo_Rubini for the idea.

For the other user, if you want to handle SFSymbol in canvas (and dark mode ):

In the paint Event of the canvas:

if color.IsDarkMode then
  
  Var tColor As New ColorGroup(Color.LightGray)
  dim clientIcon as picture = SystemImage("book",13.0,SystemImageWeights.Medium, SymbolScale.Large,tColor)
  g.drawpicture(clientIcon, 0, 0, 16, 16, 0, 0, clientIcon.width, clientIcon.height)
else
  
  Var tColor As New ColorGroup(Color.Black)
  dim clientIcon as picture = SystemImage("book",13.0,SystemImageWeights.Medium, SymbolScale.Large,tColor)
  g.drawpicture(clientIcon, 0, 0, 16, 16, 0, 0, clientIcon.width, clientIcon.height)
  
end if


In the app event / appearanceChanged:

Window1.Iconclient.Refresh

No, please :wink:

1st:
This shouldn’t be necessary - the Paint Event of the Canvas should be raised by the the Framework when the appearance changes.

2nd:
If you see something like ‘Window1.ControlX.’ then choose a different design (or at least think about it).
‘App’ shouldn’t know and invoke calls on Controls on a window. ‘Iconclient’ should be a private Control on the Window, not a public one.

1 Like

As @Jürg said,
the paint event of the canvas should be enough to deal with darkMode.
Something like:

Var tColor As New ColorGroup(color.Black, Color.LightGray)
dim clientIcon as picture = SystemImage(“book”,13.0,SystemImageWeights.Medium, SymbolScale.Large,tColor)
g.drawpicture(clientIcon, 0, 0, 16, 16, 0, 0, clientIcon.width, clientIcon.height)

Since I do not own an M1 machine, could you be so kind as to test with g.DrawPicture clientIcon,1,0 ?
and let me know if you get the same result as when using g.drawpicture(clientIcon, 0, 0, 16, 16, 0, 0, clientIcon.width, clientIcon.height)?
That is, if using g.DrawPicture clientIcon,1,0 you get the same result in Intel and M1.
Thank you

I’d recommend putting the creation of the color group and the image in a different function, not in the Paint event.

You should only include actual drawing code in the paint event, otherwise once you get a more complete UI, it will lead to application slow downs and performance issues.

Add a method called “updateImages” which then creates your images, call this on window open and when you receive the notification from the OS that the theme changed. (IIRC with naked Xojo, that’s in the application event. Once you invest in a toolkit, it’s possible for the window or even a canvas to know when the theme changes).

Starting with these kind of practices now, will save complications later.

p.s. I’d also recommend using the now deprecated textColor as that should give you close to the correct OS color per theme without you having to care about what theme is selected.