I've made a tiny test GtkD DUB project (with GtkD 3.9.0 as dependency) to make a minimal reproducible example of a problem I am having in a larger project. Apparently Box is not expanding the middle Widget (in this case Button) to take all available space. Am I doing something wrong?
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();
}
When I make the same structure in Glade and go to preview, it shows the button expanded to fill all available space, so either I am doing something wrong, or there is a bug in GtkD...
Mike Wey (the GtkD author) solved the mystery in this thread - https://forum.gtkd.org/groups/GtkD/thread/2069/ ... Apparently I was calling both add() and packStart() not knowing that packStart() actually adds the Widget, so it looks like adding widget twice (once with add() and then with packStart()) messes the thing.
So code with add() calls removed works as expected:
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();
}