📄 133.html
字号:
<HTML><TITLE>Geometry Management: Slicing for Size Changes</TITLE><BODY BGCOLOR="#FFF0E0" VLINK="#0FBD0F" TEXT="#101000" LINK="#0F0FDD">
<A NAME="top"><H1>Slicing for Size Changes</H1></A>
<P> Figure 13.3a shows what Figure 13.2a would look like after the user has
resized the root window with the mouse. The window is larger. Although you
cannot see it, the horizontal slices are wider. The boxes are the same size.
This is default behavior. There are two options that change it.
<P><CENTER><TABLE BORDER>
<CAPTION><ADDR>Figure 13.3a: Figure 13.2a resized.</ADDR></CAPTION>
<TR ALIGN=center><TD><IMG SRC="F13x3a.JPG" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Figs/F13x3a.JPG">
</TD></TR>
</TABLE></CENTER><P>
<P> By default, horizontal slices grow or shrink horizontally to fit the space
available to them. Vertical slices grow or shrink vertically. The widgets
associated with them do not grow or shrink. If their slices become too small
for them, they will be truncated. To make widgets grow with their slices, use
<TT><NAME=#S13.3fillpack>-fill</A> both</TT>. The middle slice in Figure 13.2b is packed the
same way as in Figure 13.2a. The first slice is packed with <TT>-fill both</TT>.
You can see the difference.
<P><CENTER><TABLE BORDER>
<CAPTION><ADDR>Figure 13.3b: Controlling widget resizing.</ADDR></CAPTION>
<TR ALIGN=center><TD><IMG SRC="F13x3b.JPG" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Figs/F13x3b.JPG">
</TD></TR>
<TR><TD><PRE>pack [box . white h] -fill both
pack [box . grey50 h]
pack [box . black h] -expand true -fill both </PRE></TD></TR>
</TABLE></CENTER><P>
<P> In Figure 13.3a, the space under the rectangles belongs to no slice.
This is because, by default, horizontal slices do not expand vertically. To
make horizontal or vertical slices expand in <CITE>both</CITE> directions, use
<TT><NAME=#S13.3expandpack>-expand</A> true</TT>. In Figure 13.3b, <TT>-expand true</TT> has been
used with the black slice. So that the black frame will fill the entire
expanded slice, the <TT>-fill both</TT> option is used as well.
<P> In Figure 13.3b, the slices have expanded because the user resized the window.
That is not the only way to make a slice larger than necessary to accommodate
its associated widget. The same effect as you see in Figure 13.3b could be
obtained by creating a larger black box while leaving the white and grey boxes
the same. Then the window would be expanded to accommodate the black back and
the slices for the white and grey boxes would need to expand accordingly.
Because of the way it is packed, the white box would fill its slice.
<P> Figure 13.3c is like Figure 13.3b but the middle slice is configured to
expand vertically as well as horizontally. When multiple slices
expand in the same space, <TT>pack</TT> allocates space between them in a way
that is roughly proportional to their sizes.
<P><CENTER><TABLE BORDER>
<CAPTION><ADDR>Figure 13.3c: Using <TT>-fill</TT> options.</ADDR></CAPTION>
<TR ALIGN=center><TD><IMG SRC="F13x3c.JPG" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Figs/F13x3c.JPG">
</TD></TR>
<TR><TD><PRE>pack [box . white h] -fill both
pack [box . grey50 h] -expand true
pack [box . black h] -expand true -fill both </PRE></TD></TR>
</TABLE></CENTER><P>
<P> <STRONG>Summary</STRONG> <DL><DD>
<P> <UL>
<P> <P><LI> Widgets are associated with slices when they are packed.
<P> <P><LI> Use <TT>-fill both</TT> to make a widget fill its slice at
all times.
<P> <P><LI> Vertical slices expand vertically. Horizontal slices expand
horizontally. Use <TT>-expand true</TT> to make any slice expand in
both directions.
<P> <P><LI> Remember that invisible frames whose purpose is to contain other
slicings are governed by the same principles. Use both <TT>-fill both</TT> and
<TT>-expand true</TT> when packing them unless you have a good reason not to.
</UL> </DL>
<P> <P><A NAME="13.3a">
<STRONG>Exercise 13.3a</STRONG> </A><DL><DD>
Make these two vertical slices:
<PRE>
pack [frame .f1] -side left
pack [frame .f2] -side left
</PRE>
Continue by slicing each vertical slice horizontally with two colored
boxes. Try it a couple of different ways to see the effects of different
uses of <TT>-fill both</TT> and <TT>-expand true</TT> on both the horizontal
and the vertical slices.
<P>
<A HREF="13.9.html#Sol13.3a" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/13.9.html#Sol13.3a">Solution</A></DL>
<P> <P><A NAME="13.3b">
<STRONG>Exercise 13.3b</STRONG> </A><DL><DD>
Write a script that slices the root window into three
colored boxes and two padding frames arranged in a horizontal line. The
frames appear between the boxes and expand to keep the boxes equally apart
from each other – you can give them an initial width or not as you
like. <P>
<A HREF="13.9.html#Sol13.3b" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/13.9.html#Sol13.3b">Solution</A></DL>
<P> <P><A NAME="13.3c">
<STRONG>Exercise 13.3c</STRONG> </A><DL><DD>
Pack a 1 centimeter square red box in such a way that it stays
centered in the root window as the user expands and contracts it. So long as
the root window is big enough, the square should stay the same size. <P>
<A HREF="13.9.html#Sol13.3c" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/13.9.html#Sol13.3c">Solution</A></DL>
<P><CENTER><TABLE BORDER>
<CAPTION><ADDR>Figure 13.3d: Exercise 13.3d.</ADDR></CAPTION>
<TR ALIGN=center><TD><IMG SRC="F13x3d.JPG" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Figs/F13x3d.JPG">
</TD></TR>
</TABLE></CENTER><P>
<P> <P><A NAME="13.3d">
<STRONG>Exercise 13.3d</STRONG> </A><DL><DD>
Write a script to produce the pattern of white, grey, and
black frames shown in Figure 13.3d. The white frame represents a text area.
The grey frames represent scrollbars. The white frame should expand in both
directions with an enlarging window. The grey frames should expand only
lengthwise and the black frame should remain the same size.
<P> To achieve this affect you should begin with a horizontal or vertical
slicing into two frames. I will describe the problems as if the first
slicing were horizontal.
<P> The top horizontal slice must expand in two directions. If it did not, you
would be unable to get the white box to expand in two directions. As you pack
the vertical slices within the top horizontal slice, remember you want them
to expand in different ways.
<P> The bottom horizontal slice must not expand in the vertical direction. This
restriction prevents the boxes within it from expanding vertically – no
matter how you pack them into their slices. The lower horizontal scrollbar
must expand horizontally as far as the white box does. Make it expand as much
as possible up to the fixed-size black box.
<P> <P>
<A HREF="13.9.html#Sol13.3d" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/13.9.html#Sol13.3d">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.2.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/13.2.html">section</A><WBR>
<STRONG>Next</STRONG>
<A HREF="13.4.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/13.4.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 + -