Tutorials9 min read

Create a Draggable Slider with a Dynamic Number Indicator

Use Variable and Chain to show your slider's dynamically changing value, just like magic!

Abhas Sinha
Abhas Sinha, User Experience Designer @ MicrosoftAugust 30, 2021
Draggable Slider Using Chain Thumbnail

Introduction

Surfacing a slider's value dynamically can add a lot of value and delight when designing quite a lot of experiences. Adjusting the volume, the brightness, or even the speed for text to speech are a few such examples. But that's just the tip of the iceberg — think of a slider for purchasing a storage plan, or the number of pizzas to order, or for reacting to a story on social-media-gram! The implementation can make a lot of experiences easier and more intuitive to use.

But that's not the only thing that's easy — ProtoPie's in-built Chain trigger and access to Variables can help you prototype this experience with just as much delight.

In this lesson, you'll learn how to:

  1. Make the slider's knob draggable
  2. Show a dynamic trail behind the knob using Chain
  3. Make the number indicator move with the knob using Chain
  4. Show the current value of the knob using a Variable

In the end, you'll be able to make something like this!

Draggable Slider Prototype Made With ProtoPie

Step-by-step instructions

1. Make the slider's knob draggable

 1. Select the Knob layer, and in the properties panel, click on Make Editable.

Make the Knob editable

 2. Once you're done, set the Origin to center.

Set the Origin to center

💡 Why did we have to make the layer editable? Wasn't it editable already?

When we import layers from other design tools, such as Figma, or Sketch, some objects are initially imported as images with pre-set values, and not full vector objects. Making such layers editable turns them into vector objects that ProtoPie can offer more functionality with. In this case, we want to make the Knob layer editable so that we can get its true size, and adjust its Origin position.

Once you change the Knob layer to editable, you will notice the size of its bounding box also changes. Earlier, the layer's shadow and fill were baked into the layer as a whole. After you make it editable, you will also be able to adjust its fill value, its shadow value, and because they're not baked in anymore, the size of its bounding box also changes.

💡 Why did we set the Origin to Center?

We want to be able to show the position and add interactions based on the center of the Knob, but the default origin position was set to the top-left corner. Changing it to the center will make it easy for us to find its position when adding interactions as we go forward.

 3. Select the Knob layer, and add a Drag trigger. Click on + and add a Move response to it. Set the move direction to horizontal.

 4. Change the Limit of the Move response from None to Custom Limit. For the custom limit, set Min X to 0, and Max X to 212.

Change the Limit of the Move response from None to Custom Limit

💡 Why "Custom Limit", and why these numbers?

By choosing Custom Limit, we restrict the movement of Knob to specific points on the screen. Without this, the layer could move across the full width of the screen.

For our case, the movement should be restricted to the Track layer. Since the width of Track is 212, we set that as the maximum value Knob can be dragged to. And the minimum value it can be dragged to is 0. These values work because Knob is inside of the Slider container, and 0 and 212 are relative to it.

 5. Select the Knob layer, and from the properties panel, enable Touch Area. Set it to 20 for all sides. We do this to make the layer more touch-friendly since the layer Knob is very small at 20 ✕ 20 by itself. After setting the Touch Area, the touchable area for Knob will become 60 ✕ 60.

Change the touch area

2. Show a dynamic trail behind the knob using Chain

 1. Select the layer Active, and from the properties panel, click on Make Editable. For this case, we want it to be editable so that we can adjust its width.

Make the Active layer editable

 2. Select Knob, and add a Chain trigger. Select Active, and add a Scale response to the same Chain trigger.

 3. Select the Scale response, and for Range1, set the width to 0 at X = 0, and 212 at X = 212.

Add a Chain trigger to the knob

💡 Why these values?

Since Knob can move from X = 0 to X = 212, we use the same values for the X position in Range1. As Knob moves from 0 to 212, the width of Active should match its position which goes from width = 0 to width = 212.

Since we had earlier set the Origin of Knob to be the center, the changes in the width of Active perfectly match the position of Knob.

3. Make the number indicator move with the knob using Chain

 1. Select the container Number and Slider (press Shift and click them in the layers panel to select both), and press Ctrl+G (Cmd+G on a Mac) to group them into a new container.

Give a container to Number and Slider

💡 Why did I have to put them in a new container?

We do this because every object's coordinates are relative to its container. Putting Number in a container that is as wide as Slider will mean that at X = 0, Number will be on the left edge of the container, and at X = 212, it will be at the right edge of the container. As we go forward into moving Number, it will be super easy for us to use these values.

If we didn't make this new container, we would have had to find the X value for Number manually by dragging Number to the left and right edges of Slider.

 2. Select Number and set the Origin to center — for the same reason as we had used the center as the Origin earlier. This will allow us to use the same X values as Knob as we go forward.

Select "Number" and set the Origin to center

 3. Under the Chain trigger for Knob, add a Move response. Make sure the Move response is assigned to the container Number. Assign the following values to Range1 under Move.

Add a move response to Number

💡 Why did I have to assign the Move response to "Number"?

In ProtoPie's Trigger and Response model, we must make sure the right layers are selected for each. In this case, Chain is our trigger, and it is applied to Knob. In Response we want to Move the Number container. Hence, we change the assignment of Move to Number.

💡 Why these values?

Since Knob can move from X = 0 to X = 212, we use those values for the X position in Range1. As Knob moves from 0 to 212, Number should match its position, so we also move Number from X = 0 to X = 212.

Since we have also set the Origin of Number as the center, its movement will line up perfectly with the movement of Knob.

4. Show the current value of the knob using a Variable

 1. Create a new variable — we can choose For All Scenes for this example. Under the Chain trigger, add an Assign response. Select value as the target of the Assign response. Use the following values:

Under the Chain trigger, add an Assign response

💡 Why these values?

Since Knob can move from X = 0 to X = 212, we use those values for the X position in Range1. As Knob moves from 0 to 212, we want to show the value of value going from 0 to 100.

This means that when Knob is at X = 0, Value will be 0, and when Knob is at X = 212, Value will be at 212.

 2. To test if our value assignment is working correctly, click on the bug icon next to the variable to see its live value. Open the Preview window and try dragging — you should be able to see the value changing as you drag. You will notice that you're seeing a value up to two decimal places. Don't worry, we'll address this in step 6.

Check in the preview screen

 3. Press Add Trigger and add a Detect trigger. Assign it to value.

Press Add Trigger and add a Detect trigger

 4. Select the text layer Value, and in the properties panel, click on Make Editable. This will allow us to customize the text.

 5. Under the Detect trigger, click + and add a Text response.

 6. For the Text response, change the content from Text to Formula. Use the formula round(value).

For the Text response, change the content from Text to Formula.

💡 Wait, what did we just do?

We just used the round(source:NUMBER) function. It accepts a number value and returns the number in a rounded format. That means if the number being given to the round() function has decimal values, we will receive a rounded whole number as the output.

  • round(source:NUMBER) → NUMBER

We used the round() function on Value since we noticed in step 3 that we were seeing a decimal value of two places. Our intention with the design is to show whole numbers only, so we use this formula.

That's it!

Awesome work! You've learned how to create a draggable element and give it a custom limit. You've also learned how to use Chain to control the movement, width, and dynamic number value of different elements! That's quite a lot, but that's not all — you've also learned how to round a numerical value to a whole number and assign it to a text layer dynamically!

Continue experimenting with these methods in ProtoPie, and create even more realistic experiences. We would love to see your crazy experiments. Create your own prototype and share it on Twitter or Instagram with #MadeWithProtoPie