Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can achieve interrupt play by setting the <code>Enable</code> property of your slider to <code>off</code> or <code>inactive</code> when you press your play button and using a <code>ButtonDownFcn</code> function that stops play and sets <code>Enable</code> back to <code>on</code>.</p> <p>Using a <code>togglebutton</code> as my play button (other control widgets should work as long as you can save a boolean flag somewhere accessible), I used the following as <code>Callback</code> for the button:</p> <pre><code>function playcallback(toggle_button, ~, slider_) set(slider_, 'Enable', 'inactive'); %slider is disabled while get(toggle_button, 'Value') %Value is used as flag for playing current_value = get(slider_, 'Value'); set(slider_, 'Value', rem(current_value + 0.01, 1)); %shift slider (looping) pause(1/50); end set(slider_, 'Enable', 'on'); %done playing, turn slider back on end </code></pre> <p>And the following as <code>ButtonDownFcn</code> for the slider:</p> <pre><code>function stopslide(~, ~, toggle_button) %play flag off: in playcallback, the while loop stops, %the slider is enabled and the playcallback function returns set(toggle_button, 'Value', 0); end </code></pre> <p>You can register these callbacks like this:</p> <pre><code>set(toggle_button_handle, 'Callback', {@playcallback, slider_handle}); set(slider_handle, 'ButtonDownFcn', {@stopslide, toggle_button_handle}); </code></pre> <p>Caveat: if you start adding other widgets interacting with the slider/play button in a similar manner to this, you increase your chance of introducing race conditions.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload