7.2.3. Boxes

来源:互联网 发布:霸屏软件 编辑:程序博客网 时间:2024/05/19 20:19

学习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关于子控件包的参数)
  • 7.2.3.1.2. Per-container packing options (关于容器的参数)

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 之间的一个数字作为命令行选项,以查看不同的包装放置中使用的选项。

源代码

 

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 100棉衬衣皱了怎么办? 短袖t恤袖口大了怎么办 短袖底下卷边了怎么办 棉质短袖衫缩水怎么办 纯棉t恤缩水了怎么办 t恤缩水变小了怎么办 衣服掉在雨棚上怎么办 车衣密码锁忘记密码怎么办 衣服的铁拉链弯怎么办 去旅行衣服皱了怎么办 衣服抽绳出来了怎么办 裤子的绑带掉了怎么办 网纱裙的边卷了怎么办 堵奶宝宝吸不通怎么办 棉麻裙子掉毛怎么办 10个月宝宝吃手怎么办 婴儿连体衣长了怎么办 冰丝面料变长了怎么办 t恤袖口大了怎么办 长袖t恤袖子长了怎么办 机打的扣子掉了怎么办 四个月宝宝头扁怎么办 鞋子前面穿翘了怎么办 休完产假没人带怎么办 休完产假孩子吃奶怎么办 巴布豆童鞋里面臭了到底怎么办 连体裤有点卡档怎么办 宝宝连体衣扣子掉了怎么办 买衣服被骂了怎么办? 把人车刮了跑了怎么办 打工打不下去了怎么办 白色衣服变粉了怎么办 一量血压就紧张怎么办 一紧张就血压高怎么办 不在上班时间在单位受伤怎么办 生活过得太压抑怎么办 高低床踏板断了怎么办 高低床 孩子摔下来怎么办 小孩子太小高低床爬梯怎么办 辞职后单位不发工资怎么办 买了个上下床搬家怎么办