Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpectedly huge paddings when wrapping a checkbox inside a blank widget #294

Open
WebFreak001 opened this issue Jun 30, 2021 · 5 comments

Comments

@WebFreak001
Copy link
Contributor

WebFreak001 commented Jun 30, 2021

using wrapped checkbox:
grafik

using checkbox:
grafik

code:

/+ dub.sdl:
dependency "arsd-official:minigui" version="~>10.1.0"
+/

import arsd.minigui;
import std.conv;
import std.stdio;

void main(string[] args)
{
	auto window = new MainWindow();

	auto layout = new VerticalLayout(window);

	foreach (i; 0 .. 4)
	{
		auto pair = new HorizontalLayout(layout);
		new LineEdit(pair).content = text("Checkbox ", i + 1);
		// new Checkbox("active", pair);
		new WrappedCheckbox(pair, i);
	}

	window.loop();
}

class WrappedCheckbox : Widget
{
	// mixin Padding!"1";

	Checkbox cb;
	int i;

	this(Widget parent, int i)
	{
		super(parent);
		cb = new Checkbox("active", this);
		cb.addEventListener(EventType.change, &this.update);
		this.i = i;
	}

	void update()
	{
		writeln("change ", i, " to ", cb.isChecked);
	}
}

it seems it somehow resizes to fill all space now

@adamdruppe
Copy link
Owner

The checkbox class has a max height, the widget class does not. so the wrapped one ends up flexing to 25% of the available window.

@WebFreak001
Copy link
Contributor Author

WebFreak001 commented Jun 30, 2021

while that's logical I think it might be a bit unreasonable to require people to clone widgets exactly with all their properties properly. Would it be possible to make the paddings and other styles changable? My use-case was that I just wanted to give the checkbox a little bit of padding

@adamdruppe
Copy link
Owner

it isn't padding, it is maxHeight. change that in your wrapper and you'll see the behavior magically change

class YourWidget {
override int maxHeight() { return 30; }
}

that kind of thing

(I think. haven't tried)

@WebFreak001
Copy link
Contributor Author

WebFreak001 commented Jun 30, 2021

sorry I think you misunderstood, I wanted to say:

I'm making this wrapper class because I want to add padding.

I don't want to reimplement all the specifics of my padded widget (checkbox -> maxHeight, etc.)

Would it be reasonable to allow users to change margin/padding/etc on layouts if not on widgets?

@adamdruppe
Copy link
Owner

oh yeah i do want to change the spacing from the parent too, i was thinking about adding that pretty soon as a kind of like grid spacing or something

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants