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: Optimize layout of parent controls when size of control is set #2504

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions src/Eto.Wpf/Forms/PixelLayoutHandler.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,28 @@ public void Add(Control child, int x, int y)
swc.Canvas.SetLeft(element, x);
swc.Canvas.SetTop(element, y);
Control.Children.Add(element);
UpdatePreferredSize();
OnChildPreferredSizeUpdated();
}

public void Move(Control child, int x, int y)
{
var element = child.GetContainerControl();
swc.Canvas.SetLeft(element, x);
swc.Canvas.SetTop(element, y);
UpdatePreferredSize();
OnChildPreferredSizeUpdated();
}

public void Remove(Control child)
{
var element = child.GetContainerControl();
Control.Children.Remove(element);
UpdatePreferredSize();
OnChildPreferredSizeUpdated();
}

public override void Remove(sw.FrameworkElement child)
{
Control.Children.Remove(child);
UpdatePreferredSize();
OnChildPreferredSizeUpdated();
}

int suspended;
Expand Down
6 changes: 3 additions & 3 deletions src/Eto.Wpf/Forms/TableLayoutHandler.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public void Add(Control child, int x, int y)
}
Control.Children.Add(control);
}
UpdatePreferredSize();
OnChildPreferredSizeUpdated();
}

public void Move(Control child, int x, int y)
Expand All @@ -420,7 +420,7 @@ public void Move(Control child, int x, int y)
SetScale(handler, x, y);
}
controls[x, y] = child;
UpdatePreferredSize();
OnChildPreferredSizeUpdated();
}

public void Remove(Control child)
Expand All @@ -434,7 +434,7 @@ public override void Remove(sw.FrameworkElement child)
var y = swc.Grid.GetRow(child);
Control.Children.Remove(child);
controls[x, y] = null;
UpdatePreferredSize();
OnChildPreferredSizeUpdated();
}
}
}
2 changes: 1 addition & 1 deletion src/Eto.Wpf/Forms/WpfContainer.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface IWpfContainer
{
void Remove(sw.FrameworkElement child);

void UpdatePreferredSize();
void OnChildPreferredSizeUpdated();
}

public abstract class WpfContainer<TControl, TWidget, TCallback> : WpfFrameworkElement<TControl, TWidget, TCallback>, Container.IHandler, IWpfContainer
Expand Down
8 changes: 7 additions & 1 deletion src/Eto.Wpf/Forms/WpfFrameworkElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,16 @@ public virtual void UpdatePreferredSize()
{
if (Widget.Loaded)
{
Widget.VisualParent.GetWpfContainer()?.UpdatePreferredSize();
Widget.VisualParent.GetWpfContainer()?.OnChildPreferredSizeUpdated();
}
}

public virtual void OnChildPreferredSizeUpdated()
{
if (double.IsNaN(UserPreferredSize.Width) || double.IsNaN(UserPreferredSize.Height))
UpdatePreferredSize();
}

public virtual void SetScale(bool xscale, bool yscale)
{
XScale = xscale;
Expand Down
4 changes: 2 additions & 2 deletions src/Eto.Wpf/Forms/WpfPanel.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public Control Content
else
border.Child = null;
Control.InvalidateMeasure();
UpdatePreferredSize();
OnChildPreferredSizeUpdated();
}
}

Expand All @@ -125,7 +125,7 @@ public override void Remove(sw.FrameworkElement child)
{
content = null;
border.Child = null;
UpdatePreferredSize();
OnChildPreferredSizeUpdated();
}
}
}
Expand Down