⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tsizer.tex

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 TEX
📖 第 1 页 / 共 2 页
字号:
\section{Sizer overview}\label{sizeroverview}Classes: \helpref{wxSizer}{wxsizer}, \helpref{wxGridSizer}{wxgridsizer}, \helpref{wxFlexGridSizer}{wxflexgridsizer}, \helpref{wxBoxSizer}{wxboxsizer}, \helpref{wxStaticBoxSizer}{wxstaticboxsizer}, \helpref{CreateButtonSizer}{createbuttonsizer}Sizers, as represented by the wxSizer class and its descendants inthe wxWidgets class hierarchy, have become the method of choice todefine the layout of controls in dialogs in wxWidgets because oftheir ability to create visually appealing dialogs independent of theplatform, taking into account the differences in size and style ofthe individual controls. Unlike the original wxWidgets Dialog Editor,editors such as wxDesigner, DialogBlocks, XRCed and wxWorkshop create dialogs based exclusively on sizers,practically forcing the user to create platform independent layouts without compromises.The next section describes and shows what can be done with sizers.The following sections briefly describe how to program with individual sizer classes.For information about the new wxWidgets resource system, which can describesizer-based dialogs, see the \helpref{XML-based resource system overview}{xrcoverview}.\subsection{The idea behind sizers}\label{ideabehindsizers}The layout algorithm used by sizers in wxWidgets is closely related to layoutsystems in other GUI toolkits, such as Java's AWT, the GTK toolkit or the Qt toolkit. It isbased upon the idea of individual subwindows reporting their minimal requiredsize and their ability to get stretched if the size of the parent window has changed.This will most often mean that the programmer does not set the start-up size ofa dialog, the dialog will rather be assigned a sizer and this sizerwill be queried about the recommended size. This sizer in turn will query itschildren (which can be normal windows, empty space or other sizers) so thata hierarchy of sizers can be constructed. Note that wxSizer does not derive from wxWindowand thus does not interfere with tab ordering and requires very few resources comparedto a real window on screen.What makes sizers so well fitted for use in wxWidgets is the fact that every controlreports its own minimal size and the algorithm can handle differences in font sizesor different window (dialog item) sizes on different platforms without problems. For example, ifthe standard font as well as the overall design of Linux/GTK widgets requires more space thanon Windows, the initial dialog size will automatically be bigger on Linux/GTK than on Windows.There are currently five different kinds of sizers available in wxWidgets. Each representseither a certain way to lay out dialog items in a dialog or it fulfills a special tasksuch as wrapping a static box around a dialog item (or another sizer). These sizers willbe discussed one by one in the text below. For more detailed information on how to use sizersprogrammatically, please refer to the section \helpref{Programming with Sizers}{boxsizerprogramming}.\subsubsection{Common features}\label{sizerscommonfeatures}All sizers are containers, that is, they are used to lay out one dialog item (or severaldialog items), which they contain. Such items are sometimes referred to as the childrenof the sizer. Independent of how the individual sizers lay out their children, all childrenhave certain features in common:{\bf A minimal size:} This minimal size is usually identical tothe initial size of the controls and may either be set explicitly in the wxSize fieldof the control constructor or may be calculated by wxWidgets, typically by settingthe height and/or the width of the item to -1. Note that only some controls cancalculate their size (such as a checkbox) whereas others (such as a listbox)don't have any natural width or height and thus require an explicit size. Some controlscan calculate their height, but not their width (e.g. a single line text control):\newcommand{\myimage}[1]{\mbox{\image{0cm;0cm}{#1}}}\begin{center}\myimage{sizer03.eps}\gifsep\myimage{sizer04.eps}\gifsep\myimage{sizer05.eps}\end{center}{\bf A border:} The border is just empty space and is used to separate dialog itemsin a dialog. This border can either be all around, or at any combination of sidessuch as only above and below the control. The thickness of this border must be setexplicitly, typically 5 points. The following samples show dialogs with only onedialog item (a button) and a border of 0, 5, and 10 pixels around the button:\begin{center}\myimage{sizer00.eps}\gifsep\myimage{sizer01.eps}\gifsep\myimage{sizer02.eps}\end{center}{\bf An alignment:} Often, a dialog item is given more space than its minimal sizeplus its border. Depending on what flags are used for the respective dialogitem, the dialog item can be made to fill out the available space entirely, i.e.it will grow to a size larger than the minimal size, or it will be moved to eitherthe centre of the available space or to either side of the space. The followingsample shows a listbox and three buttons in a horizontal box sizer; one buttonis centred, one is aligned at the top, one is aligned at the bottom:\begin{center}\myimage{sizer06.eps}\end{center}{\bf A stretch factor:} If a sizer contains more than one child and it is offeredmore space than its children and their borders need, the question arises how todistribute the surplus space among the children. For this purpose, a stretchfactor may be assigned to each child, where the default value of 0 indicates that the childwill not get more space than its requested minimum size. A value of more than zerois interpreted in relation to the sum of all stretch factors in the childrenof the respective sizer, i.e. if two children get a stretch factor of 1, they willget half the extra space each {\it independent of whether one control has a minimalsizer inferior to the other or not}. The following sample shows a dialog withthree buttons, the first one has a stretch factor of 1 and thus gets stretched,whereas the other two buttons have a stretch factor of zero and keep theirinitial width:\begin{center}\myimage{sizer07.eps}\end{center}Within wxDesigner, this stretch factor gets set from the {\it Option} menu.\subsubsection{Hiding controls using sizers}\label{sizershiding}You can hide controls contained in sizers the same way you would hide any control,using the \helpref{wxWindow::Show}{wxwindowshow} method.However, wxSizer also offers a separate method which can tell the sizer not to consider that control in its size calculations.  To hide a window using the sizer,call \helpref{wxSizer::Show}{wxsizershow}.  You must then call Layout on the sizer to force an update.This is useful when hiding parts of the interface, since you can avoid removingthe controls from the sizer and having to add them back later.Note: This is supported only by wxBoxSizer and wxFlexGridSizer.\wxheading{wxBoxSizer}\helpref{wxBoxSizer}{wxboxsizer} can lay out its children either verticallyor horizontally, depending on what flag is being used in its constructor.When using a vertical sizer, each child can be centered, aligned to theright or aligned to the left. Correspondingly, when using a horizontalsizer, each child can be centered, aligned at the bottom or aligned atthe top. The stretch factor described in the last paragraph is usedfor the main orientation, i.e. when using a horizontal box sizer, thestretch factor determines how much the child can be stretched horizontally.The following sample shows the same dialog as in the last sample,only the box sizer is a vertical box sizer now:\begin{center}\myimage{sizer08.eps}\end{center}\wxheading{wxStaticBoxSizer}\helpref{wxStaticBoxSixer}{wxstaticboxsizer} is the same as a wxBoxSizer, but surrounded by astatic box. Here is a sample:\begin{center}\myimage{sizer09.eps}\end{center}\wxheading{wxGridSizer}\helpref{wxGridSizer}{wxgridsizer} is a two-dimensional sizer. All children are given thesame size, which is the minimal size required by the biggest child, inthis case the text control in the left bottom border. Either the numberof columns or the number or rows is fixed and the grid sizer will growin the respectively other orientation if new children are added:\begin{center}\myimage{sizer10.eps}\end{center}For programming information, see \helpref{wxGridSizer}{wxgridsizer}.\wxheading{wxFlexGridSizer}Another two-dimensional sizer derived fromwxGridSizer. The width of each column and the height of each roware calculated individually according to the minimal requirementsfrom the respectively biggest child. Additionally, columns androws can be declared to be stretchable if the sizer is assigneda size different from the one it requested. The following sample showsthe same dialog as the one above, but using a flex grid sizer:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -