📄 136.html
字号:
<HTML><TITLE>Geometry Management: The Cavity</TITLE><BODY BGCOLOR="#FFF0E0" VLINK="#0FBD0F" TEXT="#101000" LINK="#0F0FDD">
<A NAME="top"><H1>The Cavity</H1></A>
<P> When the root window first appears, it seems to be a hole with nothing in
it. When viewed from <TT>pack</TT>, this hole is called the
<CITE><NAME=#G13.6cavity>cavity</A></CITE>. A cavity is a place where you can put a slicing.
Any frame and any Tk window, other than the command window, has a cavity.
<P> According to the cavity paradigm, each newly packed widget goes into a
cavity. The size of a cavity is not fixed – it varies as the window is
resized. When you pack another widget into a cavity you are placing it on one
side of that cavity. The <TT>-side</TT> option, whose values are "top,"
"bottom," "left" and "right," is used to determine which side. The
widget occupies a slice that fills the whole side of the cavity that was
current when it was created. With the creation of a new slice, the new cavity
is the old cavity minus this slice.
<P> Although the cavity paradigm is simple and flexible, it is confusing to use.
Look at Figure 13.6a and try to do the following: Point to the cavity or
cavities. Explain why the grey box on the left is not centered vertically.
Explain what will happen when a user expands the window.
<P><CENTER><TABLE BORDER>
<CAPTION><ADDR>Figure 13.6a: A use of the cavity paradigm.</ADDR></CAPTION>
<TR ALIGN=center><TD><IMG SRC="F13x6a.JPG" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Figs/F13x6a.JPG">
</TD></TR>
<TR><TD><PRE>pack [box . grey50] -expand true
pack [box . grey50] -side left
pack [frame .fr] -side bottom -expand true -fill both
pack [box . black] -side left
pack [box . white] -side right
pack [box .fr black] -side right
pack [box .fr white] -side right </PRE></TD></TR>
</TABLE></CENTER><P>
<P> The cavity paradigm is not easy to master and does not encourage windows
that are intellectually manageable. The slicing paradigm, on the other hand,
has both these pleasant properties. Unfortunately, the slicing paradigm
requires extra frames if it is to accomplish as much as the cavity paradigm.
This section suggests a blending of the two that gives you the flexibility of
the cavity paradigm while encouraging you to think in terms of slices.
<P> In this blended paradigm every slice goes into some cavity as described
above. The difference is that you think of cavities in terms of slicings.
Each slicing may have an <CITE><NAME=#G13.6ttchdcvty>attached cavity</A></CITE> which is where an
additional slice, if any, will be positioned.
<P> Horizontal slicings are not created with just <TT>-side top</TT> (the default)
but also with <TT>-side bottom</TT>. Whenever <TT>-side top</TT> is used, the
newly created slice is on the top of the attached cavity of the new slicing.
Whenever <TT>-side bottom</TT> is used, the newly created slice is on the
bottom of the attached cavity of the new slicing. Each additional slice goes
into the attached cavity of the previous version of the slicing.
<P> For vertical slicings the situation is similar. They are created with the
"left" and "right" values of the <TT>-side</TT> option. Whenever
<TT>-side left</TT> is used, the newly created slice is on the left of the
attached cavity of the new slicing. Whenever <TT>-side right</TT> is used,
the newly created slice is on the right of the attached cavity of the new
slicing. Each additional slice goes into the attached cavity of the previous
version of the slicing.
<P> If a vertical slice is put into the attached cavity of a horizontal slicing,
the horizontal slicing becomes <CITE>complete</CITE> and its attached cavity is lost.
If a horizontal slice is put into the attached cavity of a vertical slicing,
the vertical slicing becomes <CITE>complete</CITE> and its attached cavity is lost.
<P> <P><A NAME="13.6a">
<STRONG>Exercise 13.6a</STRONG> </A><DL><DD>
Place comments in the script for Figure 13.6a that describe
each slicing. After you understand the slicings explain what the
window will do when the user expands it. Your explanation should involve
attached cavities as well as slices that expand or stretch in their
lengthwise direction.
<P> <P>
<A HREF="13.9.html#Sol13.6a" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/13.9.html#Sol13.6a">Solution</A></DL>
<P> The solution to this exercise is certainly easier to fathom than the same
code as it shown in Figure 13.6a. However, a greater benefit of thinking in
terms of slicings may
be that you are more likely to pack your windows in ways that can
be more easily described. "More easily described" implies "more easily
understood."
<P><A NAME="13.6b">
<STRONG>Exercise 13.6b</STRONG> </A><DL><DD>
Redo Exercise
<A HREF="13.3.html#13.3d" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/13.3.html#13.3d">13.3d</A> but this time begin with a
slicing in the opposite direction from your original solution. Also do not
create two slices for this original slicing. Complete the first slicing at
one slice by slicing in the other direction. Your solution will, therefore,
have one fewer invisible frames. <P>
<A HREF="13.9.html#Sol13.6b" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/13.9.html#Sol13.6b">Solution</A></DL>
<!-- Linkbar -->
<P><CENTER><FONT SIZE=2><NOBR>
<STRONG>From</STRONG>
<A HREF="javascript:if(confirm('http://www.mapfree.com/sbf/tcl/book/home.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.mapfree.com/sbf/tcl/book/home.html'" tppabs="http://www.mapfree.com/sbf/tcl/book/home.html">Tcl/Tk For Programmers</A><WBR>
<STRONG>Previous</STRONG>
<A HREF="13.5.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/13.5.html">section</A><WBR>
<STRONG>Next</STRONG>
<A HREF="13.7.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/13.7.html">section</A><WBR>
<STRONG>All</STRONG>
<A HREF="13.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/13.html">sections</A><WBR>
<STRONG>Author</STRONG>
<A HREF="javascript:if(confirm('http://www.mapfree.com/mp/jaz/home.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.mapfree.com/mp/jaz/home.html'" tppabs="http://www.mapfree.com/mp/jaz/home.html">J. A. Zimmer</A><WBR>
<STRONG>Copyright</STRONG>
<A HREF="copyright.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/copyright.html">Notice</A><WBR>
<P>
<I>Jun 17, 1998</I>
</NOBR></FONT></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -