Skip to content

Commit

Permalink
Mac: Fix sizing of labels when initially shown on a PixelLayout
Browse files Browse the repository at this point in the history
  • Loading branch information
cwensley committed Oct 14, 2020
1 parent d11f0fd commit 88dda97
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Eto.Mac/Forms/Controls/MacLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ public abstract class MacLabel<TControl, TWidget, TCallback> : MacView<TControl,

protected override SizeF GetNaturalSize(SizeF availableSize)
{
// set attributes if it hasn't been loaded yet, so we get the correct size.
if (!Widget.Loaded)
SetAttributes(true);

if (float.IsPositiveInfinity(availableSize.Width))
{
if (naturalSizeInfinity != null)
Expand Down Expand Up @@ -393,6 +397,7 @@ public override void OnLoad(EventArgs e)
{
base.OnLoad(e);
SetAttributes(true);
InvalidateMeasure();
}

public override void AttachEvent(string id)
Expand Down
15 changes: 15 additions & 0 deletions test/Eto.Test/UnitTests/Forms/Layout/PixelLayoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,20 @@ public void SettingChildSizeShouldNotChangePosition()
return layout;
});
}

[Test, ManualTest]
public void LabelsShouldGetCorrectSize()
{
ManualForm("Labels should end with a period", form => {
// note: this actually failed only when the form was the initial window, as it calculated its size before it was even shown.
form.ClientSize = new Size(200, 200);

var layout = new PixelLayout();
layout.Add(new Label { Text = "Hello world.", BackgroundColor = Colors.Yellow, TextColor = Colors.Black }, 50, 50);
layout.Add(new Label { Text = "Bonjour monde.", BackgroundColor = Colors.LightGreen, TextColor = Colors.Black }, 20, 20);
form.Content = layout;
return layout;
});
}
}
}

0 comments on commit 88dda97

Please sign in to comment.