7.2.3. Boxes

学习gtkmm有几周了,英语太烂了,硬着头皮边看边记,还没把握,发上来,大家斧正

7.2.3. Boxes

Most packing uses boxes as in the above example. These are invisible containers into which we can pack our widgets. When packing widgets into a horizontal box, the objects are inserted horizontally from left to right or right to left depending on whether pack_start() or pack_end() is used. In a vertical box, widgets are packed from top to bottom or vice versa. You may use any combination of boxes inside or beside other boxes to create the desired effect.

大多数包装如同上个例子一样使用Boxes。我们将控件打包放置进这些不可见的容器中。放入在水平盒中的控件依据使用pack_start() 还是 pack_end()水平地从左到右或从右到左放置。在竖直盒中从上到下或反过来竖直排列。你可以嵌套、排列任意组合这些盒子(Boxes)以得到你想要的效果。

§  7.2.3.1. Adding widgets

§  7.2.3.2. 示例

7.2.3.1. Adding widgets(添加空件)

7.2.3.1.1. Per-child packing options(关于子控件包的参数)

The pack_start() and pack_end() methods place widgets inside these containers. The pack_start() method will start at the top and work its way down in a VBox, or pack left to right in an HBox. pack_end() will do the opposite, packing from bottom to top in a VBox, or right to left in an HBox. Using these methods allows us to right justify or left justify our widgets. We will use pack_start() in most of our examples.

pack_start() pack_end()方法放置子控件到容器里。Pack_start()方法在VBox中自顶向下的方式,在HBox中从左到右排列放置子控件。Pack_end()则相反。使用这些方法允许我们将子控件右对齐或左对齐。我们在大量例子中使用pack_start()

There are several options governing how widgets are to be packed, and this can be confusing at first. If you have difficulties then it is sometimes a good idea to play with the glade GUI designer to see what is possible. You might even decide to use the Gtk::Builder API to load your GUI at runtime.

有几个管理操作子控件包装放置的选项参数,开始可能有点不好理解(?)。如果有困难,有时间可试试glade GUI designer,看哪些是可能的。甚至你可能会决定使用Gtk::Builder API在运行时装入你的GUI

There are basically five different styles, as shown in this picture:

有五种基本的不同包装放置,如图所示:

7-7 Box Packing 1

Each line contains one horizontal box (HBox) with several buttons. Each of the buttons on a line is packed into the HBox with the same arguments to the pack_start() method).

每一行都包含一个水平框(HBox)及其中的几个按钮。每行按钮被使用相同的参数的pack_start() 方法包装放置进 HBox

This is the declaration of the pack_start() method:

这是pack_start()方法的定义:

void pack_start(Gtk::Widget& child,

                PackOptions options = PACK_EXPAND_WIDGET,

                guint padding = 0);

The first argument is the widget you're packing. In our example these are all Buttons.

第一个参数是你正在包装放置的控件。在我们的示例中,就是那些按钮。

The options argument can take one of these three options:

options 参数可以是以下三个选项之一:

  • PACK_SHRINK: Space is contracted to the child widget size. The widget will take up just-enough space and never expand.
    PACK_SHRINK: 空间被缩小到子控件的尺寸。该控件不会展开,只是占用足够的空间。

§  PACK_EXPAND_PADDING: Extra space is filled with padding. The widgets will be spaced out evenly, but their sizes won't change - there will be empty space between the widgets instead.
PACK_EXPAND_PADDING: 空白充满额外的空间。控件均匀间隔,不改变大小-控件间由空白空间充满。

§  PACK_EXPAND_WIDGET: Extra space is taken up by increasing the child widget size, without changing the amount of space between widgets.
PACK_EXPAND_WIDGET: 子控件缩放占据空白空间,而不更改的子控件之间的间距。

The padding argument specifies the width of an extra border area to leave around the packed widget.

参数padding指定空白的边界区到子控件周围边缘的宽度。

参考

7.2.3.1.2. Per-container packing options(关于容器的参数)

Here's the constructor for the box widgets:

这里是box控件的构造函数:

Gtk::Box(bool homogeneous = false, int spacing = 0);

Passing true for homogeneous will cause all of the contained widgets to be the same size. spacing is a (minimum) number of pixels to leave between each widget.

传递 true 给参数homogeneous将导致所有包含子控件为相同的大小。保留每个控件之间的间距 (最小)像素数。

What's the difference between spacing (set when the box is created) and padding (set when elements are packed)? Spacing is added between objects, and padding is added on either side of a widget. The following figure should make it clearer:

(创建box时设置)的spacing参数和(包装放置元素时设置)的padding参数之间的区别是什么?spacing参数子控件之间的间距和padding参数指该控件的两边加上填充空白区的值。下图应该使它更清晰:

7-8 Box Packing 2

7.2.3.2. 示例

Here is the source code for the example that produced the screenshots above. When you run this example, provide a number between 1 and 3 as a command-line option, to see different packing options in use.

这里是如上图示例的源代码。当您运行此示例时,请提供 1 3 之间的一个数字作为命令行选项,以查看不同的包装放置中使用的选项。

源代码

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值