picoe / Eto

Cross platform GUI framework for desktop and mobile applications in .NET
Other
3.67k stars 335 forks source link

how to avoid autosize of the parent controls #939

Closed msasso69 closed 6 years ago

msasso69 commented 6 years ago

Hi,

I'm using Eto and I have now a quite a complex UI, but now I have the need to size some custom controls according to the size of the container. What I do is to register to the SizeChanged event of the parent container and according to the available size I set the size of my child controls accordingly. The problem is that the parent controls are affected as well and once I reach the top level parent all the children are re-sized. On Wpf at the end somehow Eto stops resizing the UI (but takes ages), on Mac it loops forever.

Here is the Mac stack trace and a more detailed description of what happens:

Here Eto fires the SizeChanged event:

Eto.PropertyStore.TriggerEvent<System.EventArgs>(string key = "Control.SizeChanged", VisualSEO.EtoFormGui.Controls.CustomTabControl sender = {VisualSEO.EtoFormGui.Controls.CustomTabControl}, System.EventArgs args = {System.EventArgs}) in /Users/utonto/Eto/Source/Eto/PropertyStore.cs:234

Here I size my custom controls according to the size of the parent control:

VisualSEO.EtoFormGui.Controls.CustomTabControl.AnonymousMethod__1(VisualSEO.EtoFormGui.Controls.CustomTabControl sender = {VisualSEO.EtoFormGui.Controls.CustomTabControl}, System.EventArgs e = {System.EventArgs}) in /Users/utonto/vssrepo6/EtoFormGui/Controls/CustomTabControl.cs:149
VisualSEO.EtoFormGui.Controls.CustomTabControl.UpdateTabHeaderSizes(Eto.Drawing.Size size = {196,18}) in /Users/utonto/vssrepo6/EtoFormGui/Controls/CustomTabControl.cs:443
VisualSEO.EtoFormGui.Controls.CustomTabHeader.set_Size(Eto.Drawing.Size value = {196,18}) in /Users/utonto/vssrepo6/EtoFormGui/Controls/CustomTabHeader.cs:78
VisualSEO.EtoFormGui.Controls.CustomTabHeader.SetButtonSizes() in /Users/utonto/vssrepo6/EtoFormGui/Controls/CustomTabHeader.cs:94

Here Eto receives the size that I set form my custom control:

Eto.Forms.Control.set_Size(Eto.Drawing.Size value = {196,18}) in /Users/utonto/Eto/Source/Eto/Forms/Controls/Control.cs:682

If you look at the following stack track you can see that the parent control is affected as well:

Eto.Mac.Forms.MacView<Eto.Mac.Forms.Controls.DrawableHandler.EtoDrawableView,Eto.Forms.Drawable,Eto.Forms.Drawable.ICallback>.set_Size(Eto.Drawing.Size value = {196,18}) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacView.cs:185
Eto.Mac.Forms.MacView<Eto.Mac.Forms.Controls.DrawableHandler.EtoDrawableView,Eto.Forms.Drawable,Eto.Forms.Drawable.ICallback>.LayoutIfNeeded(Eto.Drawing.SizeF? oldPreferredSize = {197,18}, bool force = false) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacView.cs:209

and all the chain of parent controls are also affected:

Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.TableLayout,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.TableLayout,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.TableLayout,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.TableLayout,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.TableLayout,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.TableLayout,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.TableLayout,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.TableLayout,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.Controls.SplitterHandler.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/Controls/SplitterHandler.cs:41
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSSplitView,Eto.Forms.Splitter,Eto.Forms.Splitter.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.TableLayout,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.TableLayout,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.TableLayout,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.TableLayout,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.TableLayout,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.Controls.SplitterHandler.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/Controls/SplitterHandler.cs:41
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSSplitView,Eto.Forms.Splitter,Eto.Forms.Splitter.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:146
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSWindow,Eto.Forms.Form,Eto.Forms.Window.ICallback>.LayoutParent(bool updateSize = true) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:156

untill I probably reach the top when Eto instruct to resize all children:

Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSWindow,Eto.Forms.Form,Eto.Forms.Window.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:118
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:118
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSSplitView,Eto.Forms.Splitter,Eto.Forms.Splitter.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:118
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:118
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:118
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.TableLayout,Eto.Forms.Control.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:118
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:118
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:118
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.TableLayout,Eto.Forms.Control.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:118
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:118
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.TableLayout,Eto.Forms.Control.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:118
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:118
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.TableLayout,Eto.Forms.Control.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:118
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:118
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:118
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.TableLayout,Eto.Forms.Control.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:118
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:118
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSSplitView,Eto.Forms.Splitter,Eto.Forms.Splitter.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:118
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:118
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:118
Eto.Mac.Forms.MacContainer<MonoMac.AppKit.NSView,Eto.Forms.TableLayout,Eto.Forms.Control.ICallback>.LayoutAllChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacContainer.cs:115
Eto.Mac.Forms.TableLayoutHandler.LayoutChildren() in /Users/utonto/Eto/Source/Eto.Mac/Forms/TableLayoutHandler.cs:288
MonoMac.AppKit.NSView.set_Frame(MonoMac.CoreGraphics.CGRect value = {{X=4,Y=0,Width=3436,Height=399,5}}) in 
MonoMac.ObjCRuntime.Messaging.void_objc_msgSendSuper_CGRect() in 
Eto.Mac.Forms.MacView<MonoMac.AppKit.NSView,Eto.Forms.Panel,Eto.Forms.Control.ICallback>.SetFrameSizeAction(System.IntPtr sender = 0x167943f0, System.IntPtr sel = 0xffffffff9940d758, MonoMac.CoreGraphics.CGSize size = {{Width=3436,Height=399,5}}) in /Users/utonto/Eto/Source/Eto.Mac/Forms/MacView.cs:385
Eto.Forms.Control.Callback.OnSizeChanged(VisualSEO.EtoFormGui.Controls.CustomTabControl widget = {VisualSEO.EtoFormGui.Controls.CustomTabControl}, System.EventArgs e = {System.EventArgs}) in /Users/utonto/Eto/Source/Eto/Forms/Controls/Control.cs:1334
Eto.Forms.Control.OnSizeChanged(System.EventArgs e = {System.EventArgs}) in /Users/utonto/Eto/Source/Eto/Forms/Controls/Control.cs:128
Eto.PropertyStore.TriggerEvent<System.EventArgs>(string key = "Control.SizeChanged", VisualSEO.EtoFormGui.Controls.CustomTabControl sender = {VisualSEO.EtoFormGui.Controls.CustomTabControl}, System.EventArgs args = {System.EventArgs}) in /Users/utonto/Eto/Source/Eto/PropertyStore.cs:234

untill I reach again my the code in my custom control where I registered for the SizeChanged event:

VisualSEO.EtoFormGui.Controls.CustomTabControl.AnonymousMethod__1(VisualSEO.EtoFormGui.Controls.CustomTabControl sender = {VisualSEO.EtoFormGui.Controls.CustomTabControl}, System.EventArgs e = {System.EventArgs}) in /Users/utonto/vssrepo6/EtoFormGui/Controls/CustomTabControl.cs:149

This loops forever :(

The only thing that I could think of is to set a flag before resizing my custom controls (flag that I reset when my custom controls are resized) and ignore the SizeChanged event while the flag is on.

I'm wondering though whether my approach is correct or if there is a better way to handle the problem, maybe instructing Eto not to relayout the parents.

Any clue?

Specifications

cwensley commented 6 years ago

You might be able to get it to work by making sure none of the controls are scaled/expanded as you'd just be fighting with the layout system on which size to actually give the controls. For example, the last column & row of a TableLayout is by default scaled to fit the rest of its container, or any row/column that you have set xscale or yscale to true.

Another option is to use the PixelLayout so you specify the position and size of each control. For example, your custom tab header.

msasso69 commented 6 years ago

Thanks for your reply @cwensley,

I'm not sure I'm getting your advice correctly: if the custom control that I'm resizing will be smaller than the Layout in which it is contained I assume that the containing Layout is not resized as well. Is this assumption correct? Or all Layouts (except for PixelLayout) always adapt their sizes in order to perfectly fit the contained controls? Have I understood correctly that PixelLayout never adapts to the content? (Ok this I can easily find out ;) Anyway let me ask you another question: very rarely in the Eto.Test I see you using PixelLayout, and in the Wiki you highly discourage the usage of it in favour of the other Layout types because of their auto size capabilities, so I avoided it as hell and massively used StackLayout and TableLayout. Doing so I ended up in intensive (Table/Stack)Layout nesting and a very slow UI. I hope that the reason of my poor performances is that I'm bouncing from bottom to top and all the way back the resize event as I recently found out, and for sure I'll work on this starting from using PixelLayout for containing my custom tab header as you suggested, but (and here is my question) is the usage of many nested Layout the correct way to design a UI with Eto, or should I limit the nesting to the bare minimum? I never used PixelLayout because looked to me too much old Winforms style, but now I'm starting to think that if I used it I could completely avoid the nested Layout and the UI would be much faster. Is this correct? Which is the faster Layout container?

Thanks

Note: Excuse my "funny" English and sorry if I bother you with so many questions!

cwensley commented 6 years ago

if the custom control that I'm resizing will be smaller than the Layout in which it is contained I assume that the containing Layout is not resized as well. Is this assumption correct?

No, that is incorrect. The parent layout (other than Window, Scrollable, or Splitter) will always resize to reflect the size change of a child control, unless the parent has its size set explicitly. For example, this is an invalid case as it is conflicts with the layout:

var myControl = new Drawable { Size = new Size(200, 200) };
var button = new Button { Text = "Click Me" };
var table = new TableLayout {
    Rows = {
        new TableRow(myControl) { ScaleHeight = true },
        button
    }
};
var form = new Form { Content = table };

button.Click += (sender, e) => myControl.Size = new Size(100, 100);

The TableLayout will ensure that myControl takes up all space of its cell. If you do want the control to be resized manually, you need to account for the extra space that will be needed. This can be done by using the TableLayout.AutoSized helper like so:

var table = new TableLayout
{
    Rows = {
        new TableRow(TableLayout.AutoSized(myControl)) { ScaleHeight = true },
        button
    }
};

or, perhaps a PixelLayout:

var pixel = new PixelLayout();
pixel.Add(myControl, 0, 0);

var table = new TableLayout
{
    Rows = {
        new TableRow(pixel) { ScaleHeight = true },
        button
    }
};

Have I understood correctly that PixelLayout never adapts to the content?

The PixelLayout does adapt to the content by autosizing itself based on the controls it contains and their sizes. If you do not want it to do this, set its size explicitly.

is the usage of many nested Layout the correct way to design a UI with Eto, or should I limit the nesting to the bare minimum

Like many UI frameworks, the more you nest the more the UI will have to do to update all those levels of containers. Limiting the nesting to only what you need is the correct way to do it.

I never used PixelLayout because looked to me too much old Winforms style, but now I'm starting to think that if I used it I could completely avoid the nested Layout and the UI would be much faster. Is this correct? Which is the faster Layout container?

Using PixelLayout won't necessarily fix all the performance problems as it does adapt to the content as mentioned.

This all being said, there might be things that can be done to improve performance on one platform or the other. Are you only testing on macOS? The other platforms will definitely have different performance characteristics so if say it's going really fast on WPF but really dog slow on macOS it might be a good idea to see why. A lot of the layout logic on macOS is done manually within Eto so there may be room for improvement.

I can think of at least one thing I've been meaning to do but never saw the need (most UI's I've dealt with don't have performance problems), which is to queue a layout pass instead of updating it each time. This might change the behaviour slightly though as the new sizes wouldn't necessarily be reflected right away.

Note: Excuse my "funny" English and sorry if I bother you with so many questions!

No problem, you're English isn't too hard to follow and questions are always welcome. (;

msasso69 commented 6 years ago

Thanks Curtis, you definitely gave me some useful hints :) now it's my turn to play with my UI and manage to speed it up.

cwensley commented 6 years ago

@msasso69 PR #1020 might help the performance issues as it'll drastically reduce the number of times it needs to layout the controls. There's still a lot of room for improvement, but hopefully that will help.

msasso69 commented 6 years ago

This is a really good news, I'm looking forward to trying it now! :)

cwensley commented 6 years ago

Hey @msasso69, I'm closing this for now as I think this has been greatly improved. If you have more info (e.g. a sample app) that can reproduce any further performance issues, feel free to comment further on this issue.

cwensley commented 6 years ago

@msasso69 check out #1112, it might help a ton more to speed up your complex UI on Mac.