diff --git a/Terminal.Gui/Application.cs b/Terminal.Gui/Application.cs index d825fb872..3b18a1b5d 100644 --- a/Terminal.Gui/Application.cs +++ b/Terminal.Gui/Application.cs @@ -526,12 +526,8 @@ public static partial class Application MoveCurrent (Current); } - //if (Toplevel.LayoutStyle == LayoutStyle.Computed) { toplevel.SetRelativeLayout (Driver.Screen.Size); - //} - - // BUGBUG: This call is likely not needed. toplevel.LayoutSubviews (); toplevel.PositionToplevels (); toplevel.FocusFirst (); diff --git a/Terminal.Gui/View/Layout/DimAuto.cs b/Terminal.Gui/View/Layout/DimAuto.cs index 0dbeb43da..dc8a55aa9 100644 --- a/Terminal.Gui/View/Layout/DimAuto.cs +++ b/Terminal.Gui/View/Layout/DimAuto.cs @@ -78,7 +78,7 @@ public class DimAuto () : Dim // TODO: This whole body of code is a WIP (for https://github.com/gui-cs/Terminal.Gui/pull/3451). subviewsSize = 0; - List visibleSubviews = us.Subviews.Where (v => v.Visible).ToList (); + List includedSubviews = us.Subviews.ToList();//.Where (v => !v.ExcludeFromLayout).ToList (); List subviews; #region Not Anchored and Are Not Dependent @@ -95,14 +95,14 @@ public class DimAuto () : Dim // [ ] DimView if (dimension == Dimension.Width) { - subviews = visibleSubviews.Where (v => v.X is not PosAnchorEnd + subviews = includedSubviews.Where (v => v.X is not PosAnchorEnd && v.X is not PosAlign // && v.X is not PosCenter && v.Width is not DimFill).ToList (); } else { - subviews = visibleSubviews.Where (v => v.Y is not PosAnchorEnd + subviews = includedSubviews.Where (v => v.Y is not PosAnchorEnd && v.Y is not PosAlign // && v.Y is not PosCenter && v.Height is not DimFill).ToList (); @@ -127,11 +127,11 @@ public class DimAuto () : Dim // [x] PosAnchorEnd if (dimension == Dimension.Width) { - subviews = visibleSubviews.Where (v => v.X is PosAnchorEnd).ToList (); + subviews = includedSubviews.Where (v => v.X is PosAnchorEnd).ToList (); } else { - subviews = visibleSubviews.Where (v => v.Y is PosAnchorEnd).ToList (); + subviews = includedSubviews.Where (v => v.Y is PosAnchorEnd).ToList (); } int maxAnchorEnd = 0; @@ -171,13 +171,13 @@ public class DimAuto () : Dim // [ ] DimPercent if (dimension == Dimension.Width) { - subviews = visibleSubviews.Where (v => v.Width is DimFill + subviews = includedSubviews.Where (v => v.Width is DimFill // || v.X is PosCenter ).ToList (); } else { - subviews = visibleSubviews.Where (v => v.Height is DimFill + subviews = includedSubviews.Where (v => v.Height is DimFill //|| v.Y is PosCenter ).ToList (); } diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 94348fc75..f9f55503c 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -315,6 +315,29 @@ public partial class View // EndLayout + private bool _excludeFromLayout; + + /// + /// Gets or sets whether this View will be excluded from layout computations. + /// + /// + /// If set to , the layout engine will ignore this view. Any subviews of this view will still be laid out. + /// Any views that have Pos or Dim objects that reference this view must have set to as well + /// + public bool ExcludeFromLayout + { + get => _excludeFromLayout; + set + { + if (value == _excludeFromLayout) + { + return; + } + _excludeFromLayout = value; + SetNeedsLayout(); + } + } + /// /// Controls how the View's is computed during . If the style is /// set to , LayoutSubviews does not change the . If the style is diff --git a/Terminal.Gui/View/View.cs b/Terminal.Gui/View/View.cs index 1632eca2f..f4e9c2d0d 100644 --- a/Terminal.Gui/View/View.cs +++ b/Terminal.Gui/View/View.cs @@ -252,6 +252,7 @@ public partial class View : Responder, ISupportInitializeNotification } Initialized?.Invoke (this, EventArgs.Empty); + LayoutSubviews(); } #endregion Constructors and Initialization diff --git a/UICatalog/Scenarios/AdornmentEditor.cs b/UICatalog/Scenarios/AdornmentEditor.cs index 008e3e367..a83aef990 100644 --- a/UICatalog/Scenarios/AdornmentEditor.cs +++ b/UICatalog/Scenarios/AdornmentEditor.cs @@ -85,6 +85,9 @@ public class AdornmentEditor : View public AdornmentEditor () { + Width = Dim.Auto (DimAutoStyle.Content); + Height = Dim.Auto (DimAutoStyle.Content); + BorderStyle = LineStyle.Dashed; Initialized += AdornmentEditor_Initialized; } @@ -166,10 +169,6 @@ public class AdornmentEditor : View { subview.Enabled = AdornmentToEdit is { }; } - - Width = Dim.Auto (minimumContentDim: Dim.Func (() => expandButton.Widest)); - Height = Dim.Auto (); - LayoutSubviews (); } private EventHandler ColorPickerColorChanged () diff --git a/UICatalog/Scenarios/AdornmentsEditor.cs b/UICatalog/Scenarios/AdornmentsEditor.cs index 746cc516b..020835420 100644 --- a/UICatalog/Scenarios/AdornmentsEditor.cs +++ b/UICatalog/Scenarios/AdornmentsEditor.cs @@ -27,8 +27,8 @@ public class AdornmentsEditor : View ColorScheme = Colors.ColorSchemes ["Dialog"]; Title = $"AdornmentsEditor"; - Width = Dim.Auto (); - Height = Dim.Fill (); + Width = Dim.Auto (DimAutoStyle.Content); + Height = Dim.Auto (DimAutoStyle.Content); BorderStyle = LineStyle.Double; //SuperViewRendersLineCanvas = true; @@ -123,6 +123,7 @@ public class AdornmentsEditor : View Add (_diagRulerCheckBox); _diagRulerCheckBox.Y = Pos.Bottom (_diagPaddingCheckBox); + } private void Application_MouseEvent (object sender, MouseEvent e) diff --git a/UICatalog/Scenarios/ContentScrolling.cs b/UICatalog/Scenarios/ContentScrolling.cs index 01587f056..c9cd6387f 100644 --- a/UICatalog/Scenarios/ContentScrolling.cs +++ b/UICatalog/Scenarios/ContentScrolling.cs @@ -355,8 +355,8 @@ public class ContentScrolling : Scenario { X = Pos.Center (), Y = Pos.Bottom (textView) + 1, - Width = 30, - Height = 10 + Width = Dim.Auto(DimAutoStyle.Content, maximumContentDim: Dim.Func (() => view.ContentSize.Width)), + Height = Dim.Auto (DimAutoStyle.Content, maximumContentDim: Dim.Percent(20)), }; charMap.Accept += (s, e) => diff --git a/UICatalog/Scenarios/ExpanderButton.cs b/UICatalog/Scenarios/ExpanderButton.cs index 6c56f76c7..b1a1c3211 100644 --- a/UICatalog/Scenarios/ExpanderButton.cs +++ b/UICatalog/Scenarios/ExpanderButton.cs @@ -45,7 +45,10 @@ public class ExpanderButton : Button Initialized += ExpanderButton_Initialized; } - private void ExpanderButton_Initialized (object sender, EventArgs e) { Orient (); } + private void ExpanderButton_Initialized (object sender, EventArgs e) + { + ExpandOrCollapse (Collapsed); + } private Orientation _orientation = Orientation.Horizontal; @@ -76,7 +79,24 @@ public class ExpanderButton : Button { _orientation = newOrientation; - Orient (); + if (Orientation == Orientation.Vertical) + { + X = Pos.AnchorEnd (); + Y = 0; + CollapsedGlyph = new ('\u21d1'); // ⇑ + ExpandedGlyph = new ('\u21d3'); // ⇓ + } + else + { + X = 0; + Y = Pos.AnchorEnd (); + CollapsedGlyph = new ('\u21d0'); // ⇐ + ExpandedGlyph = new ('\u21d2'); // ⇒ + } + + Text = $"{(Collapsed ? CollapsedGlyph : ExpandedGlyph)}"; + + ExpandOrCollapse (Collapsed); } return args.Cancel; @@ -98,7 +118,7 @@ public class ExpanderButton : Button /// public Rune ExpandedGlyph { get; set; } - private bool _collapsed = true; + private bool _collapsed = false; /// /// Gets or sets a value indicating whether the view is collapsed. @@ -121,6 +141,8 @@ public class ExpanderButton : Button { _collapsed = newValue; + ExpandOrCollapse (_collapsed); + View superView = SuperView; if (superView is Adornment adornment) @@ -128,17 +150,17 @@ public class ExpanderButton : Button superView = adornment.Parent; } - bool expanded = Orientation == Orientation.Vertical ? superView.Viewport.Height > 0 : superView.Viewport.Width > 0; - Orient (); - foreach (View subview in superView.Subviews) { - subview.Visible = !expanded; + subview.Visible = !Collapsed; + subview.Enabled = !Collapsed; } - Text = $"{(Collapsed ? CollapsedGlyph : ExpandedGlyph)}"; + // BUGBUG: This should not be needed. There's some bug in the layout system that doesn't update the layout. + superView.SuperView?.LayoutSubviews (); } + return args.Cancel; } @@ -147,13 +169,7 @@ public class ExpanderButton : Button /// to true. /// public event EventHandler> CollapsedChanging; - - // TODO: This is a workaround for Dim.Auto() not working as expected. - /// - /// Gets or sets the widest/tallest dimension of the view. - /// - public int Widest { get; set; } - + /// /// Collapses or Expands the view. /// @@ -165,13 +181,10 @@ public class ExpanderButton : Button return true; } - private void Orient () - { - if (!IsInitialized) - { - return; - } + private Dim _previousDim; + private void ExpandOrCollapse (bool collapse) + { View superView = SuperView; if (superView is Adornment adornment) @@ -179,48 +192,41 @@ public class ExpanderButton : Button superView = adornment.Parent; } - bool expanded = Orientation == Orientation.Vertical ? superView.Viewport.Height > 0 : superView.Viewport.Width > 0; - - if (expanded) + if (superView is null) { + return; + } + + if (collapse) + { + // Collapse if (Orientation == Orientation.Vertical) { - Widest = superView.ContentSize.Width; + _previousDim = superView.Height; superView.Height = 1; } else { - Widest = superView.ContentSize.Height; + _previousDim = superView.Width; superView.Width = 1; } } else { + if (_previousDim is null) + { + return; + } + + // Expand if (Orientation == Orientation.Vertical) { - superView.Height = Dim.Auto (); + superView.Height = _previousDim; } else { - superView.Width = Dim.Auto (); + superView.Width = _previousDim; } } - - if (Orientation == Orientation.Vertical) - { - X = Pos.AnchorEnd (); - Y = 0; - CollapsedGlyph = new ('\u21d1'); // ⇑ - ExpandedGlyph = new ('\u21d3'); // ⇓ - } - else - { - X = 0; - Y = Pos.AnchorEnd (); - CollapsedGlyph = new ('\u21d0'); // ⇐ - ExpandedGlyph = new ('\u21d2'); // ⇒ - } - - Text = $"{(Collapsed ? CollapsedGlyph : ExpandedGlyph)}"; } }