MATLAB Creating Graphical User Interfaces

(ff) #1

  • Component — Specify the UI component that executes the callback.

  • Callback — Specify the callback property. The callback property maps the callback
    function to a specific interaction. Some components have more than one callback
    property available. For example, sliders have two callback properties:
    ValueChangedFcn and ValueChangingFcn. The ValueChangedFcn property
    executes after the user moves the slider and releases the mouse. The
    ValueChangingFcn property for the same component executes repeatedly while
    the user moves the slider.

  • Name — Specify a name for the callback function. App Designer provides a default
    name, but you can change it in the text field. If your app has existing callbacks, the
    Name field has a down-arrow next to it, indicating that you can select an existing
    callback from a list.


Using Callback Function Input Arguments


All callbacks in App Designer have the following input arguments in the function
signature:



  • app — The app object. Use this object to access UI components in the app as well as
    other variables stored as properties.

  • event — An object that contains specific information about the user's interaction with
    the UI component.


The app argument provides the app object to your callback. You can access any
component (and all component-specific properties) within any callback by using this
syntax:


app.Component.Property


For example, this command sets the Value property of a gauge to 50. In this case, the
name of the gauge is PressureGauge.


app.PressureGauge.Value = 50;


The event argument provides an object that has different properties, depending on the
specific callback that is executing. The object properties contain information that is
relevant to the type of interaction that the callback is responding to. For example, the
event argument in a ValueChangingFcn callback of a slider contains a property called
Value. That property stores the slider value as the user moves the thumb (before they
release the mouse). Here is a slider callback function that uses the event argument to
make a gauge track the value of the slider.


Write Callbacks in App Designer
Free download pdf