Article Preview
Buy Now
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):
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 = 1and 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
AppearanceChangedevent forApplicationclass, which is very handy to switch colors. Or you check withIsDarkModefunction every time you draw something and decide the color.However, as
CellBackgroundPaintevent in theListboxclass is called foreach 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
NSColorMBSclass. TheNSColorMBS.alternatingContentBackgroundColorsfunction returns an array with twoNSColorobjects 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.








