Wx Collection details: wxWidgets-wxsizer

Source: Internet
Author: User
Tags wxwidgets

Wxsizer is a nested container used to arrange the position of the control. This article introduces it.

Dish

 

When we need to write our own dialog, we need to arrange the location of the control to make the interface look beautiful. But if there are many controls, do we need to specify coordinates for each one? Another important issue is that this process is not "WYSIWYG "! (Of course, wxWidgets also has a visual interface editor, which is not considered here ). this is not suitable for programmers who transfer data from VC/Delphi, because the IDE has an integrated interface editor, which makes it easy to adjust the interface. for those who have written AWT (Java), GTK, and QT, I believe they have used Layout-like things. in wxWidgets, wxsizer does this.
Let's talk about some basic concepts first.
1. All sizers are containers and can be nested.
2. Minimum Size of item
Generally, the minimum size of the widget is the default value during initial testing. some controls can calculate their size (such as checkbox), but some are difficult to calculate, such as ListBox, the width and height are not sure, because there can be a scroll bar :-). some can calculate the height, but cannot calculate the width, such as text control.
3. The border of the item
The blank space around the control is surrounded. each widget has its own border. the border size can be set. you can also set the position. For example, there is only a border on the left, up or down, and no left or right.
4. items are alignable.
You can center, top, small, left, right, and other Alignment Methods.
5. item is scalable
An item generally occupies space including the minimum size and border of the item, but this can be scaled.
6. items can be manually set to hidden.
Use the wxsizer: Show function. note that the layout function will be called later to force update the interface layout. this function is useful when we want to hide some interfaces. to avoid this: remove the control from sizer and add it as needed. note that only wxboxsizer and wxflexgridsizer are supported.
Let's take a look at which classes are provided by wxWidgets to complete the control layout task.
Wxsizer, wxgridsizer, wxflexgridsizer, wxboxsizer, wxstaticboxsizer
Wxsizer is a base class, which is generally not directly used.
Wxboxsizer:
You can specify whether to arrange items horizontally or vertically. You can select either of them. If you want to arrange items horizontally or vertically, you need to use them in nesting mode.
Wxstaticboxsizer:
It is exactly the same as wxboxsizer, that is, adding a static box as the border.
Wxgridsizer:
It is a table-like layout. Note that the size of all grids is the same. The specific size depends on the largest one in item.
Wxflexgridsizer:
The upgraded version of wxgridsizer. The height of each row and the width of each column are independent. The specific size depends on the largest height/width of the row/column.
The following describes how to use wxboxsizer by analyzing the Add function of wxboxsizer.
The prototype is as follows:
Wxsizeritem * Add (wxwindow * window, int proportion = 0, int flag = 0, int
Border = 0, wxobject * userdata = NULL)
Wxsizeritem * Add (wxsizer * sizer, int proportion = 0, int flag = 0, int
Border = 0, wxobject * userdata = NULL)
One is for wxwindow, the other is for nested wxsizer, and other parameters are consistent.
Parameter description:
Proportion:
This parameter is used in wxboxsizer. As mentioned above, each wxboxsizer can specify a direction, which can be considered as the main direction of wxboxsizer.
If this parameter is set to 1, it indicates that the item to be added can be scaled in the main direction.
Flag:
Specifies the position of the item border (you can use the "|" operator symbol to combine top/bottom/left/right ).
Specifies the item alignment mode (you can use the "|" operation symbol to combine the upper/lower/left/right/vertical center/horizontal center ).
There is also a special wxexpand. whether the item can be scaled in the non-main direction. The main direction of scaling is specified by proportion. there is also a special note (for both the main direction and the non-main direction). If the parent-level sizer cannot be scaled, the sub-level sizer cannot be changed, it is invalid even if it is set to be scalable. if the parent node can be scaled, the sub-level sizer can be set to not be scaled.
Here we will not give a specific example. For more information, see "topic" in wxWidgets help.
"Programming with" of "sizer overview" in overviews"
Wxboxsizer ". This article is also written in reference to" sizer overview.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.