Mac UI Tips
From Xojo Documentation
|You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!|
Cocoa is the current user interface framework supported by Macs. If you are moving an older project from Carbon (an older Mac UI framework) to Xojo, your existing applications should just work for the most part, but there are some differences to consider.
General UI Differences
- Resizable windows can be resized from any window edge.
- Spellchecking and grammar checking are now available in TextField and TextArea controls by setting AutomaticallyCheckSpelling property to ON in the Inspector.
- Buttons have a ButtonStyle property than can be used to change the look of the button.
- Windows in your apps can be dragged around the screen while code is running.
- Timers, threads and sockets continue to get events when menus or OS modal dialog boxes are displayed.
- StyledText draws much faster.
All drawing using a Canvas must be done from the Paint event or a method called from it. If you have older projects that use the Graphics property of a Canvas directly, you will have to update them to use the Graphics object from the DesktopCanvas.Paint event instead.
All drawing now takes place in a ‘generic’ colorspace that is independent of the current output device. This means that colors will render more similarly between screens and printers.
You cannot have any code that is in a thread that modifies anything related to the user interface (which runs on what is called the main thread). If your app does this it will raise a ThreadAccessingUIException exception. If your user interface needs to be updated based on information in a thread, you should instead have the UI request the information from the thread.
One way to do this is to use the Thread.UserInterfaceUpdate method that allows you to periodically updates the UI based on information passed to it.
Mac apps can only display font styles that are available. You cannot force a font to display in bold or italic if it does not have bold or italic variations available. In this situation, the Bold or Italic properties will not affect the font.
To check if the font you wish to use has the variation you need, use the system Font Book app in the Applications folder.
Prior to 2018r4, displaying of digits used a non-proportional font even though the system font was always proportional. Apple changed this behavior starting with the macOS 10.11 SDK, which Xojo started using in 2018r4. So if you require a non-proportional font for displaying digits you will need to change your font accordingly.
Unhandled KeyDown event handlers cause a Beep instead of behaving silently. This is intentional and gives the user feedback that their action did not do anything. To eliminate the Beep, Return True from the KeyDown event handler.
Additionally, the KeyDown event handler literally means “a key was pressed” and does not attempt to interpret the key event for dead key sequences or input methods. For example, pressing Option+E and then E again results in two key presses sent to KeyDown, not a single key press with the value “é”.
These older Mac features are no longer supported: