Skip to content

Commit

Permalink
Merge pull request #2585 from cwensley/curtis/mac-fix-endless-updates…
Browse files Browse the repository at this point in the history
…-with-label

Mac: Fix possible lockup with wrapped label when its size was very small
  • Loading branch information
cwensley authored Nov 28, 2023
2 parents 7719478 + 4399547 commit 015f78b
Showing 1 changed file with 13 additions and 37 deletions.
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

0 comments on commit 015f78b

Please sign in to comment.