Themes and Dark Mode
Overview
Many programs let you choose how they look. Dark mode draws light text on dark backgrounds, and light mode does the opposite. Some people find one easier to read than the other, and some need very strong contrast to read at all. In Quorum, the look of every control comes from one object, its interface options. In this tutorial, you will switch a form to dark mode, let a person switch while the program runs, build a theme of your own, change the colors of the newer controls such as combo boxes and calendars, and give some buttons their own colors.
Goals
You have the following goals for this tutorial:
By the end of this lesson, you can
- Switch a form between light mode and dark mode
- Build your own theme as a class, and use it in a form or a game
- Change the colors of every control of one kind, including combo boxes, color wells and calendars, by changing the interface options
- Give a group of controls their own colors with a named set of options
- Choose colors with enough contrast for people to read
Warm up
Do you use dark mode on a phone, computer or app? Why or why not? Think about a time when text on a screen was hard to read, maybe in bright sunlight or late at night. What made it hard? If you were designing an app, who might want light mode, who might want dark mode, and who might need something else?
Vocabulary
You will be learning about the following vocabulary words:
| Term | Definition |
|---|---|
| Theme | A set of colors and shapes used by all of the controls in a program so they look like they belong together. |
| Light mode | A theme with dark text on light backgrounds. |
| Dark mode | A theme with light text on dark backgrounds. |
| Interface options | The Quorum object that holds a program's theme. Every control asks it for its colors. |
| Named options | A smaller set of interface options stored under a name, such as "Button" or "Calendar". Controls that use that name get those colors first. |
| Override | A color set on one control. It replaces the theme's color for that control only. |
| Contrast | How different two colors look from each other. Text needs high contrast with its background to be easy to read. |
New Code to Learn
You will be using the following new pieces of code:
| Quorum Code | Code Example | Explanation |
|---|---|---|
| SetToDarkMode() | form:SetToDarkMode() | Switches a form to Quorum's dark mode theme. |
| SetToLightMode() | form:SetToLightMode() | Switches a form back to Quorum's light mode theme. Forms start in light mode. |
| DarkModeOptions | class HighContrastOptions is DarkModeOptions | Quorum's dark mode theme. Your own theme can start from it. |
| LightModeOptions | LightModeOptions light | Quorum's light mode theme. Games and forms start with this theme. |
| SetInterfaceOptions(InterfaceOptions options) | form:SetInterfaceOptions(highContrast) | Gives a running form or game a new theme. Every control is redrawn with it. |
| GetInterfaceOptions() | InterfaceOptions options = GetInterfaceOptions() | Returns the theme a game is using now so you can change it. |
| SetButtonBackgroundColor(ColorGroup value) | options:SetButtonBackgroundColor(color:Navy()) | Sets the background color for every button that uses the theme. |
| SetBackgroundColor(text controlType, ColorGroup value) | SetBackgroundColor("ComboBox", color:Black()) | Sets the background color in the named options for one kind of control. There are actions like it for the font, border and focus border colors. |
| SetInterfaceOptions(text name, InterfaceOptions options) | options:SetInterfaceOptions("Warning", warning) | Stores a set of named options inside the theme. |
| SetInterfaceOptionsKey(text key) | deleteButton:SetInterfaceOptionsKey("Warning") | Makes a control use the named options with this name. |
CSTA Standards
This tutorial covers the following CSTA standards:
For teachers · 2026 CSTA K–12 Computer Science Standards
High School · Algorithms & Design
Design a computing technology using human-centered design principles.
Also in 7 other lessons
Middle School · Algorithms & Design
Evaluate which human-centered design principles are present or missing in an existing computing technology.
Also in 5 other lessons
Specialty I · Software Development
Refine a user interface design using accessibility and responsive design tools.
Also in 13 other lessons
Middle School · Systems & Security
Examine how access to computing systems can vary based on personal and social factors, such as physical ability, geographic location, socioeconomic status, and age.
Also in 3 other lessons
Explore
Where a control gets its colors
When Quorum draws a control, such as a button, it needs many colors: the background, the text, the border, the color when it has the focus, and the color when the mouse is over it. It asks for each color in this order:
- The control itself. If you set a color on this one control, that color wins. This is called an override.
- The control's named options. Each kind of control has a name, called
its key. Every
Buttonuses the options named "Button", for example. If those options have the color, it is used. - The theme's own colors. Anything not found above comes from the interface options as a whole.
The whole set of interface options is the program's theme. Quorum comes
with two themes: LightModeOptions and DarkModeOptions. Every game and
every form starts in light mode.
Dark mode in a form
To show a form in dark mode, call SetToDarkMode before Display:
use Libraries.Interface.Forms.Form
use Libraries.Interface.Forms.Page
use Libraries.Interface.Controls.Button
use Libraries.Interface.Controls.Checkbox
use Libraries.Interface.Controls.TextField
Form form
form:SetToDarkMode()
Page page = form:GetMainPage()
page:SetTitle("Club Settings")
page:AddLabel("Nickname")
TextField nickname = page:AddTextField("Nickname")
nickname:SetDescription("The name other club members see.")
Checkbox reminders = page:AddCheckbox("Send me reminders")
reminders:SetDescription("Check this box to get a reminder before each meeting.")
Button save = page:AddButton("Save")
save:SetDescription("Saves your settings.")
form:Display()
The theme changes only colors and shapes. A screen reader still reads the same names and descriptions, and the keys still work the same way.
Letting a person choose
The best choice is often to let each person decide. This form has a button that switches between the two themes. It uses a form behavior, a behavior that can find the form and page it belongs to, as you saw in the Behaviors tutorial:
use Libraries.Interface.Forms.Form
use Libraries.Interface.Forms.Page
use Libraries.Interface.Forms.FormBehavior
use Libraries.Interface.Events.BehaviorEvent
use Libraries.Interface.Controls.Button
use Libraries.Game.Graphics.Label
class Main is FormBehavior
boolean darkMode = false
action Main
Form form
Page page = form:GetMainPage()
page:SetTitle("Theme Switcher")
page:AddLabel("Status", "This program is in light mode.")
Button switchButton = page:AddButton("Switch between light and dark mode")
switchButton:SetDescription("Changes the colors of every control in this program.")
switchButton:SetBehavior(me)
form:Display()
end
action Run(BehaviorEvent event)
Form form = GetForm()
Page page = GetPage()
Label status = page:GetLabel("Status")
if darkMode
form:SetToLightMode()
status:SetText("This program is in light mode.")
else
form:SetToDarkMode()
status:SetText("This program is in dark mode.")
end
darkMode = not darkMode
end
end
Press Tab to reach the button, then Space or Enter to press it. The status label says which mode is on, in words, and a screen reader user can press Shift+Tab to read it. Do not rely on the colors alone to show what changed.
Your own theme
A theme is a class. To make your own, start from one of Quorum's themes and
change what you need in on create. This theme starts from dark mode and
makes the buttons black and white, with a yellow focus color that is easy
to spot. Put it in a file named HighContrastOptions.quorum:
use Libraries.Game.Graphics.Color
use Libraries.Interface.Options.DarkModeOptions
class HighContrastOptions is DarkModeOptions
on create
Color color
SetButtonBackgroundColor(color:Black())
SetButtonFontColor(color:White())
SetButtonBorderColor(color:White())
SetButtonBorderThickness(2)
// When a button has the focus, make it very easy to see.
SetButtonFocusColor(color:Yellow())
SetButtonFocusFontColor(color:Black())
SetButtonFocusBorderColor(color:Yellow())
end
end
A form starts with light mode or dark mode, so give it your theme once it is running, from a behavior. This form has a combo box and a button that turns high contrast on and off:
use Libraries.Interface.Forms.Form
use Libraries.Interface.Forms.Page
use Libraries.Interface.Forms.FormBehavior
use Libraries.Interface.Events.BehaviorEvent
use Libraries.Interface.Controls.Button
use Libraries.Interface.Controls.ComboBox
use Libraries.Containers.Array
use Libraries.Game.Graphics.Label
class Main is FormBehavior
boolean highContrast = false
action Main
Form form
Page page = form:GetMainPage()
page:SetTitle("Reading Settings")
Array<text> sizes
sizes:Add("Small")
sizes:Add("Medium")
sizes:Add("Large")
page:AddLabel("Text size")
ComboBox size = page:AddComboBox("Text size", sizes)
size:SetDescription("Choose how big the text should be.")
page:AddLabel("Status", "High contrast is off.")
Button contrast = page:AddButton("Turn high contrast on or off")
contrast:SetDescription("Switches between the normal colors and high contrast colors.")
contrast:SetBehavior(me)
form:Display()
end
action Run(BehaviorEvent event)
Form form = GetForm()
Page page = GetPage()
Label status = page:GetLabel("Status")
if highContrast
form:SetToLightMode()
status:SetText("High contrast is off.")
else
HighContrastOptions options
form:SetInterfaceOptions(options)
status:SetText("High contrast is on.")
end
highContrast = not highContrast
end
end
A new theme is a new object. If you changed colors in the old theme while the program ran, those changes are not in the new one. Putting your changes in a class, as here, means they are never lost.
Colors for the newer controls
Combo boxes, sliders, color wells and calendars each have their own key, and you can
give them colors in your theme with actions that take the key as text, such
as SetBackgroundColor("ComboBox", color:Black()). Here is what each color
means for them:
- "ComboBox": the background and border of the field, the foreground color of the arrow that opens the list, and the focus border. The list that opens uses the "MenuPanel" options.
- "ComboBoxChoice": the mouse-over color of a row in a combo box's open list. The row picked with the keyboard keeps the list's selection color.
- "Slider": the background color is the track, the foreground color is the filled part of the track, the accent color is the thumb and the border color is the thumb's edge. While the slider has the focus, the focus border color is the thumb and its halo, and the focus color is the thumb's edge.
- "ColorWell": the background, the border (which is also the edge of the color swatch), and the focus border. The color picker that opens uses the "MenuPanel" options, like a combo box's list.
- "Calendar": the font color is the days' numbers, the foreground color is dimmed days, the border color is the ring around today, the accent color fills the chosen day, the focus border is the ring around the day the keys are on, and the mouse-over color is the circle under the mouse.
Spreadsheets use "Spreadsheet" in the same way.
Add these lines to the end of on create in HighContrastOptions, so the
combo box, color wells and calendars show a yellow ring when they have the
focus too:
SetBackgroundColor("ComboBox", color:Black())
SetBorderColor("ComboBox", color:White())
SetFocusBorderColor("ComboBox", color:Yellow())
SetFocusBorderColor("ColorWell", color:Yellow())
SetFocusBorderColor("Calendar", color:Yellow())
Changing the theme in a game
In a game, you work with the interface options directly. GetInterfaceOptions
returns the theme the game is using. Change it before you add your
controls. This game makes every button navy blue with white text and a
thicker border:
use Libraries.Game.Game
use Libraries.Game.Graphics.Color
use Libraries.Interface.Controls.Control
use Libraries.Interface.Controls.Button
use Libraries.Interface.Layouts.FlowLayout
use Libraries.Interface.Options.InterfaceOptions
class Main is Game
Color color
action Main
StartGame()
end
action CreateGame
// Change the theme first, so every button below uses it.
InterfaceOptions options = GetInterfaceOptions()
options:SetButtonBackgroundColor(color:Navy())
options:SetButtonFontColor(color:White())
options:SetButtonBorderThickness(2)
Control panel
FlowLayout panelLayout
panel:SetLayout(panelLayout)
panel:SetPosition(300, 300)
Button play
play:SetSize(200, 100)
play:SetName("Play")
play:SetDescription("Starts a new game.")
panel:Add(play)
Button quit
quit:SetSize(200, 100)
quit:SetName("Quit")
quit:SetDescription("Closes the game.")
panel:Add(quit)
Add(panel)
// In a game, you set the Tab order yourself.
play:SetNextFocus(quit)
quit:SetPreviousFocus(play)
quit:SetNextFocus(play)
play:SetPreviousFocus(quit)
SetFocus(play)
end
end
SetButtonBackgroundColor stores the color in the "Button" named options,
so only buttons change. There are actions like it for most kinds of
control, such as SetCheckboxBackgroundColor, SetTextFieldFontColor and
SetLabelFontColor. Actions without a control's name, such as
SetBackgroundColor(color:Navy()), change the theme's own colors, which
every control falls back on. A game can also use your own theme: put
HighContrastOptions highContrast and SetInterfaceOptions(highContrast)
at the start of CreateGame.
Named options: colors for some controls
Sometimes a few controls need to look different. A button that deletes
something might be dark red to warn people. You can store your own named
options in the theme, then tell a control to use that name with
SetInterfaceOptionsKey.
A control uses only one name. A button that uses "Warning" no longer looks
in "Button", so it would lose the button colors you did not set. To keep
them, start from a copy of the "Button" options with
CopyInterfaceOptions. Add these lines to CreateGame from the last
program, before Add(panel):
// Start from the normal button options, then change two colors.
InterfaceOptions warning = options:CopyInterfaceOptions(options:BUTTON)
warning:SetBackgroundColor(color:Maroon())
warning:SetFontColor(color:White())
options:SetInterfaceOptions("Warning", warning)
Button deleteButton
deleteButton:SetSize(200, 100)
deleteButton:SetName("Delete saved game")
deleteButton:SetDescription("Deletes your saved game. This cannot be undone.")
deleteButton:SetInterfaceOptionsKey("Warning")
panel:Add(deleteButton)
Put the button in the Tab order too, between quit and play. Notice
that the button's name says what it does. Color alone cannot warn someone
who cannot see it, or who sees red and green the same way. The name and
description warn everyone.
Overrides: one control at a time
You can also set a color on a single control, such as
play:SetBackgroundColor(color:Green()). This override wins over every
theme, so the button stays green in light mode and dark mode. A green
button with white text may be easy to read in one theme and hard in the
other. Use overrides only when a color must never change.
Choosing colors people can read
A theme is only good if people can read it. Text needs enough contrast with the color behind it. The Web Content Accessibility Guidelines ask for a contrast ratio of at least 4.5 to 1 for normal text. Quorum's own light mode was chosen with this in mind: even the dimmed days of a calendar keep 4.5 to 1 against the calendar's background. You can learn how to measure contrast in Luminance and Color Contrast, and how to choose colors in Color in Application.
Some people need larger controls as well as stronger colors. A game can
make every control bigger with SetInterfaceScale. For example,
SetInterfaceScale(1.5) makes controls one and a half times their size.
Engage
In this activity, you and a partner design a theme for a real kind of user,
and check that it's easy to read and to use with the keyboard. The goal is
to change a theme's colors on purpose, for a reason, and to measure whether
text stands out enough from its background. Start by choosing who your
theme is for, such as someone who reads their phone outside in sunlight,
someone who uses a computer late at night, or someone with low vision. Each
partner then writes a class that starts from LightModeOptions or
DarkModeOptions and changes at least four colors, including the focus
colors, so a keyboard user can always see where they are.
Next, make a form with at least three controls, including a combo box or a calendar, each with a name and a description, and add a button that switches to your theme. Measure the contrast of your text and background colors with a contrast checker, and change any pair below 4.5 to 1. Finally, trade programs and use only the keyboard to reach each control. Can you always tell which control has the focus? Which design principles did your partner's theme follow, and which did it miss?
Wrap up
Themes let one change reach every control in a program. Which of your colors did you have to change after checking contrast? Why might a program offer more than two themes? What else, besides color, could a person want to choose about how a program looks?