Browse Source

POC of DimAuotStyle.Text

Tig Kindel 1 year ago
parent
commit
7ecf844ccc

+ 3 - 3
Terminal.Gui/View/Layout/PosDim.cs

@@ -702,9 +702,9 @@ public class Dim {
 	/// <param name="max">Specifies the maximum dimension that view will be automatically sized to. NOT CURRENTLY SUPPORTED.</param>
 	public static Dim Auto (DimAutoStyle style = DimAutoStyle.Subviews, Dim min = null, Dim max = null)
 	{
-		if (style == DimAutoStyle.Text) {
-			throw new NotImplementedException (@"DimAutoStyle.Text is not implemented.");
-		}
+		//if (style == DimAutoStyle.Text) {
+		//	throw new NotImplementedException (@"DimAutoStyle.Text is not implemented.");
+		//}
 		//if (min != null) {
 		//	throw new NotImplementedException (@"min is not implemented");
 		//}

+ 10 - 7
Terminal.Gui/View/Layout/ViewLayout.cs

@@ -828,13 +828,17 @@ public partial class View {
 					var thickness = GetAdornmentsThickness ();
 					//newDimension = GetNewDimension (auto._min, location, dimension, autosize);
 					if (width) {
-						var furthestRight = Subviews.Count == 0 ? 0 : Subviews.Where (v => v.X is not Pos.PosAnchorEnd).Max (v => v.Frame.X + v.Frame.Width);
-						//Debug.Assert(superviewBounds.Width == (SuperView?.Bounds.Width ?? 0));
-						newDimension = int.Max (furthestRight + thickness.Left + thickness.Right, auto._min?.Anchor (superviewBounds.Width) ?? 0);
+						var max = int.Max (GetAutoSize ().Width, auto._min?.Anchor (superviewBounds.Width) ?? 0);
+						if (auto._style == Dim.DimAutoStyle.Subviews) {
+							max = Subviews.Count == 0 ? 0 : Subviews.Where (v => v.X is not Pos.PosAnchorEnd).Max (v => v.Frame.X + v.Frame.Width);
+						}
+						newDimension = int.Max (max + thickness.Left + thickness.Right, auto._min?.Anchor (superviewBounds.Width) ?? 0);
 					} else {
-						var furthestBottom = Subviews.Count == 0 ? 0 : Subviews.Max (v => v.Frame.Y + v.Frame.Height);
-						//Debug.Assert (superviewBounds.Height == (SuperView?.Bounds.Height ?? 0));
-						newDimension = int.Max (furthestBottom + thickness.Top + thickness.Bottom, auto._min?.Anchor (superviewBounds.Height) ?? 0);
+						var max = int.Max (GetAutoSize ().Height, auto._min?.Anchor (superviewBounds.Height) ?? 0);
+						if (auto._style == Dim.DimAutoStyle.Subviews) {
+							max = Subviews.Count == 0 ? 0 : Subviews.Where (v => v.Y is not Pos.PosAnchorEnd).Max (v => v.Frame.Y + v.Frame.Height);
+						}
+						newDimension = int.Max (max + thickness.Top + thickness.Bottom, auto._min?.Anchor (superviewBounds.Height) ?? 0);
 					}
 					break;
 
@@ -929,7 +933,6 @@ public partial class View {
 			// BUGBUG: Why is this AFTER setting Frame? Seems duplicative.
 			if (!SetFrameToFitText ()) {
 				SetTextFormatterSize ();
-				SetTextFormatterSize ();
 			}
 		}
 	}

+ 30 - 16
UICatalog/Scenarios/DimAutoDemo.cs

@@ -1,4 +1,5 @@
 using Terminal.Gui;
+using static Terminal.Gui.Dim;
 
 namespace UICatalog.Scenarios;
 
@@ -15,48 +16,61 @@ public class DimAutoDemo : Scenario {
 
 	public override void Setup ()
 	{
-		var textField = new TextField { Text = "Type here", X = 1, Y = 0, Width = 20, Height = 1 };
+		var textField = new TextField { Text = "", X = 1, Y = 0, Width = 20, Height = 1 };
 
-		var label = new Label {
-			X = Pos.Left (textField),
+		var hlabel = new Label {
+			Text = textField.Text,
+			X = Pos.Left (textField) + 1,
 			Y = Pos.Bottom (textField),
-			AutoSize = true,
+			AutoSize = false,
+			Width = Dim.Auto (style: DimAutoStyle.Text, min: 20),
 			ColorScheme = Colors.ColorSchemes["Error"]
 		};
 
-		textField.TextChanged += (s, e) => {
-			label.Text = textField.Text;
+		var vlabel = new Label {
+			Text = textField.Text,
+			X = Pos.Left (textField),
+			Y = Pos.Bottom (textField) + 1,
+			AutoSize = false,
+			Height = Dim.Auto (style: DimAutoStyle.Text, min: 10),
+			ColorScheme = Colors.ColorSchemes ["Error"],
+			TextDirection = TextDirection.TopBottom_LeftRight
 		};
 
-		var resetButton = new Button () {
-			Text = "P_ut Button Back",
-			Y = Pos.Bottom (label)
+		textField.TextChanged += (s, e) => {
+			hlabel.Text = textField.Text;
+			vlabel.Text = textField.Text;
 		};
-		resetButton.X = Pos.AnchorEnd () - 19;
 
 		var movingButton = new Button () {
-			Text = "Press to make button move down.",
-			X = 0,
-			Y = Pos.Bottom (resetButton),
+			Text = "P_ress to make button move down.",
+			X = 2,
+			Y = Pos.Bottom (hlabel),
 			Width = 10
 		};
 		movingButton.Clicked += (s, e) => {
 			movingButton.Y = movingButton.Frame.Y + 1;
 		};
 
+		var resetButton = new Button () {
+			Text = "P_ut Button Back",
+			X = 30,//Pos.AnchorEnd () - 19,
+			Y = Pos.Top (movingButton),
+		};
+
 
 		var view = new FrameView () {
 			Title = "Type in the TextField to make View grow.",
 			X = 3,
 			Y = 3,
-			Width = Dim.Auto (min: Dim.Percent (50)),
+			Width = Dim.Auto (min: 50),
 			Height = Dim.Auto (min: 10)
 		};
 		view.ValidatePosDim = true;
-		view.Add (textField, label, resetButton, movingButton);
+		view.Add (textField, hlabel, vlabel, resetButton, movingButton);
 
 		resetButton.Clicked += (s, e) => {
-			movingButton.Y = Pos.Bottom (resetButton);
+			movingButton.Y = Pos.Bottom (hlabel);
 		};
 
 		var dlgButton = new Button () {