scroll(testCase,comp,direction)
performs a scroll gesture, such as a scroll wheel movement, with the pointer located at the
center of the specified component comp. The method mimics a user
scrolling in the specified direction.
Test a vertical scroll gesture on axes whose background color changes based on the scroll direction.
Create a UI figure with axes whose background color changes based on the direction of a vertical scroll. To program the axes behavior, create a window scroll wheel callback for the figure by specifying its WindowScrollWheelFcn callback property. See the code of the callback function changeColor, which is used to change the axes background color based on the scroll direction, at the end of this example.
Test a scroll gesture on the axes in the down direction. The gesture executes the window scroll wheel callback, which sets the axes background color based on the scroll direction.
testCase.scroll(ax,"down")
Test if the axes background color is now green, or [0 1 0]. The test passes.
testCase.verifyEqual(ax.Color,[0 1 0])
Verification passed.
Callback Function
This code shows the callback function used in this example. The function queries the VerticalScrollCount property of event to identify the scroll direction.
function changeColor(src,event)
if event.VerticalScrollCount < 0 % scrolling up
src.Children.Color = "red";
elseif event.VerticalScrollCount > 0 % scrolling down
src.Children.Color = "green";
endend
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window.
Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.