Dynamic Visibility
Dynamic visibility is a fundamental capability of Squirrel that allows your project to show and hide components in response to user interactions and/or data conditions. Use dynamic visibility to show a pop-up information screen, hide a component until it is required, show and hide objects in timed sequences, switch between different visual representations of data and many other different scenarios besides.
Each component that can be added to the canvas has dynamic visibility properties that are configured in exactly the same way. The component will be visible when the content of the Status property field is equal to the content of the Value property field. Leaving both property fields empty will ensure that the component is always visible as the Status and Value property fields are equally empty.
Both dynamic visibility property fields can be bound to cells in the spreadsheet, and by using spreadsheet logic, the visibility of objects can be changed dynamically according to this comparison between the Status and Value properties.
The following are three tutorials that describe different ways to use dynamic visibility. Each tutorial section has a video showing one example that you can watch, or you can follow along using a different example in the step-by-step instructions if you prefer.
Dynamic Visibility the Basics
Step-by-step:
- Add a component to your canvas and make sure that it is selected. In the properties panel expand the DYNAMIC VISIBILITY section.
- Set the Status by clicking on the Bind Data icon above the Status field:
- Select a single empty cell in the Spreadsheet and click the Confirm button.
- Next, set the Value property by entering a word or number you wish to use into the Value input field. The value can be anything:
-
- Boolean value
- Word
- Number
- Phrase
-
- The component will compare the contents of the cell bound to the Status property to see if it matches the Value property.
- Enter Debug mode by clicking the DEBUG button.
The component will not be visible because the empty cell bound to the Status property is not equal to the Value entered in the property field.
- Change back to Design mode.
- In the spreadsheet, select the cell that you bound to the Status property and enter the exact value as you entered into the Value property.
- Enter Debug mode again.
This time the component remains visible because the Status property and the Value property are equal.
This is the simplest demonstration of Dynamic Visibility; but we can take this basic concept much further and start to configure component visibility based on user and data driven interaction i.e. show a component based on a user’s selection, or show a component once a data value reaches a specified threshold.
Dynamic Visibility using Data Insertion
Step-by-step:
- For this example, you’ll need two components: a control component and a display component. Add a Radio Button component and a Text Label component to the canvas.
- Open the Spreadsheet and add the number 1 into cell A1, 2 into A2 and 3 into A3.
- Set the Radio Button component properties:
-
- Properties Panel > GENERAL > List Items > bind to cells A1, A2 and A3 (click on cell A1 and drag the mouse until the selection also includes cells A2 and A3)
- Properties Panel > DATA INSERTION > Series 1 > Type > Label > Destination > bind to C2
- Select the Text Label component:
-
- Properties Panel > LABEL TEXT > Add some text to the label e.g. “Now you see me…” or “BOO!”
- Properties Panel > DYNAMIC VISIBILITY > Status, bind to C2.
- Properties Panel > DYNAMIC VISIBILITY > Value field > input the number 2.
- Enter debug mode by clicking the DEBUG button.
- Interact with the Radio Button component. Note that the Text Label is only visible when option 2 of the radio button component is selected (when the value of C2 is equal to 2).
Dynamic Visibility using Formulas
Step-by-step:
- For this example you’ll need two components: a control component and a display component. Add a Slider component and a Text Label component to the canvas.
- Select the Slider component:
-
- Properties Panel > GENERAL > Value field bind to A1.
- Open the Spreadsheet and select cell B1. Enter the following formula:
- Select the Text Label component:
-
- Properties Panel > LABEL TEXT > Text To Display amend to LOW STOCK!
- Properties Panel > TEXT STYLING > amend the properties of the text field to make it look like a warning label.
- Properties Panel > DYNAMIC VISIBILITY > Status field bind to B1.
- Properties Panel > DYNAMIC VISIBILITY > Type 1 into the Value field.
- Enter Debug mode by clicking the Debug button.
- Interact with the Slider control, as the slider moves above 75, the LOW STOCK! warning Text Label will display.
That’s the end of this tutorial on Dynamic Visibility. Hopefully you’ve been inspired to try it out in some of your projects. If you’ve done something fabulous using Dynamic Visibility, do get in touch; we love seeing how ingenious Squirrel creators can be!