Tig Kindel il y a 2 ans
Parent
commit
7f1471283f

+ 1 - 1
Terminal.Gui/Core/Application.cs

@@ -1279,7 +1279,7 @@ namespace Terminal.Gui {
 			}
 
 			foreach (var top in toplevels) {
-				if (top != Current && top.Visible && (!top.NeedDisplay.IsEmpty || top.ChildNeedsDisplay || top.LayoutNeeded)) {
+				if (top != Current && top.Visible && (!top._needsDisplay.IsEmpty || top._childNeedsDisplay || top.LayoutNeeded)) {
 					MdiTop.SetSubViewNeedsDisplay ();
 					return true;
 				}

+ 52 - 35
Terminal.Gui/Core/View.cs

@@ -6,6 +6,7 @@ using System.Linq;
 using System.Reflection;
 using NStack;
 
+
 namespace Terminal.Gui {
 	/// <summary>
 	/// Determines the LayoutStyle for a <see cref="View"/>, if Absolute, during <see cref="View.LayoutSubviews"/>, the
@@ -203,7 +204,13 @@ namespace Terminal.Gui {
 		/// Gets or sets the specifier character for the hotkey (e.g. '_'). Set to '\xffff' to disable hotkey support for this View instance. The default is '\xffff'. 
 		/// </summary>
 		public virtual Rune HotKeySpecifier {
-			get => TextFormatter.HotKeySpecifier;
+			get {
+				if (TextFormatter != null) {
+					return TextFormatter.HotKeySpecifier;
+				} else {
+					return new Rune ('\xFFFF');
+				}
+			}
 			set {
 				TextFormatter.HotKeySpecifier = value;
 				SetHotKey ();
@@ -795,7 +802,7 @@ namespace Terminal.Gui {
 		/// <summary>
 		/// Gets or sets the <see cref="Terminal.Gui.TextFormatter"/> which can be handled differently by any derived class.
 		/// </summary>
-		public TextFormatter TextFormatter { get; set; }
+		public TextFormatter? TextFormatter { get; set; }
 
 		/// <summary>
 		/// Returns the container for this view, or null if this view has not been added to a container.
@@ -916,10 +923,10 @@ namespace Terminal.Gui {
 		void SetInitialProperties (ustring text, Rect rect, LayoutStyle layoutStyle = LayoutStyle.Computed,
 		    TextDirection direction = TextDirection.LeftRight_TopBottom, Border border = null)
 		{
-
 			TextFormatter = new TextFormatter ();
 			TextFormatter.HotKeyChanged += TextFormatter_HotKeyChanged;
 			TextDirection = direction;
+
 			shortcutHelper = new ShortcutHelper ();
 			CanFocus = false;
 			TabIndex = -1;
@@ -927,17 +934,11 @@ namespace Terminal.Gui {
 			LayoutStyle = layoutStyle;
 			// BUGBUG: CalcRect doesn't account for line wrapping
 
-			// TODO: Remove this once v2's new Frames is ready
 			Border = border;
-			if (Border != null) {
-				Border.Child = this;
-			}
-
+			Text = text;
+			LayoutStyle = layoutStyle;
 			var r = rect.IsEmpty ? TextFormatter.CalcRect (0, 0, text, direction) : rect;
 			Frame = r;
-
-			Text = text;
-
 			OnResizeNeeded ();
 		}
 
@@ -947,7 +948,9 @@ namespace Terminal.Gui {
 		/// </summary>
 		protected virtual void UpdateTextFormatterText ()
 		{
-			TextFormatter.Text = text;
+			if (TextFormatter != null) {
+				TextFormatter.Text = text;
+			}
 		}
 
 		/// <summary>
@@ -1081,8 +1084,9 @@ namespace Terminal.Gui {
 		/// </remarks>
 		public virtual void Add (View view)
 		{
-			if (view == null)
+			if (view == null) {
 				return;
+			}
 			if (subviews == null) {
 				subviews = new List<View> ();
 			}
@@ -1126,10 +1130,12 @@ namespace Terminal.Gui {
 		/// </remarks>
 		public void Add (params View [] views)
 		{
-			if (views == null)
+			if (views == null) {
 				return;
-			foreach (var view in views)
+			}
+			foreach (var view in views) {
 				Add (view);
+			}
 		}
 
 		/// <summary>
@@ -1137,8 +1143,9 @@ namespace Terminal.Gui {
 		/// </summary>
 		public virtual void RemoveAll ()
 		{
-			if (subviews == null)
+			if (subviews == null) {
 				return;
+			}
 
 			while (subviews.Count > 0) {
 				Remove (subviews [0]);
@@ -1152,8 +1159,7 @@ namespace Terminal.Gui {
 		/// </remarks>
 		public virtual void Remove (View view)
 		{
-			if (view == null || subviews == null)
-				return;
+			if (view == null || subviews == null) return;
 
 			var touched = view.Frame;
 			subviews.Remove (view);
@@ -1162,17 +1168,15 @@ namespace Terminal.Gui {
 			view.tabIndex = -1;
 			SetNeedsLayout ();
 			SetNeedsDisplay ();
-			if (subviews.Count < 1) {
-				CanFocus = false;
-			}
+
+			if (subviews.Count < 1) CanFocus = false;
+
 			foreach (var v in subviews) {
 				if (v.Frame.IntersectsWith (touched))
 					view.SetNeedsDisplay ();
 			}
 			OnRemoved (view);
-			if (focused == view) {
-				focused = null;
-			}
+			if (focused == view) focused = null;
 		}
 
 		void PerformActionForSubview (View subview, Action<View> action)
@@ -1382,7 +1386,7 @@ namespace Terminal.Gui {
 		/// </remarks>
 		public Rect ClipToBounds ()
 		{
-			var clip = Bounds ;
+			var clip = Bounds;
 
 
 			return SetClip (clip);
@@ -1410,7 +1414,7 @@ namespace Terminal.Gui {
 		/// <param name="region">View-relative region for the frame to be drawn.</param>
 		/// <param name="padding">The padding to add around the outside of the drawn frame.</param>
 		/// <param name="fill">If set to <see langword="true"/> it fill will the contents.</param>
-		[ObsoleteAttribute("This method is obsolete in v2. Use use LineCanvas or Frame instead instead.", false)]
+		[ObsoleteAttribute ("This method is obsolete in v2. Use use LineCanvas or Frame instead instead.", false)]
 		public void DrawFrame (Rect region, int padding = 0, bool fill = false)
 		{
 			var scrRect = ViewToScreen (region);
@@ -1739,7 +1743,7 @@ namespace Terminal.Gui {
 				Driver.SetAttribute (GetNormalColor ());
 			}
 
-			Clear (ViewToScreen(bounds));
+			Clear (ViewToScreen (bounds));
 
 			// Invoke DrawContentEvent
 			OnDrawContent (bounds);
@@ -1757,7 +1761,7 @@ namespace Terminal.Gui {
 							// Draw the subview
 							// Use the view's bounds (view-relative; Location will always be (0,0)
 							//if (view.Visible && view.Frame.Width > 0 && view.Frame.Height > 0) {
-								view.Redraw (view.Bounds);
+							view.Redraw (view.Bounds);
 							//}
 						}
 						view.ClearNeedsDisplay ();
@@ -2728,9 +2732,11 @@ namespace Terminal.Gui {
 			get => text;
 			set {
 				text = value;
-				SetHotKey ();
-				UpdateTextFormatterText ();
-				OnResizeNeeded ();
+				if (IsInitialized) {
+					SetHotKey ();
+					UpdateTextFormatterText ();
+					OnResizeNeeded ();
+				}
 			}
 		}
 
@@ -2810,7 +2816,7 @@ namespace Terminal.Gui {
 		public virtual TextDirection TextDirection {
 			get => TextFormatter.Direction;
 			set {
-				if (TextFormatter.Direction != value) {
+				if (IsInitialized && TextFormatter.Direction != value) {
 					var isValidOldAutSize = autoSize && IsValidAutoSize (out var _);
 					var directionChanged = TextFormatter.IsHorizontalDirection (TextFormatter.Direction)
 					    != TextFormatter.IsHorizontalDirection (value);
@@ -2919,7 +2925,14 @@ namespace Terminal.Gui {
 			get => border;
 			set {
 				if (border != value) {
+
+					//InitializeFrames ();
+					//BorderFrame.Thickness = new Thickness (2);
+					//BorderFrame.BorderStyle = value?.BorderStyle ?? BorderStyle.Single;
+					//BorderFrame.ColorScheme = ColorScheme;
+
 					border = value;
+
 					SetNeedsDisplay ();
 				}
 			}
@@ -2940,6 +2953,9 @@ namespace Terminal.Gui {
 
 		void SetHotKey ()
 		{
+			if (TextFormatter == null) {
+				return; // throw new InvalidOperationException ("Can't set HotKey unless a TextFormatter has been created");
+			}
 			TextFormatter.FindHotKey (text, HotKeySpecifier, true, out _, out var hk);
 			if (hotKey != hk) {
 				HotKey = hk;
@@ -3056,7 +3072,7 @@ namespace Terminal.Gui {
 
 		/// <summary>
 		/// Gets the dimensions required for <see cref="Text"/> ignoring a <see cref="Terminal.Gui.TextFormatter.HotKeySpecifier"/>.
-		/// /// <summary/>
+		/// </summary>
 		/// <returns></returns>
 		public Size GetSizeNeededForTextWithoutHotKey ()
 		{
@@ -3066,7 +3082,7 @@ namespace Terminal.Gui {
 
 		/// <summary>
 		/// Gets the dimensions required for <see cref="Text"/> accounting for a <see cref="Terminal.Gui.TextFormatter.HotKeySpecifier"/> .
-		/// <summary/>
+		/// </summary>
 		/// <returns></returns>
 		public Size GetSizeNeededForTextAndHotKey ()
 		{
@@ -3239,13 +3255,14 @@ namespace Terminal.Gui {
 				oldCanFocus = CanFocus;
 				oldTabIndex = tabIndex;
 
-				//UpdateTextFormatterText ();
+				UpdateTextFormatterText ();
 				// TODO: Figure out why ScrollView and other tests fail if this call is put here 
 				// instead of the constructor.
 				// OnSizeChanged ();
 
 			} else {
 				//throw new InvalidOperationException ("The view is already initialized.");
+
 			}
 
 			if (subviews?.Count > 0) {

+ 0 - 24
Terminal.Gui/Views/FrameView.cs

@@ -106,30 +106,6 @@ namespace Terminal.Gui {
 			DrawFrame (new Rect (0, 0, Frame.Width, Frame.Height), 0, fill: true);
 		}
 
-		/// <summary>
-		/// Add the specified <see cref="View"/> to this container.
-		/// </summary>
-		/// <param name="view"><see cref="View"/> to add to this container</param>
-		public override void Add (View view)
-		{
-			if (view.CanFocus)
-				CanFocus = true;
-		}
-
-
-		/// <summary>
-		///   Removes a <see cref="View"/> from this container.
-		/// </summary>
-		/// <remarks>
-		/// </remarks>
-		public override void Remove (View view)
-		{
-			if (view == null)
-				return;
-
-			SetNeedsDisplay ();
-		}
-
 
 		///<inheritdoc/>
 		public override bool OnEnter (View view)

+ 1 - 4
Terminal.Gui/Windows/Dialog.cs

@@ -149,10 +149,7 @@ namespace Terminal.Gui {
 
 		void Initialize (ustring title, Border border)
 		{
-			if (border != null) {
-				Border = border;
-				Border.Title = title;
-			}
+			Title = title;
 		}
 
 		/// <summary>

+ 4 - 4
Terminal.Gui/Windows/MessageBox.cs

@@ -290,12 +290,12 @@ namespace Terminal.Gui {
 
 			if (useErrorColors) {
 				d.ColorScheme = Colors.Error;
-				d.Border.BorderBrush = Colors.Error.Normal.Foreground;
-				d.Border.Background = Colors.Error.Normal.Background;
+				d.Border.ForgroundColor = Colors.Error.Normal.Foreground;
+				d.Border.BackgroundColor = Colors.Error.Normal.Background;
 			} else {
 				d.ColorScheme = Colors.Dialog;
-				d.Border.BorderBrush = Colors.Dialog.Normal.Foreground;
-				d.Border.Background = Colors.Dialog.Normal.Background;
+				d.Border.ForgroundColor = Colors.Dialog.Normal.Foreground;
+				d.Border.BackgroundColor = Colors.Dialog.Normal.Background;
 			}
 
 			if (!ustring.IsNullOrEmpty (message)) {

+ 1 - 1
UICatalog/Scenarios/BordersComparisons.cs

@@ -13,7 +13,7 @@ namespace UICatalog.Scenarios {
 			var drawMarginFrame = false;
 			var borderThickness = new Thickness (1, 2, 3, 4);
 			var borderBrush = Color.BrightMagenta;
-			;
+
 			var padding = new Thickness (1, 2, 3, 4);
 			var background = Color.Cyan;
 			var effect3D = true;

+ 1 - 2
UICatalog/Scenarios/ComputedLayout.cs

@@ -95,9 +95,8 @@ namespace UICatalog.Scenarios {
 			labelList.Add (new Label ($"{i++}-{txt}") { TextAlignment = Terminal.Gui.TextAlignment.Justified, Width = Dim.Fill (), X = 0, Y = Pos.Bottom (labelList.LastOrDefault ()), ColorScheme = Colors.Dialog });
 			subWin.Add (labelList.ToArray ());
 
-			// #522 repro?
 			var frameView = new FrameView () {
-				X = 2, //Pos.Center (),
+				X = 2, 
 				Y = Pos.Bottom (subWin),
 				Width = 30,
 				Height = 7

+ 2 - 2
UICatalog/Scenarios/Dialogs.cs

@@ -10,10 +10,10 @@ namespace UICatalog.Scenarios {
 	[ScenarioCategory ("Dialogs")]
 	public class Dialogs : Scenario {
 		static int CODE_POINT = '你'; // We know this is a wide char
-		public override void Init (ColorScheme colorScheme)
+		public override void Init ()
 		{
 			Application.Init ();
-			Application.Top.ColorScheme = colorScheme;
+			//Application.Top.ColorScheme = colorScheme;
 		}
 
 		public override void Setup ()

+ 7 - 4
UICatalog/Scenarios/ViewExperiments.cs

@@ -4,10 +4,13 @@ namespace UICatalog.Scenarios {
 	[ScenarioMetadata (Name: "_ View Experiments", Description: "v2 View Experiments")]
 	[ScenarioCategory ("Controls")]
 	public class ViewExperiments : Scenario {
-		public override void Init (ColorScheme colorScheme)
+		public override void Init ()
 		{
 			Application.Init ();
-			Application.Top.ColorScheme = colorScheme;
+			//Application.Init ();
+			//ConfigurationManager.Themes.Theme = Theme;
+			//ConfigurationManager.Apply ();
+			//Application.Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
 
 		}
 
@@ -119,8 +122,8 @@ namespace UICatalog.Scenarios {
 			var view5 = new View () {
 				X = Pos.Right (view4) + 1,
 				Y = 3,
-				Height = Dim.Fill(2),
-				Width = Dim.Fill(),
+				Height = Dim.Fill (2),
+				Width = Dim.Fill (),
 				Title = "View5",
 				Text = "View #5 (Right(view4)+1 Fill",
 				TextAlignment = TextAlignment.Centered

+ 1 - 0
UICatalog/UICatalog.cs

@@ -311,6 +311,7 @@ namespace UICatalog {
 				};
 
 				ContentPane = new TileView () {
+					Id = "ContentPane",
 					X = 0,
 					Y = 1, // for menu
 					Width = Dim.Fill (),