Download this file

141 lines (116 with data), 11.1 kB

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