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

📄 tconstr.tex

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 TEX
字号:
\section{Constraints overview}\label{constraintsoverview}Classes: \helpref{wxLayoutConstraints}{wxlayoutconstraints}, \helpref{wxIndividualLayoutConstraint}{wxindividuallayoutconstraint}.{\bf Note:} constraints are now deprecated and you should use \helpref{sizers}{sizeroverview} instead.Objects of class wxLayoutConstraint can be associated with a window to definethe way it is laid out, with respect to its siblings or the parent.The class consists of the following eight constraints of class wxIndividualLayoutConstraint,some or all of which should be accessed directly to set the appropriateconstraints.\begin{itemize}\itemsep=0pt\item {\bf left:} represents the left hand edge of the window\item {\bf right:} represents the right hand edge of the window\item {\bf top:} represents the top edge of the window\item {\bf bottom:} represents the bottom edge of the window\item {\bf width:} represents the width of the window\item {\bf height:} represents the height of the window\item {\bf centreX:} represents the horizontal centre point of the window\item {\bf centreY:} represents the vertical centre point of the window\end{itemize}The constraints are initially set to have the relationship wxUnconstrained,which means that their values should be calculated by looking at known constraints.To calculate the position and size of the control, the layout algorithm needs toknow exactly 4 constraints (as it has 4 numbers to calculate from them), so youshould always set exactly 4 of the constraints from the above table.If you want the controls height or width to have the default value, you may usea special value for the constraint: wxAsIs. If the constraint is wxAsIs, thedimension will not be changed which is useful for the dialog controls whichoften have the default size (e.g. the buttons whose size is determined by theirlabel).The constrains calculation is done in \helpref{wxWindow::Layout}{wxwindowlayout} function which evaluates constraints. To call it you can either call\helpref{wxWindow::SetAutoLayout}{wxwindowsetautolayout} if the parent windowis a frame, panel or a dialog to tell default OnSize handlers to call Layoutautomatically whenever the window size changes, or override OnSize and callLayout yourself (note that you do have to call \helpref{Layout}{wxwindowlayout} yourself if the parent window is not aframe, panel or dialog).\subsection{Constraint layout: more details}\label{constraintlayoutdetails}By default, windows do not have a wxLayoutConstraints object. In this case, much layoutmust be done explicitly, by performing calculations in OnSize members, exceptfor the case of frames that have exactly one subwindow (not counting toolbar andstatusbar which are also positioned by the frame automatically), where wxFrame::OnSizetakes care of resizing the child to always fill the frame.To avoid the need for these rather awkward calculations, the user can createa wxLayoutConstraints object and associate it with a window with wxWindow::SetConstraints.This object contains a constraint for each of the window edges, two for the centre point,and two for the window size. By setting some or all of these constraints appropriately,the user can achieve quite complex layout by defining relationships between windows.In wxWidgets, each window can be constrained relative to either its {\itsiblings} on the same window, or the {\it parent}. The layout algorithmtherefore operates in a top-down manner, finding the correct layout forthe children of a window, then the layout for the grandchildren, and soon. Note that this differs markedly from native Motif layout, whereconstraints can ripple upwards and can eventually change the framewindow or dialog box size. We assume in wxWidgets that the {\it user} isalways `boss' and specifies the size of the outer window, to whichsubwindows must conform. Obviously, this might be a limitation in somecircumstances, but it suffices for most situations, and thesimplification avoids some of the nightmarish problems associated withprogramming Motif.When the user sets constraints, many of the constraints for windowsedges and dimensions remain unconstrained. For a given window,the wxWindow::Layout algorithm first resets all constraintsin all children to have unknown edge or dimension values, and then iterates through the constraints,evaluating them. For unconstrained edges and dimensions, ittries to find the value using known relationships that always hold. For example,an unconstrained {\it width} may be calculated from the {\it left} and {\it right edges}, ifboth are currently known. For edges and dimensions with user-supplied constraints, theseconstraints are evaluated if the inputs of the constraint are known.The algorithm stops when all child edges and dimension are known (success), or there are unknown edges or dimensions but there has been no change in this cycle (failure).It then sets all the window positions and sizes according to the values it has found.Because the algorithm is iterative, the order in which constraints are considered isirrelevant, however you may reduce the number of iterations (and thus speed upthe layout calculations) by creating the controls in such order that as manyconstraints as possible can be calculated during the first iteration. For example, ifyou have 2 buttons which you'd like to position in the lower right corner, it isslightly more efficient to first create the second button and specify that itsright border IsSameAs(parent, wxRight) and then create the first one byspecifying that it should be LeftOf() the second one than to do in a morenatural left-to-right order.\subsection{Window layout examples}\label{layoutexamples}\subsubsection{Example 1: subwindow layout}\label{subwindowlayoutexample}This example specifies a panel and a window side by side,with a text subwindow below it.\begin{verbatim}  frame->panel = new wxPanel(frame, -1, wxPoint(0, 0), wxSize(1000, 500), 0);  frame->scrollWindow = new MyScrolledWindow(frame, -1, wxPoint(0, 0), wxSize(400, 400), wxRETAINED);  frame->text_window = new MyTextWindow(frame, -1, wxPoint(0, 250), wxSize(400, 250));  // Set constraints for panel subwindow  wxLayoutConstraints *c1 = new wxLayoutConstraints;  c1->left.SameAs       (frame, wxLeft);  c1->top.SameAs        (frame, wxTop);  c1->right.PercentOf   (frame, wxWidth, 50);  c1->height.PercentOf  (frame, wxHeight, 50);  frame->panel->SetConstraints(c1);  // Set constraints for scrollWindow subwindow  wxLayoutConstraints *c2 = new wxLayoutConstraints;  c2->left.SameAs       (frame->panel, wxRight);  c2->top.SameAs        (frame, wxTop);  c2->right.SameAs      (frame, wxRight);  c2->height.PercentOf  (frame, wxHeight, 50);  frame->scrollWindow->SetConstraints(c2);  // Set constraints for text subwindow  wxLayoutConstraints *c3 = new wxLayoutConstraints;  c3->left.SameAs       (frame, wxLeft);  c3->top.Below         (frame->panel);  c3->right.SameAs      (frame, wxRight);  c3->bottom.SameAs     (frame, wxBottom);  frame->text_window->SetConstraints(c3);\end{verbatim}\subsubsection{Example 2: panel item layout}\label{panelitemlayoutexample}This example sizes a button width to 80 percent of the panel width, and centresit horizontally. A listbox and multitext item are placed below it. The listboxtakes up 40 percent of the panel width, and the multitext item takes upthe remainder of the width. Margins of 5 pixels are used.\begin{verbatim}  // Create some panel items  wxButton *btn1 = new wxButton(frame->panel, -1, "A button") ;  wxLayoutConstraints *b1 = new wxLayoutConstraints;  b1->centreX.SameAs    (frame->panel, wxCentreX);  b1->top.SameAs        (frame->panel, wxTop, 5);  b1->width.PercentOf   (frame->panel, wxWidth, 80);  b1->height.PercentOf  (frame->panel, wxHeight, 10);  btn1->SetConstraints(b1);  wxListBox *list = new wxListBox(frame->panel, -1, "A list",                                  wxPoint(-1, -1), wxSize(200, 100));  wxLayoutConstraints *b2 = new wxLayoutConstraints;  b2->top.Below         (btn1, 5);  b2->left.SameAs       (frame->panel, wxLeft, 5);  b2->width.PercentOf   (frame->panel, wxWidth, 40);  b2->bottom.SameAs     (frame->panel, wxBottom, 5);  list->SetConstraints(b2);  wxTextCtrl *mtext = new wxTextCtrl(frame->panel, -1, "Multiline text", "Some text",                        wxPoint(-1, -1), wxSize(150, 100), wxTE_MULTILINE);  wxLayoutConstraints *b3 = new wxLayoutConstraints;  b3->top.Below         (btn1, 5);  b3->left.RightOf      (list, 5);  b3->right.SameAs      (frame->panel, wxRight, 5);  b3->bottom.SameAs     (frame->panel, wxBottom, 5);  mtext->SetConstraints(b3);\end{verbatim}

⌨️ 快捷键说明

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