Browse Source

Revamped Slider - Make it a showcase for how to build a View that uses Dim.Auto

Tig 1 year ago
parent
commit
0b969d9eb0

+ 2 - 2
Terminal.Gui/View/Layout/Dim.cs

@@ -412,7 +412,7 @@ public class DimAuto (DimAutoStyle style, Dim minimumContentDim, Dim maximumCont
         {
             Debug.WriteLine ($"WARNING: DimAuto specifies a min size ({autoMin}), but the SuperView's bounds are smaller ({superviewContentSize}).");
 
-            return superviewContentSize;
+            //return superviewContentSize;
         }
 
         if (Style.HasFlag (DimAutoStyle.Text))
@@ -478,7 +478,7 @@ public class DimAuto (DimAutoStyle style, Dim minimumContentDim, Dim maximumCont
         }
 
         // If max: is set, clamp the return - BUGBUG: Not tested
-        return int.Min (max, MaximumContentDim?.Anchor (superviewContentSize) ?? superviewContentSize);
+        return int.Min (max, MaximumContentDim?.Anchor (superviewContentSize) ?? max);
     }
 
     internal override bool ReferencesOtherViews ()

+ 114 - 50
Terminal.Gui/Views/Slider.cs

@@ -1,4 +1,6 @@
-namespace Terminal.Gui;
+using Microsoft.CodeAnalysis.Options;
+
+namespace Terminal.Gui;
 
 /// <summary><see cref="EventArgs"/> for <see cref="Slider{T}"/> <see cref="SliderOption{T}"/> events.</summary>
 public class SliderOptionEventArgs : EventArgs
@@ -256,17 +258,16 @@ public class Slider<T> : View
         SetDefaultStyle ();
         SetCommands ();
 
-        Enter += (s, e) => { };
-
+        SetContentSize ();
         // BUGBUG: This should not be needed - Need to ensure SetRelativeLayout gets called during EndInit
         Initialized += (s, e) =>
-                         {
-                             SetContentSizeBestFit ();
-                         };
+                       {
+                           SetContentSize ();
+                       };
 
         LayoutStarted += (s, e) =>
                           {
-                              SetContentSizeBestFit ();
+                              SetContentSize ();
                           };
 
     }
@@ -357,6 +358,32 @@ public class Slider<T> : View
 
     #region Properties
 
+    /// <inheritdoc />
+    public override string Text
+    {
+        get
+        {
+            if (_options.Count == 0)
+            {
+                return string.Empty;
+            }
+            // Return labels as a CSV string
+            return string.Join (",", _options);
+        }
+        set
+        {
+            if (string.IsNullOrEmpty (value))
+            {
+                Options = [];
+            }
+            else
+            {
+                var list = value.Split (',').Select (x => x.Trim ());
+                Options = list.Select (x => new SliderOption<T> { Legend = x }).ToList ();
+            }
+        }
+    }
+
     /// <summary>Allow no selection.</summary>
     public bool AllowEmpty
     {
@@ -372,6 +399,7 @@ public class Slider<T> : View
         }
     }
 
+    // BUGBUG: InnerSpacing is ignored; SetContentSize overwrites it.
     /// <summary>Gets or sets the number of rows/columns between <see cref="Options"/></summary>
     public int InnerSpacing
     {
@@ -380,7 +408,7 @@ public class Slider<T> : View
         {
             _config._innerSpacing = value;
 
-            SetContentSizeBestFit ();
+           // SetContentSize ();
         }
     }
 
@@ -423,8 +451,7 @@ public class Slider<T> : View
         {
             _config._sliderOrientation = newOrientation;
             SetKeyBindings ();
-
-            SetContentSizeBestFit ();
+            SetContentSize ();
         }
 
         return args.Cancel;
@@ -438,7 +465,7 @@ public class Slider<T> : View
         {
             _config._legendsOrientation = value;
 
-            SetContentSizeBestFit ();
+            SetContentSize ();
         }
     }
 
@@ -465,12 +492,11 @@ public class Slider<T> : View
             // _options should never be null
             _options = value ?? throw new ArgumentNullException (nameof (value));
 
-            if (!IsInitialized || _options.Count == 0)
+            if (_options.Count == 0)
             {
                 return;
             }
-
-            SetContentSizeBestFit ();
+            SetContentSize ();
         }
     }
 
@@ -488,7 +514,7 @@ public class Slider<T> : View
         set
         {
             _config._showEndSpacing = value;
-            SetNeedsDisplay ();
+            SetContentSize ();
         }
     }
 
@@ -499,7 +525,22 @@ public class Slider<T> : View
         set
         {
             _config._showLegends = value;
-            SetContentSizeBestFit ();
+            SetContentSize ();
+        }
+    }
+
+    private bool _useMinimumSizeForDimAuto;
+
+    /// <summary>
+    /// Gets or sets whether the minimum or ideal size will be used when Height or Width are set to Dim.Auto.
+    /// </summary>
+    public bool UseMinimumSizeForDimAuto
+    {
+        get => _useMinimumSizeForDimAuto;
+        set
+        {
+            _useMinimumSizeForDimAuto = value;
+            SetContentSize ();
         }
     }
 
@@ -607,69 +648,61 @@ public class Slider<T> : View
         // Last = '┤',
     }
 
-    /// <summary>Adjust the dimensions of the Slider to the best value.</summary>
-    public void SetContentSizeBestFit ()
+    /// <summary>Sets the dimensions of the Slider to the ideal values.</summary>
+    public void SetContentSize ()
     {
-        if (/*!IsInitialized ||*/ /*!(Height is DimAuto && Width is DimAuto) || */_options.Count == 0)
+        if (_options.Count == 0)
         {
             return;
         }
 
-        CalcSpacingConfig ();
-
-        Thickness adornmentsThickness = GetAdornmentsThickness ();
+        bool horizontal = _config._sliderOrientation == Orientation.Horizontal;
 
-        var svWidth = SuperView?.ContentSize.Width ?? 0;
-        var svHeight = SuperView?.ContentSize.Height ?? 0;
-
-        if (_config._sliderOrientation == Orientation.Horizontal)
+        if (UseMinimumSizeForDimAuto)
         {
-            SetContentSize (new (int.Min (svWidth, CalcBestLength ()), int.Min (svHeight, CalcThickness ())));
+            CalcSpacingConfig (0);
         }
         else
         {
-            SetContentSize (new (int.Min (svWidth, CalcThickness ()), int.Min (svHeight, CalcBestLength ())));
+            CalcSpacingConfig (horizontal ? Viewport.Width : Viewport.Height);
         }
+        SetContentSize (new (GetIdealWidth (), GetIdealHeight ()));
 
         return;
 
-        void CalcSpacingConfig ()
+        void CalcSpacingConfig (int size)
         {
             _config._innerSpacing = 0;
             _config._startSpacing = 0;
             _config._endSpacing = 0;
 
-            int size = 0;
-            if (ContentSize is { })
-            {
-                size = _config._sliderOrientation == Orientation.Horizontal ? ContentSize.Width : ContentSize.Height;
-            }
-
             int max_legend; // Because the legends are centered, the longest one determines inner spacing
 
             if (_config._sliderOrientation == _config._legendsOrientation)
             {
-                max_legend = int.Max (_options.Max (s => s.Legend?.Length ?? 1), 1);
+                max_legend = int.Max (_options.Max (s => s.Legend?.GetColumns () ?? 1), 1);
             }
             else
             {
                 max_legend = 1;
             }
 
-            int min_size_that_fits_legends = _options.Count == 1 ? max_legend : max_legend / (_options.Count - 1);
+            int min_size_that_fits_legends = _options.Count == 1 ? max_legend : _options.Sum (o => o.Legend.GetColumns ());
 
             string first;
             string last;
 
-            if (max_legend >= size)
+            if (min_size_that_fits_legends > size)
             {
+                _config._showLegendsAbbr = false;
+
                 if (_config._sliderOrientation == _config._legendsOrientation)
                 {
                     _config._showLegendsAbbr = true;
 
                     foreach (SliderOption<T> o in _options.Where (op => op.LegendAbbr == default (Rune)))
                     {
-                        o.LegendAbbr = (Rune)(o.Legend?.Length > 0 ? o.Legend [0] : ' ');
+                        o.LegendAbbr = (Rune)(o.Legend?.GetColumns () > 0 ? o.Legend [0] : ' ');
                     }
                 }
 
@@ -731,9 +764,38 @@ public class Slider<T> : View
         return length;
     }
 
-    /// <summary>Calculates the ideal dimension required for all options, inner spacing, and legends (non-abbreviated).</summary>
+    /// <summary>
+    /// Gets the ideal width of the slider. The ideal width is the minimum width required to display all options and inner spacing.
+    /// </summary>
+    /// <returns></returns>
+    public int GetIdealWidth ()
+    {
+        if (UseMinimumSizeForDimAuto)
+        {
+            return Orientation == Orientation.Horizontal ? CalcMinLength () : CalcIdealThickness ();
+
+        }
+        return Orientation == Orientation.Horizontal ? CalcIdealLength () : CalcIdealThickness ();
+    }
+
+    /// <summary>
+    /// Gets the ideal height of the slider. The ideal height is the minimum height required to display all options and inner spacing.
+    /// </summary>
     /// <returns></returns>
-    private int CalcBestLength ()
+    public int GetIdealHeight ()
+    {
+        if (UseMinimumSizeForDimAuto)
+        {
+            return Orientation == Orientation.Horizontal ? CalcIdealThickness () : CalcMinLength ();
+        }
+        return Orientation == Orientation.Horizontal ? CalcIdealThickness () : CalcIdealLength ();
+    }
+
+    /// <summary>
+    /// Calculates the ideal dimension required for all options, inner spacing, and legends (non-abbreviated, with one space between).
+    /// </summary>
+    /// <returns></returns>
+    private int CalcIdealLength ()
     {
         if (_options.Count == 0)
         {
@@ -748,23 +810,25 @@ public class Slider<T> : View
 
             if (_config._legendsOrientation == _config._sliderOrientation && _options.Count > 0)
             {
-                max_legend = int.Max (_options.Max (s => s.Legend?.Length + 1 ?? 1), 1);
-                length += max_legend * _options.Count;
-
-                //length += (max_legend / 2);
+                // Each legend should be centered in a space the width of the longest legend, with one space between.
+                // Calculate the total length required for all legends.
+                max_legend = int.Max (_options.Max (s => s.Legend?.GetColumns () ?? 1), 1);
+                length = max_legend * _options.Count + (_options.Count - 1);
             }
             else
             {
-                length += 1;
+                length += _options.Count;
             }
         }
 
-        return int.Max (length, CalcMinLength ());
+        return length;
     }
 
-    /// <summary>Calculates the min dimension required for the slider and legends</summary>
+    /// <summary>
+    /// Calculates the minimum dimension required for the slider and legends.
+    /// </summary>
     /// <returns></returns>
-    private int CalcThickness ()
+    private int CalcIdealThickness ()
     {
         var thickness = 1; // Always show the slider.
 
@@ -772,7 +836,7 @@ public class Slider<T> : View
         {
             if (_config._legendsOrientation != _config._sliderOrientation && _options.Count > 0)
             {
-                thickness += _options.Max (s => s.Legend?.Length ?? 0);
+                thickness += _options.Max (s => s.Legend?.GetColumns () ?? 0);
             }
             else
             {

+ 73 - 36
UICatalog/Scenarios/DimAutoDemo.cs

@@ -1,6 +1,6 @@
 using System;
+using System.Collections.Generic;
 using Terminal.Gui;
-using static Terminal.Gui.Dim;
 
 namespace UICatalog.Scenarios;
 
@@ -17,89 +17,119 @@ public class DimAutoDemo : Scenario
         {
             Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
         };
+
+        // For diagnostics
         appWindow.Padding.Thickness = new Thickness (1);
 
-        var view = new FrameView
+        FrameView dimAutoFrameView = CreateDimAutoContentFrameView ();
+
+        FrameView sliderFrameView = CreateSliderFrameView ();
+        sliderFrameView.X = Pos.Right(dimAutoFrameView) + 1;
+        sliderFrameView.Width = Dim.Fill ();
+        sliderFrameView.Height = Dim.Fill ();
+
+
+        //var dlgButton = new Button
+        //{
+        //    Text = "Open Test _Dialog",
+        //    X = Pos.Right (dimAutoFrameView),
+        //    Y = Pos.Top (dimAutoFrameView)
+        //};
+        //dlgButton.Accept += DlgButton_Clicked;
+
+        appWindow.Add (dimAutoFrameView, sliderFrameView /*dlgButton*/);
+
+        // Run - Start the application.
+        Application.Run (appWindow);
+        appWindow.Dispose ();
+
+        // Shutdown - Calling Application.Shutdown is required.
+        Application.Shutdown ();
+    }
+
+    private static FrameView CreateDimAutoContentFrameView ()
+    {
+        var dimAutoFrameView = new FrameView
         {
             Title = "Type to make View grow",
             X = 0,
             Y = 0,
-            Width = Auto (DimAutoStyle.Content, minimumContentDim: Dim.Percent (25)),
-            Height = Auto (DimAutoStyle.Content, minimumContentDim: 10)
+            Width = Dim.Auto (DimAutoStyle.Content, minimumContentDim: Dim.Percent (25)),
+            Height = Dim.Auto (DimAutoStyle.Content, minimumContentDim: 10)
         };
-        view.Margin.Thickness = new Thickness (1);
-        view.ValidatePosDim = true;
+        dimAutoFrameView.Margin.Thickness = new Thickness (1);
+        dimAutoFrameView.ValidatePosDim = true;
 
         var textEdit = new TextView
         {
             Text = "",
             X = 0, Y = 0, Width = 20, Height = 4
         };
-        view.Add (textEdit);
+        dimAutoFrameView.Add (textEdit);
 
         var vlabel = new Label
         {
             Text = textEdit.Text,
             X = Pos.Left (textEdit),
             Y = Pos.Bottom (textEdit) + 1,
-            Width = Auto (DimAutoStyle.Text, 1),
-            Height = Auto (DimAutoStyle.Text, 8),
+            Width = Dim.Auto (DimAutoStyle.Text, 1),
+            Height = Dim.Auto (DimAutoStyle.Text, 8),
             ColorScheme = Colors.ColorSchemes ["Error"],
             TextDirection = TextDirection.TopBottom_LeftRight
         };
         vlabel.Id = "vlabel";
-        view.Add (vlabel);
+        dimAutoFrameView.Add (vlabel);
 
         var hlabel = new Label
         {
             Text = textEdit.Text,
             X = Pos.Right (vlabel) + 1,
             Y = Pos.Bottom (textEdit),
-            Width = Auto (DimAutoStyle.Text, 20),
-            Height = Auto (DimAutoStyle.Text, 1),
+            Width = Dim.Auto (DimAutoStyle.Text, 20),
+            Height = Dim.Auto (DimAutoStyle.Text, 1),
             ColorScheme = Colors.ColorSchemes ["Error"]
         };
         hlabel.Id = "hlabel";
-        view.Add (hlabel);
+        dimAutoFrameView.Add (hlabel);
 
         var heightAuto = new View
         {
             X = Pos.Right (vlabel) + 1,
             Y = Pos.Bottom (hlabel) + 1,
             Width = 20,
-            Height = Auto (),
+            Height = Dim.Auto (),
             ColorScheme = Colors.ColorSchemes ["Error"],
             Title = "W: 20, H: Auto",
             BorderStyle = LineStyle.Rounded
         };
         heightAuto.Id = "heightAuto";
-        view.Add (heightAuto);
+        dimAutoFrameView.Add (heightAuto);
 
         var widthAuto = new View
         {
             X = Pos.Right (heightAuto) + 1,
             Y = Pos.Bottom (hlabel) + 1,
-            Width = Auto (),
+            Width = Dim.Auto (),
             Height = 5,
             ColorScheme = Colors.ColorSchemes ["Error"],
             Title = "W: Auto, H: 5",
             BorderStyle = LineStyle.Rounded
         };
         widthAuto.Id = "widthAuto";
-        view.Add (widthAuto);
+        dimAutoFrameView.Add (widthAuto);
 
         var bothAuto = new View
         {
             X = Pos.Right (widthAuto) + 1,
             Y = Pos.Bottom (hlabel) + 1,
-            Width = Auto (),
-            Height = Auto (),
+            Width = Dim.Auto (),
+            Height = Dim.Auto (),
             ColorScheme = Colors.ColorSchemes ["Error"],
             Title = "W: Auto, H: Auto",
             BorderStyle = LineStyle.Rounded
         };
         bothAuto.Id = "bothAuto";
-        view.Add (bothAuto);
+        dimAutoFrameView.Add (bothAuto);
 
         textEdit.ContentsChanged += (s, e) =>
                                     {
@@ -117,7 +147,7 @@ public class DimAutoDemo : Scenario
             Y = Pos.Bottom (vlabel)
         };
         movingButton.Accept += (s, e) => { movingButton.Y = movingButton.Frame.Y + 1; };
-        view.Add (movingButton);
+        dimAutoFrameView.Add (movingButton);
 
         var resetButton = new Button
         {
@@ -127,24 +157,31 @@ public class DimAutoDemo : Scenario
         };
 
         resetButton.Accept += (s, e) => { movingButton.Y = Pos.Bottom (hlabel); };
-        view.Add (resetButton);
+        dimAutoFrameView.Add (resetButton);
+
+        return dimAutoFrameView;
+    }
 
-        var dlgButton = new Button
+    private static FrameView CreateSliderFrameView ()
+    {
+        var sliderFrameView = new FrameView
         {
-            Text = "Open Test _Dialog",
-            X = Pos.Right (view),
-            Y = Pos.Top (view)
+            Title = "Slider - Example of a DimAuto View",
         };
-        dlgButton.Accept += DlgButton_Clicked;
-
-        appWindow.Add (view, dlgButton);
 
-        // Run - Start the application.
-        Application.Run (appWindow);
-        appWindow.Dispose ();
+        List<object> options = new () { "One", "Two", "Three", "Four" };
+        Slider slider = new (options)
+        {
+            X = 0,
+            Y = 0,
+            Type = SliderType.Multiple,
+            AllowEmpty = false,
+            BorderStyle = LineStyle.Double,
+            Title = "_Slider"
+        };
+        sliderFrameView.Add (slider);
 
-        // Shutdown - Calling Application.Shutdown is required.
-        Application.Shutdown ();
+        return sliderFrameView;
     }
 
     private void DlgButton_Clicked (object sender, EventArgs e)
@@ -152,7 +189,7 @@ public class DimAutoDemo : Scenario
         var dlg = new Dialog
         {
             Title = "Test Dialog",
-            Width = Auto (minimumContentDim: Percent (10))
+            Width = Dim.Auto (minimumContentDim: Dim.Percent (10))
 
             //Height = Dim.Auto (min: Dim.Percent (50))
         };
@@ -163,7 +200,7 @@ public class DimAutoDemo : Scenario
             TextFormatter = new () { WordWrap = true },
             X = 0,
             Y = 0, //Pos.Bottom (label) + 1,
-            Width = Fill (10),
+            Width = Dim.Fill (10),
             Height = 1
         };
 

+ 47 - 20
UICatalog/Scenarios/Sliders.cs

@@ -120,10 +120,17 @@ public class Sliders : Scenario
         v.Add (one);
     }
 
-    public override void Setup ()
+    public override void Main ()
     {
+        Application.Init ();
+
+        Window app = new ()
+        {
+            Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
+        };
+
         MakeSliders (
-                     Win,
+                     app,
                      new List<object>
                      {
                          500,
@@ -149,7 +156,7 @@ public class Sliders : Scenario
             ColorScheme = Colors.ColorSchemes ["Dialog"]
         };
 
-        Win.Add (configView);
+        app.Add (configView);
 
         #region Config Slider
 
@@ -158,6 +165,7 @@ public class Sliders : Scenario
             Title = "Options",
             X = 0,
             Y = 0,
+            Width = Dim.Fill (),
             Type = SliderType.Multiple,
             AllowEmpty = true,
             BorderStyle = LineStyle.Single
@@ -178,7 +186,7 @@ public class Sliders : Scenario
 
         optionsSlider.OptionsChanged += (sender, e) =>
                                  {
-                                     foreach (Slider s in Win.Subviews.OfType<Slider> ())
+                                     foreach (Slider s in app.Subviews.OfType<Slider> ())
                                      {
                                          s.ShowLegends = e.Options.ContainsKey (0);
                                          s.RangeAllowSingle = e.Options.ContainsKey (1);
@@ -209,22 +217,38 @@ public class Sliders : Scenario
                                          }
                                      }
 
-                                     if (Win.IsInitialized)
+                                     if (app.IsInitialized)
                                      {
-                                         Win.LayoutSubviews ();
+                                         app.LayoutSubviews ();
                                      }
                                  };
         optionsSlider.SetOption (0); // Legends
         optionsSlider.SetOption (1); // RangeAllowSingle
         optionsSlider.SetOption (3); // DimAuto
 
+        CheckBox dimAutoUsesMin = new ()
+        {
+            Text = "DimAuto uses minimum size (vs. ideal)",
+            X = 0,
+            Y = Pos.Bottom (optionsSlider)
+        };
+
+        dimAutoUsesMin.Toggled += (sender, e) =>
+                                  {
+                                      foreach (Slider s in app.Subviews.OfType<Slider> ())
+                                      {
+                                          s.UseMinimumSizeForDimAuto = !s.UseMinimumSizeForDimAuto;
+                                      }
+                                  };
+        configView.Add (dimAutoUsesMin);
+
         #region Slider Orientation Slider
 
         Slider<string> orientationSlider = new (new List<string> { "Horizontal", "Vertical" })
         {
             Title = "Slider Orientation",
             X = 0,
-            Y = Pos.Bottom (optionsSlider) + 1,
+            Y = Pos.Bottom (dimAutoUsesMin) + 1,
             BorderStyle = LineStyle.Single
         };
 
@@ -236,7 +260,7 @@ public class Sliders : Scenario
                                                     {
                                                         View prev = null;
 
-                                                        foreach (Slider s in Win.Subviews.OfType<Slider> ())
+                                                        foreach (Slider s in app.Subviews.OfType<Slider> ())
                                                         {
                                                             if (e.Options.ContainsKey (0))
                                                             {
@@ -300,7 +324,7 @@ public class Sliders : Scenario
                                                             }
                                                         }
 
-                                                        Win.LayoutSubviews ();
+                                                        app.LayoutSubviews ();
                                                     };
 
         #endregion Slider Orientation Slider
@@ -321,7 +345,7 @@ public class Sliders : Scenario
 
         legendsOrientationSlider.OptionsChanged += (sender, e) =>
                                                      {
-                                                         foreach (Slider s in Win.Subviews.OfType<Slider> ())
+                                                         foreach (Slider s in app.Subviews.OfType<Slider> ())
                                                          {
                                                              if (e.Options.ContainsKey (0))
                                                              {
@@ -357,19 +381,19 @@ public class Sliders : Scenario
                                                              }
                                                          }
 
-                                                         Win.LayoutSubviews ();
+                                                         app.LayoutSubviews ();
                                                      };
 
         #endregion Legends Orientation Slider
 
         #region Color Slider
 
-        foreach (Slider s in Win.Subviews.OfType<Slider> ())
+        foreach (Slider s in app.Subviews.OfType<Slider> ())
         {
-            s.Style.OptionChar.Attribute = Win.GetNormalColor ();
-            s.Style.SetChar.Attribute = Win.GetNormalColor ();
-            s.Style.LegendAttributes.SetAttribute = Win.GetNormalColor ();
-            s.Style.RangeChar.Attribute = Win.GetNormalColor ();
+            s.Style.OptionChar.Attribute = app.GetNormalColor ();
+            s.Style.SetChar.Attribute = app.GetNormalColor ();
+            s.Style.LegendAttributes.SetAttribute = app.GetNormalColor ();
+            s.Style.RangeChar.Attribute = app.GetNormalColor ();
         }
 
         Slider<(Color, Color)> sliderFGColor = new ()
@@ -417,7 +441,7 @@ public class Sliders : Scenario
                                             {
                                                 (Color, Color) data = e.Options.First ().Value.Data;
 
-                                                foreach (Slider s in Win.Subviews.OfType<Slider> ())
+                                                foreach (Slider s in app.Subviews.OfType<Slider> ())
                                                 {
                                                     s.ColorScheme = new ColorScheme (s.ColorScheme);
 
@@ -471,7 +495,7 @@ public class Sliders : Scenario
                                             {
                                                 (Color, Color) data = e.Options.First ().Value.Data;
 
-                                                foreach (Slider s in Win.Subviews.OfType<Slider> ())
+                                                foreach (Slider s in app.Subviews.OfType<Slider> ())
                                                 {
                                                     s.ColorScheme = new ColorScheme (s.ColorScheme)
                                                     {
@@ -488,7 +512,10 @@ public class Sliders : Scenario
 
         #endregion Config Slider
 
-        Win.FocusFirst ();
-        Top.Initialized += (s, e) => Top.LayoutSubviews ();
+        app.FocusFirst ();
+
+        Application.Run (app);
+        app.Dispose ();
+        Application.Shutdown ();
     }
 }

+ 6 - 6
UnitTests/View/Layout/Dim.AutoTests.cs

@@ -364,7 +364,7 @@ public class DimAutoTests (ITestOutputHelper output)
 
         superView.BeginInit ();
         superView.EndInit ();
-        Assert.Throws<InvalidOperationException> (() => superView.Add (subView));
+        superView.Add (subView);
 
         subView.Width = 10;
         superView.Add (subView);
@@ -372,11 +372,11 @@ public class DimAutoTests (ITestOutputHelper output)
         superView.LayoutSubviews (); // no throw
 
         subView.Width = Dim.Fill ();
-        Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
+        superView.SetRelativeLayout (new (0, 0));
         subView.Width = 10;
 
         subView.Height = Dim.Fill ();
-        Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
+        superView.SetRelativeLayout (new (0, 0));
         subView.Height = 10;
 
         subView.Height = Dim.Percent (50);
@@ -435,15 +435,15 @@ public class DimAutoTests (ITestOutputHelper output)
         superView.LayoutSubviews (); // no throw
 
         subView.Height = Dim.Fill () + 3;
-        Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
+         superView.SetRelativeLayout (new (0, 0));
         subView.Height = 0;
 
         subView.Height = 3 + Dim.Fill ();
-        Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
+        superView.SetRelativeLayout (new (0, 0));
         subView.Height = 0;
 
         subView.Height = 3 + 5 + Dim.Fill ();
-        Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
+        superView.SetRelativeLayout (new (0, 0));
         subView.Height = 0;
 
         subView.Height = 3 + 5 + Dim.Percent (10);

+ 13 - 10
UnitTests/Views/SliderTests.cs

@@ -156,8 +156,8 @@ public class SliderTests
         Assert.False (slider.ShowEndSpacing);
         Assert.Equal (SliderType.Single, slider.Type);
         Assert.Equal (0, slider.InnerSpacing);
-        Assert.Equal (Dim.Auto (DimAutoStyle.Content), slider.Width);
-        Assert.Equal (Dim.Auto (DimAutoStyle.Content), slider.Height);
+        Assert.True (slider.Width is DimAuto);
+        Assert.True (slider.Height is DimAuto);
         Assert.Equal (0, slider.FocusedOption);
     }
 
@@ -169,8 +169,14 @@ public class SliderTests
 
         // Act
         Slider<int> slider = new (options);
+        slider.SetRelativeLayout (new (100, 100));
 
         // Assert
+        // 0123456789
+        // 1 2 3
+        Assert.Equal (0, slider.InnerSpacing);
+        Assert.Equal (new Size (5, 2), slider.ContentSize);
+        Assert.Equal (new Size (5, 2), slider.Frame.Size);
         Assert.NotNull (slider);
         Assert.NotNull (slider.Options);
         Assert.Equal (options.Count, slider.Options.Count);
@@ -341,8 +347,9 @@ public class SliderTests
     {
         // Arrange
         Slider<int> slider = new (new () { 1, 2, 3, 4 });
+        // 0123456789
+        // 1234
 
-        // Set auto size to true to enable testing
         slider.InnerSpacing = 2;
 
         // 0123456789
@@ -503,8 +510,6 @@ public class SliderTests
         {
             Orientation = Orientation.Vertical,
             Type = SliderType.Multiple,
-            Width = Dim.Auto (DimAutoStyle.Content),
-            Height = Dim.Auto (DimAutoStyle.Content)
         };
         view.Add (slider);
         view.BeginInit ();
@@ -519,7 +524,7 @@ public class SliderTests
         view.LayoutSubviews ();
         slider.SetRelativeLayout (view.Viewport.Size);
 
-        Assert.Equal (new (1, 1), slider.Frame.Size);
+        Assert.Equal (expectedSize, slider.Frame.Size);
     }
 
     [Fact]
@@ -537,7 +542,6 @@ public class SliderTests
         {
             Orientation = Orientation.Vertical,
             Type = SliderType.Multiple,
-            Width = Dim.Auto (DimAutoStyle.Content),
             Height = 10
         };
         view.Add (slider);
@@ -553,7 +557,7 @@ public class SliderTests
         view.LayoutSubviews ();
         slider.SetRelativeLayout (view.Viewport.Size);
 
-        Assert.Equal (new (1, 10), slider.Frame.Size);
+        Assert.Equal (expectedSize, slider.Frame.Size);
     }
 
     [Fact]
@@ -572,7 +576,6 @@ public class SliderTests
             Orientation = Orientation.Vertical,
             Type = SliderType.Multiple,
             Width = 10,
-            Height = Dim.Auto (DimAutoStyle.Content)
         };
         view.Add (slider);
         view.BeginInit ();
@@ -587,7 +590,7 @@ public class SliderTests
         view.LayoutSubviews ();
         slider.SetRelativeLayout (view.Viewport.Size);
 
-        Assert.Equal (new (10, 1), slider.Frame.Size);
+        Assert.Equal (expectedSize, slider.Frame.Size);
     }
 
     // Add more tests for different scenarios and edge cases.