Dark Mode and TextArea.TextColor

Per the various blog posts as well as the user guide, the default color for the TextArea.TextColor is &c00000000, and as long as code sets this property to the default value, it should behave correctly in Dark Mode as well as Light Mode. However, this has not been my experience. I have confirmed that TextArea.TextColor returns &c00000000 in both Dark and Light Modes for any TextArea whose TextColor property has not been modified in anyway. However, setting TextColor to &c00000000 at any time will result in text being rendered black regardless of the display mode.

Here’s a simple experiment to demonstrate the issue:

  • create a new project and add a TextArea to Window1. Add some default text to the “Text” property.
  • Add the following code to TextArea1.open: me.TextColor = me.TextColor

This will result in text being rendered black, regardless of whether the app is started in Dark Mode or Light Mode. If, on the other hand, the line of code in TextArea1.open is commented out, the text color behaves correctly for both Dark and Light mode.

Why is that?

Because of a bug, the automatic conversion only works based on the color set in the IDE. if you need to change the color later in code, you should use Realbasic.TextColor instead, which will automatically return the correct color value based on the theme which the app is currently using.

Thanks. Is this a bug that will be fixed in an upcoming release?

Replacing the code in TextArea1.Open with me.TextColor = REALbasic.TextColor does indeed set the proper color based on the theme when the app starts. However, if one were to switch the theme while the app is running, the text color doesn’t adjust automatically. Will this get fixed?


Wait, why are you setting the color in the open event? If you just leave the default colors, it should just work automatically. That’s what we do in the IDE.

FWIW, my feeling on this whole dark/light thing is that once the novelty wears off, users won’t be switching back and forth between themes, so most of this becomes a non issue. So the only place you should need to set a color is in a custom control.

Setting the color in the open event is only a test to troubleshoot an issue I came across in one of my projects. In that project (a serial terminal), the user can set the text and background colors of the terminal window (which is a TextArea) via the preferences. The default for the text color in the preferences is &c00000000, and the preferences are applied when a new terminal window opens or when the users changes a setting. So once I flipped the “Supports Dark Mode” switch in the IDE and tested the app, I noticed that the text in the TextArea was always black, even in DarkMode, while all other controls behaved properly, and I couldn’t figure out why since every piece of documentation I read indicated that TextColor = &c0000000 should work. Now I know :slight_smile:

I have a textarea that gets colored in various ways, and for this I need to reset its textColor to textcolor:
19r1.1 and r2:
me.textColor = textColor or me.textColor = color.textColor

Switching to darkMode the textarea remains black (or white if the app started in darkmode).

I’d appreciate if this issue (Greg himself called it a bug) got addressed and corrected.

@Greg O’Lone : [quote]users won’t be switching back and forth between themes, so most of this becomes a non issue[/quote]

Well, is this a good reason to keep bugs around (smiley!)?

It’s not. But if you don’t need to change the color, leave it as-is and you’ll get the automatic switching by default.

If you can’t do that, use &c000000 for text and &cFFFFFF for the background, even if you’re in dark mode and it should do the right thing for you.

Users may not flip back and forth but those of us writing the software they use do just to test that things work right in either mode

For those of us who work in theater, especially during tech rehearsals, dark mode is a godsend. It cuts down on the glare from our laptops (which have cues and other paperwork in them) so we can see the stage clearly. Then during breaks, we go back to regular mode for checking our email, etc.

Dark mode was one of the most-requested features on my Lightwright wish list, I’m glad it’s relatively easy to implement now.

There are lots of other professions and situations where you don’t want a glaring laptop, but aren’t going to use dark mode at home - except maybe a teenager who’s online while watching a movie at home with mom and dad…

No, you are forgetting about the new “Auto” mode in Catalina, which switches at sunrise/sunset. I use it! And was happy to see the 2019r2 IDE fixed most of its dark mode switching issues (I had to relaunch 2019r1.1 every sunset!) And even for the last year in Mojave, I used Flux to auto-toggle dark mode (actually still do in Catalina, as I prefer it over Night Shift.)