source: MML/trunk/machine/SOLEIL/common/toolbox/GUILayout/layoutHelp/Examples/minimizeexample.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.9 KB
Line 
1function minimizeexample()
2%MINIMIZEEXAMPLE: An example of using the panelbox minimize/maximize
3
4%   Copyright 2007-2009 The MathWorks Ltd.
5%   1.1    2012/05/08 08:03:00
6
7width = 200;
8pheightmin = 20;
9pheightmax = 100;
10
11% Create the window and main layout
12fig = figure( 'Name', 'Collapsable GUI', ...'
13    'NumberTitle', 'off', ...
14    'Toolbar', 'none', ...
15    'MenuBar', 'none' );
16box = uiextras.VBox( 'Parent', fig );
17
18panel{1} = uiextras.BoxPanel( 'Title', 'Panel 1', 'Parent', box );
19panel{2} = uiextras.BoxPanel( 'Title', 'Panel 2', 'Parent', box );
20panel{3} = uiextras.BoxPanel( 'Title', 'Panel 3', 'Parent', box );
21set( box, 'Sizes', pheightmax*ones(1,3) );
22
23% Add some contents
24uicontrol( 'Style', 'PushButton', 'String', 'Button 1', 'Parent', panel{1} );
25uicontrol( 'Style', 'PushButton', 'String', 'Button 2', 'Parent', panel{2} );
26uicontrol( 'Style', 'PushButton', 'String', 'Button 3', 'Parent', panel{3} );
27
28% Resize the window
29pos = get( fig, 'Position' );
30set( fig, 'Position', [pos(1,1:2),width,sum(box.Sizes)] );
31
32% Hook up the minimize callback
33set( panel{1}, 'MinimizeFcn', {@nMinimize, 1} );
34set( panel{2}, 'MinimizeFcn', {@nMinimize, 2} );
35set( panel{3}, 'MinimizeFcn', {@nMinimize, 3} );
36
37%-------------------------------------------------------------------------%
38    function nMinimize( eventSource, eventData, whichpanel ) %#ok<INUSL>
39        % A panel has been maximized/minimized
40        s = get( box, 'Sizes' );
41        pos = get( fig, 'Position' );
42        panel{whichpanel}.IsMinimized = ~panel{whichpanel}.IsMinimized;
43        if panel{whichpanel}.IsMinimized
44            s(whichpanel) = pheightmin;
45        else
46            s(whichpanel) = pheightmax;
47        end
48        set( box, 'Sizes', s );
49       
50        % Resize the figure, keeping the top stationary
51        delta_height = pos(1,4) - sum( box.Sizes );
52        set( fig, 'Position', pos(1,:) + [0 delta_height 0 -delta_height] );
53    end % nMinimize
54
55end % EOF
Note: See TracBrowser for help on using the repository browser.