Toolbar height with retina 2x images, cross-platform?

I have a tool bar which looks great on Mac OS X, using retina sized 64x64 icons (which scale down to 32x32). However, on Win32 builds the toolbar is gigantic.

I tried the following code at runtime to shrink the icons down to 32x32

Toolbar1.Open
  #if TargetWin32
    // try making all the icons 1/2 size on windows
   for i as integer = 0 to me.Count-1
     dim t as ToolItem = me.Item(i)
     dim tb as ToolButton = ToolButton(t)
     if tb.Icon <> nil then
       dim p as picture = tb.icon
       dim p2 as new Picture (p.width/2,p.height/2, 32) // use old-style picture or else it crashes!
       p2.graphics.drawPicture p,0,0,p2.width,p2.height,0,0,p.width,p.height
       p2.mask.graphics.drawPicture p.copyMask,0,0,p2.width,p2.height,0,0,p.width,p.height
       tb.icon = p2
     end if
   next
  #endif

But all I end up with is a tall toolbar with stretched pixellated images.

Is there any way to have a single toolbar item in my project that looks good on Windows too?

RetinaKit might help with managing the correct icons.
Plus, it’s part of this awesome bundle for a short time.

Tim, my question is about Windows 32 (Win32) builds, not OS X.

Ok, I figured it out.

  • On Win32, the toolbar height seems set by the size of the icon in the IDE. Swapping out icons at runtime has no effect.
  • In OSX Cocoa, the toolbar height adapts to the size of your icons at runtime.

So a workable solution:

  • In the IDE, use the @1x sized icons, which will work fine on Win32 builds.
  • In Toolbar.Open, swap out your icons for Cocoa at runtime:
Toolbar1.Open
#if TargetCocoa
   me.ToolButton1.icon = icon2x  // these should be the @2x resolution icon
   me.ToolButton2.icon = anotherIcon2x  
   etc...

A neat thing about retina kit is that it handles windows and linux for you :slight_smile:

It’s essentially the same effect as you described in your last post where you set @1x on the toolbar and then it gets changed at display time, but with rk it will handle the need for @2x on Mac and provide the image needed when not @2x.

Also, seems like the proper toolbar icon sizes are:

  • Cocoa: 64x64
  • Windows: 48x48

So I was wrong earlier saying that @1x and @2x sizes are workable.