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

Fixed margin not correctly applied #386

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

IceReaper
Copy link
Contributor

Fixes #385
The width / Height properties are always without margin. Basicaly content + padding + border.
The result variable here however needs to calculate the outer bounds of space consumed, which includes margin.
This is also stated in the lines directly above, where MBPWith and MBPHeight is added.
The statements below override the resulting dimensions, but totaly forget to add the margin, which this PR fixes.

Code example:

public class MainMenuWidget : VerticalStackPanel
{
	public MainMenuWidget(PrototypeGame game)
	{
		this.HorizontalAlignment = HorizontalAlignment.Center;
		this.VerticalAlignment = VerticalAlignment.Center;
		this.Padding = new(9);
		this.Background = new SolidBrush(new Color(0x10, 0x10, 0x10));
		this.Border = new SolidBrush(new Color(0x80, 0x80, 0x80));
		this.BorderThickness = new(1);

		this.AddChild(
			new Label
			{
				Text = "Prototype",
				HorizontalAlignment = HorizontalAlignment.Center,
				Margin = new(0, 0, 0, 10),
				Height = 10
			}
		);

		this.AddChild(new TextButton { Text = "Play", Width = 100, Height = 15, Margin = new(0, 0, 0, 10) });
		this.AddChild(new TextButton { Text = "Exit", Width = 100, Height = 15 });
	}
}

Before this PR:
image

With this PR:
image

@rds1983
Copy link
Owner

rds1983 commented Oct 23, 2023

Sorry for the late response.
So you propose that the margin should be added to the Width/Height?
And if the Widget has Width/Height set to 100/100 and Margin set to 10, then it's size should be 110/110.
It's definitely reasonable. Though probably need to look how fixed size/margin is handled in other UI libraries.
Before making decision on how it'll be in Myra.

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

Successfully merging this pull request may close these issues.

Margin is handled wrong.
2 participants