source: MML/trunk/machine/SOLEIL/common/toolbox/GUILayout/layoutHelp/Examples/callbackexample.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 1.0 KB
Line 
1function callbackexample()
2
3% Create application data
4colorNames = {
5    'Red'
6    'Orange'
7    'Yellow'
8    'Green'
9    'Blue'
10    'Indigo'
11    'Violet'
12    };
13colorValues = [
14    1.0 0.2 0.2
15    1.0 0.6 0.2
16    1.0 1.0 0.4
17    0.6 1.0 0.6
18    0.2 0.4 1.0
19    0.4 0.1 0.6
20    0.7 0.5 1.0
21    ];
22
23% Layout the interface
24f = figure();
25p = uiextras.Panel( 'Parent', f, 'Title', 'A Panel', 'TitlePosition', 'CenterTop');
26b = uiextras.HBoxFlex( 'Parent', p, 'Spacing', 5, 'Padding', 5  );
27hList = uicontrol( 'Style', 'listbox', 'Parent', b, ...
28    'String', colorNames, ...
29    'Back', 'w' );
30hButton = uicontrol( 'Parent', b, ...
31    'Background', colorValues(1,:), ...
32    'String', colorNames{1} );
33set( b, 'Sizes', [-1 -3] );
34
35% Add user interactions
36set( hList, 'Callback', @onChangeColor );
37
38
39    function onChangeColor( source, ~ )
40        idx = get( source, 'Value' );
41        set( hButton, 'Background', colorValues(idx,:), 'String', colorNames{idx} )
42    end % onChangeColor
43
44
45end % main
Note: See TracBrowser for help on using the repository browser.