1 | function 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 | |
---|
7 | width = 200; |
---|
8 | pheightmin = 20; |
---|
9 | pheightmax = 100; |
---|
10 | |
---|
11 | % Create the window and main layout |
---|
12 | fig = figure( 'Name', 'Collapsable GUI', ...' |
---|
13 | 'NumberTitle', 'off', ... |
---|
14 | 'Toolbar', 'none', ... |
---|
15 | 'MenuBar', 'none' ); |
---|
16 | box = uiextras.VBox( 'Parent', fig ); |
---|
17 | |
---|
18 | panel{1} = uiextras.BoxPanel( 'Title', 'Panel 1', 'Parent', box ); |
---|
19 | panel{2} = uiextras.BoxPanel( 'Title', 'Panel 2', 'Parent', box ); |
---|
20 | panel{3} = uiextras.BoxPanel( 'Title', 'Panel 3', 'Parent', box ); |
---|
21 | set( box, 'Sizes', pheightmax*ones(1,3) ); |
---|
22 | |
---|
23 | % Add some contents |
---|
24 | uicontrol( 'Style', 'PushButton', 'String', 'Button 1', 'Parent', panel{1} ); |
---|
25 | uicontrol( 'Style', 'PushButton', 'String', 'Button 2', 'Parent', panel{2} ); |
---|
26 | uicontrol( 'Style', 'PushButton', 'String', 'Button 3', 'Parent', panel{3} ); |
---|
27 | |
---|
28 | % Resize the window |
---|
29 | pos = get( fig, 'Position' ); |
---|
30 | set( fig, 'Position', [pos(1,1:2),width,sum(box.Sizes)] ); |
---|
31 | |
---|
32 | % Hook up the minimize callback |
---|
33 | set( panel{1}, 'MinimizeFcn', {@nMinimize, 1} ); |
---|
34 | set( panel{2}, 'MinimizeFcn', {@nMinimize, 2} ); |
---|
35 | set( 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 | |
---|
55 | end % EOF |
---|