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

Wpf: Fix endless update cycles due to odd DPIs and wrapped labels #2043

Merged
merged 1 commit into from
Oct 19, 2021
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
22 changes: 12 additions & 10 deletions src/Eto.Wpf/Forms/Controls/LabelHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected override sw.Size MeasureOverride(sw.Size constraint)
public class LabelHandler : WpfControl<swc.Label, Label, Label.ICallback>, Label.IHandler
{
readonly swc.AccessText accessText;
double? previousWidth;
double? previousDesiredHeight;
string text;

protected override void SetDecorations(sw.TextDecorationCollection decorations)
Expand All @@ -55,24 +55,26 @@ void Control_SizeChanged(object sender, sw.SizeChangedEventArgs e)
// not loaded? don't worry about it.
if (!Control.IsLoaded)
return;
var newWidth = Control.ActualWidth;
if (previousWidth == null)
var newDesiredHeight = Control.DesiredSize.Height;
if (previousDesiredHeight == null)
{
// don't update preferred sizes when called the first time.
// when there's many labels this causes a major slowdown
// the initial size should already have been taken care of by
// the initial layout pass.
previousWidth = newWidth;
previousDesiredHeight = newDesiredHeight;
return;
}

// ignore tiny changes as in some scales (e.g. 150%, 175%) it can cause an endless update cycle
if (Math.Abs(previousWidth.Value - newWidth) < 1)
// Is this needed any more? We are now only comparing desired size vs. actual, which doesn't
// appear to have this problem
if (Math.Abs(previousDesiredHeight.Value - newDesiredHeight) < 1)
return;
// update parents when the actual width has changed
// otherwise it won't shrink vertically when it gets wider
// when wrapped
previousWidth = newWidth;

// update parents when the actual desired height has changed
// otherwise parent containers won't shrink vertically when it gets wider when wrapped
previousDesiredHeight = newDesiredHeight;
if (Wrap != WrapMode.None)
UpdatePreferredSize();
}
Expand Down