GTK+菜单栏看起来很糟糕

发布于 2024-11-28 05:30:40 字数 661 浏览 0 评论 0原文

我正在按照此处的说明编写 Gtk+ 菜单栏。

当将菜单栏打包到 VBox 上时,

// "FALSE, TRUE" and "FALSE, FALSE" actually makes no difference
gtk_box_pack_start(GTK_BOX(main_vbox), menu_bar,
                   TRUE, FALSE, 0);

看起来很糟糕,如下所示:

slim menu bar

当我更改为:

 gtk_box_pack_start(GTK_BOX(main_vbox), menu_bar,
                    TRUE, TRUE, 0);

它看起来像:

在此处输入图像描述

那么,如何让工具栏分配更小的空间呢?

I'm writing a Gtk+ menu bar following the instruction here.

When packing the bar onto a VBox with

// "FALSE, TRUE" and "FALSE, FALSE" actually makes no difference
gtk_box_pack_start(GTK_BOX(main_vbox), menu_bar,
                   TRUE, FALSE, 0);

the menu bar looks terrible, like this:

slim menu bar

And when I changed to:

 gtk_box_pack_start(GTK_BOX(main_vbox), menu_bar,
                    TRUE, TRUE, 0);

it looks like:

enter image description here

So, how to make the toolbar get a smaller space allocated?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蹲在坟头点根烟 2024-12-05 05:30:40

如果我正确理解你的问题,你想要:

  1. 去掉菜单栏周围的浅灰色填充。
  2. 执行上述操作时无需展开菜单栏以填充可用空间。

因此,您的其他小部件(即菜单栏下方的按钮栏)的打包模式开始发挥作用(为了清楚起见,我将它们称为 button_hbox 和 < code>menu_bar,因为两者都可以称为“工具栏”)。

了解传递给 gtk_box_pack_start() 在这里至关重要:

  • 如果小部件在计算布局后应消耗其容器中剩余的空白空间,则第一个 expandTRUE。以这种方式打包的小部件平等地竞争剩余空间。

  • 如果小部件应该填充它所占用的布局空间而不是居中(出现浅灰色填充),则第二个 fillTRUE

这个想法是,您在 main_vbox 中有一个(或多个,但现在我们只使用一个)主小部件,并且该小部件包含 expandfill 设置为 TRUE。它周围的卫星小部件包含设置为 FALSEexpand 和设置为 TRUEfill。例如:

+-------------------------------------------+
|  Menu bar: expand = FALSE, fill = TRUE    |
+-------------------------------------------+
|  Toolbar: expand = FALSE, fill = TRUE     |
+-------------------------------------------+  ^
|                                           |  |
|                                           |  |  The height of this widget
|  Main widget: expand = TRUE, fill = TRUE  |  |  varies depending on the 
|                                           |  |  height of its container.
|                                           |  |
+-------------------------------------------+  v
|  Status bar: expand = FALSE, fill = TRUE  |
+-------------------------------------------+

在您的情况下,由于您不希望 menu_bar 填充可用空间,因此 button_hbox 应该这样做:

// Menu bar: satellite widget, expand = FALSE, fill = TRUE
gtk_box_pack_start(GTK_BOX(main_vbox), menu_bar, FALSE, TRUE, 0);

// Button bar: main widget, expand = TRUE, fill = TRUE
gtk_box_pack_start(GTK_BOX(main_vbox), button_hbox, TRUE, TRUE, 0);

If I understand your question correctly, you want to:

  1. Get rid of the light gray padding around the menu bar.
  2. Do the above without expanding the menu bar to fill the available space.

Therefore, the packing mode of your other widget (namely the button bar below your menu bar) comes into play (for clarity, I'll refer to them as button_hbox and menu_bar, respectively, since both can qualify as "toolbars").

Understanding the boolean layout arguments passed to gtk_box_pack_start() is paramount here:

  • The first one, expand, is TRUE if the widget should consume the empty space left in its container after layout is computed. Widgets packed this way compete equally for the remaining space.

  • The second one, fill, is TRUE if the widget should fill the layout space it consumes instead of being centered within it (there comes the light gray padding).

The idea is that you have one (or more, but let's stick to one for now) main widget in main_vbox, and that widget is packed with both expand and fill set to TRUE. The satellite widgets around it are packed with expand set to FALSE and fill set to TRUE. For instance:

+-------------------------------------------+
|  Menu bar: expand = FALSE, fill = TRUE    |
+-------------------------------------------+
|  Toolbar: expand = FALSE, fill = TRUE     |
+-------------------------------------------+  ^
|                                           |  |
|                                           |  |  The height of this widget
|  Main widget: expand = TRUE, fill = TRUE  |  |  varies depending on the 
|                                           |  |  height of its container.
|                                           |  |
+-------------------------------------------+  v
|  Status bar: expand = FALSE, fill = TRUE  |
+-------------------------------------------+

In your case, since you don't want menu_bar to fill the available space, button_hbox should do so:

// Menu bar: satellite widget, expand = FALSE, fill = TRUE
gtk_box_pack_start(GTK_BOX(main_vbox), menu_bar, FALSE, TRUE, 0);

// Button bar: main widget, expand = TRUE, fill = TRUE
gtk_box_pack_start(GTK_BOX(main_vbox), button_hbox, TRUE, TRUE, 0);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文