rds1983 / Myra

UI Library for MonoGame, FNA and Stride
MIT License
704 stars 94 forks source link

Fixed margin not correctly applied #386

Open IceReaper opened 1 year ago

IceReaper commented 1 year ago

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 commented 8 months ago

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.