Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 18 in printed book and digital formats -- plus a one-year subscription (beginning with 19.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 17.2 ('Barchart API')
Instant purchase and download via GumRoad!

FEATURE

Alternating Row Colors for Dark Mode

With Dark Mode, choosing the correct colors is trickier

Issue: 17.2 (March/April 2019)
Author: Christian Schmitz
Author Bio: Christian Schmitz is the creator of the Monkeybread Software Xojo/Real Studio Plugins.
Article Description: No description available.
Article Length (in bytes): 5,405
Starting Page Number: 40
Article Number: 17206
Resource File(s):

Download Icon project17206.zip Updated: 2019-03-04 09:41:34

Related Link(s): None

Excerpt of article text...

We ported a big Xojo project to MacOS Mojave recently and in that process needed a good solution to update our alternating row colors for the listboxes. We used to have the usual code with row mod 2 = 1 and picking a color for every second row. But this is not perfect with a fixed color when the user can switch between light and dark modes. And while the average user does that while using the application, beta testers, of course, do that. So we needed a good solution for the project.

Xojo 2018r4 has the AppearanceChanged event for Application class, which is very handy to switch colors. Or you check with IsDarkMode function every time you draw something and decide the color.

However, as CellBackgroundPaint event in the Listbox class is called for each cell, it can be called hundreds of times during a single listbox redraw. So we like to optimize the handling and cache the colors.

In MBS Plugins last summer we got the dark mode additions for NSColorMBS class. The NSColorMBS.alternatingContentBackgroundColors function returns an array with two NSColor objects with the current preferred background colors for lists. We want to use this, but not call it for every event as building an array and color objects costs performance for each draw.

So here is some example code:

...End of Excerpt. Please purchase the magazine to read the full article.