GTK + 2.0 tutorial - principle of assembly component assembly box

zhaozj2021-02-16  152

Assembly component

When you create an application, you may want to place more than one component in the window. Our first HelloWorld example only uses a component, so we can simply use GTK_Container_ADD () to "assemble" this component into the window. But how do you control the positioning of each component when you want to place more components into a window? It is necessary to use packing.

Principle of assembly box

Most assemblies are reached by creating some "boxes", this is an unacceptable component container, which have two forms: one is a horizontal box (Horizontal Box), one is a vertical box (Vertical Box) . When we assemble components into the transverse box, these components are inserted from left to right or from right to left. In the longitudinal cassette, it can be assembled from the top to bottom or inversely, you can use any box combination, such as a box kit or cartridge to produce the effect you want.

To create a new horizontal box we call GTK_HBOX_NEW (), for the vertical box, with gtk_vbox_new (). GTK_BOX_PACK_START () and GTK_BOX_PACK_END () functions are used to assemble objects into these containers. GTK_BOX_PACK_START () puts objects from top to bottom into the longitudinal box, or from left to right to fit into the horizontal box. GTK_BOX_PACK_END () The opposite is that from the lower to the upper group to the longitudinal box, or from the right to left groups into the transverse box. Use these functions to allow us to adjust your components to left or right, and you can mix some other methods to achieve the design effect we want. Most of our examples use GTK_BOX_PACK_START (). The assembled object can be another container or component. In fact, many components themselves are containers, including buttons, but we usually put only one label in the button.

By using these calls, GTK will know where to put the components and will automatically adjust the size and other beautification. As for how to assemble your components here, there are some options. As you can think of, these methods have given us a lot of flexibility when placing and creating components.

转载请注明原文地址:https://www.9cbs.com/read-8477.html

New Post(0)