OSHGui icon indicating copy to clipboard operation
OSHGui copied to clipboard

Dynamically 'anchoring' elements is broken due to mistake in the code

Open NuclearC opened this issue 3 years ago • 0 comments

Take a look at this these lines of code (line ~160-180 in Control.cpp, Control::SetSize):

	size_ = size;
	
	OnSizeChanged();

	Invalidate();

	const auto offset = size_ - GetSize();
	for (auto &control : controls_)
	{
		const auto anchor = control->GetAnchor();

		if (anchor != (AnchorStyles::Top | AnchorStyles::Left))

It changes the member variable size_ and then calculates offset, which is obviously going to be {0, 0}. This breaks dynamic resizing of the parent controls, as the children will not be correctly placed after the resize.

EDIT: fixing this would be as simple as doing size - GetSize() instead of size_ - GetSize()

NuclearC avatar Feb 26 '21 14:02 NuclearC