source: MML/trunk/machine/SOLEIL/common/toolbox/GUILayout/layoutHelp/User guide5_2.html @ 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: 11.0 KB
Line 
1<html xmlns:saxon="http://icl.com/saxon">
2   <head>
3      <link rel="stylesheet" type="text/css" href="doc.css"/>
4      <link rel="stylesheet" type="text/css" href=""/>
5      <meta author="The MathWorks Ltd."/>
6      <meta copyright="2011 The MathWorks Ltd."/>
7      <title>Minimize and maximize</title>
8   </head>
9
10   
11    <body>
12      <table class="header" width="100%" border="0" cellspacing="0" cellpadding="0">
13         <tr>
14            <td bgcolor="#e4f0f8"><A href="User guide.html"><font face="Arial" bgcolor="#e4f0f8" size="+0" underline="0" color="#000000"><b>User guide</b></font></A></td>
15            <td width="36" bgcolor="#e4f0f8"><A HREF="User guide5_1.html"><IMG SRC="Images/leftarrow.png" BORDER="0" ALT="previous page"/></A><A HREF="User guide5_3.html"><IMG SRC="Images/rightarrow.png" BORDER="0" ALT="next page"/></A></td>
16         </tr>
17      </table>
18   
19
20      <br clear="all"/>
21         
22      <h2>5.2: Minimize and maximize&nbsp;<a href="User guide5.html"><img src="Images/uparrow.png" border="0" align="top" alt="Go back up one level"/></a></h2>
23     
24        <p>
25            When a <a href="uiextras.BoxPanel.html"><code class="FUNCTION">uiextras.BoxPanel</code></a> has its "MinimizeFcn"
26            filled in, a minimize/maximize button (<img src="Images/panelMinimize.png"/> / <img src="Images/panelMaximize.png"/>) is shown in the upper-right of the
27            title-bar. When the user clicks this button the specified function
28            is called. Since the behaviour of the parent container is
29            different in different use-cases, it is up to the user to write
30            some code to actually resize the panel. Note that minimizing
31            a panel to its title-bar only really makes sense inside a
32            <a href="uiextras.VBox.html"><code class="FUNCTION">uiextras.VBox</code></a> or <a href="uiextras.VBoxFlex.html"><code class="FUNCTION">uiextras.VBoxFlex</code></a>.
33                 </p>
34                 <p>The following simple example shows how to add minimize/maximize
35                     functionality to a box full of panels. Save the code into
36                 a file called "dockexample.m" to run it.</p>
37                 
38                 <p>(The code for this example can be found here:
39                     [ <a href="Examples/minimizeexample.m">view</a>
40                     | <a href="matlab: edit(fullfile(layoutRoot,'layoutHelp','Examples','minimizeexample.m'))">edit</a>
41                     | <a href="matlab: p=pwd();cd(fullfile(layoutRoot,'layoutHelp','Examples')); minimizeexample; cd(p)">run</a> ]
42                 )</p>
43                 
44                 
45                 <h4>Create the layout with three panels</h4>
46            <p>Open a new figure window and add three panels.</p>
47            <example><pre style="background-color: #eeeeff; margin-left: 20px; margin-right: 20px"><font color="#000011"><a href="matlab:doc function"><code class="FUNCTION">function</code></a> minimizeexample()
48width = 200;
49pheightmin = 20;
50pheightmax = 100;
51
52<code class="COMMENT">% Create the window and main layout</code>
53fig = <a href="matlab:doc figure"><code class="FUNCTION">figure</code></a>( <code class="STRING">'Name'</code>, <code class="STRING">'Collapsable GUI example'</code>, ...
54              <code class="STRING">'NumberTitle'</code>, <code class="STRING">'off'</code>, ...
55              <code class="STRING">'Toolbar'</code>, <code class="STRING">'none'</code>, ...
56              <code class="STRING">'MenuBar'</code>, <code class="STRING">'none'</code> );
57box = <a href="uiextras.VBox.html"><code class="FUNCTION">uiextras.VBox</code></a>( 'Parent', fig );
58
59panel{1} = <a href="uiextras.BoxPanel.html"><code class="FUNCTION">uiextras.BoxPanel</code></a>( <code class="STRING">'Title'</code>, <code class="STRING">'Panel 1'</code>, <code class="STRING">'Parent'</code>, box );
60panel{2} = <a href="uiextras.BoxPanel.html"><code class="FUNCTION">uiextras.BoxPanel</code></a>( <code class="STRING">'Title'</code>, <code class="STRING">'Panel 2'</code>, <code class="STRING">'Parent'</code>, box );
61panel{3} = <a href="uiextras.BoxPanel.html"><code class="FUNCTION">uiextras.BoxPanel</code></a>( <code class="STRING">'Title'</code>, <code class="STRING">'Panel 3'</code>, <code class="STRING">'Parent'</code>, box );
62<a href="matlab:doc set"><code class="FUNCTION">set</code></a>( box, 'Sizes', pheightmax*ones(1,3) );
63
64<code class="COMMENT">% Add some contents</code>.
65<a href="matlab:doc uicontrol"><code class="FUNCTION">uicontrol</code></a>( <code class="STRING">'Style'</code>, <code class="STRING">'PushButton'</code>, <code class="STRING">'String'</code>, <code class="STRING">'Button 1'</code>, <code class="STRING">'Parent'</code>, panel{1} );
66<a href="matlab:doc uicontrol"><code class="FUNCTION">uicontrol</code></a>( <code class="STRING">'Style'</code>, <code class="STRING">'PushButton'</code>, <code class="STRING">'String'</code>, <code class="STRING">'Button 2'</code>, <code class="STRING">'Parent'</code>, panel{2} );
67<a href="matlab:doc uicontrol"><code class="FUNCTION">uicontrol</code></a>( <code class="STRING">'Style'</code>, <code class="STRING">'PushButton'</code>, <code class="STRING">'String'</code>, <code class="STRING">'Button 3'</code>, <code class="STRING">'Parent'</code>, panel{3} );
68
69<code class="COMMENT">% Resize the window</code>
70pos = <a href="matlab:doc get"><code class="FUNCTION">get</code></a>( fig, <code class="STRING">'Position'</code> );
71<a href="matlab:doc set"><code class="FUNCTION">set</code></a>( fig, <code class="STRING">'Position'</code>, [pos(1,1:2),width,sum(box.Sizes)] );</font></pre>
72            <p style="background-color: #ddddee; margin-left: 20px; margin-right: 20px"><font color="#000022"><center><img src="Images/BoxPanelMinimizeExample1.png"/></center></font></p>
73        </example>
74       
75            <h4>Add the minimize/maximize callback</h4>
76            <p>We set each panel to call the same minimize/maximize function.
77        This function is nested inside the main function so that it has access
78    to the main function's variables. A better way to do this is to make the
79main function into a class, but this nested-function approach is fine
80for simple applications.</p>
81            <p>Note that as soon as we set the "MinimizeFcn" property the minimize/maximize
82                icon appears in the top-right of each panel. We use a cell-array to pass an
83            extra argument, the panel number, to the minimize function. This extra argument appears after the usual
84            <code>eventSource</code> and <code>eventData</code> arguments.</p>
85            <example><pre style="background-color: #eeeeff; margin-left: 20px; margin-right: 20px"><font color="#000011"><code class="COMMENT">% Hook up the minimize callback</code>.
86<a href="matlab:doc set"><code class="FUNCTION">set</code></a>( panel{1}, <code class="STRING">'MinimizeFcn'</code>, {@nMinimize, 1} );
87<a href="matlab:doc set"><code class="FUNCTION">set</code></a>( panel{2}, <code class="STRING">'MinimizeFcn'</code>, {@nMinimize, 2} );
88<a href="matlab:doc set"><code class="FUNCTION">set</code></a>( panel{3}, <code class="STRING">'MinimizeFcn'</code>, {@nMinimize, 3} );
89
90<code class="COMMENT">%-------------------------------------------------------------------------%</code><br/> 
91    <a href="matlab:doc function"><code class="FUNCTION">function</code></a> nMinimize( eventSource, eventData, whichpanel )
92        <code class="COMMENT">% A panel has been maximized/minimized</code>
93        s = <a href="matlab:doc get"><code class="FUNCTION">get</code></a>( box, <code class="STRING">'Sizes'</code> );
94        pos = <a href="matlab:doc get"><code class="FUNCTION">get</code></a>( fig, <code class="STRING">'Position'</code> );
95        panel{whichpanel}.IsMinimized = ~panel{whichpanel}.IsMinimized;
96        <a href="matlab:doc if"><code class="FUNCTION">if</code></a> panel{whichpanel}.IsMinimized
97            s(whichpanel) = pheightmin;
98        <a href="matlab:doc else"><code class="FUNCTION">else</code></a>
99            s(whichpanel) = pheightmax;
100        <a href="matlab:doc end"><code class="FUNCTION">end</code></a>&nbsp;
101        <a href="matlab:doc set"><code class="FUNCTION">set</code></a>( box, <code class="STRING">'Sizes'</code>, s );
102       
103        <code class="COMMENT">% Resize the figure, keeping the top stationary</code>
104        delta_height = pos(1,4) - <a href="matlab:doc sum"><code class="FUNCTION">sum</code></a>( box.Sizes );
105        <a href="matlab:doc set"><code class="FUNCTION">set</code></a>( fig, <code class="STRING">'Position'</code>, pos(1,:) + [0 delta_height 0 -delta_height] );
106    <a href="matlab:doc end"><code class="FUNCTION">end</code></a>&nbsp;<code class="COMMENT">% Minimize</code>&nbsp;
107
108<a href="matlab:doc end"><code class="FUNCTION">end</code></a>&nbsp;<code class="COMMENT">% Main function</code></font></pre>
109            <p style="background-color: #ddddee; margin-left: 20px; margin-right: 20px"><font color="#000022"><center><img src="Images/BoxPanelMinimizeExample2.png"/></center></font></p>
110        </example>
111       
112   
113            <h4>Click the minimize buttons</h4>
114            <p>Minimizing the middle panel causes it to shrink to just its
115            title-bar and the window shrinks accordingly. The
116    "Minimize" icon is replaced by a "Maximise" icon.</p>
117            <example><p style="background-color: #ddddee; margin-left: 20px; margin-right: 20px"><font color="#000022"><center><img src="Images/BoxPanelMinimizeExample3.png"/></center></font></p></example>
118            <p> Re-maximizing the panel would
119            cause it to re-appear in full and the window to grow again.</p>
120
121       
122     
123      <br clear="ALL"/>
124      <table class="footer" width="100%" border="0" cellspacing="0" cellpadding="0">
125         <tr>
126            <td width="18" height="15" bgcolor="#e4f0f8" align="left"><a href="User guide5_1.html"><img src="images/leftarrow.png" border="0" alt="previous page"/></a></td>
127            <td width="40%" height="15" bgcolor="#e4f0f8" align="left"><a href="User guide5_1.html"><font face="arial" bgcolor="#e4f0f8" size="normal" underline="0" color="#000000">Context help</font></a></td>
128            <td width="20%" height="15" bgcolor="#e4f0f8" align="center"><a href="index.html"><font face="arial" bgcolor="#e4f0f8" size="normal" underline="0" color="#000000">[Top]</font></a></td>
129            <td width="40%" height="15" bgcolor="#e4f0f8" align="right"><a href="User guide5_3.html"><font face="arial" bgcolor="#e4f0f8" size="normal" underline="0" color="#000000">Dock and undock</font></a></td>
130            <td width="18" height="15" bgcolor="#e4f0f8" align="right"><a href="User guide5_3.html"><img src="images/rightarrow.png" border="0" alt="next page"/></a></td>
131         </tr>
132      </table>
133      <font face="Arial" bgcolor="#e4f0f8" size="normal" underline="0" color="#000000">&copy; 2011 The MathWorks Ltd</font>
134      <TT>&#149; </TT><a href="matlab: helpview([matlabroot,'/license.txt'])">Terms of Use</a>
135      <TT>&#149; </TT><a href="matlab: helpview([matlabroot,'/patents.txt'])">Patents</a>
136      <TT>&#149; </TT><a href="matlab: helpview([matlabroot,'/trademarks.txt'])">Trademarks</a>
137   
138   </body>
139</html>
140       
Note: See TracBrowser for help on using the repository browser.