Toggle

A toggle is a type of button that can be used for binary options (true/false, on/off, etc). At this time they do not automatically include text, so you will have to make it clear what option is being toggled using labels or paragraphs. Take a look at the Scripting Reference post for information on using the toggle button to interact with other elements in your app. 

Example 1

This example uses a toggle to turn a simulation on and off.

You can copy this example into your document as-is.

<sectionNoTitle name="sectionName">

  <p>Simulation</p>
  
  <toggle name="myToggle">
    <onValueChanged>
      if myToggle.Value then  -- If the value of my toggle is 'true'
      sim:Start()
      else                    -- If the value of my toggle is 'false'
      sim:Stop()
     end
    </onValueChanged>
  </toggle>

  <timePlot name="simPlot" />

  <simulation duration="10" name="sim" period="0.01">
    <solver>
      <series>
        <sine />
        <probe ref="sectionName.simPlot" />
      </series>
    </solver>
  </simulation>
</sectionNoTitle>  

Example 2

You can use a table with the grid lines turned off to make it clear what the toggle options are.

You can copy this example into your document as-is.

<section name="sectionName">
  <title>Simulation</title>

  <table name="toggleTable" grid="false" widths="40% 20% 40%">
    <row>
      <column>
        <p style="rightText">Off</p>
      </column>
      <column>
        <toggle name="thisToggle" style="center" onValueChanged="if thisToggle.Value then sim:Start() else sim:Stop() end" />
      </column>
      <column>
        <p>On</p>
      </column>
    </row>
  </table>

  <timePlot name="simPlot" />

  <simulation duration="10" name="sim" period="0.01">
    <solver>
      <series>
        <sine />
        <probe ref="sectionName.simPlot" />
      </series>
    </solver>
  </simulation>
</section>
 
Simulation-Toggle-Off.png
Simulation-Toggle-On.png