Continuing on the preparing your Xojo made Mac app for macOS Big Sur, this article covers using Ohanaware App Kit & App Wrapper 4 to get that GUI goodness.
In order to be able to continue this series, I needed to get App Wrapper 4 much closer to release and I wanted to make a little sample application to demo some of cool functionality that you can get.
Getting the unified titlebar with Xojo 2020r1.2 isn't possible, until I added functionality to App Wrapper. AW4 can modify the application, telling the macOS that this application is compatible with BS.
Now that Xojo 2020r2 is out; Xojo's ARM Mac apps do NOT need to be modified to enable the full Big Sur GUI features. These steps are only required for Intel apps.
If you don't have an active license plan for App Wrapper, you can always take advanatge of the 14-Day trial by downloading it from ohanaware.com/appwrapper/aw4.html
Native Xojo doesn't support placing controls in the toolbar, but the App Kit has you covered there.
Dim toolie as integer = NSWindowToolbar( me.handle )
if toolie = 0 then return
NSToolbarSetNSView( toolie, <controlName>.handle, <index> )
Hiding the button labels is done by using the following code, place it under where you add the controls to the toolbar.
NSToolbarSetDisplayMode( Toolie ) = NSToolbarDisplayModeValue.iconOnly
NSImageWithSymbolNameAndFallBack( <symbolName>, <label>, <fallBackIconName> )
NSImageWithSymbolName( NSImageClass, <symbolName>, <label> )
The first function is part of the Ohanaware App Kit 1.2, it will fall back to using an icon from the system or your resources if running on macOS 10.15 or lower. With App Wrapper 4, you can rasterize SF Symbols and include them in the resources for older OS versions.
NSSegmentedControlSetImageForSegment( me.handle, _
NSImageWithSymbolNameAndFallBack( "cursorarrow.and.square.on.square.dashed", _
"Make", "cursorarrow.and.square.on.square.dashedTemplate" ), 0 )
This one is a bit tricky, as this custom control has rounded corners (to fit in with the Big Sur style) I wanted to make it show a rounded focus ring too. This could be done by watching the focus state of the control, grabbing the highlight color from the OS and drawing it myself. However the ring would Inside of the control, not on the outside, so it means redesigning the control to simulate the ring being outside... Or simply figuring out how to do it properly.
It turns out that Apple already has a way of handling this, it is just not exposed to Xojo developers. Which is where the XojoCanvasDelegates class of the Ohanaware App Kit comes in.
XojoCanvasDelegates.init
XojoCanvasDelegates.registerDelegateForCanvas( me, makeIconWell )
#if targetMacOS then
NSBezierPathFill( NSBezierPathBezierPathWithRoundedRectxRadiusyRadius( NSBezierPathClass, _
NSViewBounds( NSViewInstance ), 6, 6 ) )
return true
#endif
The above code creates a NSBezierPath of a rounded rect, using the inner rect of NSViewInstance and arc of 6, then uses NSBezierPathFill. The system then turns this into a focus ring.
This one is really easy... In the open event of the slider, add this one liner (it's one lined, but wrapped in a macOnly block).
#if targetMacOS then
NSSliderSetVertical( me.handle ) = true
#endIf
The above icons are from the OS and are drawn into the resulting icon using OS API, or in this case, they're displayed an OWGridView, where each gridItem contains a ImageWell.
Dim nsi as Ptr = NSImageFromName( "NSImageNameIconViewTemplate" )
Dim nsi as Ptr = NSImageForClassicIcon( "hdsk" )
That just left configuring the image well to do two things it doesn't as standard, no-border and to auto scale the icons to fit the well (up or down).
NSImageWellImageFrameStyle( me.handle ) = NSImageFrameStyle.none
NSControlImageScaling( me.handle ) = NSImageScaling.proportionallyUpOrDown
NSViewUnregisterDraggedTypes( me.handle )
The last line is optional, but it stop the user from being able to accidentally overwrite our icon by dragging and dropping a different one on top.
I've been wanting to write an article like this for some time, but it's taken a lot of work behind the scenes to get here.
I hope that this article helps you to build better macOS apps with Xojo, any questions, send me a message.