Progress Bars

Overview

When a program does something that takes time, like loading a level or saving a big file, people want to know two things: is it still working, and how much is left? A progress bar answers both. It is a long box that fills up from left to right as the work gets done. In this tutorial, you will add a progress bar to a page, fill it over time, and fill it one step at a time with a button. You will also learn how often a progress bar should change so that it works well for people who use screen readers.

Goals

You have the following goals for this tutorial:

By the end of this lesson, you can

  • Add a progress bar to a page with AddProgressBar, and give it a name and description
  • Change how full the bar is with SetValue, using a minimum and a maximum
  • Fill a progress bar over time with a behavior's Update action
  • Explain how often a progress bar should change so that it stays accessible

Warm up

Think about the last time you waited for something on a computer or phone: an app update, a video loading, or a game level starting. Did the program show you how long you had to wait? Was it a bar, a spinning circle, a percent, or nothing?

Vocabulary

You will be learning about the following vocabulary words:

Vocabulary
TermDefinition
Progress barA control that fills up from left to right to show how much of a task is done.
ValueThe number that says how full the progress bar is right now.
MinimumThe value that means the task has not started. The bar is empty at this value. It is 0 unless you change it.
MaximumThe value that means the task is finished. The bar is full at this value. It is 100 unless you change it.
UpdateAn action Quorum calls many times every second while a program runs, so the program can change things over time.

New Code to Learn

You will be using the following new pieces of code:

New Code to Learn
Quorum CodeCode ExampleExplanation
AddProgressBar(text name)ProgressBar bar = page:AddProgressBar("Download")Adds a progress bar to a page. It starts empty, with a minimum of 0 and a maximum of 100.
AddProgressBar(text name, number minimum, number maximum)ProgressBar quiz = page:AddProgressBar("Questions answered", 0, 5)Adds a progress bar that counts from the minimum to the maximum. It starts at the minimum.
GetProgressBar(text name)ProgressBar bar = page:GetProgressBar("Download")Finds a progress bar on a page by its name.
SetValue(number value)bar:SetValue(40)Sets how full the bar is. A value halfway between the minimum and the maximum fills half of the bar.
GetValue()number amount = bar:GetValue()Returns the bar's current value.
GetMinimum()number empty = bar:GetMinimum()Returns the value that means empty.
GetMaximum()number full = bar:GetMaximum()Returns the value that means full.
AddBehavior(Behavior behavior)bar:AddBehavior(fill)Gives an item a behavior whose Update action runs many times a second, until its IsFinished action returns true.

CSTA Standards

This tutorial covers the following CSTA standards:

For teachers · 2026 CSTA K–12 Computer Science Standards

HS-PRO-TR-20

High School · Programming

Refine a computing technology based on user feedback, testing results, and responsible design values to improve its effectiveness and impact.

Also in 4 other lessons

MS-PRO-TR-20

Middle School · Programming

Refine a computing technology based on user feedback to improve its usability and accessibility.

Also in 7 other lessons

S1-SWD-UX-04

Specialty I · Software Development

Refine a user interface design using accessibility and responsive design tools.

Also in 13 other lessons

MS-ALG-PS-03

Middle School · Algorithms & Design

Verify the accuracy of an algorithm for given inputs.

Also in 2 other lessons

Every standard, and the lessons that cover it

Explore

What a progress bar does

A progress bar has three numbers inside it:

  • the minimum, which means "nothing is done yet";
  • the maximum, which means "everything is done";
  • the value, which says where the task is right now.

The bar fills in the same share as the value. By default, the minimum is 0 and the maximum is 100, so you can think of the value as a percent. A value of 25 fills a quarter of the bar. A value of 100 fills all of it.

A progress bar does not do the work for you. Your program does the work, and then tells the bar how far along it is by calling SetValue.

Making a progress bar

To start, make a new Form project in Quorum Studio. Replace the code in Main.quorum with the program below.

use Libraries.Interface.Forms.Form
use Libraries.Interface.Forms.Page
use Libraries.Interface.Controls.ProgressBar

Form form
Page page = form:GetMainPage()
page:SetTitle("Downloads")

page:AddLabel("Song download")
ProgressBar download = page:AddProgressBar("Song download")
download:SetDescription("Shows how much of the song has downloaded")
download:SetValue(40)

form:Display()

Here is what the program does:

  • page:AddLabel adds the words "Song download". A label added just before a progress bar is shown beside it, so sighted people know what the bar is for.
  • page:AddProgressBar("Song download") adds the bar. The name you give it is also the name a screen reader says. Without a name, it would only be called "Progress Bar".
  • SetDescription gives a screen reader a little more about what the bar shows. You can even add easter eggs, little surprises for fun, just like is possible for visual users. A classic example that did this visually is the loading screen for the game "The Sims."
  • SetValue(40) fills 40 percent of the bar.

Run the program. The bar is a little less than half full.

Changing the range

You don't have to count from 0 to 100. If a quiz has 5 questions, it can make more sense to count questions. AddProgressBar can take a minimum and a maximum:

ProgressBar quiz = page:AddProgressBar("Questions answered", 0, 5)
quiz:SetValue(2)

This bar is two fifths full, because 2 of the 5 questions are answered.

Keep the value between the minimum and the maximum. Quorum stores a value outside the range, but the bar only shows it as empty or full.

Filling the bar over time

A behavior is a class with actions Quorum calls for you. You have used its Run action, which runs once when a button is pressed. A behavior also has an Update action. If you give a behavior to an item with AddBehavior, Quorum calls its Update action many times every second, until its IsFinished action returns true.

This program has a button that starts loading a level. A behavior fills the bar by 10 every second until it is full.

First, add a new class to the project named FillBehavior.quorum:

use Libraries.Interface.Behaviors.Behavior
use Libraries.Interface.Controls.ProgressBar

class FillBehavior is Behavior
    ProgressBar bar = undefined
    number timePassed = 0

    action SetProgressBar(ProgressBar bar)
        me:bar = bar
    end

    action Update(number seconds)
        timePassed = timePassed + seconds
        if timePassed >= 1
            timePassed = 0
            bar:SetValue(bar:GetValue() + 10)
        end
    end

    action IsFinished returns boolean
        return bar:GetValue() >= bar:GetMaximum()
    end
end

Then change Main.quorum to this:

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.ProgressBar

class Main is FormBehavior
    action Main
        Form form
        Page page = form:GetMainPage()
        page:SetTitle("Next Level")

        page:AddLabel("Level loading")
        ProgressBar bar = page:AddProgressBar("Level loading")
        bar:SetDescription("Shows how much of the next level has loaded")

        Button start = page:AddButton("Start Loading")
        start:SetDescription("Starts loading the next level")
        start:SetBehavior(me)

        form:Display()
    end

    action Run(BehaviorEvent event)
        Page page = GetPage()
        ProgressBar bar = page:GetProgressBar("Level loading")

        if bar:GetValue() > bar:GetMinimum() and bar:GetValue() < bar:GetMaximum()
            return now
        end

        bar:SetValue(bar:GetMinimum())
        FillBehavior fill
        fill:SetProgressBar(bar)
        bar:AddBehavior(fill)
    end
end

Here is what happens:

  • Main is a FormBehavior, so it can be the button's behavior. Its Run action runs when the button is pressed. GetPage returns the page, and GetProgressBar finds the bar by its name.
  • The if check stops a second press from starting a second fill while the bar is still filling.
  • bar:AddBehavior(fill) starts the fill. From now on, Quorum calls fill:Update many times every second.
  • Update is given seconds, how much time passed since the last call. It is usually a tiny number, like 0.016. The behavior adds it to timePassed. Once a whole second has added up, it moves the bar forward by 10.
  • When the bar is full, IsFinished returns true, and Quorum stops calling Update.

Run the program and press the button with Space or Enter, or click it. The bar fills a little more each second. After ten seconds, it is full. Press the button again to start over.

Moving the bar one step at a time

Many programs move a progress bar after each step of a task, not on a timer. This version moves the bar forward one step each time a button is pressed. When it is full, the next press starts it over.

Change Main.quorum to this:

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.ProgressBar

class Main is FormBehavior
    action Main
        Form form
        Page page = form:GetMainPage()
        page:SetTitle("Quiz")

        page:AddLabel("Questions answered")
        ProgressBar quiz = page:AddProgressBar("Questions answered", 0, 5)
        quiz:SetDescription("Shows how many of the 5 questions are done")

        Button next = page:AddButton("Next Question")
        next:SetDescription("Moves the quiz progress bar forward by one")
        next:SetBehavior(me)

        form:Display()
    end

    action Run(BehaviorEvent event)
        Page page = GetPage()
        ProgressBar quiz = page:GetProgressBar("Questions answered")

        number amount = quiz:GetValue() + 1
        if amount > quiz:GetMaximum()
            amount = quiz:GetMinimum()
        end
        quiz:SetValue(amount)
        output "Question " + amount + " of " + quiz:GetMaximum()
    end
end

Each press moves the bar forward by one fifth, and the output window in Quorum Studio says which question you are on.

Blocks

Progress bars and screen readers

A progress bar can be reached with the Tab key, like a button. A form puts it in the Tab order for you. When it has the focus, a screen reader says its name.

Each time your program calls SetValue, Quorum tells the screen reader that the value changed. You don't have to write any code for this. It happens on its own. Screen readers manage on their own how to deal with these events, even rapid ones. Often, they will skip many of them if they come quickly. Generally, this is expected and normal behavior that you should not try to adjust.

Engage

In this activity, one partner is the designer and the other is the tester, and you adapt a progress bar to show the steps of a real task. The goal is to set a progress bar's range to match a task, to give it a name and description that make sense for that task, and then to improve it from your tester's feedback. The designer picks a task that takes steps, such as baking cookies in 6 steps or a science lab in 4 parts. Then the designer changes the last program on this page so the bar's maximum matches the number of steps, and so the label, the bar and the button have names and descriptions that fit the task.

The tester then goes through every step using only the keyboard (Tab, Space and Enter). If you have a screen reader, the tester turns it on and uses it instead of the screen. The tester tells the designer one thing that was clear and one thing that was confusing. The designer fixes the confusing part, and the tester tries it again to check the fix. Then switch roles with a new task. As a challenge, add a second button named "Start Over" that sets the bar back to its minimum.

Wrap up

A progress bar is a small control, but it changes how a wait feels. When is a progress bar the wrong choice? Think about a task where your program can't know how much work is left. What could it show instead?

Next tutorial: Color Wells