Sign up

Why is the button not expanding to fill all the space?

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();
}

Re: Why is the button not expanding to fill all the space?

What I am getting when I build and run is this: https://pasteboard.co/JQk4tEf.png

Re: Why is the button not expanding to fill all the space?

On 26-02-2021 23:14, Dejan Lekic wrote:

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();
}

add is does the same as packStart but with defaults, so it messes things
up if you call both. Only using packStart should work:

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();
}

Re: Why is the button not expanding to fill all the space?

Awww man, I was banging my head why is that code working as expected for hours... Lesson learned! I should have read the packStart() doc more carefully...

Re: Why is the button not expanding to fill all the space?

For the reference: https://stackoverflow.com/questions/66394070/why-is-the-button-not-expanding-to-fill-all-the-space