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

Mac: Fix possible lockup with wrapped label when its size was very small #2585

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 13 additions & 37 deletions src/Eto.Mac/Forms/Controls/MacLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ public abstract class MacLabel<TControl, TWidget, TCallback> : MacView<TControl,
readonly NSMutableParagraphStyle paragraphStyle;
int underlineIndex;
Size availableSizeCached;
SizeF? naturalSizeInfinity;
SizeF lastSize;
bool isSizing;

public override NSView ContainerControl => Control;

Expand All @@ -110,23 +107,26 @@ protected override SizeF GetNaturalSize(SizeF availableSize)

if (float.IsPositiveInfinity(availableSize.Width))
{
if (naturalSizeInfinity != null)
return naturalSizeInfinity.Value;
if (NaturalSizeInfinity != null)
return NaturalSizeInfinity.Value;

var width = UserPreferredSize.Width;
if (width < 0) width = int.MaxValue;
var size = Control.Cell.CellSizeForBounds(new CGRect(0, 0, width, int.MaxValue)).ToEto();
naturalSizeInfinity = Size.Ceiling(size);
return naturalSizeInfinity.Value;
NaturalSizeInfinity = Size.Ceiling(size);
return NaturalSizeInfinity.Value;
}

if (Widget.Loaded && Wrap != WrapMode.None && UserPreferredSize.Width > 0)
if (Widget.Loaded && Wrap != WrapMode.None)
{
/*if (!float.IsPositiveInfinity(availableSize.Width))
availableSize.Width = Math.Max(Size.Width, availableSize.Width);
else*/
availableSize.Width = UserPreferredSize.Width;
availableSize.Height = float.PositiveInfinity;
if (UserPreferredSize.Width > 0)
{
/*if (!float.IsPositiveInfinity(availableSize.Width))
availableSize.Width = Math.Max(Size.Width, availableSize.Width);
else*/
availableSize.Width = UserPreferredSize.Width;
availableSize.Height = float.PositiveInfinity;
}
}

var availableSizeTruncated = availableSize.TruncateInfinity();
Expand All @@ -140,24 +140,6 @@ protected override SizeF GetNaturalSize(SizeF availableSize)
return NaturalSize.Value;
}

public override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
if (isSizing)
return;
isSizing = true;
var size = Size;
if (Wrap != WrapMode.None && lastSize.Width != size.Width && !Control.IsHiddenOrHasHiddenAncestor)
{
// when wrapping we use the current size, if it changes we check if we need another layout pass
// this is needed when resizing a form/label so it can wrap correctly as GetNaturalSize()
// will use the old size first, and won't necessarily know the final size of the label.
lastSize = size;
InvalidateMeasure();
}
isSizing = false;
}

protected MacLabel()
{
paragraphStyle = new NSMutableParagraphStyle();
Expand Down Expand Up @@ -343,12 +325,6 @@ protected virtual NSColor CurrentColor
}
}

public override void InvalidateMeasure()
{
base.InvalidateMeasure();
naturalSizeInfinity = null;
}

public override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Expand Down
Loading