为什么按钮没有展开以填充所有 space?
Why is the button not expanding to fill all the space?
我制作了一个小型测试 GtkD DUB 项目(以 GtkD 3.9.0 作为依赖项),以作为我在大型项目中遇到的问题的最小可重现示例。显然 Box 没有扩展中间的 Widget(在本例中为 Button)以占用所有可用的 space。我做错了什么吗?
import gtk.MainWindow;
import gtk.Label;
import gtk.Button;
import gtk.Main;
import gtk.Box;
void main(string[] args) {
Main.init(args);
MainWindow window = new MainWindow("Pack test");
Box box = new Box(Orientation.VERTICAL, 0);
Label topLabel = new Label("Top");
box.add(topLabel);
box.packStart(topLabel, false, false, 0);
Button bigButton = new Button("Big button");
box.add(bigButton);
box.packStart(bigButton, true, true, 0);
Label bottomLabel = new Label("Bottom");
box.add(bottomLabel);
box.packStart(bottomLabel, false, false, 0);
window.add(box);
window.setDefaultSize(800, 600);
window.showAll();
Main.run();
}
当我在 Glade 中创建相同的结构并进行预览时,它显示按钮展开以填充所有可用的 space,所以要么是我做错了什么,要么是 GtkD 中存在错误。 .
Mike Wey(GtkD 作者)解决了这个线程中的谜团 - https://forum.gtkd.org/groups/GtkD/thread/2069/ ... 显然我同时调用了 add() 和 packStart() 并不知道 packStart() 实际上添加了 Widget,所以看起来添加小部件两次(一次使用 add(),然后使用 packStart())搞砸了。
因此删除了 add() 调用的代码按预期工作:
import gtk.MainWindow;
import gtk.Label;
import gtk.Button;
import gtk.Main;
import gtk.Box;
void main(string[] args) {
Main.init(args);
MainWindow window = new MainWindow("Pack test");
Box box = new Box(Orientation.VERTICAL, 0);
Label topLabel = new Label("Top");
//box.add(topLabel);
box.packStart(topLabel, false, false, 0);
Button bigButton = new Button("Big button");
//box.add(bigButton);
box.packStart(bigButton, true, true, 0);
Label bottomLabel = new Label("Bottom");
//box.add(bottomLabel);
box.packStart(bottomLabel, false, false, 0);
window.add(box);
window.setDefaultSize(800, 600);
window.showAll();
Main.run();
}
我制作了一个小型测试 GtkD DUB 项目(以 GtkD 3.9.0 作为依赖项),以作为我在大型项目中遇到的问题的最小可重现示例。显然 Box 没有扩展中间的 Widget(在本例中为 Button)以占用所有可用的 space。我做错了什么吗?
import gtk.MainWindow;
import gtk.Label;
import gtk.Button;
import gtk.Main;
import gtk.Box;
void main(string[] args) {
Main.init(args);
MainWindow window = new MainWindow("Pack test");
Box box = new Box(Orientation.VERTICAL, 0);
Label topLabel = new Label("Top");
box.add(topLabel);
box.packStart(topLabel, false, false, 0);
Button bigButton = new Button("Big button");
box.add(bigButton);
box.packStart(bigButton, true, true, 0);
Label bottomLabel = new Label("Bottom");
box.add(bottomLabel);
box.packStart(bottomLabel, false, false, 0);
window.add(box);
window.setDefaultSize(800, 600);
window.showAll();
Main.run();
}
当我在 Glade 中创建相同的结构并进行预览时,它显示按钮展开以填充所有可用的 space,所以要么是我做错了什么,要么是 GtkD 中存在错误。 .
Mike Wey(GtkD 作者)解决了这个线程中的谜团 - https://forum.gtkd.org/groups/GtkD/thread/2069/ ... 显然我同时调用了 add() 和 packStart() 并不知道 packStart() 实际上添加了 Widget,所以看起来添加小部件两次(一次使用 add(),然后使用 packStart())搞砸了。
因此删除了 add() 调用的代码按预期工作:
import gtk.MainWindow;
import gtk.Label;
import gtk.Button;
import gtk.Main;
import gtk.Box;
void main(string[] args) {
Main.init(args);
MainWindow window = new MainWindow("Pack test");
Box box = new Box(Orientation.VERTICAL, 0);
Label topLabel = new Label("Top");
//box.add(topLabel);
box.packStart(topLabel, false, false, 0);
Button bigButton = new Button("Big button");
//box.add(bigButton);
box.packStart(bigButton, true, true, 0);
Label bottomLabel = new Label("Bottom");
//box.add(bottomLabel);
box.packStart(bottomLabel, false, false, 0);
window.add(box);
window.setDefaultSize(800, 600);
window.showAll();
Main.run();
}