Practical considerations on making GUIs

Making interfaces in Matlab is extremely easy and intuitive. You can look at my post on the basics if you have never done interfaces. But for today I want to focus on a few pieces of practical advices to make your interfaces good for others users (ie not only you). When it comes to share code, there are important things to consider that are not always obvious, especially since it is so easy to share code on a Multi-plateform environmemt.

Let’s start with the most obvious.

Interfaces are displayed on a screen, by definition. And every screen is different, have different number of pixels and different width and height. On your own, your interface might look like that :

But on someone else screen, it might look like :

This is because if you design your interface using proportional position for each objects, it will always be different for differents screen. One would thing the solution would be to use the absolute number of pixels as a measure for the interface (as pixels are usually of the same X and Y ratio, contrary to the full screen). But the problem comes when you design a big interface that fits quite entirely your screen. If you were to use the absolute number of pixels, the interface might be too big for someone else screen and your user won’t be able to touch some button at all!

To avoid this issue is easy in fact : you just have to allow the user to be able to resize its window to fit its own screen. The option is available here :

Make sure your GUI Options are set with Proportional as Resize behavior.

Another thing that is easily forgot is that some people actually use TAB a lot to move between fields with the keyboard.

Make sure all your buttons and objects are organized in a meaningfull manner. The Tab order editor is located at Tools->Tab Order Editor in the Guide.

Make sure you give names to all Tags in the Property inspector, even useless Text objects. I found that with time, it is much more difficult to maintain Guis if all the objects were not named appropriately. By default Matlab will call a Static Text object ‘Text10’ for instance. This is really not convenient to track down bugs as you don’t know who is that ‘Text10’.

This is probably one the most IMPORTANT advice. Users will interact with your interfaces in many different ways. Be sure that all the possible combinations or sequences of actions will be done. Some you not even thought about. For instance, some users will click on a plotting function and won’t wait for the plot to display before clicking somewhere else. This can be very annoying as you need to predict all the possible combinations to avoid bugs! In my experience, it is actually impossible to think about all the possibilities before hand. So as a very efficient solution, deactivate buttons that are not meant to be used at a particular moment. Don’t use endless sequence of IF or ELSE to check the exact state of the GUI.

This is quite easy. If you know the handle of an object h, just use :

set(h,'Enable','off');

And turn it back ON when it is meaningfull for the user to click or interact with it. As a drastic solution, I actually deactivate the entire window when long calculation are being done.

Why is this point particularly important?

Well, this is actually due to some Matlab fundamentals. For the most part, Matlab is single-threaded (not really anymore but I will come back to this in a very detailed post) BUT the interface run on a DIFFERENT thread, a Java thread. So users can STILL click on your interface, even if a calculation is currently being done on the Matlab thread. So in principle they can start 2 consecutive calculations by mistake. And depending on the way you set the property ‘Interruptible’ of your buttons, a second click might even stop the current calculation to run the second click and then finish the first click when the response to the second click is over. This is a HUGE source of bugs and misusage of interfaces in Matlab.

This entry was posted in Intermediate, Making interfaces. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *