From 63e7cea07b70d6d1097c564c4081eb60078e957b Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 00:42:45 +0000 Subject: [PATCH 001/130] Add ContentArea and fix layout related with frame to screen and vice versa. --- Terminal.Gui/View/Adornment/Adornment.cs | 28 +++++- Terminal.Gui/View/Layout/ViewLayout.cs | 104 +++++++++++++++++++++-- 2 files changed, 125 insertions(+), 7 deletions(-) diff --git a/Terminal.Gui/View/Adornment/Adornment.cs b/Terminal.Gui/View/Adornment/Adornment.cs index 37616ae509..9865ea0947 100644 --- a/Terminal.Gui/View/Adornment/Adornment.cs +++ b/Terminal.Gui/View/Adornment/Adornment.cs @@ -37,6 +37,11 @@ public override Rect Bounds set => throw new InvalidOperationException ("It makes no sense to set Bounds of a Thickness."); } + /// + /// Gets the rectangle that describes the inner area of the Adornment. The Location is always (0,0). + /// + public override Rect ContentArea => Thickness?.GetInside (new Rect (Point.Empty, Frame.Size)) ?? new Rect (Point.Empty, Frame.Size); + /// The Parent of this Adornment (the View this Adornment surrounds). /// /// Adornments are distinguished from typical View classes in that they are not sub-views, but have a parent/child @@ -107,6 +112,22 @@ public override Rect FrameToScreen () ret.Location = Parent?.FrameToScreen ().Location ?? ret.Location; + switch (this) + { + case Gui.Margin: + break; + case Gui.Border: + ret.X += Parent != null ? Parent.Margin.Thickness.Left : 0; + ret.Y += Parent != null ? Parent.Margin.Thickness.Top : 0; + + break; + case Gui.Padding: + ret.X += Parent != null ? Parent.Margin.Thickness.Left + Parent.Border.Thickness.Left : 0; + ret.Y += Parent != null ? Parent.Margin.Thickness.Top + Parent.Border.Thickness.Top : 0; + + break; + } + // We now have coordinates relative to our View. If our View's SuperView has // a SuperView, keep going... return ret; @@ -143,7 +164,12 @@ public override void OnDrawContent (Rect contentArea) TextFormatter?.Draw (screenBounds, normalAttr, normalAttr, Rect.Empty); - //base.OnDrawContent (contentArea); + LayoutSubviews (); + + base.OnDrawContent (contentArea); + + ClearLayoutNeeded (); + ClearNeedsDisplay (); } /// Does nothing for Adornment diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 82fc68745d..f50ed75a7f 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -37,6 +37,8 @@ public enum LayoutStyle public partial class View { private bool _autoSize; + + private Rect _bounds; private Rect _frame; private Dim _height = Dim.Sized (0); private Dim _width = Dim.Sized (0); @@ -188,14 +190,13 @@ public virtual Rect Bounds - Margin.Thickness.Horizontal - Border.Thickness.Horizontal - Padding.Thickness.Horizontal - ); + - _bounds.Location.X); int height = Math.Max ( 0, - Frame.Size.Height - Margin.Thickness.Vertical - Border.Thickness.Vertical - Padding.Thickness.Vertical - ); + Frame.Size.Height - Margin.Thickness.Vertical - Border.Thickness.Vertical - Padding.Thickness.Vertical - _bounds.Location.Y); - return new Rect (Point.Empty, new Size (width, height)); + return new Rect (_bounds.Location, new Size (width, height)); } set { @@ -209,6 +210,13 @@ public virtual Rect Bounds ); } #endif // DEBUG + if (ScrollBarType != ScrollBarType.None && UseNegativeBoundsLocation) + { + _bounds = value; + + return; + } + Frame = new Rect ( Frame.Location, new Size ( @@ -225,6 +233,31 @@ public virtual Rect Bounds } } + /// + /// The content area represent the View-relative rectangle used for this view. The area inside the view where subviews + /// and content are presented. The Location is always (0,0). It will be mainly used for clipping a region. + /// + public virtual Rect ContentArea + { + get + { + if (Margin == null || Border == null || Padding == null) + { + return new Rect (default (Point), Frame.Size); + } + + int width = Math.Max ( + 0, + Frame.Size.Width - Margin.Thickness.Horizontal - Border.Thickness.Horizontal - Padding.Thickness.Horizontal); + + int height = Math.Max ( + 0, + Frame.Size.Height - Margin.Thickness.Vertical - Border.Thickness.Vertical - Padding.Thickness.Vertical); + + return new Rect (Point.Empty, new Size (width, height)); + } + } + /// Gets or sets the absolute location and dimension of the view. /// /// The rectangle describing absolute location and dimension of the view, in coordinates relative to the @@ -528,7 +561,32 @@ public virtual void BoundsToScreen (int x, int y, out int rx, out int ry, bool c while (super is { }) { - boundsOffset = super.GetBoundsOffset (); + if (super is Adornment adornment) + { + boundsOffset = super.FrameToScreen ().Location; + View parent = adornment.Parent; + + switch (super) + { + case Gui.Margin: + break; + case Gui.Border: + boundsOffset.X -= parent.Margin.Thickness.Left; + boundsOffset.Y -= parent.Margin.Thickness.Top; + + break; + case Gui.Padding: + boundsOffset.X -= parent.Margin.Thickness.Left + parent.Border.Thickness.Left; + boundsOffset.Y -= parent.Margin.Thickness.Top + parent.Border.Thickness.Top; + + break; + } + } + else + { + boundsOffset = super.GetBoundsOffset (); + } + rx += super.Frame.X + boundsOffset.X; ry += super.Frame.Y + boundsOffset.Y; super = super.SuperView; @@ -748,7 +806,17 @@ public Point ScreenToFrame (int x, int y) } /// Indicates that the view does not need to be laid out. - protected void ClearLayoutNeeded () { LayoutNeeded = false; } + protected void ClearLayoutNeeded () + { + LayoutNeeded = false; + + if (Margin is { }) + { + Margin.LayoutNeeded = false; + Border.LayoutNeeded = false; + Margin.LayoutNeeded = false; + } + } internal void CollectAll (View from, ref HashSet nNodes, ref HashSet<(View, View)> nEdges) { @@ -955,6 +1023,30 @@ internal void SetNeedsLayout () view.SetNeedsLayout (); } + if (Margin != null) + { + for (var i = 0; i < 3; i++) + { + Adornment adornment = i switch + { + 0 => Margin, + 1 => Border, + 2 => Padding, + _ => null + }; + + if (adornment != null) + { + adornment.SetNeedsLayout (); + + foreach (View view in adornment.Subviews) + { + view.SetNeedsLayout (); + } + } + } + } + TextFormatter.NeedsFormat = true; SuperView?.SetNeedsLayout (); } From d1545331b630a3d119ecbc10484255ec8d59ee98 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 00:44:43 +0000 Subject: [PATCH 002/130] Propagate BeginInit and EndInit to Adornments. --- Terminal.Gui/View/View.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Terminal.Gui/View/View.cs b/Terminal.Gui/View/View.cs index 1ec8d19b6e..ad24bbdca8 100644 --- a/Terminal.Gui/View/View.cs +++ b/Terminal.Gui/View/View.cs @@ -400,6 +400,9 @@ public virtual void BeginInit () _oldCanFocus = CanFocus; _oldTabIndex = _tabIndex; + Margin?.BeginInit (); + Border?.BeginInit (); + Padding?.BeginInit (); if (_subviews?.Count > 0) { @@ -428,6 +431,9 @@ public virtual void EndInit () } IsInitialized = true; + Margin?.EndInit (); + Border?.EndInit (); + Padding?.EndInit (); // TODO: Move these into ViewText.cs as EndInit_Text() to consolodate. // TODO: Verify UpdateTextDirection really needs to be called here. From 4b88190525bca3d0dfff1699efdc1b8edc418e3a Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 00:48:50 +0000 Subject: [PATCH 003/130] Clip only to the ContentArea. --- Terminal.Gui/View/ViewDrawing.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Terminal.Gui/View/ViewDrawing.cs b/Terminal.Gui/View/ViewDrawing.cs index 0aceac855c..7f799ab414 100644 --- a/Terminal.Gui/View/ViewDrawing.cs +++ b/Terminal.Gui/View/ViewDrawing.cs @@ -129,7 +129,7 @@ public Rect ClipToBounds () } Rect previous = Driver.Clip; - Driver.Clip = Rect.Intersect (previous, BoundsToScreen (Bounds)); + Driver.Clip = Rect.Intersect (previous, BoundsToScreen (ContentArea)); return previous; } From 5d8c24ab3bc05fec41f4f5ed56cb2848e7dc4d8e Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 00:51:48 +0000 Subject: [PATCH 004/130] Allow DrawContentComplete event to be called before an overridden method. --- Terminal.Gui/View/ViewDrawing.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Terminal.Gui/View/ViewDrawing.cs b/Terminal.Gui/View/ViewDrawing.cs index 7f799ab414..a6f46c2e1c 100644 --- a/Terminal.Gui/View/ViewDrawing.cs +++ b/Terminal.Gui/View/ViewDrawing.cs @@ -185,12 +185,18 @@ public void Draw () OnRenderLineCanvas (); - // Invoke DrawContentCompleteEvent - OnDrawContentComplete (Bounds); - // BUGBUG: v2 - We should be able to use View.SetClip here and not have to resort to knowing Driver details. ClearLayoutNeeded (); ClearNeedsDisplay (); + + // Invoke DrawContentCompleteEvent + dev = new DrawEventArgs (Bounds); + DrawContentComplete?.Invoke (this, dev); + + if (!dev.Cancel) + { + OnDrawContentComplete (Bounds); + } } /// Event invoked when the content area of the View is to be drawn. @@ -384,7 +390,7 @@ public virtual void OnDrawContent (Rect contentArea) } } - // This should NOT clear + // This should NOT clear TextFormatter?.Draw ( BoundsToScreen (contentArea), HasFocus ? GetFocusColor () : GetNormalColor (), @@ -434,7 +440,7 @@ public virtual void OnDrawContent (Rect contentArea) /// This method will be called after any subviews removed with have been completed /// drawing. /// - public virtual void OnDrawContentComplete (Rect contentArea) { DrawContentComplete?.Invoke (this, new DrawEventArgs (contentArea)); } + public virtual void OnDrawContentComplete (Rect contentArea) { } // TODO: Make this cancelable /// From c69e424f159acf8f506b6ce969f9eba2cb4bad25 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 00:53:04 +0000 Subject: [PATCH 005/130] Add DrawAdornments event. --- Terminal.Gui/View/ViewDrawing.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Terminal.Gui/View/ViewDrawing.cs b/Terminal.Gui/View/ViewDrawing.cs index a6f46c2e1c..61ade0675b 100644 --- a/Terminal.Gui/View/ViewDrawing.cs +++ b/Terminal.Gui/View/ViewDrawing.cs @@ -199,6 +199,16 @@ public void Draw () } } + /// Event invoked when the adornments area of the View is to be drawn. + /// + /// Will be invoked before any subviews added with have been drawn. + /// + /// Rect provides the view-relative rectangle describing the currently visible viewport into the + /// . + /// + /// + public event EventHandler DrawAdornments; + /// Event invoked when the content area of the View is to be drawn. /// /// Will be invoked before any subviews added with have been drawn. @@ -358,6 +368,8 @@ public virtual bool OnDrawAdornments () return false; } + DrawAdornments?.Invoke (this, new DrawEventArgs (Bounds)); + // Each of these renders lines to either this View's LineCanvas // Those lines will be finally rendered in OnRenderLineCanvas Margin?.OnDrawContent (Margin.Bounds); From 5bf7f947838ba101d8f0b13ccf2c491c8ec7a90d Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 00:54:40 +0000 Subject: [PATCH 006/130] Manage needs display for adornments. --- Terminal.Gui/View/ViewDrawing.cs | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Terminal.Gui/View/ViewDrawing.cs b/Terminal.Gui/View/ViewDrawing.cs index 61ade0675b..0d42c15f25 100644 --- a/Terminal.Gui/View/ViewDrawing.cs +++ b/Terminal.Gui/View/ViewDrawing.cs @@ -560,6 +560,30 @@ public void SetNeedsDisplay (Rect region) Margin?.SetNeedsDisplay (Margin.Bounds); Border?.SetNeedsDisplay (Border.Bounds); Padding?.SetNeedsDisplay (Padding.Bounds); + + if (Margin != null) + { + for (var i = 0; i < 3; i++) + { + Adornment adornment = i switch + { + 0 => Margin, + 1 => Border, + 2 => Padding, + _ => null + }; + + if (adornment != null) + { + adornment.SetNeedsDisplay (); + + foreach (View view in adornment.Subviews) + { + view.SetNeedsDisplay (); + } + } + } + } } if (_subviews is null) @@ -595,6 +619,16 @@ protected void ClearNeedsDisplay () { _needsDisplayRect = Rect.Empty; SubViewNeedsDisplay = false; + + if (Margin is { }) + { + Margin._needsDisplayRect = Rect.Empty; + Margin.SubViewNeedsDisplay = false; + Border._needsDisplayRect = Rect.Empty; + Border.SubViewNeedsDisplay = false; + Padding._needsDisplayRect = Rect.Empty; + Padding.SubViewNeedsDisplay = false; + } } // Clips a rectangle in screen coordinates to the dimensions currently available on the screen From 37dd28cb16b1edd0f8271f25c2ac0717d27488cb Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 00:57:34 +0000 Subject: [PATCH 007/130] Allow adornments handle key bindings- --- Terminal.Gui/View/ViewKeyboard.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Terminal.Gui/View/ViewKeyboard.cs b/Terminal.Gui/View/ViewKeyboard.cs index bac9ea093c..38df72c978 100644 --- a/Terminal.Gui/View/ViewKeyboard.cs +++ b/Terminal.Gui/View/ViewKeyboard.cs @@ -406,6 +406,28 @@ public bool NewKeyDownEvent (Key keyEvent) return true; } + // Check if adornments needs to handle the key + handled = Margin?.OnInvokingKeyBindings (keyEvent); + + if (handled != null && (bool)handled) + { + return true; + } + + handled = Border?.OnInvokingKeyBindings (keyEvent); + + if (handled != null && (bool)handled) + { + return true; + } + + handled = Padding?.OnInvokingKeyBindings (keyEvent); + + if (handled != null && (bool)handled) + { + return true; + } + // TODO: The below is not right. OnXXX handlers are supposed to fire the events. // TODO: But I've moved it outside of the v-function to test something. // After (fire the cancellable event) From a02632459801a808ea8c84b255ff6bbaa74648b4 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 01:02:21 +0000 Subject: [PATCH 008/130] Add ViewScrollBar.cs to manage a built-in scroll bar on Padding. --- Terminal.Gui/View/ViewScrollBar.cs | 635 +++++++++++++++++++++++++++++ 1 file changed, 635 insertions(+) create mode 100644 Terminal.Gui/View/ViewScrollBar.cs diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs new file mode 100644 index 0000000000..93f0c252bf --- /dev/null +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -0,0 +1,635 @@ +namespace Terminal.Gui; + +/// +/// The scroll bar types used by this . +/// +public enum ScrollBarType +{ + /// + /// None scroll bar will be used and to avoid throwing an exception never use it in a constructor. + /// + None, + + /// + /// Only the vertical scroll bar will be shown. + /// + Vertical, + + /// + /// Only the horizontal scroll bar will be shown. + /// + Horizontal, + + /// + /// Both vertical and horizontal scroll bars will be shown. + /// + Both +} + +public partial class View +{ + private ScrollBarView _scrollBar; + private ScrollBarType _scrollBarType; + private int _scrollColsSize; + private int _scrollLeftOffset; + private int _scrollRowsSize; + private int _scrollTopOffset; + + /// If true the vertical/horizontal scroll bars won't be showed if it's not needed. + public bool ScrollAutoHideScrollBars + { + get => _scrollBar.AutoHideScrollBars; + set => _scrollBar.AutoHideScrollBars = value; + } + + /// + /// Gets or sets the used by this view. + /// + /// The value is out of range. + public virtual ScrollBarType ScrollBarType + { + get => _scrollBarType; + set + { + if (_scrollBar is { } && _scrollBarType == value) + { + return; + } + + _scrollBarType = value; + DisposeScrollBar (); + + switch (_scrollBarType) + { + case ScrollBarType.Vertical: + _scrollBar = new ScrollBarView { IsVertical = true }; + + break; + case ScrollBarType.Horizontal: + _scrollBar = new ScrollBarView { IsVertical = false }; + + break; + case ScrollBarType.Both: + _scrollBar = new ScrollBarView { IsVertical = true }; + _scrollBar.OtherScrollBarView = new ScrollBarView { IsVertical = false, OtherScrollBarView = _scrollBar }; + + break; + case ScrollBarType.None: + return; + default: + throw new ArgumentOutOfRangeException (); + } + + Padding.Add (_scrollBar); + AddHandlers (); + AddScrollKeyBindings (_scrollBar); + + if (_scrollBar.OtherScrollBarView != null) + { + AddScrollKeyBindings (_scrollBar.OtherScrollBarView); + } + + SetNeedsDisplay (); + } + } + + /// + /// Determines the number of columns to scrolling. + /// + public int ScrollColsSize + { + get => _scrollColsSize; + set + { + _scrollColsSize = value; + + if (ScrollBarType == ScrollBarType.None) + { + return; + } + + switch (_scrollBar.IsVertical) + { + case true when _scrollBar.OtherScrollBarView is { }: + if (_scrollBar.OtherScrollBarView.Size == _scrollColsSize) + { + return; + } + + _scrollBar.OtherScrollBarView.Size = _scrollColsSize; + + break; + case false: + if (_scrollBar.Size == _scrollColsSize) + { + return; + } + + _scrollBar.Size = _scrollColsSize; + + break; + } + + SetNeedsDisplay (); + } + } + + /// Get or sets if the view-port is kept always visible in the area of this + public bool ScrollKeepContentAlwaysInViewPort + { + get => _scrollBar.KeepContentAlwaysInViewport; + set => _scrollBar.KeepContentAlwaysInViewport = value; + } + + /// + /// Determines the left offset on scrolling. + /// + public virtual int ScrollLeftOffset + { + get => _scrollLeftOffset; + set + { + if (!UseNegativeBoundsLocation) + { + _scrollLeftOffset = value; + + if (_scrollBar is null) + { + return; + } + + if (!_scrollBar.IsVertical && _scrollBar.Position != _scrollLeftOffset) + { + _scrollBar.Position = _scrollLeftOffset; + } + else if (_scrollBar is { OtherScrollBarView.IsVertical: false } && _scrollBar?.OtherScrollBarView.Position != _scrollLeftOffset) + { + _scrollBar!.OtherScrollBarView.Position = _scrollLeftOffset; + } + } + } + } + + /// Represent a vertical or horizontal ScrollBarView other than this. + public ScrollBarView ScrollOtherScrollBarView + { + get => _scrollBar.OtherScrollBarView; + set => _scrollBar.OtherScrollBarView = value; + } + + /// The position, relative to , to set the scrollbar at. + /// The position. + public int ScrollPosition + { + get => _scrollBar.Position; + set => _scrollBar.Position = value; + } + + /// + /// Determines the number of rows to scrolling. + /// + public int ScrollRowsSize + { + get => _scrollRowsSize; + set + { + _scrollRowsSize = value; + + if (ScrollBarType == ScrollBarType.None) + { + return; + } + + switch (_scrollBar.IsVertical) + { + case true: + if (_scrollBar.Size == _scrollRowsSize) + { + return; + } + + _scrollBar.Size = _scrollRowsSize; + + break; + case false when _scrollBar.OtherScrollBarView is { }: + if (_scrollBar.OtherScrollBarView.Size == _scrollRowsSize) + { + return; + } + + _scrollBar.OtherScrollBarView.Size = _scrollRowsSize; + + break; + } + + SetNeedsDisplay (); + } + } + + /// Gets or sets the visibility for the vertical or horizontal scroll indicator. + /// true if show vertical or horizontal scroll indicator; otherwise, false. + public bool ScrollShowScrollIndicator + { + get => _scrollBar.ShowScrollIndicator; + set => _scrollBar.ShowScrollIndicator = value; + } + + /// + /// Determines the top offset on scrolling. + /// + public virtual int ScrollTopOffset + { + get => _scrollTopOffset; + set + { + if (!UseNegativeBoundsLocation) + { + _scrollTopOffset = value; + + if (_scrollBar is null) + { + return; + } + + if (_scrollBar.IsVertical && _scrollBar.Position != _scrollTopOffset) + { + _scrollBar.Position = _scrollTopOffset; + } + else if (_scrollBar is { OtherScrollBarView.IsVertical: true } && _scrollBar?.OtherScrollBarView.Position != _scrollTopOffset) + { + _scrollBar!.OtherScrollBarView.Position = _scrollTopOffset; + } + } + } + } + + /// + /// Determines if negative bounds location is allowed for scrolling the . + /// + public bool UseNegativeBoundsLocation { get; set; } + + private void AddHandlers () + { + if (_scrollBar == null) + { + return; + } + + _scrollBar.ChangedPosition += ScrollBar_ChangedPosition; + + if (_scrollBar.OtherScrollBarView != null) + { + _scrollBar.OtherScrollBarView.ChangedPosition += OtherScrollBarView_ChangedPosition; + } + } + + private void AddScrollKeyBindings (ScrollBarView scrollBar) + { + if (scrollBar.IsVertical) + { + // Things this view knows how to do + scrollBar.AddCommand ( + Command.ScrollDown, + () => + { + if (scrollBar.IsVertical) + { + scrollBar.Position++; + + return true; + } + + if (scrollBar.OtherScrollBarView is { IsVertical: true }) + { + scrollBar.OtherScrollBarView.Position++; + + return true; + } + + return false; + }); + + scrollBar.AddCommand ( + Command.ScrollUp, + () => + { + if (scrollBar.IsVertical) + { + scrollBar.Position--; + + return true; + } + + if (scrollBar.OtherScrollBarView is { IsVertical: true }) + { + scrollBar.OtherScrollBarView.Position--; + + return true; + } + + return false; + }); + + scrollBar.AddCommand ( + Command.TopHome, + () => + { + if (scrollBar.IsVertical) + { + scrollBar.Position = 0; + + return true; + } + + if (scrollBar.OtherScrollBarView is { IsVertical: true }) + { + scrollBar.OtherScrollBarView.Position = 0; + + return true; + } + + return false; + }); + + scrollBar.AddCommand ( + Command.BottomEnd, + () => + { + if (scrollBar.IsVertical) + { + scrollBar.Position = ScrollRowsSize; + + return true; + } + + if (scrollBar.OtherScrollBarView is { IsVertical: true }) + { + scrollBar.OtherScrollBarView.Position = ScrollRowsSize; + + return true; + } + + return false; + }); + + scrollBar.AddCommand ( + Command.PageDown, + () => + { + if (scrollBar.IsVertical) + { + scrollBar.Position += ContentArea.Height; + + return true; + } + + if (scrollBar.OtherScrollBarView is { IsVertical: true }) + { + scrollBar.OtherScrollBarView.Position += ContentArea.Height; + + return true; + } + + return false; + }); + + scrollBar.AddCommand ( + Command.PageUp, + () => + { + if (scrollBar.IsVertical) + { + scrollBar.Position -= ContentArea.Height; + + return true; + } + + if (scrollBar.OtherScrollBarView is { IsVertical: true }) + { + scrollBar.OtherScrollBarView.Position -= ContentArea.Height; + + return true; + } + + return false; + }); + + // Default keybindings for this view + scrollBar.KeyBindings.Add (KeyCode.CursorDown, KeyBindingScope.HotKey, Command.ScrollDown); + scrollBar.KeyBindings.Add (KeyCode.CursorUp, KeyBindingScope.HotKey, Command.ScrollUp); + scrollBar.KeyBindings.Add (KeyCode.Home, KeyBindingScope.HotKey, Command.TopHome); + scrollBar.KeyBindings.Add (KeyCode.End, KeyBindingScope.HotKey, Command.BottomEnd); + scrollBar.KeyBindings.Add (KeyCode.PageDown, KeyBindingScope.HotKey, Command.PageDown); + scrollBar.KeyBindings.Add (KeyCode.PageUp, KeyBindingScope.HotKey, Command.PageUp); + } + else + { + // Things this view knows how to do + scrollBar.AddCommand ( + Command.Left, + () => + { + if (!scrollBar.IsVertical) + { + scrollBar.Position--; + + return true; + } + + if (scrollBar.OtherScrollBarView is { IsVertical: false }) + { + scrollBar.OtherScrollBarView.Position--; + + return true; + } + + return false; + }); + + scrollBar.AddCommand ( + Command.Right, + () => + { + if (!scrollBar.IsVertical) + { + scrollBar.Position++; + + return true; + } + + if (scrollBar.OtherScrollBarView is { IsVertical: false }) + { + scrollBar.OtherScrollBarView.Position++; + + return true; + } + + return false; + }); + + scrollBar.AddCommand ( + Command.LeftHome, + () => + { + if (!scrollBar.IsVertical) + { + scrollBar.Position = 0; + + return true; + } + + if (scrollBar.OtherScrollBarView is { IsVertical: false }) + { + scrollBar.OtherScrollBarView.Position = 0; + + return true; + } + + return false; + }); + + scrollBar.AddCommand ( + Command.RightEnd, + () => + { + if (!scrollBar.IsVertical) + { + scrollBar.Position = ScrollColsSize; + + return true; + } + + if (scrollBar.OtherScrollBarView is { IsVertical: false }) + { + scrollBar.OtherScrollBarView.Position = ScrollColsSize; + + return true; + } + + return false; + }); + + scrollBar.AddCommand ( + Command.PageRight, + () => + { + if (!scrollBar.IsVertical) + { + scrollBar.Position += ContentArea.Width; + + return true; + } + + if (scrollBar.OtherScrollBarView is { IsVertical: false }) + { + scrollBar.OtherScrollBarView.Position += ContentArea.Width; + + return true; + } + + return false; + }); + + scrollBar.AddCommand ( + Command.PageLeft, + () => + { + if (!scrollBar.IsVertical) + { + scrollBar.Position -= ContentArea.Width; + + return true; + } + + if (scrollBar.OtherScrollBarView is { IsVertical: false }) + { + scrollBar.OtherScrollBarView.Position -= ContentArea.Width; + + return true; + } + + return false; + }); + + // Default keybindings for this view + scrollBar.KeyBindings.Add (KeyCode.CursorLeft, KeyBindingScope.HotKey, Command.Left); + scrollBar.KeyBindings.Add (KeyCode.CursorRight, KeyBindingScope.HotKey, Command.Right); + scrollBar.KeyBindings.Add (KeyCode.Home | KeyCode.ShiftMask, KeyBindingScope.HotKey, Command.LeftHome); + scrollBar.KeyBindings.Add (KeyCode.End | KeyCode.ShiftMask, KeyBindingScope.HotKey, Command.RightEnd); + scrollBar.KeyBindings.Add (KeyCode.PageDown | KeyCode.ShiftMask, KeyBindingScope.HotKey, Command.PageRight); + scrollBar.KeyBindings.Add (KeyCode.PageUp | KeyCode.ShiftMask, KeyBindingScope.HotKey, Command.PageLeft); + } + } + + private void DisposeScrollBar () + { + if (_scrollBar == null) + { + return; + } + + _scrollBar.ChangedPosition -= ScrollBar_ChangedPosition; + + //_scrollBar.VisibleChanged -= ScrollBar_VisibleChanged; + if (_scrollBar.OtherScrollBarView != null) + { + _scrollBar.OtherScrollBarView.ChangedPosition -= OtherScrollBarView_ChangedPosition; + + //_scrollBar.OtherScrollBarView.VisibleChanged -= OtherScrollBarView_VisibleChanged; + } + + _scrollBar.RemoveAll (); + _scrollBar = null; + } + + private void OtherScrollBarView_ChangedPosition (object sender, EventArgs e) { SetBoundsByPosition (_scrollBar.OtherScrollBarView); } + + private void ScrollBar_ChangedPosition (object sender, EventArgs e) { SetBoundsByPosition (_scrollBar); } + + private void SetBoundsByPosition (ScrollBarView scrollBar) + { + if (scrollBar.IsVertical) + { + if (UseNegativeBoundsLocation) + { + Bounds = Bounds with { Y = -scrollBar.Position }; + Bounds = Bounds with { Height = Math.Min (Bounds.Height + scrollBar.Position, ScrollRowsSize) }; + + if (Bounds.Y != -scrollBar.Position) + { + scrollBar.Position = Bounds.Y; + } + } + else + { + if (ScrollTopOffset != scrollBar.Position) + { + ScrollTopOffset = scrollBar.Position; + } + } + } + else + { + if (UseNegativeBoundsLocation) + { + Bounds = Bounds with { X = -scrollBar.Position }; + Bounds = Bounds with { Width = Math.Min (Bounds.Width + scrollBar.Position, ScrollColsSize) }; + + if (Bounds.X != -scrollBar.Position) + { + scrollBar.Position = Bounds.X; + } + } + else + { + if (ScrollLeftOffset != scrollBar.Position) + { + ScrollLeftOffset = scrollBar.Position; + } + } + } + + SetTextFormatterSize (); + SetNeedsDisplay (); + } +} From a533466fe995cda1ecb35a990ced1792146c2aa1 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 01:06:02 +0000 Subject: [PATCH 009/130] Add built-in scroll bar on TableView. --- Terminal.Gui/Views/TableView/TableView.cs | 79 +++++++++++++++++++++-- 1 file changed, 75 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/Views/TableView/TableView.cs b/Terminal.Gui/Views/TableView/TableView.cs index 06f4bc27e0..18d43ebb7b 100644 --- a/Terminal.Gui/Views/TableView/TableView.cs +++ b/Terminal.Gui/Views/TableView/TableView.cs @@ -29,6 +29,7 @@ public class TableView : View // TODO: Update to use Key instead of KeyCode private KeyCode cellActivationKey = KeyCode.Enter; private int columnOffset; + private bool ignoreEnsureSelectedCellIsVisible; private int rowOffset; private Point? scrollLeftPoint; private Point? scrollRightPoint; @@ -51,6 +52,8 @@ public TableView () CollectionNavigator = new TableCollectionNavigator (this); + DrawAdornments += TableView_DrawAdornments; + // Things this view knows how to do AddCommand ( Command.Right, @@ -341,7 +344,7 @@ public int ColumnOffset get => columnOffset; //try to prevent this being set to an out of bounds column - set => columnOffset = TableIsNullOrInvisible () ? 0 : Math.Max (0, Math.Min (Table.Columns - 1, value)); + set => ScrollLeftOffset = columnOffset = TableIsNullOrInvisible () ? 0 : Math.Max (0, Math.Min (Table.Columns - 1, value)); } /// True to select the entire row at once. False to select individual cells. Defaults to false @@ -377,7 +380,44 @@ public int ColumnOffset public int RowOffset { get => rowOffset; - set => rowOffset = TableIsNullOrInvisible () ? 0 : Math.Max (0, Math.Min (Table.Rows - 1, value)); + set => ScrollTopOffset = rowOffset = TableIsNullOrInvisible () ? 0 : Math.Max (0, Math.Min (Table.Rows - 1, value)); + } + + /// + public override int ScrollLeftOffset + { + get => base.ScrollLeftOffset; + set + { + if (base.ScrollLeftOffset != value) + { + base.ScrollLeftOffset = value; + } + + if (ColumnOffset != ScrollLeftOffset) + { + ignoreEnsureSelectedCellIsVisible = true; + ColumnOffset = ScrollLeftOffset; + } + } + } + + /// + public override int ScrollTopOffset + { + get => base.ScrollTopOffset; + set + { + if (base.ScrollTopOffset != value) + { + base.ScrollTopOffset = value; + } + + if (RowOffset != ScrollTopOffset) + { + RowOffset = ScrollTopOffset; + } + } } /// The index of in that the user has currently selected @@ -412,6 +452,8 @@ public int SelectedRow get => selectedRow; set { + ignoreEnsureSelectedCellIsVisible = false; + int oldValue = selectedRow; selectedRow = TableIsNullOrInvisible () ? 0 : Math.Min (Table.Rows - 1, Math.Max (0, value)); @@ -432,7 +474,7 @@ public int SelectedRow } /// - /// The symbol to add after each cell value and header value to visually seperate values (if not using vertical + /// The symbol to add after each cell value and header value to visually separate values (if not using vertical /// gridlines) /// public char SeparatorSymbol { get; set; } = ' '; @@ -455,6 +497,7 @@ public ITableSource Table set { table = value; + SetScrollRowsColsSize (); Update (); } } @@ -1191,7 +1234,10 @@ public void Update () EnsureValidScrollOffsets (); EnsureValidSelection (); - EnsureSelectedCellIsVisible (); + if (!ignoreEnsureSelectedCellIsVisible) + { + EnsureSelectedCellIsVisible (); + } SetNeedsDisplay (); } @@ -1971,6 +2017,21 @@ private void RenderSeparator (int col, int row, bool isHeader) AddRune (col, row, symbol); } + private void SetScrollRowsColsSize () + { + int scrollColsSize = Table?.Columns + Bounds.Width - 1 ?? 0; + + if (ScrollColsSize != scrollColsSize) + { + ScrollColsSize = scrollColsSize; + } + + if (ScrollRowsSize != Table?.Rows) + { + ScrollRowsSize = Table?.Rows ?? 0; + } + } + private bool ShouldRenderHeaders () { if (TableIsNullOrInvisible ()) @@ -1996,6 +2057,16 @@ private bool TableIsNullOrInvisible () ); } + private void TableView_DrawAdornments (object sender, DrawEventArgs e) + { + if (Table is null) + { + return; + } + + SetScrollRowsColsSize (); + } + private void ToggleCurrentCellSelection () { var e = new CellToggledEventArgs (Table, selectedColumn, selectedRow); From 809aa08486e07e69c4cf9599980d52cd9865b29b Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 01:08:50 +0000 Subject: [PATCH 010/130] Prefix private fields with underscore. --- Terminal.Gui/Views/TableView/TableView.cs | 124 +++++++++++----------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/Terminal.Gui/Views/TableView/TableView.cs b/Terminal.Gui/Views/TableView/TableView.cs index 18d43ebb7b..73af17c272 100644 --- a/Terminal.Gui/Views/TableView/TableView.cs +++ b/Terminal.Gui/Views/TableView/TableView.cs @@ -27,16 +27,16 @@ public class TableView : View public const int DefaultMinAcceptableWidth = 100; // TODO: Update to use Key instead of KeyCode - private KeyCode cellActivationKey = KeyCode.Enter; - private int columnOffset; - private bool ignoreEnsureSelectedCellIsVisible; - private int rowOffset; - private Point? scrollLeftPoint; - private Point? scrollRightPoint; - private int selectedColumn; - private int selectedRow; - private TableStyle style = new (); - private ITableSource table; + private KeyCode _cellActivationKey = KeyCode.Enter; + private int _columnOffset; + private bool _ignoreEnsureSelectedCellIsVisible; + private int _rowOffset; + private Point? _scrollLeftPoint; + private Point? _scrollRightPoint; + private int _selectedColumn; + private int _selectedRow; + private TableStyle _style = new (); + private ITableSource _table; /// Initializes a class using layout. /// The table to display in the control @@ -316,17 +316,17 @@ public TableView () /// The key which when pressed should trigger event. Defaults to Enter. public KeyCode CellActivationKey { - get => cellActivationKey; + get => _cellActivationKey; set { - if (cellActivationKey != value) + if (_cellActivationKey != value) { - KeyBindings.Replace (cellActivationKey, value); + KeyBindings.Replace (_cellActivationKey, value); // of API user is mixing and matching old and new methods of keybinding then they may have lost // the old binding (e.g. with ClearKeybindings) so KeyBindings.Replace alone will fail KeyBindings.Add (value, Command.Accept); - cellActivationKey = value; + _cellActivationKey = value; } } } @@ -341,10 +341,10 @@ public KeyCode CellActivationKey /// This property allows very wide tables to be rendered with horizontal scrolling public int ColumnOffset { - get => columnOffset; + get => _columnOffset; //try to prevent this being set to an out of bounds column - set => ScrollLeftOffset = columnOffset = TableIsNullOrInvisible () ? 0 : Math.Max (0, Math.Min (Table.Columns - 1, value)); + set => ScrollLeftOffset = _columnOffset = TableIsNullOrInvisible () ? 0 : Math.Max (0, Math.Min (Table.Columns - 1, value)); } /// True to select the entire row at once. False to select individual cells. Defaults to false @@ -379,8 +379,8 @@ public int ColumnOffset /// public int RowOffset { - get => rowOffset; - set => ScrollTopOffset = rowOffset = TableIsNullOrInvisible () ? 0 : Math.Max (0, Math.Min (Table.Rows - 1, value)); + get => _rowOffset; + set => ScrollTopOffset = _rowOffset = TableIsNullOrInvisible () ? 0 : Math.Max (0, Math.Min (Table.Rows - 1, value)); } /// @@ -396,7 +396,7 @@ public override int ScrollLeftOffset if (ColumnOffset != ScrollLeftOffset) { - ignoreEnsureSelectedCellIsVisible = true; + _ignoreEnsureSelectedCellIsVisible = true; ColumnOffset = ScrollLeftOffset; } } @@ -423,15 +423,15 @@ public override int ScrollTopOffset /// The index of in that the user has currently selected public int SelectedColumn { - get => selectedColumn; + get => _selectedColumn; set { - int oldValue = selectedColumn; + int oldValue = _selectedColumn; //try to prevent this being set to an out of bounds column - selectedColumn = TableIsNullOrInvisible () ? 0 : Math.Min (Table.Columns - 1, Math.Max (0, value)); + _selectedColumn = TableIsNullOrInvisible () ? 0 : Math.Min (Table.Columns - 1, Math.Max (0, value)); - if (oldValue != selectedColumn) + if (oldValue != _selectedColumn) { OnSelectedCellChanged ( new SelectedCellChangedEventArgs ( @@ -449,16 +449,16 @@ public int SelectedColumn /// The index of in that the user has currently selected public int SelectedRow { - get => selectedRow; + get => _selectedRow; set { - ignoreEnsureSelectedCellIsVisible = false; + _ignoreEnsureSelectedCellIsVisible = false; - int oldValue = selectedRow; + int oldValue = _selectedRow; - selectedRow = TableIsNullOrInvisible () ? 0 : Math.Min (Table.Rows - 1, Math.Max (0, value)); + _selectedRow = TableIsNullOrInvisible () ? 0 : Math.Min (Table.Rows - 1, Math.Max (0, value)); - if (oldValue != selectedRow) + if (oldValue != _selectedRow) { OnSelectedCellChanged ( new SelectedCellChangedEventArgs ( @@ -466,7 +466,7 @@ public int SelectedRow SelectedColumn, SelectedColumn, oldValue, - selectedRow + _selectedRow ) ); } @@ -482,10 +482,10 @@ public int SelectedRow /// Contains options for changing how the table is rendered public TableStyle Style { - get => style; + get => _style; set { - style = value; + _style = value; Update (); } } @@ -493,10 +493,10 @@ public TableStyle Style /// The data table to render in the view. Setting this property automatically updates and redraws the control. public ITableSource Table { - get => table; + get => _table; set { - table = value; + _table = value; SetScrollRowsColsSize (); Update (); } @@ -888,18 +888,18 @@ public override bool MouseEvent (MouseEvent me) if (me.Flags.HasFlag (MouseFlags.Button1Clicked)) { - if (scrollLeftPoint != null - && scrollLeftPoint.Value.X == boundsX - && scrollLeftPoint.Value.Y == boundsY) + if (_scrollLeftPoint != null + && _scrollLeftPoint.Value.X == boundsX + && _scrollLeftPoint.Value.Y == boundsY) { ColumnOffset--; EnsureValidScrollOffsets (); SetNeedsDisplay (); } - if (scrollRightPoint != null - && scrollRightPoint.Value.X == boundsX - && scrollRightPoint.Value.Y == boundsY) + if (_scrollRightPoint != null + && _scrollRightPoint.Value.X == boundsX + && _scrollRightPoint.Value.Y == boundsY) { ColumnOffset++; EnsureValidScrollOffsets (); @@ -944,8 +944,8 @@ public override void OnDrawContent (Rect contentArea) Move (0, 0); - scrollRightPoint = null; - scrollLeftPoint = null; + _scrollRightPoint = null; + _scrollLeftPoint = null; // What columns to render at what X offset in viewport ColumnToRender [] columnsToRender = CalculateViewport (Bounds).ToArray (); @@ -1166,7 +1166,7 @@ public void SelectAll () MultiSelectedRegions.Push ( new TableSelection ( new Point (SelectedColumn, SelectedRow), - new Rect (0, 0, Table.Columns, table.Rows) + new Rect (0, 0, Table.Columns, _table.Rows) ) ); Update (); @@ -1186,7 +1186,7 @@ public void SetSelection (int col, int row, bool extendExistingSelection) { // if we are trying to increase the column index then // we are moving right otherwise we are moving left - bool lookRight = col > selectedColumn; + bool lookRight = col > _selectedColumn; col = GetNearestVisibleColumn (col, lookRight, true); @@ -1234,7 +1234,7 @@ public void Update () EnsureValidScrollOffsets (); EnsureValidSelection (); - if (!ignoreEnsureSelectedCellIsVisible) + if (!_ignoreEnsureSelectedCellIsVisible) { EnsureSelectedCellIsVisible (); } @@ -1329,7 +1329,7 @@ private void AddRuneAt (ConsoleDriver d, int col, int row, Rune ch) /// private int CalculateMaxCellWidth (int col, int rowsToRender, ColumnStyle colStyle) { - int spaceRequired = table.ColumnNames [col].EnumerateRunes ().Sum (c => c.GetColumns ()); + int spaceRequired = _table.ColumnNames [col].EnumerateRunes ().Sum (c => c.GetColumns ()); // if table has no rows if (RowOffset < 0) @@ -1651,7 +1651,7 @@ private string GetRepresentation (object value, ColumnStyle colStyle) private bool IsColumnVisible (int columnIndex) { // if the column index provided is out of bounds - if (columnIndex < 0 || columnIndex >= table.Columns) + if (columnIndex < 0 || columnIndex >= _table.Columns) { return false; } @@ -1706,7 +1706,7 @@ private void RenderHeaderMidline (int row, ColumnToRender [] columnsToRender) ClearLine (row, Bounds.Width); //render start of line - if (style.ShowVerticalHeaderLines) + if (_style.ShowVerticalHeaderLines) { AddRune (0, row, Glyphs.VLine); } @@ -1716,7 +1716,7 @@ private void RenderHeaderMidline (int row, ColumnToRender [] columnsToRender) ColumnToRender current = columnsToRender [i]; ColumnStyle colStyle = Style.GetColumnStyleIfAny (current.Column); - string colName = table.ColumnNames [current.Column]; + string colName = _table.ColumnNames [current.Column]; RenderSeparator (current.X - 1, row, true); @@ -1731,7 +1731,7 @@ private void RenderHeaderMidline (int row, ColumnToRender [] columnsToRender) } //render end of line - if (style.ShowVerticalHeaderLines) + if (_style.ShowVerticalHeaderLines) { AddRune (Bounds.Width - 1, row, Glyphs.VLine); } @@ -1831,7 +1831,7 @@ private void RenderHeaderUnderline (int row, int availableWidth, ColumnToRender if (Style.ShowHorizontalScrollIndicators && moreColumnsToLeft) { rune = Glyphs.LeftArrow; - scrollLeftPoint = new Point (c, row); + _scrollLeftPoint = new Point (c, row); } } @@ -1852,7 +1852,7 @@ private void RenderHeaderUnderline (int row, int availableWidth, ColumnToRender if (Style.ShowHorizontalScrollIndicators && moreColumnsToRight) { rune = Glyphs.RightArrow; - scrollRightPoint = new Point (c, row); + _scrollRightPoint = new Point (c, row); } } @@ -1956,7 +1956,7 @@ private void RenderRow (int row, int rowToRender, ColumnToRender [] columnsToRen string render = TruncateOrPad (val, representation, current.Width, colStyle); // While many cells can be selected (see MultiSelectedRegions) only one cell is the primary (drives navigation etc) - bool isPrimaryCell = current.Column == selectedColumn && rowToRender == selectedRow; + bool isPrimaryCell = current.Column == _selectedColumn && rowToRender == _selectedRow; RenderCell (cellColor, render, isPrimaryCell); @@ -1981,7 +1981,7 @@ private void RenderRow (int row, int rowToRender, ColumnToRender [] columnsToRen Driver.SetAttribute (Enabled ? rowScheme.Normal : rowScheme.Disabled); } - if (style.AlwaysUseNormalColorForVerticalCellLines && style.ShowVerticalCellLines) + if (_style.AlwaysUseNormalColorForVerticalCellLines && _style.ShowVerticalCellLines) { Driver.SetAttribute (rowScheme.Normal); } @@ -1994,7 +1994,7 @@ private void RenderRow (int row, int rowToRender, ColumnToRender [] columnsToRen } } - if (style.ShowVerticalCellLines) + if (_style.ShowVerticalCellLines) { Driver.SetAttribute (rowScheme.Normal); @@ -2011,7 +2011,7 @@ private void RenderSeparator (int col, int row, bool isHeader) return; } - bool renderLines = isHeader ? style.ShowVerticalHeaderLines : style.ShowVerticalCellLines; + bool renderLines = isHeader ? _style.ShowVerticalHeaderLines : _style.ShowVerticalCellLines; Rune symbol = renderLines ? Glyphs.VLine : (Rune)SeparatorSymbol; AddRune (col, row, symbol); @@ -2039,7 +2039,7 @@ private bool ShouldRenderHeaders () return false; } - return Style.AlwaysShowHeaders || rowOffset == 0; + return Style.AlwaysShowHeaders || _rowOffset == 0; } /// @@ -2069,7 +2069,7 @@ private void TableView_DrawAdornments (object sender, DrawEventArgs e) private void ToggleCurrentCellSelection () { - var e = new CellToggledEventArgs (Table, selectedColumn, selectedRow); + var e = new CellToggledEventArgs (Table, _selectedColumn, _selectedRow); OnCellToggled (e); if (e.Cancel) @@ -2082,7 +2082,7 @@ private void ToggleCurrentCellSelection () return; } - TableSelection [] regions = GetMultiSelectedRegionsContaining (selectedColumn, selectedRow).ToArray (); + TableSelection [] regions = GetMultiSelectedRegionsContaining (_selectedColumn, _selectedRow).ToArray (); TableSelection [] toggles = regions.Where (s => s.IsToggled).ToArray (); // Toggle it off @@ -2115,10 +2115,10 @@ private void ToggleCurrentCellSelection () // Toggle on a single cell selection MultiSelectedRegions.Push ( CreateTableSelection ( - selectedColumn, + _selectedColumn, SelectedRow, - selectedColumn, - selectedRow, + _selectedColumn, + _selectedRow, true ) ); @@ -2189,7 +2189,7 @@ out int idx ) { // if the column index provided is out of bounds - if (columnIndex < 0 || columnIndex >= table.Columns) + if (columnIndex < 0 || columnIndex >= _table.Columns) { idx = columnIndex; From 55993f324e1690dc7310cfd811ec22d2e32fe251 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 01:10:10 +0000 Subject: [PATCH 011/130] Add built-in scroll bar in TreeView. --- Terminal.Gui/Views/TreeView/TreeView.cs | 48 +++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/Views/TreeView/TreeView.cs b/Terminal.Gui/Views/TreeView/TreeView.cs index 4fd0e41fdb..4a591d36d9 100644 --- a/Terminal.Gui/Views/TreeView/TreeView.cs +++ b/Terminal.Gui/Views/TreeView/TreeView.cs @@ -81,6 +81,8 @@ public TreeView () { CanFocus = true; + DrawAdornments += TreeView_DrawAdornments; + // Things this view knows how to do AddCommand ( Command.PageUp, @@ -391,6 +393,24 @@ public KeyCode ObjectActivationKey /// The root objects in the tree, note that this collection is of root objects only. public IEnumerable Objects => roots.Keys; + /// + public override int ScrollLeftOffset + { + get => base.ScrollLeftOffset; + set + { + if (base.ScrollLeftOffset != value) + { + base.ScrollLeftOffset = value; + } + + if (ScrollOffsetHorizontal != ScrollLeftOffset) + { + ScrollOffsetHorizontal = ScrollLeftOffset; + } + } + } + /// The amount of tree view that has been scrolled to the right (horizontally). /// /// Setting a value of less than 0 will result in a offset of 0. To see changes in the UI call @@ -399,7 +419,7 @@ public KeyCode ObjectActivationKey public int ScrollOffsetHorizontal { get => scrollOffsetHorizontal; - set => scrollOffsetHorizontal = Math.Max (0, value); + set => ScrollLeftOffset = scrollOffsetHorizontal = Math.Max (0, value); } /// The amount of tree view that has been scrolled off the top of the screen (by the user scrolling down). @@ -410,7 +430,25 @@ public int ScrollOffsetHorizontal public int ScrollOffsetVertical { get => scrollOffsetVertical; - set => scrollOffsetVertical = Math.Max (0, value); + set => ScrollTopOffset = scrollOffsetVertical = Math.Max (0, value); + } + + /// + public override int ScrollTopOffset + { + get => base.ScrollTopOffset; + set + { + if (base.ScrollTopOffset != value) + { + base.ScrollTopOffset = value; + } + + if (ScrollOffsetVertical != ScrollTopOffset) + { + ScrollOffsetVertical = ScrollTopOffset; + } + } } /// @@ -1594,6 +1632,12 @@ private Branch HitTest (int y) /// /// The branch for or null if it is not currently exposed in the tree. private Branch ObjectToBranch (T toFind) { return BuildLineMap ().FirstOrDefault (o => o.Model.Equals (toFind)); } + + private void TreeView_DrawAdornments (object sender, DrawEventArgs e) + { + ScrollRowsSize = ContentHeight; + ScrollColsSize = GetContentWidth (true); + } } internal class TreeSelection where T : class From 7e4dc56a4529c4dc8869f0a8d312f2309ce48e48 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 01:14:01 +0000 Subject: [PATCH 012/130] Prefix private fields with underscore. --- Terminal.Gui/Views/TreeView/TreeView.cs | 64 ++++++++++++------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/Terminal.Gui/Views/TreeView/TreeView.cs b/Terminal.Gui/Views/TreeView/TreeView.cs index 4a591d36d9..478fa3770a 100644 --- a/Terminal.Gui/Views/TreeView/TreeView.cs +++ b/Terminal.Gui/Views/TreeView/TreeView.cs @@ -62,16 +62,16 @@ public class TreeView : View, ITreeView where T : class private readonly Stack> multiSelectedRegions = new (); /// Cached result of - private IReadOnlyCollection> cachedLineMap; + private IReadOnlyCollection> _cachedLineMap; - private CursorVisibility desiredCursorVisibility = CursorVisibility.Invisible; + private CursorVisibility _desiredCursorVisibility = CursorVisibility.Invisible; - private KeyCode objectActivationKey = KeyCode.Enter; - private int scrollOffsetHorizontal; - private int scrollOffsetVertical; + private KeyCode _objectActivationKey = KeyCode.Enter; + private int _scrollOffsetHorizontal; + private int _scrollOffsetVertical; /// private variable for - private T selectedObject; + private T _selectedObject; /// /// Creates a new tree view with absolute positioning. Use to set set @@ -340,12 +340,12 @@ public TreeView () /// public CursorVisibility DesiredCursorVisibility { - get => MultiSelect ? desiredCursorVisibility : CursorVisibility.Invisible; + get => MultiSelect ? _desiredCursorVisibility : CursorVisibility.Invisible; set { - if (desiredCursorVisibility != value) + if (_desiredCursorVisibility != value) { - desiredCursorVisibility = value; + _desiredCursorVisibility = value; if (HasFocus) { @@ -379,13 +379,13 @@ public CursorVisibility DesiredCursorVisibility /// Key which when pressed triggers . Defaults to Enter. public KeyCode ObjectActivationKey { - get => objectActivationKey; + get => _objectActivationKey; set { - if (objectActivationKey != value) + if (_objectActivationKey != value) { KeyBindings.Replace (ObjectActivationKey, value); - objectActivationKey = value; + _objectActivationKey = value; } } } @@ -418,8 +418,8 @@ public override int ScrollLeftOffset /// public int ScrollOffsetHorizontal { - get => scrollOffsetHorizontal; - set => ScrollLeftOffset = scrollOffsetHorizontal = Math.Max (0, value); + get => _scrollOffsetHorizontal; + set => ScrollLeftOffset = _scrollOffsetHorizontal = Math.Max (0, value); } /// The amount of tree view that has been scrolled off the top of the screen (by the user scrolling down). @@ -429,8 +429,8 @@ public int ScrollOffsetHorizontal /// public int ScrollOffsetVertical { - get => scrollOffsetVertical; - set => ScrollTopOffset = scrollOffsetVertical = Math.Max (0, value); + get => _scrollOffsetVertical; + set => ScrollTopOffset = _scrollOffsetVertical = Math.Max (0, value); } /// @@ -457,11 +457,11 @@ public override int ScrollTopOffset /// public T SelectedObject { - get => selectedObject; + get => _selectedObject; set { - T oldValue = selectedObject; - selectedObject = value; + T oldValue = _selectedObject; + _selectedObject = value; if (!ReferenceEquals (oldValue, value)) { @@ -722,7 +722,7 @@ public void AdjustSelectionToNextItemBeginningWith ( public bool CanExpand (T o) { return ObjectToBranch (o)?.CanExpand () ?? false; } /// Collapses the - public void Collapse () { Collapse (selectedObject); } + public void Collapse () { Collapse (_selectedObject); } /// Collapses the supplied object if it is currently expanded . /// The object to collapse. @@ -1020,7 +1020,7 @@ public void GoToFirst () } /// Clears any cached results of the tree state. - public void InvalidateLineMap () { cachedLineMap = null; } + public void InvalidateLineMap () { _cachedLineMap = null; } /// Returns true if the given object is exposed in the tree and expanded otherwise false. /// @@ -1254,7 +1254,7 @@ public override bool OnProcessKeyDown (Key keyEvent) if (newIndex is int && newIndex != -1) { SelectedObject = map.ElementAt ((int)newIndex).Model; - EnsureVisible (selectedObject); + EnsureVisible (_selectedObject); SetNeedsDisplay (); return true; @@ -1366,7 +1366,7 @@ public void ScrollDown () /// Scrolls the view area up a single line without changing the current selection. public void ScrollUp () { - if (scrollOffsetVertical > 0) + if (_scrollOffsetVertical > 0) { ScrollOffsetVertical--; SetNeedsDisplay (); @@ -1496,9 +1496,9 @@ protected override void Dispose (bool disposing) /// internal IReadOnlyCollection> BuildLineMap () { - if (cachedLineMap is { }) + if (_cachedLineMap is { }) { - return cachedLineMap; + return _cachedLineMap; } List> toReturn = new (); @@ -1513,12 +1513,12 @@ internal IReadOnlyCollection> BuildLineMap () } } - cachedLineMap = new ReadOnlyCollection> (toReturn); + _cachedLineMap = new ReadOnlyCollection> (toReturn); // Update the collection used for search-typing - KeystrokeNavigator.Collection = cachedLineMap.Select (b => AspectGetter (b.Model)).ToArray (); + KeystrokeNavigator.Collection = _cachedLineMap.Select (b => AspectGetter (b.Model)).ToArray (); - return cachedLineMap; + return _cachedLineMap; } /// Raises the DrawLine event @@ -1642,7 +1642,7 @@ private void TreeView_DrawAdornments (object sender, DrawEventArgs e) internal class TreeSelection where T : class { - private readonly HashSet included = new (); + private readonly HashSet _included = []; /// Creates a new selection between two branches in the tree /// @@ -1651,7 +1651,7 @@ internal class TreeSelection where T : class public TreeSelection (Branch from, int toIndex, IReadOnlyCollection> map) { Origin = from; - included.Add (Origin.Model); + _included.Add (Origin.Model); int oldIdx = map.IndexOf (from); @@ -1661,10 +1661,10 @@ public TreeSelection (Branch from, int toIndex, IReadOnlyCollection // Select everything between the old and new indexes foreach (Branch alsoInclude in map.Skip (lowIndex).Take (highIndex - lowIndex)) { - included.Add (alsoInclude.Model); + _included.Add (alsoInclude.Model); } } public Branch Origin { get; } - public bool Contains (T model) { return included.Contains (model); } + public bool Contains (T model) { return _included.Contains (model); } } From 07ac230cf59535d6e271a02393adee353e8db78b Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 01:15:45 +0000 Subject: [PATCH 013/130] Add built-in scroll bar on ComboBox for the ListView. --- Terminal.Gui/Views/ComboBox.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index d7251ccce8..37b655d12c 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -136,6 +136,13 @@ public bool ReadOnly } } + /// + public override ScrollBarType ScrollBarType + { + get => _listview.ScrollBarType; + set => _listview.ScrollBarType = value; + } + /// Current search text public string SearchText { From 9325536edb053c3a141cc08dff6eacf3c763c74d Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 01:17:51 +0000 Subject: [PATCH 014/130] Add built-in scroll bar in ListView. --- Terminal.Gui/Views/ListView.cs | 83 +++++++++++++++++++++++++++++++--- 1 file changed, 76 insertions(+), 7 deletions(-) diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs index a85f8ec6c3..0d932eb391 100644 --- a/Terminal.Gui/Views/ListView.cs +++ b/Terminal.Gui/Views/ListView.cs @@ -94,7 +94,7 @@ public class ListView : View private int _lastSelectedItem = -1; private int _selected = -1; private IListDataSource _source; - private int _top, _left; + private int _topItem, _leftItem; /// /// Initializes a new instance of . Set the property to display @@ -104,6 +104,8 @@ public ListView () { CanFocus = true; + DrawAdornments += ListView_DrawAdornments; + // Things this view knows how to do AddCommand (Command.LineUp, () => MoveUp ()); AddCommand (Command.LineDown, () => MoveDown ()); @@ -198,7 +200,7 @@ public bool AllowsMultipleSelection /// The left position. public int LeftItem { - get => _left; + get => _leftItem; set { if (_source is null) @@ -211,7 +213,7 @@ public int LeftItem throw new ArgumentException ("value"); } - _left = value; + ScrollLeftOffset = _leftItem = value; SetNeedsDisplay (); } } @@ -219,6 +221,42 @@ public int LeftItem /// Gets the widest item in the list. public int MaxLength => _source?.Length ?? 0; + /// + public override int ScrollLeftOffset + { + get => base.ScrollLeftOffset; + set + { + if (base.ScrollLeftOffset != value) + { + base.ScrollLeftOffset = value; + } + + if (LeftItem != ScrollLeftOffset) + { + _left = ScrollLeftOffset; + } + } + } + + /// + public override int ScrollTopOffset + { + get => base.ScrollTopOffset; + set + { + if (base.ScrollTopOffset != value) + { + base.ScrollTopOffset = value; + } + + if (TopItem != ScrollTopOffset) + { + _top = ScrollTopOffset; + } + } + } + /// Gets or sets the index of the currently selected item. /// The selected item. public int SelectedItem @@ -254,6 +292,7 @@ public IListDataSource Source _top = 0; _selected = -1; _lastSelectedItem = -1; + SetScrollRowsColsSize (); SetNeedsDisplay (); } } @@ -262,7 +301,7 @@ public IListDataSource Source /// The top item. public int TopItem { - get => _top; + get => _topItem; set { if (_source is null) @@ -275,11 +314,23 @@ public int TopItem throw new ArgumentException ("value"); } - _top = Math.Max (value, 0); + ScrollTopOffset = _topItem = Math.Max (value, 0); SetNeedsDisplay (); } } + private int _left + { + get => _leftItem; + set => ScrollLeftOffset = _leftItem = value; + } + + private int _top + { + get => _topItem; + set => ScrollTopOffset = _topItem = value; + } + /// /// If and are both , /// unmarks all marked items other than the currently selected. @@ -857,7 +908,24 @@ public Task SetSourceAsync (IList source) ); } - private void ListView_LayoutStarted (object sender, LayoutEventArgs e) { EnsureSelectedItemVisible (); } + private void ListView_DrawAdornments (object sender, DrawEventArgs e) { SetScrollRowsColsSize (); } + + private void ListView_LayoutStarted (object sender, LayoutEventArgs e) + { + SetScrollRowsColsSize (); + EnsureSelectedItemVisible (); + } + + private void SetScrollRowsColsSize () + { + try + { + ScrollRowsSize = Source?.Count ?? 0; + ScrollColsSize = MaxLength; + } + catch (NotImplementedException) + { } + } } /// @@ -1016,7 +1084,8 @@ private int GetMaxLengthItem () private void RenderUstr (ConsoleDriver driver, string ustr, int col, int line, int width, int start = 0) { - string u = TextFormatter.ClipAndJustify (ustr, width, TextAlignment.Left); + string str = start > ustr.GetColumns () ? string.Empty : ustr.Substring (start); + string u = TextFormatter.ClipAndJustify (str, width, TextAlignment.Left); driver.AddStr (u); width -= u.GetColumns (); From 95c4cc21b30708ea3e54b57a14fcdc4d3b15e070 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 01:38:07 +0000 Subject: [PATCH 015/130] Apply changes for use scroll bar in adornments. --- Terminal.Gui/Views/ScrollBarView.cs | 513 +++++++++++++++------------- 1 file changed, 273 insertions(+), 240 deletions(-) diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index 3310bab449..badedb548d 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -19,7 +19,6 @@ public class ScrollBarView : View { private bool _autoHideScrollBars = true; private View _contentBottomRightCorner; - private bool _hosted; private bool _keepContentAlwaysInViewport = true; private int _lastLocation = -1; private ScrollBarView _otherScrollBarView; @@ -38,74 +37,13 @@ public class ScrollBarView : View /// public ScrollBarView () { + ShowScrollIndicator = true; WantContinuousButtonPressed = true; ClearOnVisibleFalse = false; - - Added += (s, e) => CreateBottomRightCorner (e.Parent); - Initialized += ScrollBarView_Initialized; - } - - /// - /// Initializes a new instance of the class using - /// layout. - /// - /// The view that will host this scrollbar. - /// If set to true this is a vertical scrollbar, otherwise, the scrollbar is horizontal. - /// - /// If set to true (default) will have the other scrollbar, otherwise will - /// have only one. - /// - public ScrollBarView (View host, bool isVertical, bool showBothScrollIndicator = true) - { - if (host is null) - { - throw new ArgumentNullException ("The host parameter can't be null."); - } - - if (host.SuperView is null) - { - throw new ArgumentNullException ("The host SuperView parameter can't be null."); - } - - _hosted = true; - IsVertical = isVertical; - ColorScheme = host.ColorScheme; - X = isVertical ? Pos.Right (host) - 1 : Pos.Left (host); - Y = isVertical ? Pos.Top (host) : Pos.Bottom (host) - 1; - Host = host; CanFocus = false; - Enabled = host.Enabled; - Visible = host.Visible; - Initialized += ScrollBarView_Initialized; - - //Host.CanFocusChanged += Host_CanFocusChanged; - Host.EnabledChanged += Host_EnabledChanged; - Host.VisibleChanged += Host_VisibleChanged; - Host.SuperView.Add (this); - AutoHideScrollBars = true; - - if (showBothScrollIndicator) - { - OtherScrollBarView = new ScrollBarView - { - IsVertical = !isVertical, - ColorScheme = host.ColorScheme, - Host = host, - CanFocus = false, - Enabled = host.Enabled, - Visible = host.Visible, - OtherScrollBarView = this - }; - OtherScrollBarView._hosted = true; - OtherScrollBarView.X = OtherScrollBarView.IsVertical ? Pos.Right (host) - 1 : Pos.Left (host); - OtherScrollBarView.Y = OtherScrollBarView.IsVertical ? Pos.Top (host) : Pos.Bottom (host) - 1; - OtherScrollBarView.Host.SuperView.Add (OtherScrollBarView); - OtherScrollBarView.ShowScrollIndicator = true; - } - ShowScrollIndicator = true; - CreateBottomRightCorner (Host); - ClearOnVisibleFalse = false; + Added += ScrollBarView_Added; + Initialized += ScrollBarView_Initialized; } /// If true the vertical/horizontal scroll bars won't be showed if it's not needed. @@ -122,10 +60,6 @@ public bool AutoHideScrollBars } } - // BUGBUG: v2 - for consistency this should be named "Parent" not "Host" - /// Get or sets the view that host this - public View Host { get; internal set; } - /// If set to true this is a vertical scrollbar, otherwise, the scrollbar is horizontal. public bool IsVertical { @@ -150,32 +84,8 @@ public bool KeepContentAlwaysInViewport if (_keepContentAlwaysInViewport != value) { _keepContentAlwaysInViewport = value; - var pos = 0; - - if (value && !_vertical && _position + Host.Bounds.Width > _size) - { - pos = _size - Host.Bounds.Width + (_showBothScrollIndicator ? 1 : 0); - } - - if (value && _vertical && _position + Host.Bounds.Height > _size) - { - pos = _size - Host.Bounds.Height + (_showBothScrollIndicator ? 1 : 0); - } - - if (pos != 0) - { - Position = pos; - } - - if (OtherScrollBarView is { } && OtherScrollBarView._keepContentAlwaysInViewport != value) - { - OtherScrollBarView.KeepContentAlwaysInViewport = value; - } - if (pos == 0) - { - Refresh (); - } + AdjustContentInViewport (); } } } @@ -194,6 +104,12 @@ public ScrollBarView OtherScrollBarView } _otherScrollBarView = value; + _otherScrollBarView._otherScrollBarView = this; + + if (SuperView != null && _otherScrollBarView?.SuperView is null && !SuperView.Subviews.Contains (_otherScrollBarView)) + { + SuperView.Add (_otherScrollBarView); + } } } @@ -204,17 +120,20 @@ public int Position get => _position; set { - _position = value; - if (IsInitialized) { // We're not initialized so we can't do anything fancy. Just cache value. SetPosition (value); } + else + { + _position = value; + } } } // BUGBUG: v2 - Why can't we get rid of this and just use Visible? + // We need this property to distinguish from Visible which will also affect the parent /// Gets or sets the visibility for the vertical or horizontal scroll indicator. /// true if show vertical or horizontal scroll indicator; otherwise, false. public bool ShowScrollIndicator @@ -222,28 +141,18 @@ public bool ShowScrollIndicator get => _showScrollIndicator; set { - //if (value == showScrollIndicator) { - // return; - //} - _showScrollIndicator = value; - if (IsInitialized) + if (value) { - SetNeedsLayout (); - - if (value) - { - Visible = true; - } - else - { - Visible = false; - Position = 0; - } - - SetWidthHeight (); + Visible = true; + } + else + { + Visible = false; } + + SetNeedsDisplay (); } } @@ -251,7 +160,7 @@ public bool ShowScrollIndicator /// The size. /// /// The is typically the size of the virtual content. E.g. when a Scrollbar is part of a - /// the Size is set to the appropriate dimension of . + /// the Size is set to the appropriate dimension of . /// public int Size { @@ -262,13 +171,13 @@ public int Size if (IsInitialized) { - SetRelativeLayout (SuperView?.Frame ?? Host.Frame); ShowHideScrollBars (false); - SetNeedsDisplay (); } } } + internal bool IsBuiltIn => SuperView is Adornment; + private bool _showBothScrollIndicator => OtherScrollBarView?._showScrollIndicator == true && _showScrollIndicator; /// This event is raised when the position on the scrollbar has changed. @@ -290,14 +199,16 @@ public override bool MouseEvent (MouseEvent mouseEvent) return false; } - if (!Host.CanFocus) + View host = SuperView is Adornment adornment ? adornment.Parent : SuperView; + + if (!host.CanFocus) { return true; } - if (Host?.HasFocus == false) + if (host?.HasFocus == false) { - Host.SetFocus (); + host.SetFocus (); } int location = _vertical ? mouseEvent.Y : mouseEvent.X; @@ -325,19 +236,19 @@ public override bool MouseEvent (MouseEvent mouseEvent) || mouseEvent.Flags == MouseFlags.WheeledRight || mouseEvent.Flags == MouseFlags.WheeledLeft)) { - return Host.MouseEvent (mouseEvent); + return host.MouseEvent (mouseEvent); } - if (mouseEvent.Flags == MouseFlags.Button1Pressed && location == 0) + if (_lastLocation == -1 && mouseEvent.Flags == MouseFlags.Button1Pressed && location == 0) { if (pos > 0) { Position = pos - 1; } } - else if (mouseEvent.Flags == MouseFlags.Button1Pressed && location == barsize + 1) + else if (_lastLocation == -1 && mouseEvent.Flags == MouseFlags.Button1Pressed && location == barsize + 1) { - if (CanScroll (1, out _, _vertical)) + if (CanScroll (pos + 1, out _, _vertical)) { Position = pos + 1; } @@ -372,16 +283,20 @@ public override bool MouseEvent (MouseEvent mouseEvent) if (location > _lastLocation) { - if (location - _posBarOffset < barsize) + if (location == barsize) + { + Position = Size; + } + else if (location - _posBarOffset < barsize) { int np = (location - _posBarOffset) * Size / barsize + Size / barsize; - if (CanScroll (np - pos, out int nv, _vertical)) + if (CanScroll (np, out int nv, _vertical)) { Position = pos + nv; } } - else if (CanScroll (Size - pos, out int nv, _vertical)) + else if (CanScroll (Size, out int nv, _vertical)) { Position = Math.Min (pos + nv, Size); } @@ -392,7 +307,7 @@ public override bool MouseEvent (MouseEvent mouseEvent) { int np = (location - _posBarOffset) * Size / barsize - Size / barsize; - if (CanScroll (np - pos, out int nv, _vertical)) + if (CanScroll (np, out int nv, _vertical)) { Position = pos + nv; } @@ -402,6 +317,10 @@ public override bool MouseEvent (MouseEvent mouseEvent) Position = 0; } } + else if (location == _lastLocation) + { + Position = Size; + } else if (location - _posBarOffset >= barsize && posBottomRightTee - posTopLeftTee >= 3 && CanScroll (Size - pos, out int nv, _vertical)) { Position = Math.Min (pos + nv, Size); @@ -417,14 +336,14 @@ public override bool MouseEvent (MouseEvent mouseEvent) } else if (location > posBottomRightTee) { - if (CanScroll (barsize, out int nv, _vertical)) + if (CanScroll (pos + barsize, out int nv, _vertical)) { Position = pos + nv; } } else if (location < posTopLeftTee) { - if (CanScroll (-barsize, out int nv, _vertical)) + if (CanScroll (pos - barsize, out int nv, _vertical)) { Position = pos + nv; } @@ -435,7 +354,7 @@ public override bool MouseEvent (MouseEvent mouseEvent) } else if (location == barsize) { - if (CanScroll (Size - pos, out int nv, _vertical)) + if (CanScroll (Size, out int nv, _vertical)) { Position = Math.Min (pos + nv, Size); } @@ -466,7 +385,14 @@ public override void OnDrawContent (Rect contentArea) return; } - Driver.SetAttribute (Host.HasFocus ? ColorScheme.Focus : GetNormalColor ()); + if (IsBuiltIn) + { + Driver.SetAttribute (((Adornment)SuperView).Parent.HasFocus ? ColorScheme.Focus : GetNormalColor ()); + } + else + { + Driver.SetAttribute (SuperView.HasFocus ? ColorScheme.Focus : GetNormalColor ()); + } if (_vertical) { @@ -680,28 +606,81 @@ public override bool OnEnter (View view) return base.OnEnter (view); } + /// + public override bool OnMouseEnter (MouseEvent mouseEvent) + { + Application.GrabMouse (this); + + return base.OnMouseEnter (mouseEvent); + } + + /// + public override bool OnMouseLeave (MouseEvent mouseEvent) + { + if (Application.MouseGrabView != null && Application.MouseGrabView != this) + { + Application.UngrabMouse (); + } + + return base.OnMouseLeave (mouseEvent); + } + /// Only used for a hosted view that will update and redraw the scrollbars. public virtual void Refresh () { ShowHideScrollBars (); } - internal bool CanScroll (int n, out int max, bool isVertical = false) + // param n is the new position and the max is the positive/negative value that can be scrolled for the new position + internal bool CanScroll (int n, out int maxToScroll, bool isVertical = false) { - if (Host?.Bounds.IsEmpty != false) + if (SuperView is null || SuperView?.Bounds.IsEmpty == true) { - max = 0; + maxToScroll = 0; return false; } - int s = GetBarsize (isVertical); - int newSize = Math.Max (Math.Min (_size - s, _position + n), 0); - max = _size > s + newSize ? newSize == 0 ? -_position : n : _size - (s + _position) - 1; + int barSize = GetBarSize (isVertical); + int newPosition = Math.Max (Math.Min (_size - barSize, n), 0); + + maxToScroll = _size > barSize + newPosition + ? newPosition - _position + : _size - (barSize + _position) - (barSize == 0 && _showBothScrollIndicator ? 1 : 0); + + return _size >= barSize + newPosition && maxToScroll != 0; + } - if (_size >= s + newSize && max != 0) + private void AdjustContentInViewport (bool refresh = true) + { + if (SuperView is null) { - return true; + return; + } + + var pos = 0; + + if (KeepContentAlwaysInViewport && !_vertical && _position + SuperView.Bounds.Width > _size + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0)) + { + pos = Math.Max (_size - SuperView.Bounds.Width + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0), 0); } - return false; + if (KeepContentAlwaysInViewport && _vertical && _position + SuperView.Bounds.Height > _size + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0)) + { + pos = Math.Max (_size - SuperView.Bounds.Height + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0), 0); + } + + if (pos != 0) + { + Position = pos; + } + + if (OtherScrollBarView is { } && OtherScrollBarView.KeepContentAlwaysInViewport != KeepContentAlwaysInViewport) + { + OtherScrollBarView.KeepContentAlwaysInViewport = KeepContentAlwaysInViewport; + } + + if (pos == 0 && refresh) + { + Refresh (); + } } private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = false) @@ -777,7 +756,14 @@ private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = fa private void ContentBottomRightCorner_DrawContent (object sender, DrawEventArgs e) { - Driver.SetAttribute (Host.HasFocus ? ColorScheme.Focus : GetNormalColor ()); + if (IsBuiltIn) + { + Driver.SetAttribute (((Adornment)SuperView).Parent.HasFocus ? ColorScheme.Focus : GetNormalColor ()); + } + else + { + Driver.SetAttribute (SuperView.HasFocus ? ColorScheme.Focus : GetNormalColor ()); + } // I'm forced to do this here because the Clear method is // changing the color attribute and is different of this one @@ -785,14 +771,6 @@ private void ContentBottomRightCorner_DrawContent (object sender, DrawEventArgs e.Cancel = true; } - //private void Host_CanFocusChanged () - //{ - // CanFocus = Host.CanFocus; - // if (otherScrollBarView is { }) { - // otherScrollBarView.CanFocus = CanFocus; - // } - //} - private void ContentBottomRightCorner_MouseClick (object sender, MouseEventEventArgs me) { if (me.MouseEvent.Flags == MouseFlags.WheeledDown @@ -804,7 +782,14 @@ private void ContentBottomRightCorner_MouseClick (object sender, MouseEventEvent } else if (me.MouseEvent.Flags == MouseFlags.Button1Clicked) { - Host.SetFocus (); + if (IsBuiltIn) + { + ((Adornment)SuperView).Parent.SetFocus (); + } + else + { + SuperView.SetFocus (); + } } me.Handled = true; @@ -812,26 +797,25 @@ private void ContentBottomRightCorner_MouseClick (object sender, MouseEventEvent private void CreateBottomRightCorner (View host) { - if (Host is null) - { - Host = host; - } - - if (Host != null + if (host != null && ((_contentBottomRightCorner is null && OtherScrollBarView is null) || (_contentBottomRightCorner is null && OtherScrollBarView is { } && OtherScrollBarView._contentBottomRightCorner is null))) { - _contentBottomRightCorner = new ContentBottomRightCorner { Visible = Host.Visible }; + if (IsBuiltIn && ((Adornment)host).Parent.ScrollBarType != ScrollBarType.Both) + { + return; + } + + _contentBottomRightCorner = new ContentBottomRightCorner { Visible = host.Visible }; + host.Add (_contentBottomRightCorner); - if (_hosted) + if (IsBuiltIn) { - Host.SuperView.Add (_contentBottomRightCorner); - _contentBottomRightCorner.X = Pos.Right (Host) - 1; - _contentBottomRightCorner.Y = Pos.Bottom (Host) - 1; + _contentBottomRightCorner.X = Pos.AnchorEnd (); + _contentBottomRightCorner.Y = Pos.AnchorEnd (); } else { - Host.Add (_contentBottomRightCorner); _contentBottomRightCorner.X = Pos.AnchorEnd (1); _contentBottomRightCorner.Y = Pos.AnchorEnd (1); } @@ -841,24 +825,71 @@ private void CreateBottomRightCorner (View host) _contentBottomRightCorner.MouseClick += ContentBottomRightCorner_MouseClick; _contentBottomRightCorner.DrawContent += ContentBottomRightCorner_DrawContent; } + else if (host != null + && _contentBottomRightCorner == null + && OtherScrollBarView != null + && OtherScrollBarView._contentBottomRightCorner != null) + + { + _contentBottomRightCorner = OtherScrollBarView._contentBottomRightCorner; + } } - private int GetBarsize (bool isVertical) + private int GetBarSize (bool isVertical) { - if (Host?.Bounds.IsEmpty != false) + if (SuperView is null || SuperView?.Bounds.IsEmpty == true) { return 0; } + if (IsBuiltIn) + { + return isVertical ? KeepContentAlwaysInViewport + ? SuperView.Bounds.Height + : 0 : + KeepContentAlwaysInViewport ? SuperView.Bounds.Width : 0; + } + return isVertical ? KeepContentAlwaysInViewport - ? Host.Bounds.Height + (_showBothScrollIndicator ? -2 : -1) + ? SuperView.Bounds.Height - (_showBothScrollIndicator ? 1 : 0) : 0 : - KeepContentAlwaysInViewport ? Host.Bounds.Width + (_showBothScrollIndicator ? -2 : -1) : 0; + KeepContentAlwaysInViewport ? SuperView.Bounds.Width - (_showBothScrollIndicator ? 1 : 0) : 0; + } + + private void ManageScrollBarThickness () + { + if (!IsBuiltIn) + { + return; + } + + ((Adornment)SuperView).Thickness = ((Adornment)SuperView).Parent.ScrollBarType switch + { + ScrollBarType.None => new Thickness (0), + ScrollBarType.Vertical => new Thickness (0, 0, ShowScrollIndicator ? 1 : 0, 0), + ScrollBarType.Horizontal => new Thickness (0, 0, 0, ShowScrollIndicator ? 1 : 0), + ScrollBarType.Both => new Thickness ( + 0, + 0, + IsVertical + ? ShowScrollIndicator ? 1 : 0 + : OtherScrollBarView?.IsVertical == true + ? OtherScrollBarView?.ShowScrollIndicator == true ? 1 : 0 + : 0, + !IsVertical + ? ShowScrollIndicator ? 1 : 0 + : OtherScrollBarView?.IsVertical == false + ? OtherScrollBarView?.ShowScrollIndicator == true ? 1 : 0 + : 0), + _ => throw new ArgumentOutOfRangeException () + }; } - private void Host_EnabledChanged (object sender, EventArgs e) + private void Parent_DrawAdornments (object sender, DrawEventArgs e) { AdjustContentInViewport (); } + + private void Parent_EnabledChanged (object sender, EventArgs e) { - Enabled = Host.Enabled; + Enabled = SuperView.Enabled; if (_otherScrollBarView is { }) { @@ -868,11 +899,11 @@ private void Host_EnabledChanged (object sender, EventArgs e) _contentBottomRightCorner.Enabled = Enabled; } - private void Host_VisibleChanged (object sender, EventArgs e) + private void Parent_VisibleChanged (object sender, EventArgs e) { - if (!Host.Visible) + if (!SuperView.Visible) { - Visible = Host.Visible; + Visible = SuperView.Visible; if (_otherScrollBarView is { }) { @@ -887,26 +918,50 @@ private void Host_VisibleChanged (object sender, EventArgs e) } } - private void ScrollBarView_Initialized (object sender, EventArgs e) + private void ScrollBarView_Added (object sender, SuperViewChangedEventArgs e) { - SetWidthHeight (); - SetRelativeLayout (SuperView?.Frame ?? Host?.Frame ?? Frame); + if (IsBuiltIn) + { + X = IsVertical ? Pos.AnchorEnd () : 0; + Y = IsVertical ? 0 : Pos.AnchorEnd (); + } + else + { + X = IsVertical ? Pos.AnchorEnd (1) : 0; + Y = IsVertical ? 0 : Pos.AnchorEnd (1); + } - if (OtherScrollBarView is null) + if (OtherScrollBarView is { SuperView: null } && !e.Parent.Subviews.Contains (OtherScrollBarView)) { - // Only do this once if both scrollbars are enabled - ShowHideScrollBars (); + e.Parent.Add (OtherScrollBarView); } + CreateBottomRightCorner (e.Parent); + + View parent = e.Parent is Adornment ? ((Adornment)e.Parent).Parent : e.Parent; + + //e.Parent.CanFocusChanged += Host_CanFocusChanged; + parent.EnabledChanged += Parent_EnabledChanged; + parent.VisibleChanged += Parent_VisibleChanged; + parent.DrawAdornments += Parent_DrawAdornments; + + ManageScrollBarThickness (); + } + + private void ScrollBarView_Initialized (object sender, EventArgs e) + { + SetWidthHeight (); + ShowHideScrollBars (); + SetPosition (Position); } // Helper to assist Initialized event handler private void SetPosition (int newPosition) { - if (CanScroll (newPosition - _position, out int max, _vertical)) + if (CanScroll (newPosition, out int max, _vertical)) { - if (max == newPosition - _position) + if (max == newPosition) { _position = newPosition; } @@ -919,21 +974,26 @@ private void SetPosition (int newPosition) { _position = Math.Max (_position + max, 0); } - else + else if (max > 0) { _position = Math.Max (newPosition, 0); } + else + { + // Doesn't change the position + return; + } OnChangedPosition (); SetNeedsDisplay (); + OtherScrollBarView?.SetNeedsDisplay (); + _contentBottomRightCorner?.SetNeedsDisplay (); + OtherScrollBarView?._contentBottomRightCorner?.SetNeedsDisplay (); } // BUGBUG: v2 - rationalize this with View.SetMinWidthHeight private void SetWidthHeight () { - // BUGBUG: v2 - If Host is also the ScrollBarView's superview, this is all bogus because it's not - // supported that a view can reference it's superview's Dims. This code also assumes the host does - // not have a margin/borderframe/padding. if (!IsInitialized) { return; @@ -941,65 +1001,62 @@ private void SetWidthHeight () if (_showBothScrollIndicator) { - Width = _vertical ? 1 : - Host != SuperView ? Dim.Width (Host) - 1 : Dim.Fill () - 1; - Height = _vertical ? Host != SuperView ? Dim.Height (Host) - 1 : Dim.Fill () - 1 : 1; + Width = _vertical ? 1 : SuperView is Adornment ? Dim.Fill () : Dim.Fill (1); + Height = _vertical ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) : 1; _otherScrollBarView.Width = _otherScrollBarView._vertical ? 1 : - Host != SuperView ? Dim.Width (Host) - 1 : Dim.Fill () - 1; + SuperView is Adornment ? Dim.Fill () : Dim.Fill (1); _otherScrollBarView.Height = _otherScrollBarView._vertical - ? Host != SuperView ? Dim.Height (Host) - 1 : Dim.Fill () - 1 + ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) : 1; } else if (_showScrollIndicator) { - Width = _vertical ? 1 : - Host != SuperView ? Dim.Width (Host) : Dim.Fill (); - Height = _vertical ? Host != SuperView ? Dim.Height (Host) : Dim.Fill () : 1; + Width = _vertical ? 1 : Dim.Fill (); + Height = _vertical ? Dim.Fill () : 1; } else if (_otherScrollBarView?._showScrollIndicator == true) { - _otherScrollBarView.Width = _otherScrollBarView._vertical ? 1 : - Host != SuperView ? Dim.Width (Host) : Dim.Fill () - 0; + _otherScrollBarView.Width = _otherScrollBarView._vertical ? 1 : Dim.Fill (); - _otherScrollBarView.Height = _otherScrollBarView._vertical - ? Host != SuperView ? Dim.Height (Host) : Dim.Fill () - 0 - : 1; + _otherScrollBarView.Height = _otherScrollBarView._vertical ? Dim.Fill () : 1; + } + + if (IsBuiltIn) + { + ManageScrollBarThickness (); + AdjustContentInViewport (false); } } private void ShowHideScrollBars (bool redraw = true) { - if (!_hosted || (_hosted && !_autoHideScrollBars)) + if (!IsInitialized) { - if (_contentBottomRightCorner is { } && _contentBottomRightCorner.Visible) - { - _contentBottomRightCorner.Visible = false; - } - else if (_otherScrollBarView != null - && _otherScrollBarView._contentBottomRightCorner != null - && _otherScrollBarView._contentBottomRightCorner.Visible) - { - _otherScrollBarView._contentBottomRightCorner.Visible = false; - } - return; } - bool pending = CheckBothScrollBars (this); + SetRelativeLayout (SuperView?.Bounds ?? Bounds); - if (_otherScrollBarView is { }) + if (AutoHideScrollBars) { - CheckBothScrollBars (_otherScrollBarView, pending); + bool pending = CheckBothScrollBars (this); + + if (_otherScrollBarView is { }) + { + _otherScrollBarView.SetRelativeLayout (SuperView?.Bounds ?? Bounds); + CheckBothScrollBars (_otherScrollBarView, pending); + } } SetWidthHeight (); - SetRelativeLayout (SuperView?.Frame ?? Host.Frame); + SetRelativeLayout (SuperView?.Bounds ?? Bounds); if (_otherScrollBarView is { }) { - OtherScrollBarView.SetRelativeLayout (SuperView?.Frame ?? Host.Frame); + OtherScrollBarView.SetWidthHeight (); + OtherScrollBarView.SetRelativeLayout (SuperView?.Bounds ?? Bounds); } if (_showBothScrollIndicator) @@ -1038,39 +1095,15 @@ private void ShowHideScrollBars (bool redraw = true) _otherScrollBarView._contentBottomRightCorner.Visible = false; } - if (Host?.Visible == true && _showScrollIndicator && !Visible) + if (SuperView?.Visible == true && _showScrollIndicator && !Visible) { Visible = true; } - if (Host?.Visible == true && _otherScrollBarView?._showScrollIndicator == true && !_otherScrollBarView.Visible) + if (SuperView?.Visible == true && _otherScrollBarView?._showScrollIndicator == true && !_otherScrollBarView.Visible) { _otherScrollBarView.Visible = true; } - - if (!redraw) - { - return; - } - - if (_showScrollIndicator) - { - Draw (); - } - - if (_otherScrollBarView is { } && _otherScrollBarView._showScrollIndicator) - { - _otherScrollBarView.Draw (); - } - - if (_contentBottomRightCorner is { } && _contentBottomRightCorner.Visible) - { - _contentBottomRightCorner.Draw (); - } - else if (_otherScrollBarView is { } && _otherScrollBarView._contentBottomRightCorner is { } && _otherScrollBarView._contentBottomRightCorner.Visible) - { - _otherScrollBarView._contentBottomRightCorner.Draw (); - } } internal class ContentBottomRightCorner : View From d4926ac93a39deec6608cfbf3c3c6befcb4f02ca Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 01:44:07 +0000 Subject: [PATCH 016/130] Make the ScrollView mirror the ScrollBarView properties. --- Terminal.Gui/Views/ScrollView.cs | 134 +++++++++++++------------------ 1 file changed, 58 insertions(+), 76 deletions(-) diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index d1be39a8a0..90d4945bf8 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -30,13 +30,9 @@ public class ScrollView : View private readonly ContentView _contentView; private readonly ScrollBarView _horizontal; private readonly ScrollBarView _vertical; - private bool _autoHideScrollBars = true; private View _contentBottomRightCorner; private Point _contentOffset; private Size _contentSize; - private bool _keepContentAlwaysInViewport = true; - private bool _showHorizontalScrollIndicator; - private bool _showVerticalScrollIndicator; /// /// Initializes a new instance of the class using @@ -45,32 +41,32 @@ public class ScrollView : View public ScrollView () { _contentView = new ContentView (); + base.Add (_contentView); _vertical = new ScrollBarView { X = Pos.AnchorEnd (1), Y = 0, Width = 1, - Height = Dim.Fill (_showHorizontalScrollIndicator ? 1 : 0), Size = 1, - IsVertical = true, - Host = this + IsVertical = true }; _horizontal = new ScrollBarView { X = 0, Y = Pos.AnchorEnd (1), - Width = Dim.Fill (_showVerticalScrollIndicator ? 1 : 0), Height = 1, Size = 1, - IsVertical = false, - Host = this + IsVertical = false }; - _vertical.OtherScrollBarView = _horizontal; _horizontal.OtherScrollBarView = _vertical; - base.Add (_contentView); + + // The _horizontal will be automatically added + // through the OtherScrollBarView property + base.Add (_vertical); + CanFocus = true; MouseEnter += View_MouseEnter; @@ -135,12 +131,13 @@ public ScrollView () /// If true the vertical/horizontal scroll bars won't be showed if it's not needed. public bool AutoHideScrollBars { - get => _autoHideScrollBars; + get => _horizontal?.AutoHideScrollBars ?? _vertical.AutoHideScrollBars; set { - if (_autoHideScrollBars != value) + if (_horizontal.AutoHideScrollBars || _vertical.AutoHideScrollBars != value) { - _autoHideScrollBars = value; + _vertical.AutoHideScrollBars = value; + _horizontal.AutoHideScrollBars = value; if (Subviews.Contains (_vertical)) { @@ -198,43 +195,13 @@ public Size ContentSize /// Get or sets if the view-port is kept always visible in the area of this public bool KeepContentAlwaysInViewport { - get => _keepContentAlwaysInViewport; + get => _horizontal?.KeepContentAlwaysInViewport ?? _vertical.KeepContentAlwaysInViewport; set { - if (_keepContentAlwaysInViewport != value) + if (_horizontal.KeepContentAlwaysInViewport || _vertical.KeepContentAlwaysInViewport != value) { - _keepContentAlwaysInViewport = value; - _vertical.OtherScrollBarView.KeepContentAlwaysInViewport = value; - _horizontal.OtherScrollBarView.KeepContentAlwaysInViewport = value; - Point p = default; - - if (value && -_contentOffset.X + Bounds.Width > _contentSize.Width) - { - p = new Point ( - _contentSize.Width - Bounds.Width + (_showVerticalScrollIndicator ? 1 : 0), - -_contentOffset.Y - ); - } - - if (value && -_contentOffset.Y + Bounds.Height > _contentSize.Height) - { - if (p == default (Point)) - { - p = new Point ( - -_contentOffset.X, - _contentSize.Height - Bounds.Height + (_showHorizontalScrollIndicator ? 1 : 0) - ); - } - else - { - p.Y = _contentSize.Height - Bounds.Height + (_showHorizontalScrollIndicator ? 1 : 0); - } - } - - if (p != default (Point)) - { - ContentOffset = p; - } + _vertical.KeepContentAlwaysInViewport = value; + _horizontal.KeepContentAlwaysInViewport = value; } } } @@ -243,34 +210,37 @@ public bool KeepContentAlwaysInViewport /// true if show horizontal scroll indicator; otherwise, false. public bool ShowHorizontalScrollIndicator { - get => _showHorizontalScrollIndicator; + get => _horizontal.ShowScrollIndicator; set { - if (value != _showHorizontalScrollIndicator) + if (value != _horizontal.ShowScrollIndicator) { - _showHorizontalScrollIndicator = value; + _horizontal.ShowScrollIndicator = value; SetNeedsLayout (); if (value) { _horizontal.OtherScrollBarView = _vertical; - base.Add (_horizontal); - _horizontal.ShowScrollIndicator = value; - _horizontal.AutoHideScrollBars = _autoHideScrollBars; - _horizontal.OtherScrollBarView.ShowScrollIndicator = value; + + if (!Subviews.Contains (_horizontal)) + { + base.Add (_horizontal); + } + + _horizontal.ShowScrollIndicator = true; + _horizontal.AutoHideScrollBars = AutoHideScrollBars; + _horizontal.OtherScrollBarView.ShowScrollIndicator = true; _horizontal.MouseEnter += View_MouseEnter; _horizontal.MouseLeave += View_MouseLeave; } else { base.Remove (_horizontal); - _horizontal.OtherScrollBarView = null; + _horizontal.ShowScrollIndicator = false; _horizontal.MouseEnter -= View_MouseEnter; _horizontal.MouseLeave -= View_MouseLeave; } } - - _vertical.Height = Dim.Fill (_showHorizontalScrollIndicator ? 1 : 0); } } @@ -278,34 +248,37 @@ public bool ShowHorizontalScrollIndicator /// true if show vertical scroll indicator; otherwise, false. public bool ShowVerticalScrollIndicator { - get => _showVerticalScrollIndicator; + get => _vertical.ShowScrollIndicator; set { - if (value != _showVerticalScrollIndicator) + if (value != _vertical.ShowScrollIndicator) { - _showVerticalScrollIndicator = value; + _vertical.ShowScrollIndicator = value; SetNeedsLayout (); if (value) { _vertical.OtherScrollBarView = _horizontal; - base.Add (_vertical); - _vertical.ShowScrollIndicator = value; - _vertical.AutoHideScrollBars = _autoHideScrollBars; - _vertical.OtherScrollBarView.ShowScrollIndicator = value; + + if (!Subviews.Contains (_vertical)) + { + base.Add (_vertical); + } + + _vertical.ShowScrollIndicator = true; + _vertical.AutoHideScrollBars = AutoHideScrollBars; + _vertical.OtherScrollBarView.ShowScrollIndicator = true; _vertical.MouseEnter += View_MouseEnter; _vertical.MouseLeave += View_MouseLeave; } else { Remove (_vertical); - _vertical.OtherScrollBarView = null; + _vertical.ShowScrollIndicator = false; _vertical.MouseEnter -= View_MouseEnter; _vertical.MouseLeave -= View_MouseLeave; } } - - _horizontal.Width = Dim.Fill (_showVerticalScrollIndicator ? 1 : 0); } } @@ -318,6 +291,10 @@ public override void Add (View view) _contentBottomRightCorner = view; base.Add (view); } + else if (view is ScrollBarView) + { + base.Add (view); + } else { if (!IsOverridden (view, "MouseEvent")) @@ -355,7 +332,7 @@ public override bool MouseEvent (MouseEvent me) { ScrollUp (1); } - else if (me.Flags == MouseFlags.WheeledRight && _showHorizontalScrollIndicator) + else if (me.Flags == MouseFlags.WheeledRight && _horizontal.ShowScrollIndicator) { ScrollRight (1); } @@ -476,7 +453,7 @@ public override void Remove (View view) /// Number of lines to scroll. public bool ScrollDown (int lines) { - if (_vertical.CanScroll (lines, out _, true)) + if (_vertical.CanScroll (_vertical.Position + lines, out _, true)) { ContentOffset = new Point (_contentOffset.X, _contentOffset.Y - lines); @@ -506,7 +483,7 @@ public bool ScrollLeft (int cols) /// Number of columns to scroll by. public bool ScrollRight (int cols) { - if (_horizontal.CanScroll (cols, out _)) + if (_horizontal.CanScroll (_horizontal.Position + cols, out _)) { ContentOffset = new Point (_contentOffset.X - cols, _contentOffset.Y); @@ -534,13 +511,13 @@ public bool ScrollUp (int lines) /// protected override void Dispose (bool disposing) { - if (!_showVerticalScrollIndicator) + if (!_vertical.ShowScrollIndicator) { // It was not added to SuperView, so it won't get disposed automatically _vertical?.Dispose (); } - if (!_showHorizontalScrollIndicator) + if (!_horizontal.ShowScrollIndicator) { // It was not added to SuperView, so it won't get disposed automatically _horizontal?.Dispose (); @@ -551,7 +528,7 @@ protected override void Dispose (bool disposing) private void DrawScrollBars () { - if (_autoHideScrollBars) + if (AutoHideScrollBars) { ShowHideScrollBars (); } @@ -577,7 +554,12 @@ private void DrawScrollBars () private void SetContentBottomRightCornerVisibility () { - if (_showHorizontalScrollIndicator && _showVerticalScrollIndicator) + if (_contentBottomRightCorner is null) + { + return; + } + + if (_horizontal.ShowScrollIndicator && _vertical.ShowScrollIndicator) { _contentBottomRightCorner.Visible = true; } From 13ac7163bc988dbe69f925a3ff5312882c89241b Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 01:47:29 +0000 Subject: [PATCH 017/130] Rename private field to _boundsWidth. --- Terminal.Gui/Views/TextView.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index ca9717110b..de26b3c113 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -1469,7 +1469,7 @@ private void ProcessChanges (ref HistoryTextItem historyTextItem) internal class WordWrapManager { - private int _frameWidth; + private int _boundsWidth; private bool _isWrapModelRefreshing; private List _wrappedModelLines = new (); public WordWrapManager (TextModel model) { Model = model; } @@ -1485,7 +1485,7 @@ public void AddLine (int row, int col) line.RemoveRange (modelCol, restCount); Model.AddLine (modelRow + 1, rest); _isWrapModelRefreshing = true; - WrapModel (_frameWidth, out _, out _, out _, out _, modelRow + 1); + WrapModel (_boundsWidth, out _, out _, out _, out _, modelRow + 1); _isWrapModelRefreshing = false; } @@ -1570,7 +1570,7 @@ public bool Insert (int row, int col, RuneCell cell) List line = GetCurrentLine (GetModelLineFromWrappedLines (row)); line.Insert (GetModelColFromWrappedLines (row, col), cell); - if (line.Count > _frameWidth) + if (line.Count > _boundsWidth) { return true; } @@ -1597,7 +1597,7 @@ public bool RemoveAt (int row, int col) line.RemoveAt (modelCol); } - if (line.Count > _frameWidth || (row + 1 < _wrappedModelLines.Count && _wrappedModelLines [row + 1].ModelLine == modelRow)) + if (line.Count > _boundsWidth || (row + 1 < _wrappedModelLines.Count && _wrappedModelLines [row + 1].ModelLine == modelRow)) { return true; } @@ -1649,7 +1649,7 @@ public bool RemoveLine (int row, int col, out bool lineRemoved, bool forward = t line.AddRange (nextLine); Model.RemoveLine (modelRow + 1); - if (line.Count > _frameWidth) + if (line.Count > _boundsWidth) { return true; } @@ -1665,7 +1665,7 @@ public bool RemoveLine (int row, int col, out bool lineRemoved, bool forward = t prevLine.AddRange (line); Model.RemoveLine (modelRow); - if (prevLine.Count > _frameWidth) + if (prevLine.Count > _boundsWidth) { return true; } @@ -1721,7 +1721,7 @@ bool preserveTrailingSpaces Model = model; WrapModel ( - _frameWidth, + _boundsWidth, out nRow, out nCol, out nStartRow, @@ -1750,7 +1750,7 @@ public TextModel WrapModel ( bool preserveTrailingSpaces = true ) { - _frameWidth = width; + _boundsWidth = width; int modelRow = _isWrapModelRefreshing ? row : GetModelLineFromWrappedLines (row); int modelCol = _isWrapModelRefreshing ? col : GetModelColFromWrappedLines (row, col); From da1632aabb1ab1e12a5b93d7dab112fb50416101 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 01:54:27 +0000 Subject: [PATCH 018/130] Add built-in scroll bar in TextView. Add improvement to the word wrap and read only. --- Terminal.Gui/Views/TextView.cs | 183 ++++++++++++++++++++++----------- 1 file changed, 121 insertions(+), 62 deletions(-) diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index de26b3c113..5b4596d86d 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -32,7 +32,7 @@ public class RuneCell : IEquatable /// if the current object is equal to the parameter; otherwise, /// . /// - public bool Equals (RuneCell? other) { return other is { } && Rune.Equals (other.Rune) && ColorScheme == other.ColorScheme; } + public bool Equals (RuneCell? other) { return other is { } && Rune.Equals (other.Rune) && ColorScheme! == other.ColorScheme!; } /// Returns a string that represents the current object. /// A string that represents the current object. @@ -1996,6 +1996,10 @@ public TextView () LayoutComplete += TextView_LayoutComplete; + Padding.ThicknessChanged += Padding_ThicknessChanged; + + DrawAdornments += TextView_DrawAdornments; + // Things this view knows how to do AddCommand ( Command.PageDown, @@ -2693,15 +2697,15 @@ public int LeftColumn return; } - _leftColumn = Math.Max (Math.Min (value, Maxlength - 1), 0); + ScrollLeftOffset = _leftColumn = Math.Max (Math.Min (value, Maxlength - 1), 0); } } /// Gets the number of lines. public int Lines => _model.Count; - /// Gets the maximum visible length line. - public int Maxlength => _model.GetMaxVisibleLine (_topRow, _topRow + Frame.Height, TabWidth); + /// Gets the maximum visible length line including additional last column to accommodate the cursor. + public int Maxlength => _model.GetMaxVisibleLine (_topRow, _topRow + Bounds.Height, TabWidth) + (ReadOnly ? 0 : 1); /// Gets or sets a value indicating whether this is a multiline text view. public bool Multiline @@ -2770,6 +2774,7 @@ public bool ReadOnly _isReadOnly = value; SetNeedsDisplay (); + WrapTextModel (); Adjust (); } } @@ -2794,6 +2799,42 @@ public int RightOffset } } + /// + public override int ScrollLeftOffset + { + get => base.ScrollLeftOffset; + set + { + if (base.ScrollLeftOffset != value) + { + base.ScrollLeftOffset = value; + } + + if (LeftColumn != ScrollLeftOffset) + { + LeftColumn = ScrollLeftOffset; + } + } + } + + /// + public override int ScrollTopOffset + { + get => base.ScrollTopOffset; + set + { + if (base.ScrollTopOffset != value) + { + base.ScrollTopOffset = value; + } + + if (TopRow != ScrollTopOffset) + { + TopRow = ScrollTopOffset; + } + } + } + /// Length of the selected text. public int SelectedLength => GetSelectedLength (); @@ -2885,7 +2926,7 @@ public override string Text if (_wordWrap) { _wrapManager = new WordWrapManager (_model); - _model = _wrapManager.WrapModel (_frameWidth, out _, out _, out _, out _); + _model = _wrapManager.WrapModel (Bounds.Width, out _, out _, out _, out _); } TextChanged?.Invoke (this, EventArgs.Empty); @@ -2899,7 +2940,7 @@ public override string Text public int TopRow { get => _topRow; - set => _topRow = Math.Max (Math.Min (value, Lines - 1), 0); + set => ScrollTopOffset = _topRow = Math.Max (Math.Min (value, Lines - 1), 0); } /// @@ -2930,7 +2971,8 @@ public bool WordWrap if (_wordWrap) { _wrapManager = new WordWrapManager (_model); - _model = _wrapManager.WrapModel (_frameWidth, out _, out _, out _, out _); + + WrapTextModel (); } else if (!_wordWrap && _wrapManager is { }) { @@ -2941,7 +2983,6 @@ public bool WordWrap } } - private int _frameWidth => Math.Max (Frame.Width - (RightOffset != 0 ? 2 : 1), 0); /// Allows clearing the items updating the original text. public void ClearHistoryChanges () { _historyText?.Clear (Text); } @@ -3415,15 +3456,15 @@ public override bool MouseEvent (MouseEvent ev) if (_model.Count > 0 && _shiftSelecting && Selecting) { - if (CurrentRow - _topRow + BottomOffset >= Frame.Height - 1 && _model.Count + BottomOffset > _topRow + CurrentRow) + if (CurrentRow - _topRow + BottomOffset >= Bounds.Height - 1 && _model.Count + BottomOffset > _topRow + CurrentRow) { - ScrollTo (_topRow + Frame.Height); + ScrollTo (_topRow + Bounds.Height); } else if (_topRow > 0 && CurrentRow <= _topRow) { - ScrollTo (_topRow - Frame.Height); + ScrollTo (_topRow - Bounds.Height); } - else if (ev.Y >= Frame.Height) + else if (ev.Y >= Bounds.Height) { ScrollTo (_model.Count + BottomOffset); } @@ -3432,15 +3473,15 @@ public override bool MouseEvent (MouseEvent ev) ScrollTo (0); } - if (CurrentColumn - _leftColumn + RightOffset >= Frame.Width - 1 && line.Count + RightOffset > _leftColumn + CurrentColumn) + if (CurrentColumn - _leftColumn + RightOffset >= Bounds.Width - 1 && line.Count + RightOffset > _leftColumn + CurrentColumn) { - ScrollTo (_leftColumn + Frame.Width, false); + ScrollTo (_leftColumn + Bounds.Width, false); } else if (_leftColumn > 0 && CurrentColumn <= _leftColumn) { - ScrollTo (_leftColumn - Frame.Width, false); + ScrollTo (_leftColumn - Bounds.Width, false); } - else if (ev.X >= Frame.Width) + else if (ev.X >= Bounds.Width) { ScrollTo (line.Count + RightOffset, false); } @@ -3609,8 +3650,8 @@ public override void OnDrawContent (Rect contentArea) SetNormalColor (); (int width, int height) offB = OffSetBackground (); - int right = Frame.Width + offB.width + RightOffset; - int bottom = Frame.Height + offB.height + BottomOffset; + int right = Bounds.Width + offB.width + RightOffset; + int bottom = Bounds.Height + offB.height + BottomOffset; var row = 0; for (int idxRow = _topRow; idxRow < _model.Count; idxRow++) @@ -3860,9 +3901,9 @@ public override void PositionCursor () if (Selecting) { // BUGBUG: customized rect aren't supported now because the Redraw isn't using the Intersect method. - //var minRow = Math.Min (Math.Max (Math.Min (selectionStartRow, currentRow) - topRow, 0), Frame.Height); - //var maxRow = Math.Min (Math.Max (Math.Max (selectionStartRow, currentRow) - topRow, 0), Frame.Height); - //SetNeedsDisplay (new Rect (0, minRow, Frame.Width, maxRow)); + //var minRow = Math.Min (Math.Max (Math.Min (selectionStartRow, currentRow) - topRow, 0), Bounds.Height); + //var maxRow = Math.Min (Math.Max (Math.Max (selectionStartRow, currentRow) - topRow, 0), Bounds.Height); + //SetNeedsDisplay (new Rect (0, minRow, Bounds.Width, maxRow)); SetNeedsDisplay (); } @@ -3885,7 +3926,7 @@ public override void PositionCursor () cols += TabWidth + 1; } - if (!TextModel.SetCol (ref col, Frame.Width, cols)) + if (!TextModel.SetCol (ref col, Bounds.Width, cols)) { col = CurrentColumn; @@ -3897,7 +3938,7 @@ public override void PositionCursor () int posX = CurrentColumn - _leftColumn; int posY = CurrentRow - _topRow; - if (posX > -1 && col >= posX && posX < Frame.Width - RightOffset && _topRow <= CurrentRow && posY < Frame.Height - BottomOffset) + if (posX > -1 && col >= posX && posX < Bounds.Width - RightOffset && _topRow <= CurrentRow && posY < Bounds.Height - BottomOffset) { ResetCursorVisibility (); Move (col, CurrentRow - _topRow); @@ -3965,13 +4006,13 @@ public void ScrollTo (int idx, bool isRow = true) if (isRow) { - _topRow = Math.Max (idx > _model.Count - 1 ? _model.Count - 1 : idx, 0); + ScrollTopOffset = _topRow = Math.Max (idx > _model.Count - 1 ? _model.Count - 1 : idx, 0); } else if (!_wordWrap) { int maxlength = - _model.GetMaxVisibleLine (_topRow, _topRow + Frame.Height + RightOffset, TabWidth); - _leftColumn = Math.Max (!_wordWrap && idx > maxlength - 1 ? maxlength - 1 : idx, 0); + _model.GetMaxVisibleLine (_topRow, _topRow + Bounds.Height + RightOffset, TabWidth); + ScrollLeftOffset = _leftColumn = Math.Max (!_wordWrap && idx > maxlength - 1 ? maxlength - 1 : idx, 0); } SetNeedsDisplay (); @@ -4149,18 +4190,19 @@ private void Adjust () need = true; } else if (!_wordWrap - && (CurrentColumn - _leftColumn + RightOffset > Frame.Width + offB.width || dSize.size + RightOffset >= Frame.Width + offB.width)) + && (CurrentColumn - _leftColumn + 1 + RightOffset > Bounds.Width + offB.width || dSize.size + 1 + RightOffset >= Bounds.Width + offB.width)) { _leftColumn = TextModel.CalculateLeftColumn ( line, _leftColumn, CurrentColumn, - Frame.Width + offB.width - RightOffset, + Bounds.Width + offB.width - RightOffset, TabWidth ); need = true; } - else if ((_wordWrap && _leftColumn > 0) || (dSize.size + RightOffset < Frame.Width + offB.width && tSize.size + RightOffset < Frame.Width + offB.width)) + else if ((_wordWrap && _leftColumn > 0) + || (dSize.size + RightOffset < Bounds.Width + offB.width && tSize.size + RightOffset < Bounds.Width + offB.width)) { if (_leftColumn > 0) { @@ -4174,9 +4216,9 @@ private void Adjust () _topRow = CurrentRow; need = true; } - else if (CurrentRow - _topRow + BottomOffset >= Frame.Height + offB.height) + else if (CurrentRow - _topRow + BottomOffset >= Bounds.Height + offB.height) { - _topRow = Math.Min (Math.Max (CurrentRow - Frame.Height + 1 + BottomOffset, 0), CurrentRow); + _topRow = Math.Min (Math.Max (CurrentRow - Bounds.Height + 1 + BottomOffset, 0), CurrentRow); need = true; } else if (_topRow > 0 && CurrentRow < _topRow) @@ -4317,7 +4359,7 @@ private void ClearRegion () else { // BUGBUG: customized rect aren't supported now because the Redraw isn't using the Intersect method. - //SetNeedsDisplay (new Rect (0, startRow - topRow, Frame.Width, startRow - topRow + 1)); + //SetNeedsDisplay (new Rect (0, startRow - topRow, Bounds.Width, startRow - topRow + 1)); SetNeedsDisplay (); } @@ -4413,7 +4455,7 @@ private bool DeleteTextBackwards () else { // BUGBUG: customized rect aren't supported now because the Redraw isn't using the Intersect method. - //SetNeedsDisplay (new Rect (0, currentRow - topRow, 1, Frame.Width)); + //SetNeedsDisplay (new Rect (0, currentRow - topRow, 1, Bounds.Width)); SetNeedsDisplay (); } } @@ -4505,7 +4547,7 @@ private bool DeleteTextForwards () _wrapNeeded = true; } - DoSetNeedsDisplay (new Rect (0, CurrentRow - _topRow, Frame.Width, CurrentRow - _topRow + 1)); + DoSetNeedsDisplay (new Rect (0, CurrentRow - _topRow, Bounds.Width, CurrentRow - _topRow + 1)); } else { @@ -4528,8 +4570,8 @@ private bool DeleteTextForwards () new Rect ( CurrentColumn - _leftColumn, CurrentRow - _topRow, - Frame.Width, - CurrentRow - _topRow + 1 + Bounds.Width, + Math.Max (CurrentRow - _topRow + 1, 0) ) ); } @@ -4823,7 +4865,7 @@ private void Insert (RuneCell cell) if (!_wrapNeeded) { // BUGBUG: customized rect aren't supported now because the Redraw isn't using the Intersect method. - //SetNeedsDisplay (new Rect (0, prow, Math.Max (Frame.Width, 0), Math.Max (prow + 1, 0))); + //SetNeedsDisplay (new Rect (0, prow, Math.Max (Bounds.Width, 0), Math.Max (prow + 1, 0))); SetNeedsDisplay (); } } @@ -4860,9 +4902,9 @@ private void InsertAllText (string text) HistoryText.LineStatus.Replaced ); - if (!_wordWrap && CurrentColumn - _leftColumn > Frame.Width) + if (!_wordWrap && CurrentColumn - _leftColumn > Bounds.Width) { - _leftColumn = Math.Max (CurrentColumn - Frame.Width + 1, 0); + _leftColumn = Math.Max (CurrentColumn - Bounds.Width + 1, 0); } if (_wordWrap) @@ -4872,7 +4914,7 @@ private void InsertAllText (string text) else { // BUGBUG: customized rect aren't supported now because the Redraw isn't using the Intersect method. - //SetNeedsDisplay (new Rect (0, currentRow - topRow, Frame.Width, Math.Max (currentRow - topRow + 1, 0))); + //SetNeedsDisplay (new Rect (0, currentRow - topRow, Bounds.Width, Math.Max (currentRow - topRow + 1, 0))); SetNeedsDisplay (); } @@ -4968,7 +5010,7 @@ private bool InsertText (Key a, ColorScheme? colorScheme = null) Insert (new RuneCell { Rune = a.AsRune, ColorScheme = colorScheme }); CurrentColumn++; - if (CurrentColumn >= _leftColumn + Frame.Width) + if (CurrentColumn >= _leftColumn + Bounds.Width) { _leftColumn++; SetNeedsDisplay (); @@ -5086,7 +5128,7 @@ private void KillToEndOfLine () UpdateWrapModel (); - DoSetNeedsDisplay (new Rect (0, CurrentRow - _topRow, Frame.Width, Frame.Height)); + DoSetNeedsDisplay (new Rect (0, CurrentRow - _topRow, Bounds.Width, Bounds.Height)); _lastWasKill = setLastWasKill; DoNeededAction (); @@ -5191,7 +5233,7 @@ private void KillToStartOfLine () UpdateWrapModel (); - DoSetNeedsDisplay (new Rect (0, CurrentRow - _topRow, Frame.Width, Frame.Height)); + DoSetNeedsDisplay (new Rect (0, CurrentRow - _topRow, Bounds.Width, Bounds.Height)); _lastWasKill = setLastWasKill; DoNeededAction (); @@ -5261,7 +5303,7 @@ private void KillWordBackward () UpdateWrapModel (); - DoSetNeedsDisplay (new Rect (0, CurrentRow - _topRow, Frame.Width, Frame.Height)); + DoSetNeedsDisplay (new Rect (0, CurrentRow - _topRow, Bounds.Width, Bounds.Height)); DoNeededAction (); } @@ -5320,7 +5362,7 @@ private void KillWordForward () UpdateWrapModel (); - DoSetNeedsDisplay (new Rect (0, CurrentRow - _topRow, Frame.Width, Frame.Height)); + DoSetNeedsDisplay (new Rect (0, CurrentRow - _topRow, Bounds.Width, Bounds.Height)); DoNeededAction (); } @@ -5336,7 +5378,7 @@ private void Model_LinesLoaded (object sender, EventArgs e) if (!_multiline && !IsInitialized) { CurrentColumn = Text.GetRuneCount (); - _leftColumn = CurrentColumn > Frame.Width + 1 ? CurrentColumn - Frame.Width + 1 : 0; + _leftColumn = CurrentColumn > Bounds.Width + 1 ? CurrentColumn - Bounds.Width + 1 : 0; } } @@ -5370,7 +5412,7 @@ private void MoveDown () CurrentRow++; - if (CurrentRow + BottomOffset >= _topRow + Frame.Height) + if (CurrentRow + BottomOffset >= _topRow + Bounds.Height) { _topRow++; SetNeedsDisplay (); @@ -5379,7 +5421,7 @@ private void MoveDown () TrackColumn (); PositionCursor (); } - else if (CurrentRow > Frame.Height) + else if (CurrentRow > Bounds.Height) { Adjust (); } @@ -5390,7 +5432,7 @@ private void MoveDown () private void MoveEndOfLine () { List currentLine = GetCurrentLine (); - CurrentColumn = currentLine.Count; + CurrentColumn = Math.Max (currentLine.Count - (ReadOnly ? 1 : 0), 0); Adjust (); DoNeededAction (); } @@ -5414,7 +5456,7 @@ private void MoveLeft () } List currentLine = GetCurrentLine (); - CurrentColumn = currentLine.Count; + CurrentColumn = Math.Max (currentLine.Count - (ReadOnly ? 1 : 0), 0); } } @@ -5434,7 +5476,7 @@ private bool MoveNextView () private void MovePageDown () { - int nPageDnShift = Frame.Height - 1; + int nPageDnShift = Bounds.Height - 1; if (CurrentRow >= 0 && CurrentRow < _model.Count) { @@ -5464,7 +5506,7 @@ private void MovePageDown () private void MovePageUp () { - int nPageUpShift = Frame.Height - 1; + int nPageUpShift = Bounds.Height - 1; if (CurrentRow > 0) { @@ -5502,7 +5544,7 @@ private void MoveRight () { List currentLine = GetCurrentLine (); - if (CurrentColumn < currentLine.Count) + if ((ReadOnly ? CurrentColumn + 1 : CurrentColumn) < currentLine.Count) { CurrentColumn++; } @@ -5513,7 +5555,7 @@ private void MoveRight () CurrentRow++; CurrentColumn = 0; - if (CurrentRow >= _topRow + Frame.Height) + if (CurrentRow >= _topRow + Bounds.Height) { _topRow++; SetNeedsDisplay (); @@ -5614,19 +5656,25 @@ private void MoveWordForward () var w = 0; var h = 0; - if (SuperView?.Frame.Right - Frame.Right < 0) + if (SuperView?.Bounds.Right - Bounds.Right < 0) { - w = SuperView!.Frame.Right - Frame.Right - 1; + w = SuperView!.Bounds.Right - Bounds.Right - 1; } - if (SuperView?.Frame.Bottom - Frame.Bottom < 0) + if (SuperView?.Bounds.Bottom - Bounds.Bottom < 0) { - h = SuperView!.Frame.Bottom - Frame.Bottom - 1; + h = SuperView!.Bounds.Bottom - Bounds.Bottom - 1; } return (w, h); } + private void Padding_ThicknessChanged (object? sender, ThicknessEventArgs e) + { + WrapTextModel (); + Adjust (); + } + private bool PointInSelection (int col, int row) { long start, end; @@ -5870,7 +5918,7 @@ private void ProcessMouseClick (MouseEvent ev, out List line) if (idx - _leftColumn >= r.Count + RightOffset) { - CurrentColumn = Math.Max (r.Count - _leftColumn + RightOffset, 0); + CurrentColumn = Math.Max (r.Count - _leftColumn + RightOffset - (ReadOnly ? 1 : 0), 0); } else { @@ -6156,7 +6204,7 @@ private bool ProcessReturn () var fullNeedsDisplay = false; - if (CurrentRow >= _topRow + Frame.Height) + if (CurrentRow >= _topRow + Bounds.Height) { _topRow++; fullNeedsDisplay = true; @@ -6183,7 +6231,7 @@ private bool ProcessReturn () else { // BUGBUG: customized rect aren't supported now because the Redraw isn't using the Intersect method. - //SetNeedsDisplay (new Rect (0, currentRow - topRow, 2, Frame.Height)); + //SetNeedsDisplay (new Rect (0, currentRow - topRow, 2, Bounds.Height)); SetNeedsDisplay (); } @@ -6438,6 +6486,17 @@ private string StringFromRunes (List cells) return StringExtensions.ToString (encoded); } + private void TextView_DrawAdornments (object? sender, DrawEventArgs e) + { + if (ScrollBarType != ScrollBarType.None) + { + ScrollColsSize = Maxlength; + ScrollRowsSize = Lines; + ScrollLeftOffset = LeftColumn; + ScrollTopOffset = TopRow; + } + } + private void TextView_Initialized (object sender, EventArgs e) { Autocomplete.HostControl = this; @@ -6536,7 +6595,7 @@ private void WrapTextModel () if (_wordWrap && _wrapManager is { }) { _model = _wrapManager.WrapModel ( - _frameWidth, + Math.Max (Bounds.Width - (ReadOnly ? 0 : 1), 0), // For the cursor on the last column of a line out int nRow, out int nCol, out int nStartRow, From 8390eada5da43aa8d82ee773a53d21a2129dc578 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 01:59:54 +0000 Subject: [PATCH 019/130] Add feature to manage subviews on adornments for mouse handling. --- Terminal.Gui/Application.cs | 157 +++++++++++++++++++++++++----------- 1 file changed, 108 insertions(+), 49 deletions(-) diff --git a/Terminal.Gui/Application.cs b/Terminal.Gui/Application.cs index 46f2bc9ff4..09355c0eea 100644 --- a/Terminal.Gui/Application.cs +++ b/Terminal.Gui/Application.cs @@ -1458,21 +1458,63 @@ public static void OnMouseEvent (MouseEventEventArgs a) { // If the mouse is grabbed, send the event to the view that grabbed it. // The coordinates are relative to the Bounds of the view that grabbed the mouse. - Point newxy = MouseGrabView.ScreenToFrame (a.MouseEvent.X, a.MouseEvent.Y); + Point newxy; + MouseEvent nme; - var nme = new MouseEvent + if (MouseGrabView.SuperView is Adornment) { - X = newxy.X, - Y = newxy.Y, - Flags = a.MouseEvent.Flags, - OfX = a.MouseEvent.X - newxy.X, - OfY = a.MouseEvent.Y - newxy.Y, - View = view - }; + View previousView = view; + int previousScreenX = screenX; + int previousScreenY = screenY; + view = View.FindDeepestView (view?.Padding, screenX, screenY, out screenX, out screenY); + + if (view is { }) + { + nme = new MouseEvent + { + X = screenX, + Y = screenY, + Flags = a.MouseEvent.Flags, + OfX = a.MouseEvent.X - screenX, + OfY = a.MouseEvent.Y - screenY, + View = view + }; + } + else + { + view = previousView; + + nme = new MouseEvent + { + X = previousScreenX, + Y = previousScreenY, + Flags = a.MouseEvent.Flags, + OfX = a.MouseEvent.X - previousScreenX, + OfY = a.MouseEvent.Y - previousScreenY, + View = view + }; + } + + WantContinuousButtonPressedView = view is { WantContinuousButtonPressed: true } ? view : null; + } + else + { + newxy = MouseGrabView.ScreenToFrame (a.MouseEvent.X, a.MouseEvent.Y); + + nme = new MouseEvent + { + X = newxy.X, + Y = newxy.Y, + Flags = a.MouseEvent.Flags, + OfX = a.MouseEvent.X - newxy.X, + OfY = a.MouseEvent.Y - newxy.Y, + View = view + }; + } if (OutsideRect (new Point (nme.X, nme.Y), MouseGrabView.Bounds)) { - // The mouse has moved outside the bounds of the the view that + // The mouse has moved outside the bounds of the view that // grabbed the mouse, so we tell the view that last got // OnMouseEnter the mouse is leaving // BUGBUG: That sentence makes no sense. Either I'm missing something @@ -1480,7 +1522,7 @@ public static void OnMouseEvent (MouseEventEventArgs a) _mouseEnteredView?.OnMouseLeave (a.MouseEvent); } - //System.Diagnostics.Debug.WriteLine ($"{nme.Flags};{nme.X};{nme.Y};{mouseGrabView}"); + //System.Diagnostics.Debug.WriteLine ($"{nme.Flags};{nme.X};{nme.Y};{MouseGrabView}"); if (MouseGrabView?.OnMouseEvent (nme) == true) { return; @@ -1502,11 +1544,11 @@ public static void OnMouseEvent (MouseEventEventArgs a) } } - bool AdornmentHandledMouseEvent (Adornment frame) + bool AdornmentHandledMouseEvent (Adornment adornment) { - if (frame?.Thickness.Contains (frame.FrameToScreen (), a.MouseEvent.X, a.MouseEvent.Y) ?? false) + if (adornment?.Thickness.Contains (adornment.FrameToScreen (), a.MouseEvent.X, a.MouseEvent.Y) ?? false) { - Point boundsPoint = frame.ScreenToBounds (a.MouseEvent.X, a.MouseEvent.Y); + Point boundsPoint = adornment.ScreenToBounds (a.MouseEvent.X, a.MouseEvent.Y); var me = new MouseEvent { @@ -1515,9 +1557,9 @@ bool AdornmentHandledMouseEvent (Adornment frame) Flags = a.MouseEvent.Flags, OfX = boundsPoint.X, OfY = boundsPoint.Y, - View = frame + View = adornment }; - frame.OnMouseEvent (me); + adornment.OnMouseEvent (me); return true; } @@ -1531,6 +1573,13 @@ bool AdornmentHandledMouseEvent (Adornment frame) // TODO: Debate whether inside-out or outside-in is the right strategy if (AdornmentHandledMouseEvent (view?.Padding)) { + view = View.FindDeepestView (view?.Padding, screenX, screenY, out _, out _); + + if (view is { } && AdornmentViewHandledMouseEvent ()) + { + return; + } + return; } @@ -1541,42 +1590,10 @@ bool AdornmentHandledMouseEvent (Adornment frame) // TODO: This is a temporary hack to work around the fact that // drag handling is handled in Toplevel (See Issue #2537) - var me = new MouseEvent - { - X = screenX, - Y = screenY, - Flags = a.MouseEvent.Flags, - OfX = screenX, - OfY = screenY, - View = view - }; - - if (_mouseEnteredView is null) - { - _mouseEnteredView = view; - view.OnMouseEnter (me); - } - else if (_mouseEnteredView != view) - { - _mouseEnteredView.OnMouseLeave (me); - view.OnMouseEnter (me); - _mouseEnteredView = view; - } - - if (!view.WantMousePositionReports && a.MouseEvent.Flags == MouseFlags.ReportMousePosition) + if (AdornmentViewHandledMouseEvent ()) { return; } - - WantContinuousButtonPressedView = view.WantContinuousButtonPressed ? view : null; - - if (view.OnMouseEvent (me)) - { - // Should we bubble up the event, if it is not handled? - //return; - } - - BringOverlappedTopToFront (); } return; @@ -1631,6 +1648,48 @@ bool AdornmentHandledMouseEvent (Adornment frame) BringOverlappedTopToFront (); } } + + bool AdornmentViewHandledMouseEvent () + { + var me = new MouseEvent + { + X = screenX, + Y = screenY, + Flags = a.MouseEvent.Flags, + OfX = screenX, + OfY = screenY, + View = view + }; + + if (_mouseEnteredView is null) + { + _mouseEnteredView = view; + view.OnMouseEnter (me); + } + else if (_mouseEnteredView != view) + { + _mouseEnteredView.OnMouseLeave (me); + view.OnMouseEnter (me); + _mouseEnteredView = view; + } + + if (!view.WantMousePositionReports && a.MouseEvent.Flags == MouseFlags.ReportMousePosition) + { + return true; + } + + WantContinuousButtonPressedView = view.WantContinuousButtonPressed ? view : null; + + if (view.OnMouseEvent (me)) + { + // Should we bubble up the event, if it is not handled? + //return; + } + + BringOverlappedTopToFront (); + + return false; + } } #endregion Mouse handling From f6db34d58180000c5a18849b011e3321b1d6c0b7 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 02:02:35 +0000 Subject: [PATCH 020/130] Fix CharacterMap scenario. --- UICatalog/Scenarios/CharacterMap.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index b0f955e262..16b2610307 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -303,8 +303,7 @@ public CharMap () ContentSize = new Size ( RowWidth, - (MaxCodePoint / 16 + (ShowHorizontalScrollIndicator ? 2 : 1)) * _rowHeight - ); + MaxCodePoint / 16 * _rowHeight + 1 + _rowHeight); AddCommand ( Command.ScrollUp, From 1e2b22591d8270ff1b4d57152034dbc48783428c Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 02:17:03 +0000 Subject: [PATCH 021/130] Fixes scenarios to use the built-in scroll bar. --- UICatalog/Scenarios/CsvEditor.cs | 35 +------- UICatalog/Scenarios/Editor.cs | 86 +------------------- UICatalog/Scenarios/ListColumns.cs | 39 +-------- UICatalog/Scenarios/ListViewWithSelection.cs | 44 +--------- UICatalog/Scenarios/ListsAndCombos.cs | 76 +---------------- UICatalog/Scenarios/ProcessTable.cs | 2 +- UICatalog/Scenarios/TableEditor.cs | 37 +-------- UICatalog/Scenarios/TreeViewFileSystem.cs | 37 +-------- UICatalog/Scenarios/Wizards.cs | 44 +--------- UICatalog/UICatalog.cs | 8 +- 10 files changed, 26 insertions(+), 382 deletions(-) diff --git a/UICatalog/Scenarios/CsvEditor.cs b/UICatalog/Scenarios/CsvEditor.cs index 36a7cf1215..4ea27f2646 100644 --- a/UICatalog/Scenarios/CsvEditor.cs +++ b/UICatalog/Scenarios/CsvEditor.cs @@ -605,40 +605,7 @@ private void SetFormat () private void SetTable (DataTable dataTable) { _tableView.Table = new DataTableSource (_currentTable = dataTable); } - private void SetupScrollBar () - { - var scrollBar = new ScrollBarView (_tableView, true); - - scrollBar.ChangedPosition += (s, e) => - { - _tableView.RowOffset = scrollBar.Position; - - if (_tableView.RowOffset != scrollBar.Position) - { - scrollBar.Position = _tableView.RowOffset; - } - - _tableView.SetNeedsDisplay (); - }; - /* - scrollBar.OtherScrollBarView.ChangedPosition += (s,e) => { - tableView.LeftItem = scrollBar.OtherScrollBarView.Position; - if (tableView.LeftItem != scrollBar.OtherScrollBarView.Position) { - scrollBar.OtherScrollBarView.Position = tableView.LeftItem; - } - tableView.SetNeedsDisplay (); - };*/ - - _tableView.DrawContent += (s, e) => - { - scrollBar.Size = _tableView.Table?.Rows ?? 0; - scrollBar.Position = _tableView.RowOffset; - - //scrollBar.OtherScrollBarView.Size = tableView.Maxlength - 1; - //scrollBar.OtherScrollBarView.Position = tableView.LeftItem; - scrollBar.Refresh (); - }; - } + private void SetupScrollBar () { _tableView.ScrollBarType = ScrollBarType.Both; } private void Sort (bool asc) { diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index 91251a13e4..6b46c70fc2 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -28,7 +28,6 @@ public class Editor : Scenario private MenuItem _miForceMinimumPosToZero; private byte [] _originalText; private bool _saved = true; - private ScrollBarView _scrollBar; private TabView _tabView; private string _textToFind; private string _textToReplace; @@ -59,8 +58,7 @@ public override void Init () Y = 0, Width = Dim.Fill (), Height = Dim.Fill (), - BottomOffset = 1, - RightOffset = 1 + ScrollBarType = ScrollBarType.Both }; CreateDemoFile (_fileName); @@ -270,71 +268,6 @@ public override void Init () Application.Top.Add (statusBar); - _scrollBar = new ScrollBarView (_textView, true); - - _scrollBar.ChangedPosition += (s, e) => - { - _textView.TopRow = _scrollBar.Position; - - if (_textView.TopRow != _scrollBar.Position) - { - _scrollBar.Position = _textView.TopRow; - } - - _textView.SetNeedsDisplay (); - }; - - _scrollBar.OtherScrollBarView.ChangedPosition += (s, e) => - { - _textView.LeftColumn = _scrollBar.OtherScrollBarView.Position; - - if (_textView.LeftColumn != _scrollBar.OtherScrollBarView.Position) - { - _scrollBar.OtherScrollBarView.Position = _textView.LeftColumn; - } - - _textView.SetNeedsDisplay (); - }; - - _scrollBar.VisibleChanged += (s, e) => - { - if (_scrollBar.Visible && _textView.RightOffset == 0) - { - _textView.RightOffset = 1; - } - else if (!_scrollBar.Visible && _textView.RightOffset == 1) - { - _textView.RightOffset = 0; - } - }; - - _scrollBar.OtherScrollBarView.VisibleChanged += (s, e) => - { - if (_scrollBar.OtherScrollBarView.Visible && _textView.BottomOffset == 0) - { - _textView.BottomOffset = 1; - } - else if (!_scrollBar.OtherScrollBarView.Visible && _textView.BottomOffset == 1) - { - _textView.BottomOffset = 0; - } - }; - - _textView.DrawContent += (s, e) => - { - _scrollBar.Size = _textView.Lines; - _scrollBar.Position = _textView.TopRow; - - if (_scrollBar.OtherScrollBarView != null) - { - _scrollBar.OtherScrollBarView.Size = _textView.Maxlength; - _scrollBar.OtherScrollBarView.Position = _textView.LeftColumn; - } - - _scrollBar.LayoutSubviews (); - _scrollBar.Refresh (); - }; - Win.KeyDown += (s, e) => { if (_winDialog != null && (e.KeyCode == KeyCode.Esc || e == Application.QuitKey)) @@ -786,7 +719,7 @@ private MenuItem [] CreateKeepChecked () item.Title = "Keep Content Always In Viewport"; item.CheckType |= MenuItemCheckStyle.Checked; item.Checked = true; - item.Action += () => _scrollBar.KeepContentAlwaysInViewport = (bool)(item.Checked = !item.Checked); + item.Action += () => _textView.ScrollKeepContentAlwaysInViewPort = (bool)(item.Checked = !item.Checked); return new [] { item }; } @@ -826,20 +759,7 @@ private MenuItem CreateWrapChecked () item.CheckType |= MenuItemCheckStyle.Checked; item.Checked = _textView.WordWrap; - item.Action += () => - { - _textView.WordWrap = (bool)(item.Checked = !item.Checked); - - if (_textView.WordWrap) - { - _scrollBar.OtherScrollBarView.ShowScrollIndicator = false; - _textView.BottomOffset = 0; - } - else - { - _textView.BottomOffset = 1; - } - }; + item.Action += () => { _textView.WordWrap = (bool)(item.Checked = !item.Checked); }; return item; } diff --git a/UICatalog/Scenarios/ListColumns.cs b/UICatalog/Scenarios/ListColumns.cs index 060d038c2b..2f8701e3ed 100644 --- a/UICatalog/Scenarios/ListColumns.cs +++ b/UICatalog/Scenarios/ListColumns.cs @@ -65,7 +65,8 @@ public override void Setup () ShowHorizontalHeaderUnderline = false, ShowHorizontalBottomline = false, ExpandLastColumn = false - } + }, + ScrollBarType = ScrollBarType.Both }; var listColStyle = new ListColumnStyle (); @@ -330,41 +331,7 @@ private void SetTable (IList list) } } - private void SetupScrollBar () - { - var scrollBar = new ScrollBarView (_listColView, true); // (listColView, true, true); - - scrollBar.ChangedPosition += (s, e) => - { - _listColView.RowOffset = scrollBar.Position; - - if (_listColView.RowOffset != scrollBar.Position) - { - scrollBar.Position = _listColView.RowOffset; - } - - _listColView.SetNeedsDisplay (); - }; - /* - scrollBar.OtherScrollBarView.ChangedPosition += (s,e) => { - listColView.ColumnOffset = scrollBar.OtherScrollBarView.Position; - if (listColView.ColumnOffset != scrollBar.OtherScrollBarView.Position) { - scrollBar.OtherScrollBarView.Position = listColView.ColumnOffset; - } - listColView.SetNeedsDisplay (); - }; - */ - - _listColView.DrawContent += (s, e) => - { - scrollBar.Size = _listColView.Table?.Rows ?? 0; - scrollBar.Position = _listColView.RowOffset; - - //scrollBar.OtherScrollBarView.Size = listColView.Table?.Columns - 1 ?? 0; - //scrollBar.OtherScrollBarView.Position = listColView.ColumnOffset; - scrollBar.Refresh (); - }; - } + private void SetupScrollBar () { } private void TableViewKeyPress (object sender, Key e) { diff --git a/UICatalog/Scenarios/ListViewWithSelection.cs b/UICatalog/Scenarios/ListViewWithSelection.cs index bd0151ce40..d18a945dea 100644 --- a/UICatalog/Scenarios/ListViewWithSelection.cs +++ b/UICatalog/Scenarios/ListViewWithSelection.cs @@ -47,58 +47,22 @@ public override void Setup () Y = 2, Height = Dim.Fill (), Width = Dim.Fill (1), - - //ColorScheme = Colors.ColorSchemes ["TopLevel"], AllowsMarking = false, - AllowsMultipleSelection = false + AllowsMultipleSelection = false, + ScrollBarType = ScrollBarType.Both }; _listView.RowRender += ListView_RowRender; Win.Add (_listView); - var scrollBar = new ScrollBarView (_listView, true); - - scrollBar.ChangedPosition += (s, e) => - { - _listView.TopItem = scrollBar.Position; - - if (_listView.TopItem != scrollBar.Position) - { - scrollBar.Position = _listView.TopItem; - } - - _listView.SetNeedsDisplay (); - }; - - scrollBar.OtherScrollBarView.ChangedPosition += (s, e) => - { - _listView.LeftItem = scrollBar.OtherScrollBarView.Position; - - if (_listView.LeftItem != scrollBar.OtherScrollBarView.Position) - { - scrollBar.OtherScrollBarView.Position = _listView.LeftItem; - } - - _listView.SetNeedsDisplay (); - }; - - _listView.DrawContent += (s, e) => - { - scrollBar.Size = _listView.Source.Count - 1; - scrollBar.Position = _listView.TopItem; - scrollBar.OtherScrollBarView.Size = _listView.MaxLength - 1; - scrollBar.OtherScrollBarView.Position = _listView.LeftItem; - scrollBar.Refresh (); - }; - _listView.SetSource (_scenarios); var k = "Keep Content Always In Viewport"; var keepCheckBox = new CheckBox { - X = Pos.AnchorEnd (k.Length + 3), Y = 0, Text = k, Checked = scrollBar.AutoHideScrollBars + X = Pos.AnchorEnd (k.Length + 3), Y = 0, Text = k, Checked = _listView.ScrollAutoHideScrollBars }; - keepCheckBox.Toggled += (s, e) => scrollBar.KeepContentAlwaysInViewport = (bool)keepCheckBox.Checked; + keepCheckBox.Toggled += (s, e) => _listView.ScrollKeepContentAlwaysInViewPort = (bool)keepCheckBox.Checked; Win.Add (keepCheckBox); } diff --git a/UICatalog/Scenarios/ListsAndCombos.cs b/UICatalog/Scenarios/ListsAndCombos.cs index 4c84006ef6..c00bdd8cec 100644 --- a/UICatalog/Scenarios/ListsAndCombos.cs +++ b/UICatalog/Scenarios/ListsAndCombos.cs @@ -47,46 +47,12 @@ public override void Setup () Y = Pos.Bottom (lbListView) + 1, Height = Dim.Fill (2), Width = Dim.Percent (40), - Source = new ListWrapper (items) + Source = new ListWrapper (items), + ScrollBarType = ScrollBarType.Both }; listview.SelectedItemChanged += (s, e) => lbListView.Text = items [listview.SelectedItem]; Win.Add (lbListView, listview); - var scrollBar = new ScrollBarView (listview, true); - - scrollBar.ChangedPosition += (s, e) => - { - listview.TopItem = scrollBar.Position; - - if (listview.TopItem != scrollBar.Position) - { - scrollBar.Position = listview.TopItem; - } - - listview.SetNeedsDisplay (); - }; - - scrollBar.OtherScrollBarView.ChangedPosition += (s, e) => - { - listview.LeftItem = scrollBar.OtherScrollBarView.Position; - - if (listview.LeftItem != scrollBar.OtherScrollBarView.Position) - { - scrollBar.OtherScrollBarView.Position = listview.LeftItem; - } - - listview.SetNeedsDisplay (); - }; - - listview.DrawContent += (s, e) => - { - scrollBar.Size = listview.Source.Count - 1; - scrollBar.Position = listview.TopItem; - scrollBar.OtherScrollBarView.Size = listview.MaxLength - 1; - scrollBar.OtherScrollBarView.Position = listview.LeftItem; - scrollBar.Refresh (); - }; - // ComboBox var lbComboBox = new Label { @@ -102,48 +68,14 @@ public override void Setup () X = Pos.Right (listview) + 1, Y = Pos.Bottom (lbListView) + 1, Height = Dim.Fill (2), - Width = Dim.Percent (40) + Width = Dim.Percent (40), + ScrollBarType = ScrollBarType.Both }; comboBox.SetSource (items); comboBox.SelectedItemChanged += (s, text) => lbComboBox.Text = text.Value.ToString (); Win.Add (lbComboBox, comboBox); - var scrollBarCbx = new ScrollBarView (comboBox.Subviews [1], true); - - scrollBarCbx.ChangedPosition += (s, e) => - { - ((ListView)comboBox.Subviews [1]).TopItem = scrollBarCbx.Position; - - if (((ListView)comboBox.Subviews [1]).TopItem != scrollBarCbx.Position) - { - scrollBarCbx.Position = ((ListView)comboBox.Subviews [1]).TopItem; - } - - comboBox.SetNeedsDisplay (); - }; - - scrollBarCbx.OtherScrollBarView.ChangedPosition += (s, e) => - { - ((ListView)comboBox.Subviews [1]).LeftItem = scrollBarCbx.OtherScrollBarView.Position; - - if (((ListView)comboBox.Subviews [1]).LeftItem != scrollBarCbx.OtherScrollBarView.Position) - { - scrollBarCbx.OtherScrollBarView.Position = ((ListView)comboBox.Subviews [1]).LeftItem; - } - - comboBox.SetNeedsDisplay (); - }; - - comboBox.DrawContent += (s, e) => - { - scrollBarCbx.Size = comboBox.Source.Count; - scrollBarCbx.Position = ((ListView)comboBox.Subviews [1]).TopItem; - scrollBarCbx.OtherScrollBarView.Size = ((ListView)comboBox.Subviews [1]).MaxLength - 1; - scrollBarCbx.OtherScrollBarView.Position = ((ListView)comboBox.Subviews [1]).LeftItem; - scrollBarCbx.Refresh (); - }; - var btnMoveUp = new Button { X = 1, Y = Pos.Bottom (lbListView), Text = "Move _Up" }; btnMoveUp.Clicked += (s, e) => { listview.MoveUp (); }; diff --git a/UICatalog/Scenarios/ProcessTable.cs b/UICatalog/Scenarios/ProcessTable.cs index c437f4c8cb..3ec4515c6f 100644 --- a/UICatalog/Scenarios/ProcessTable.cs +++ b/UICatalog/Scenarios/ProcessTable.cs @@ -17,7 +17,7 @@ public override void Setup () Win.Y = 1; // menu Win.Height = Dim.Fill (1); // status bar - tableView = new TableView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill (1) }; + tableView = new TableView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill (), ScrollBarType = ScrollBarType.Both }; // First time CreateProcessTable (); diff --git a/UICatalog/Scenarios/TableEditor.cs b/UICatalog/Scenarios/TableEditor.cs index ee7d63141a..f8620dc8f9 100644 --- a/UICatalog/Scenarios/TableEditor.cs +++ b/UICatalog/Scenarios/TableEditor.cs @@ -433,7 +433,7 @@ public override void Setup () Win.Y = 1; // menu Win.Height = Dim.Fill (1); // status bar - _tableView = new TableView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill (1) }; + _tableView = new TableView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill (1), ScrollBarType = ScrollBarType.Both }; var menu = new MenuBar { @@ -1195,40 +1195,7 @@ private void SetMinWidth () private void SetTable (DataTable dataTable) { _tableView.Table = new DataTableSource (_currentTable = dataTable); } - private void SetupScrollBar () - { - var scrollBar = new ScrollBarView (_tableView, true); - - scrollBar.ChangedPosition += (s, e) => - { - _tableView.RowOffset = scrollBar.Position; - - if (_tableView.RowOffset != scrollBar.Position) - { - scrollBar.Position = _tableView.RowOffset; - } - - _tableView.SetNeedsDisplay (); - }; - /* - scrollBar.OtherScrollBarView.ChangedPosition += (s,e) => { - tableView.LeftItem = scrollBar.OtherScrollBarView.Position; - if (tableView.LeftItem != scrollBar.OtherScrollBarView.Position) { - scrollBar.OtherScrollBarView.Position = tableView.LeftItem; - } - tableView.SetNeedsDisplay (); - };*/ - - _tableView.DrawContent += (s, e) => - { - scrollBar.Size = _tableView.Table?.Rows ?? 0; - scrollBar.Position = _tableView.RowOffset; - - //scrollBar.OtherScrollBarView.Size = tableView.Maxlength - 1; - //scrollBar.OtherScrollBarView.Position = tableView.LeftItem; - scrollBar.Refresh (); - }; - } + private void SetupScrollBar () { } private void ShowAllColumns () { diff --git a/UICatalog/Scenarios/TreeViewFileSystem.cs b/UICatalog/Scenarios/TreeViewFileSystem.cs index 0ec589ea7c..b790ae4e11 100644 --- a/UICatalog/Scenarios/TreeViewFileSystem.cs +++ b/UICatalog/Scenarios/TreeViewFileSystem.cs @@ -174,7 +174,7 @@ public override void Setup () }; Application.Top.Add (menu); - _treeViewFiles = new TreeView { X = 0, Y = 0, Width = Dim.Percent (50), Height = Dim.Fill () }; + _treeViewFiles = new TreeView { X = 0, Y = 0, Width = Dim.Percent (50), Height = Dim.Fill (), ScrollBarType = ScrollBarType.Both }; _treeViewFiles.DrawLine += TreeViewFiles_DrawLine; _detailsFrame = new DetailsFrame (_iconProvider) @@ -358,41 +358,6 @@ private void SetupScrollBar () { // When using scroll bar leave the last row of the control free (for over-rendering with scroll bar) _treeViewFiles.Style.LeaveLastRow = true; - - var scrollBar = new ScrollBarView (_treeViewFiles, true); - - scrollBar.ChangedPosition += (s, e) => - { - _treeViewFiles.ScrollOffsetVertical = scrollBar.Position; - - if (_treeViewFiles.ScrollOffsetVertical != scrollBar.Position) - { - scrollBar.Position = _treeViewFiles.ScrollOffsetVertical; - } - - _treeViewFiles.SetNeedsDisplay (); - }; - - scrollBar.OtherScrollBarView.ChangedPosition += (s, e) => - { - _treeViewFiles.ScrollOffsetHorizontal = scrollBar.OtherScrollBarView.Position; - - if (_treeViewFiles.ScrollOffsetHorizontal != scrollBar.OtherScrollBarView.Position) - { - scrollBar.OtherScrollBarView.Position = _treeViewFiles.ScrollOffsetHorizontal; - } - - _treeViewFiles.SetNeedsDisplay (); - }; - - _treeViewFiles.DrawContent += (s, e) => - { - scrollBar.Size = _treeViewFiles.ContentHeight; - scrollBar.Position = _treeViewFiles.ScrollOffsetVertical; - scrollBar.OtherScrollBarView.Size = _treeViewFiles.GetContentWidth (true); - scrollBar.OtherScrollBarView.Position = _treeViewFiles.ScrollOffsetHorizontal; - scrollBar.Refresh (); - }; } private void ShowColoredExpandableSymbols () diff --git a/UICatalog/Scenarios/Wizards.cs b/UICatalog/Scenarios/Wizards.cs index d7a03a8280..b4f15b936c 100644 --- a/UICatalog/Scenarios/Wizards.cs +++ b/UICatalog/Scenarios/Wizards.cs @@ -259,7 +259,8 @@ void Top_Loaded (object sender, EventArgs args) Height = Dim.Fill (1), WordWrap = true, AllowsTab = false, - ColorScheme = Colors.ColorSchemes ["Base"] + ColorScheme = Colors.ColorSchemes ["Base"], + ScrollBarType = ScrollBarType.Both }; var help = "This is helpful."; fourthStep.Add (someText); @@ -282,47 +283,6 @@ void Top_Loaded (object sender, EventArgs args) }; fourthStep.Add (hideHelpBtn); fourthStep.NextButtonText = "Go To Last Step"; - var scrollBar = new ScrollBarView (someText, true); - - scrollBar.ChangedPosition += (s, e) => - { - someText.TopRow = scrollBar.Position; - - if (someText.TopRow != scrollBar.Position) - { - scrollBar.Position = someText.TopRow; - } - - someText.SetNeedsDisplay (); - }; - - scrollBar.VisibleChanged += (s, e) => - { - if (scrollBar.Visible && someText.RightOffset == 0) - { - someText.RightOffset = 1; - } - else if (!scrollBar.Visible && someText.RightOffset == 1) - { - someText.RightOffset = 0; - } - }; - - someText.DrawContent += (s, e) => - { - scrollBar.Size = someText.Lines; - scrollBar.Position = someText.TopRow; - - if (scrollBar.OtherScrollBarView != null) - { - scrollBar.OtherScrollBarView.Size = someText.Maxlength; - scrollBar.OtherScrollBarView.Position = someText.LeftColumn; - } - - scrollBar.LayoutSubviews (); - scrollBar.Refresh (); - }; - fourthStep.Add (scrollBar); // Add last step var lastStep = new WizardStep { Title = "The last step" }; diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index 3abdcf754d..df99e945c3 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -378,7 +378,7 @@ public class UICatalogTopLevel : Toplevel public MenuItem? miUseSubMenusSingleFrame; public StatusItem OS; - // UI Catalog uses TableView for the scenario list instead of a ListView to demonstate how + // UI Catalog uses TableView for the scenario list instead of a ListView to demonstrate how // TableView works. There's no real reason not to use ListView. Because we use TableView, and TableView // doesn't (currently) have CollectionNavigator support built in, we implement it here, within the app. public TableView ScenarioList; @@ -498,7 +498,8 @@ public UICatalogTopLevel () Title = "Categories", BorderStyle = LineStyle.Single, SuperViewRendersLineCanvas = true, - Source = new ListWrapper (_categories) + Source = new ListWrapper (_categories), + ScrollBarType = ScrollBarType.Both }; CategoryList.OpenSelectedItem += (s, a) => { ScenarioList!.SetFocus (); }; CategoryList.SelectedItemChanged += CategoryView_SelectedChanged; @@ -517,7 +518,8 @@ public UICatalogTopLevel () CanFocus = true, Title = "Scenarios", BorderStyle = LineStyle.Single, - SuperViewRendersLineCanvas = true + SuperViewRendersLineCanvas = true, + ScrollBarType = ScrollBarType.Both }; // TableView provides many options for table headers. For simplicity we turn all From c0d1dad0c9c30da3c739bea6cadb910fecb79c3b Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 02:18:28 +0000 Subject: [PATCH 022/130] Add ScrollBarBuiltIn scenario. Need to be improvement. --- UICatalog/Scenarios/ScrollBarBuiltIn.cs | 48 +++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 UICatalog/Scenarios/ScrollBarBuiltIn.cs diff --git a/UICatalog/Scenarios/ScrollBarBuiltIn.cs b/UICatalog/Scenarios/ScrollBarBuiltIn.cs new file mode 100644 index 0000000000..6c1a16b999 --- /dev/null +++ b/UICatalog/Scenarios/ScrollBarBuiltIn.cs @@ -0,0 +1,48 @@ +using System.Linq; +using Terminal.Gui; + +namespace UICatalog.Scenarios; + +[ScenarioMetadata ("ScrollBar BuiltIn", "Demonstrates the scroll bar built-in the Padding Adornment.")] +[ScenarioCategory ("Controls")] +public class ScrollBarBuiltIn : Scenario +{ + public override void Init () + { + Application.Init (); + Application.Top.ColorScheme = Colors.ColorSchemes ["Base"]; + } + + public override void Setup () + { + var view = new View + { + X = Pos.Center (), Y = Pos.Center (), Width = 15, Height = 8, ScrollBarType = ScrollBarType.Both, + Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", + UseNegativeBoundsLocation = true + }; + + //var view = new View + //{ + // X = 5, Y = 5, Width = 9, Height = 6, ScrollBarType = ScrollBarType.Both, + // Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", UseNegativeBoundsLocation = true + //}; + view.TextFormatter.WordWrap = false; + view.TextFormatter.MultiLine = true; + view.TextFormatter.FillRemaining = true; + view.CanFocus = true; + view.Padding.ColorScheme = Colors.ColorSchemes ["Menu"]; + string [] strings = view.Text.Split ("\n").ToArray (); + view.ScrollColsSize = strings.OrderByDescending (s => s.Length).First ().GetColumns (); + view.ScrollRowsSize = strings.Length; + view.Margin.Thickness = new Thickness (1); + view.Margin.ColorScheme = Colors.ColorSchemes ["Dialog"]; + view.BorderStyle = LineStyle.Single; + var win = new Window (); + win.Add (view); + + var btn = new Button { X = Pos.Center (), Y = Pos.Bottom (view), Text = "Test" }; + win.Add (btn); + Application.Top.Add (win); + } +} From 02825862d41e0185543d54aa2ff6fa6d0d922a53 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 02:34:31 +0000 Subject: [PATCH 023/130] Fixes and added unit tests to handle the built-in scroll bars. --- UnitTests/View/Adornment/AdornmentTests.cs | 321 ++++++++++- UnitTests/Views/AllViewsTests.cs | 9 +- UnitTests/Views/ScrollBarViewTests.cs | 639 ++++++++++++++------- UnitTests/Views/ScrollViewTests.cs | 100 ++-- UnitTests/Views/TextViewTests.cs | 13 +- 5 files changed, 827 insertions(+), 255 deletions(-) diff --git a/UnitTests/View/Adornment/AdornmentTests.cs b/UnitTests/View/Adornment/AdornmentTests.cs index 6efa822eab..5d7232c744 100644 --- a/UnitTests/View/Adornment/AdornmentTests.cs +++ b/UnitTests/View/Adornment/AdornmentTests.cs @@ -7,6 +7,37 @@ public class AdornmentTests private readonly ITestOutputHelper _output; public AdornmentTests (ITestOutputHelper output) { _output = output; } + [Fact] + public void BoundsToScreen_All_Adornments_With_Thickness () + { + var parent = new View { X = 1, Y = 2, Width = 10, Height = 10 }; + parent.Margin.Thickness = new Thickness (1); + parent.Border.Thickness = new Thickness (1); + parent.Padding.Thickness = new Thickness (1); + + parent.BeginInit (); + parent.EndInit (); + + Assert.Equal (new Rect (1, 2, 10, 10), parent.Frame); + Assert.Equal (new Rect (0, 0, 4, 4), parent.Bounds); + Assert.Equal (new Rect (0, 0, 10, 10), parent.Margin.Frame); + Assert.Equal (new Rect (1, 1, 8, 8), parent.Margin.Bounds); + Assert.Equal (new Rect (1, 1, 8, 8), parent.Border.Frame); + Assert.Equal (new Rect (1, 1, 6, 6), parent.Border.Bounds); + Assert.Equal (new Rect (2, 2, 6, 6), parent.Padding.Frame); + Assert.Equal (new Rect (1, 1, 4, 4), parent.Padding.Bounds); + + Assert.Null (parent.Margin.SuperView); + Rect boundsAsScreen = parent.BoundsToScreen (parent.Bounds); + Assert.Equal (new Rect (4, 5, 4, 4), boundsAsScreen); + boundsAsScreen = parent.Margin.BoundsToScreen (parent.Margin.Bounds); + Assert.Equal (new Rect (2, 3, 8, 8), boundsAsScreen); + boundsAsScreen = parent.Border.BoundsToScreen (parent.Border.Bounds); + Assert.Equal (new Rect (2, 3, 6, 6), boundsAsScreen); + boundsAsScreen = parent.Padding.BoundsToScreen (parent.Padding.Bounds); + Assert.Equal (new Rect (2, 3, 4, 4), boundsAsScreen); + } + [Fact] public void BoundsToScreen_Uses_Parent_Not_SuperView () { @@ -19,12 +50,293 @@ public void BoundsToScreen_Uses_Parent_Not_SuperView () Assert.Equal (new Rect (0, 0, 10, 10), parent.Bounds); Assert.Equal (new Rect (0, 0, 10, 10), parent.Margin.Frame); Assert.Equal (new Rect (0, 0, 10, 10), parent.Margin.Bounds); + Assert.Equal (new Rect (0, 0, 10, 10), parent.Border.Frame); + Assert.Equal (new Rect (0, 0, 10, 10), parent.Border.Bounds); + Assert.Equal (new Rect (0, 0, 10, 10), parent.Padding.Frame); + Assert.Equal (new Rect (0, 0, 10, 10), parent.Padding.Bounds); Assert.Null (parent.Margin.SuperView); - Rect boundsAsScreen = parent.Margin.BoundsToScreen (new Rect (1, 2, 5, 5)); + Rect boundsAsScreen = parent.BoundsToScreen (new Rect (1, 2, 5, 5)); + Assert.Equal (new Rect (2, 4, 5, 5), boundsAsScreen); + boundsAsScreen = parent.Margin.BoundsToScreen (new Rect (1, 2, 5, 5)); + Assert.Equal (new Rect (2, 4, 5, 5), boundsAsScreen); + boundsAsScreen = parent.Border.BoundsToScreen (new Rect (1, 2, 5, 5)); + Assert.Equal (new Rect (2, 4, 5, 5), boundsAsScreen); + boundsAsScreen = parent.Padding.BoundsToScreen (new Rect (1, 2, 5, 5)); Assert.Equal (new Rect (2, 4, 5, 5), boundsAsScreen); } + [Fact] + [SetupFakeDriver] + public void Draw_Centered_View_With_Thickness_One_On_All_Adornments () + { + ((FakeDriver)Application.Driver).SetBufferSize (20, 11); + + Attribute [] attrs = + [ + Attribute.Default, + new Attribute (ColorName.White, ColorName.Blue), + new Attribute (ColorName.Black, ColorName.DarkGray), + new Attribute (ColorName.White, ColorName.Red), + new Attribute (ColorName.Black, ColorName.Gray) + ]; + + var top = new View { Width = 20, Height = 11, ColorScheme = new ColorScheme { Normal = attrs [0] } }; + + var parent = new View + { + X = Pos.Center (), Y = Pos.Center (), Width = 10, Height = 9, + ColorScheme = new ColorScheme { Normal = attrs [4] }, + BorderStyle = LineStyle.Single, Text = "Test", + TextAlignment = TextAlignment.Centered, VerticalTextAlignment = VerticalTextAlignment.Middle + }; + + parent.Margin.ColorScheme = new ColorScheme + { Normal = attrs [1] }; + parent.Margin.Thickness = new Thickness (1); + + parent.Border.ColorScheme = new ColorScheme + { Normal = attrs [2] }; + + parent.Padding.ColorScheme = new ColorScheme + { Normal = attrs [3] }; + parent.Padding.Thickness = new Thickness (1); + top.Add (parent); + top.BeginInit (); + top.EndInit (); + + top.Draw (); + Assert.Equal ("(0,0,10,9)", parent.Margin.Frame.ToString ()); + Assert.Equal ("(1,1,8,7)", parent.Border.Frame.ToString ()); + Assert.Equal ("(2,2,6,5)", parent.Padding.Frame.ToString ()); + Assert.Equal ("(5,1,10,9)", parent.Frame.ToString ()); + Assert.Equal ("(1,1,8,7)", parent.Margin.Bounds.ToString ()); + Assert.Equal ("(1,1,6,5)", parent.Border.Bounds.ToString ()); + Assert.Equal ("(1,1,4,3)", parent.Padding.Bounds.ToString ()); + Assert.Equal ("(0,0,4,3)", parent.Bounds.ToString ()); + Assert.Equal ("(1,1,8,7)", parent.Margin.ContentArea.ToString ()); + Assert.Equal ("(1,1,6,5)", parent.Border.ContentArea.ToString ()); + Assert.Equal ("(1,1,4,3)", parent.Padding.ContentArea.ToString ()); + Assert.Equal ("(0,0,4,3)", parent.ContentArea.ToString ()); + + TestHelpers.AssertDriverContentsWithFrameAre ( + @" + ┌──────┐ + │ │ + │ │ + │ Test │ + │ │ + │ │ + └──────┘", + _output); + + TestHelpers.AssertDriverAttributesAre ( + @" +00000000000000000000 +00000111111111100000 +00000122222222100000 +00000123333332100000 +00000123444432100000 +00000123444432100000 +00000123444432100000 +00000123333332100000 +00000122222222100000 +00000111111111100000 +00000000000000000000", + null, + attrs); + } + + [Fact] + [SetupFakeDriver] + public void Draw_Centered_View_With_Thickness_One_On_All_Adornments_Inside_Another_Container () + { + ((FakeDriver)Application.Driver).SetBufferSize (20, 11); + + Attribute [] attrs = + [ + new Attribute (ColorName.White, ColorName.Magenta), + new Attribute (ColorName.White, ColorName.Blue), + new Attribute (ColorName.Black, ColorName.DarkGray), + new Attribute (ColorName.White, ColorName.Red), + new Attribute (ColorName.Black, ColorName.Gray) + ]; + + var superTop = new View { Width = 20, Height = 11 }; + + var parent = new View + { + X = Pos.Center (), Y = Pos.Center (), Width = 10, Height = 9, + ColorScheme = new ColorScheme { Normal = attrs [4] }, + BorderStyle = LineStyle.Single, Text = "Test", + TextAlignment = TextAlignment.Centered, VerticalTextAlignment = VerticalTextAlignment.Middle + }; + + parent.Margin.ColorScheme = new ColorScheme + { Normal = attrs [1] }; + parent.Margin.Thickness = new Thickness (1); + + parent.Border.ColorScheme = new ColorScheme + { Normal = attrs [2] }; + + parent.Padding.ColorScheme = new ColorScheme + { Normal = attrs [3] }; + parent.Padding.Thickness = new Thickness (1); + var top = new View { Width = Dim.Fill (), Height = Dim.Fill (), ColorScheme = new ColorScheme { Normal = attrs [0] }, BorderStyle = LineStyle.Single }; + top.Add (parent); + superTop.Add (top); + superTop.BeginInit (); + superTop.EndInit (); + + superTop.Draw (); + Assert.Equal ("(0,0,20,11)", top.Margin.Frame.ToString ()); + Assert.Equal ("(0,0,20,11)", top.Border.Frame.ToString ()); + Assert.Equal ("(1,1,18,9)", top.Padding.Frame.ToString ()); + Assert.Equal ("(0,0,20,11)", top.Frame.ToString ()); + Assert.Equal ("(0,0,10,9)", parent.Margin.Frame.ToString ()); + Assert.Equal ("(1,1,8,7)", parent.Border.Frame.ToString ()); + Assert.Equal ("(2,2,6,5)", parent.Padding.Frame.ToString ()); + Assert.Equal ("(4,0,10,9)", parent.Frame.ToString ()); + Assert.Equal ("(1,1,8,7)", parent.Margin.Bounds.ToString ()); + Assert.Equal ("(1,1,6,5)", parent.Border.Bounds.ToString ()); + Assert.Equal ("(1,1,4,3)", parent.Padding.Bounds.ToString ()); + Assert.Equal ("(0,0,4,3)", parent.Bounds.ToString ()); + Assert.Equal ("(1,1,8,7)", parent.Margin.ContentArea.ToString ()); + Assert.Equal ("(1,1,6,5)", parent.Border.ContentArea.ToString ()); + Assert.Equal ("(1,1,4,3)", parent.Padding.ContentArea.ToString ()); + Assert.Equal ("(0,0,4,3)", parent.ContentArea.ToString ()); + + TestHelpers.AssertDriverContentsWithFrameAre ( + @" +┌──────────────────┐ +│ │ +│ ┌──────┐ │ +│ │ │ │ +│ │ │ │ +│ │ Test │ │ +│ │ │ │ +│ │ │ │ +│ └──────┘ │ +│ │ +└──────────────────┘", + _output); + + TestHelpers.AssertDriverAttributesAre ( + @" +00000000000000000000 +00000111111111100000 +00000122222222100000 +00000123333332100000 +00000123444432100000 +00000123444432100000 +00000123444432100000 +00000123333332100000 +00000122222222100000 +00000111111111100000 +00000000000000000000", + null, + attrs); + } + + [Fact] + public void FrameToScreen_All_Adornments_With_Thickness () + { + var parent = new View { X = 1, Y = 2, Width = 10, Height = 10 }; + parent.Margin.Thickness = new Thickness (1); + parent.Border.Thickness = new Thickness (1); + parent.Padding.Thickness = new Thickness (1); + + parent.BeginInit (); + parent.EndInit (); + + Assert.Equal (new Rect (1, 2, 10, 10), parent.Frame); + Assert.Equal (new Rect (0, 0, 4, 4), parent.Bounds); + Assert.Equal (new Rect (0, 0, 10, 10), parent.Margin.Frame); + Assert.Equal (new Rect (1, 1, 8, 8), parent.Margin.Bounds); + Assert.Equal (new Rect (1, 1, 8, 8), parent.Border.Frame); + Assert.Equal (new Rect (1, 1, 6, 6), parent.Border.Bounds); + Assert.Equal (new Rect (2, 2, 6, 6), parent.Padding.Frame); + Assert.Equal (new Rect (1, 1, 4, 4), parent.Padding.Bounds); + + Assert.Null (parent.Margin.SuperView); + Assert.Equal (new Rect (1, 2, 10, 10), parent.FrameToScreen ()); + Assert.Equal (new Rect (1, 2, 10, 10), parent.Margin.FrameToScreen ()); + Assert.Equal (new Rect (2, 3, 8, 8), parent.Border.FrameToScreen ()); + Assert.Equal (new Rect (3, 4, 6, 6), parent.Padding.FrameToScreen ()); + } + + [Fact] + public void FrameToScreen_All_Adornments_With_Thickness_With_SuperView () + { + var top = new View { Id = "top", Width = 12, Height = 12 }; + var parent = new View { Id = "parent", X = 1, Y = 2, Width = 10, Height = 10 }; + top.Add (parent); + parent.Margin.Thickness = new Thickness (1); + parent.Border.Thickness = new Thickness (1); + parent.Padding.Thickness = new Thickness (1); + + parent.BeginInit (); + parent.EndInit (); + + Assert.Equal (new Rect (0, 0, 12, 12), top.Frame); + Assert.Equal (new Rect (0, 0, 12, 12), top.Bounds); + Assert.Equal (new Rect (1, 2, 10, 10), parent.Frame); + Assert.Equal (new Rect (0, 0, 4, 4), parent.Bounds); + Assert.Equal (new Rect (0, 0, 10, 10), parent.Margin.Frame); + Assert.Equal (new Rect (1, 1, 8, 8), parent.Margin.Bounds); + Assert.Equal (new Rect (1, 1, 8, 8), parent.Border.Frame); + Assert.Equal (new Rect (1, 1, 6, 6), parent.Border.Bounds); + Assert.Equal (new Rect (2, 2, 6, 6), parent.Padding.Frame); + Assert.Equal (new Rect (1, 1, 4, 4), parent.Padding.Bounds); + + Assert.Null (parent.Margin.SuperView); + Assert.Equal (new Rect (0, 0, 12, 12), top.FrameToScreen ()); + Assert.Equal (new Rect (1, 2, 10, 10), parent.FrameToScreen ()); + Assert.Equal (new Rect (1, 2, 10, 10), parent.Margin.FrameToScreen ()); + Assert.Equal (new Rect (2, 3, 8, 8), parent.Border.FrameToScreen ()); + Assert.Equal (new Rect (3, 4, 6, 6), parent.Padding.FrameToScreen ()); + } + + [Theory] + [InlineData (0, 0, "Margin", false)] + [InlineData (1, 1, "Margin", false)] + [InlineData (1, 2, "Margin", true)] + [InlineData (1, 4, "Margin", true)] + [InlineData (1, 1, "Border", false)] + [InlineData (1, 2, "Border", false)] + [InlineData (2, 2, "Border", false)] + [InlineData (2, 3, "Border", true)] + [InlineData (1, 2, "Padding", false)] + [InlineData (1, 3, "Padding", false)] + [InlineData (2, 3, "Padding", false)] + [InlineData (3, 4, "Padding", true)] + public void FrameToScreen_Find_Adornment_By_Location (int x, int y, string adornment, bool expectedBool) + { + var parent = new View { X = 1, Y = 2, Width = 10, Height = 10 }; + parent.Margin.Thickness = new Thickness (1); + parent.Border.Thickness = new Thickness (1); + parent.Padding.Thickness = new Thickness (1); + + parent.BeginInit (); + parent.EndInit (); + + switch (adornment) + { + case "Margin": + Assert.Equal (parent.Margin?.Thickness.Contains (parent.Margin.FrameToScreen (), x, y) ?? false, expectedBool); + + break; + case "Border": + Assert.Equal (parent.Border?.Thickness.Contains (parent.Border.FrameToScreen (), x, y) ?? false, expectedBool); + + break; + case "Padding": + Assert.Equal (parent.Padding?.Thickness.Contains (parent.Padding.FrameToScreen (), x, y) ?? false, expectedBool); + + break; + } + } + [Fact] public void FrameToScreen_Uses_Parent_Not_SuperView () { @@ -37,9 +349,16 @@ public void FrameToScreen_Uses_Parent_Not_SuperView () Assert.Equal (new Rect (0, 0, 10, 10), parent.Bounds); Assert.Equal (new Rect (0, 0, 10, 10), parent.Margin.Frame); Assert.Equal (new Rect (0, 0, 10, 10), parent.Margin.Bounds); + Assert.Equal (new Rect (0, 0, 10, 10), parent.Border.Frame); + Assert.Equal (new Rect (0, 0, 10, 10), parent.Border.Bounds); + Assert.Equal (new Rect (0, 0, 10, 10), parent.Padding.Frame); + Assert.Equal (new Rect (0, 0, 10, 10), parent.Padding.Bounds); Assert.Null (parent.Margin.SuperView); + Assert.Equal (new Rect (1, 2, 10, 10), parent.FrameToScreen ()); Assert.Equal (new Rect (1, 2, 10, 10), parent.Margin.FrameToScreen ()); + Assert.Equal (new Rect (1, 2, 10, 10), parent.Border.FrameToScreen ()); + Assert.Equal (new Rect (1, 2, 10, 10), parent.Padding.FrameToScreen ()); } [Fact] diff --git a/UnitTests/Views/AllViewsTests.cs b/UnitTests/Views/AllViewsTests.cs index 4fe6133b2b..c7f53e0223 100644 --- a/UnitTests/Views/AllViewsTests.cs +++ b/UnitTests/Views/AllViewsTests.cs @@ -26,6 +26,11 @@ public void AllViews_Center_Properly () continue; } + var frame = new View { X = 0, Y = 0, Width = 50, Height = 50 }; + frame.Add (view); + frame.BeginInit (); + frame.EndInit (); + view.X = Pos.Center (); view.Y = Pos.Center (); @@ -36,10 +41,6 @@ public void AllViews_Center_Properly () view.Width = 10; view.Height = 10; - var frame = new View { X = 0, Y = 0, Width = 50, Height = 50 }; - frame.Add (view); - frame.BeginInit (); - frame.EndInit (); frame.LayoutSubviews (); // What's the natural width/height? diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index 7015911747..3e1bde31c0 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -26,7 +26,7 @@ public void AutoHideScrollBars_Check () Assert.Equal (1, _scrollBar.Bounds.Width); Assert.Equal ( - "Combine(View(Height,HostView()(0,0,80,25))-Absolute(1))", + "Fill(1)", _scrollBar.Height.ToString () ); Assert.Equal (24, _scrollBar.Bounds.Height); @@ -34,7 +34,7 @@ public void AutoHideScrollBars_Check () Assert.True (_scrollBar.OtherScrollBarView.Visible); Assert.Equal ( - "Combine(View(Width,HostView()(0,0,80,25))-Absolute(1))", + "Fill(1)", _scrollBar.OtherScrollBarView.Width.ToString () ); Assert.Equal (79, _scrollBar.OtherScrollBarView.Bounds.Width); @@ -49,7 +49,7 @@ public void AutoHideScrollBars_Check () Assert.Equal (1, _scrollBar.Bounds.Width); Assert.Equal ( - "Combine(View(Height,HostView()(0,0,80,25))-Absolute(1))", + "Fill(1)", _scrollBar.Height.ToString () ); Assert.Equal (24, _scrollBar.Bounds.Height); @@ -57,7 +57,7 @@ public void AutoHideScrollBars_Check () Assert.True (_scrollBar.OtherScrollBarView.Visible); Assert.Equal ( - "View(Width,HostView()(0,0,80,25))", + "Fill(0)", _scrollBar.OtherScrollBarView.Width.ToString () ); Assert.Equal (80, _scrollBar.OtherScrollBarView.Bounds.Width); @@ -72,7 +72,7 @@ public void AutoHideScrollBars_Check () Assert.Equal (1, _scrollBar.Bounds.Width); Assert.Equal ( - "Combine(View(Height,HostView()(0,0,80,25))-Absolute(1))", + "Fill(1)", _scrollBar.Height.ToString () ); Assert.Equal (24, _scrollBar.Bounds.Height); @@ -80,7 +80,7 @@ public void AutoHideScrollBars_Check () Assert.False (_scrollBar.OtherScrollBarView.Visible); Assert.Equal ( - "View(Width,HostView()(0,0,80,25))", + "Fill(0)", _scrollBar.OtherScrollBarView.Width.ToString () ); Assert.Equal (80, _scrollBar.OtherScrollBarView.Bounds.Width); @@ -95,7 +95,7 @@ public void AutoHideScrollBars_Check () Assert.Equal (1, _scrollBar.Bounds.Width); Assert.Equal ( - "View(Height,HostView()(0,0,80,25))", + "Fill(0)", _scrollBar.Height.ToString () ); Assert.Equal (25, _scrollBar.Bounds.Height); @@ -103,7 +103,7 @@ public void AutoHideScrollBars_Check () Assert.False (_scrollBar.OtherScrollBarView.Visible); Assert.Equal ( - "View(Width,HostView()(0,0,80,25))", + "Fill(0)", _scrollBar.OtherScrollBarView.Width.ToString () ); Assert.Equal (80, _scrollBar.OtherScrollBarView.Bounds.Width); @@ -118,7 +118,7 @@ public void AutoHideScrollBars_Check () Assert.Equal (1, _scrollBar.Bounds.Width); Assert.Equal ( - "Combine(View(Height,HostView()(0,0,80,25))-Absolute(1))", + "Fill(1)", _scrollBar.Height.ToString () ); Assert.Equal (24, _scrollBar.Bounds.Height); @@ -126,7 +126,7 @@ public void AutoHideScrollBars_Check () Assert.True (_scrollBar.OtherScrollBarView.Visible); Assert.Equal ( - "Combine(View(Width,HostView()(0,0,80,25))-Absolute(1))", + "Fill(1)", _scrollBar.OtherScrollBarView.Width.ToString () ); Assert.Equal (79, _scrollBar.OtherScrollBarView.Bounds.Width); @@ -149,10 +149,8 @@ public void Both_Default_Draws_Correctly () Id = "horiz", Size = width * 2, - // BUGBUG: ScrollBarView should work if Host is null - Host = super, ShowScrollIndicator = true, - IsVertical = true + IsVertical = false }; super.Add (horiz); @@ -161,10 +159,9 @@ public void Both_Default_Draws_Correctly () Id = "vert", Size = height * 2, - // BUGBUG: ScrollBarView should work if Host is null - Host = super, ShowScrollIndicator = true, - IsVertical = true + IsVertical = true, + OtherScrollBarView = horiz }; super.Add (vert); @@ -289,10 +286,12 @@ public void ClearOnVisibleFalse_Gets_Sets () var label = new Label { Text = text }; Application.Top.Add (label); - var sbv = new ScrollBarView (label, true, false) { Size = 100, ClearOnVisibleFalse = false }; + var sbv = new ScrollBarView { IsVertical = true, Size = 100, ClearOnVisibleFalse = false }; + label.Add (sbv); Application.Begin (Application.Top); Assert.True (sbv.Visible); + Assert.True (sbv.ShowScrollIndicator); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -307,9 +306,25 @@ This is a tes▼ ); sbv.Visible = false; + + // Visible is controlled by the AutoHideScrollBars and if + // ShowScrollIndicator is true the Visible is also set to true Assert.False (sbv.Visible); Application.Top.Draw (); + Assert.True (sbv.Visible); + Assert.True (sbv.ShowScrollIndicator); + + // So it's needs to set ShowScrollIndicator and AutoHideScrollBars to false + // There is no need to set the Visible to set the visibility, use the + // ShowScrollIndicator because the Visible is controlled by automatism + sbv.Visible = false; + sbv.ShowScrollIndicator = false; + sbv.AutoHideScrollBars = false; + Application.Top.Draw (); + Assert.False (sbv.Visible); + Assert.False (sbv.ShowScrollIndicator); + TestHelpers.AssertDriverContentsWithFrameAre ( @" This is a test @@ -359,85 +374,91 @@ This is a tes public void Constructor_ShowBothScrollIndicator_False_And_IsVertical_False_Refresh_Does_Not_Throws_An_Object_Null_Exception () { - // BUGBUG: v2 - Tig broke these tests; @bdisp help? - //var exception = Record.Exception (() => { - Application.Init (new FakeDriver ()); + Exception exception = Record.Exception ( + () => + { + Application.Init (new FakeDriver ()); - Toplevel top = Application.Top; + Toplevel top = Application.Top; - var win = new Window { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () }; + var win = new Window { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () }; - List source = new (); + List source = new (); - for (var i = 0; i < 50; i++) - { - var text = $"item {i} - "; + for (var i = 0; i < 50; i++) + { + var text = $"item {i} - "; - for (var j = 0; j < 160; j++) - { - var col = j.ToString (); - text += col.Length == 1 ? col [0] : col [1]; - } + for (var j = 0; j < 160; j++) + { + var col = j.ToString (); + text += col.Length == 1 ? col [0] : col [1]; + } - source.Add (text); - } + source.Add (text); + } - var listView = new ListView - { - X = 0, - Y = 0, - Width = Dim.Fill (), - Height = Dim.Fill (), - Source = new ListWrapper (source) - }; - win.Add (listView); + var listView = new ListView + { + X = 0, + Y = 0, + Width = Dim.Fill (), + Height = Dim.Fill (), + Source = new ListWrapper (source), + ScrollBarType = ScrollBarType.Horizontal + }; + win.Add (listView); - var newScrollBarView = new ScrollBarView (listView, false, false) { KeepContentAlwaysInViewport = true }; - win.Add (newScrollBarView); + Assert.True (listView.ScrollKeepContentAlwaysInViewPort); - newScrollBarView.ChangedPosition += (s, e) => - { - listView.LeftItem = newScrollBarView.Position; + var newScrollBarView = listView.Padding.Subviews [0] as ScrollBarView; - if (listView.LeftItem != newScrollBarView.Position) - { - newScrollBarView.Position = listView.LeftItem; - } + newScrollBarView!.ChangedPosition += (s, e) => + { + listView.LeftItem = newScrollBarView.Position; - Assert.Equal (newScrollBarView.Position, listView.LeftItem); - listView.SetNeedsDisplay (); - }; + if (listView.LeftItem != newScrollBarView.Position) + { + newScrollBarView.Position = listView.LeftItem; + } - listView.DrawContent += (s, e) => - { - newScrollBarView.Size = listView.MaxLength; - Assert.Equal (newScrollBarView.Size, listView.MaxLength); - newScrollBarView.Position = listView.LeftItem; - Assert.Equal (newScrollBarView.Position, listView.LeftItem); - newScrollBarView.Refresh (); - }; + Assert.Equal (newScrollBarView.Position, listView.LeftItem); + listView.SetNeedsDisplay (); + }; - top.Ready += (s, e) => - { - newScrollBarView.Position = 100; + listView.DrawContent += (s, e) => + { + newScrollBarView.Size = listView.MaxLength; + Assert.Equal (newScrollBarView.Size, listView.MaxLength); + newScrollBarView.Position = listView.LeftItem; + Assert.Equal (newScrollBarView.Position, listView.LeftItem); + newScrollBarView.Refresh (); + }; - //Assert.Equal (newScrollBarView.Position, newScrollBarView.Size - listView.LeftItem + (listView.LeftItem - listView.Bounds.Width)); - Assert.Equal (newScrollBarView.Position, listView.LeftItem); + top.Ready += (s, e) => + { + newScrollBarView.Position = 100; - //Assert.Equal (92, newScrollBarView.Position); - //Assert.Equal (92, listView.LeftItem); - Application.RequestStop (); - }; + Assert.Equal ( + newScrollBarView.Position, + newScrollBarView.Size + - listView.LeftItem + + (listView.LeftItem - listView.Bounds.Width)); + Assert.Equal (newScrollBarView.Position, listView.LeftItem); - top.Add (win); + Assert.Equal (92, newScrollBarView.Position); + Assert.Equal (92, listView.LeftItem); + Application.RequestStop (); + }; - Application.Run (); + top.Add (win); - Application.Shutdown (); + Application.Run (); - //}); + Application.Shutdown (); + }); - //Assert.Null (exception); + Assert.Null (exception); } [Fact] @@ -466,8 +487,8 @@ public void Source = new ListWrapper (source) }; win.Add (listView); - var newScrollBarView = new ScrollBarView (listView, true, false) { KeepContentAlwaysInViewport = true }; - win.Add (newScrollBarView); + var newScrollBarView = new ScrollBarView { IsVertical = true, KeepContentAlwaysInViewport = true }; + listView.Add (newScrollBarView); newScrollBarView.ChangedPosition += (s, e) => { @@ -522,10 +543,10 @@ public void ContentBottomRightCorner_Not_Redraw_If_Both_Size_Equal_To_Zero () var text = "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test"; var label = new Label { Text = text }; + var sbv = new ScrollBarView { X = Pos.AnchorEnd (1), IsVertical = true, Size = 100 }; + sbv.OtherScrollBarView = new ScrollBarView { Y = Pos.AnchorEnd (1), IsVertical = false, Size = 100, OtherScrollBarView = sbv }; + label.Add (sbv, sbv.OtherScrollBarView); Application.Top.Add (label); - - var sbv = new ScrollBarView (label, true) { Size = 100 }; - sbv.OtherScrollBarView.Size = 100; Application.Begin (Application.Top); Assert.Equal (100, sbv.Size); @@ -536,7 +557,7 @@ public void ContentBottomRightCorner_Not_Redraw_If_Both_Size_Equal_To_Zero () Assert.True (sbv.OtherScrollBarView.Visible); View contentBottomRightCorner = - label.SuperView.Subviews.First (v => v is ScrollBarView.ContentBottomRightCorner); + label.Subviews.First (v => v is ScrollBarView.ContentBottomRightCorner); Assert.True (contentBottomRightCorner is ScrollBarView.ContentBottomRightCorner); Assert.True (contentBottomRightCorner.Visible); @@ -604,9 +625,10 @@ public void ContentBottomRightCorner_Not_Redraw_If_One_Size_Equal_To_Zero () var text = "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test"; var label = new Label { Text = text }; - Application.Top.Add (label); - var sbv = new ScrollBarView (label, true, false) { Size = 100 }; + var sbv = new ScrollBarView { X = Pos.AnchorEnd (1), IsVertical = true, Size = 100 }; + label.Add (sbv); + Application.Top.Add (label); Application.Begin (Application.Top); Assert.Equal (100, sbv.Size); @@ -684,43 +706,14 @@ public void Horizontal_Default_Draws_Correctly () _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); } - [Fact] - [ScrollBarAutoInitShutdown] - public void Hosting_A_Null_SuperView_View_To_A_ScrollBarView_Throws_ArgumentNullException () - { - Assert.Throws ( - "The host SuperView parameter can't be null.", - () => new ScrollBarView (new View (), true) - ); - - Assert.Throws ( - "The host SuperView parameter can't be null.", - () => new ScrollBarView (new View (), false) - ); - } - - [Fact] - [ScrollBarAutoInitShutdown] - public void Hosting_A_Null_View_To_A_ScrollBarView_Throws_ArgumentNullException () - { - Assert.Throws ( - "The host parameter can't be null.", - () => new ScrollBarView (null, true) - ); - - Assert.Throws ( - "The host parameter can't be null.", - () => new ScrollBarView (null, false) - ); - } - [Fact] [ScrollBarAutoInitShutdown] public void Hosting_A_View_To_A_ScrollBarView () { RemoveHandlers (); - _scrollBar = new ScrollBarView (_hostView, true); + _scrollBar = new ScrollBarView { IsVertical = true, OtherScrollBarView = new ScrollBarView { IsVertical = false } }; + _hostView.Add (_scrollBar); Application.Begin (Application.Top); @@ -744,92 +737,32 @@ public void Hosting_A_View_To_A_ScrollBarView () [Fact] [AutoInitShutdown] - public void Hosting_ShowBothScrollIndicator_Invisible () + public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () { var textView = new TextView { Width = Dim.Fill (), Height = Dim.Fill (), Text = - "This is the help text for the Second Step.\n\nPress the button to see a message box.\n\nEnter name too." + "This is the help text for the Second Step.\n\nPress the button to see a message box.\n\nEnter name too.", + ScrollBarType = ScrollBarType.Both }; var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () }; win.Add (textView); - var scrollBar = new ScrollBarView (textView, true); - - scrollBar.ChangedPosition += (s, e) => - { - textView.TopRow = scrollBar.Position; - - if (textView.TopRow != scrollBar.Position) - { - scrollBar.Position = textView.TopRow; - } - - textView.SetNeedsDisplay (); - }; - - scrollBar.OtherScrollBarView.ChangedPosition += (s, e) => - { - textView.LeftColumn = scrollBar.OtherScrollBarView.Position; - - if (textView.LeftColumn != scrollBar.OtherScrollBarView.Position) - { - scrollBar.OtherScrollBarView.Position = textView.LeftColumn; - } - - textView.SetNeedsDisplay (); - }; - - scrollBar.VisibleChanged += (s, e) => - { - if (scrollBar.Visible && textView.RightOffset == 0) - { - textView.RightOffset = 1; - } - else if (!scrollBar.Visible && textView.RightOffset == 1) - { - textView.RightOffset = 0; - } - }; - - scrollBar.OtherScrollBarView.VisibleChanged += (s, e) => - { - if (scrollBar.OtherScrollBarView.Visible && textView.BottomOffset == 0) - { - textView.BottomOffset = 1; - } - else if (!scrollBar.OtherScrollBarView.Visible && textView.BottomOffset == 1) - { - textView.BottomOffset = 0; - } - }; - - textView.LayoutComplete += (s, e) => - { - scrollBar.Size = textView.Lines; - scrollBar.Position = textView.TopRow; - - if (scrollBar.OtherScrollBarView != null) - { - scrollBar.OtherScrollBarView.Size = textView.Maxlength; - scrollBar.OtherScrollBarView.Position = textView.LeftColumn; - } - - scrollBar.LayoutSubviews (); - scrollBar.Refresh (); - }; Application.Top.Add (win); Application.Begin (Application.Top); ((FakeDriver)Application.Driver).SetBufferSize (45, 20); + var scrollBar = textView.Padding.Subviews [0] as ScrollBarView; Assert.True (scrollBar.AutoHideScrollBars); Assert.False (scrollBar.ShowScrollIndicator); Assert.False (scrollBar.OtherScrollBarView.ShowScrollIndicator); Assert.Equal (5, textView.Lines); - Assert.Equal (42, textView.Maxlength); + + // The length is one more for the cursor on the last column of the line + Assert.Equal (43, textView.Maxlength); Assert.Equal (0, textView.LeftColumn); Assert.Equal (0, scrollBar.Position); Assert.Equal (0, scrollBar.OtherScrollBarView.Position); @@ -867,7 +800,9 @@ public void Hosting_ShowBothScrollIndicator_Invisible () Assert.True (textView.WordWrap); Assert.True (scrollBar.AutoHideScrollBars); Assert.Equal (7, textView.Lines); - Assert.Equal (22, textView.Maxlength); + + // The length is one more for the cursor on the last column of a line + Assert.Equal (23, textView.Maxlength); Assert.Equal (0, textView.LeftColumn); Assert.Equal (0, scrollBar.Position); Assert.Equal (0, scrollBar.OtherScrollBarView.Position); @@ -898,12 +833,14 @@ public void Hosting_ShowBothScrollIndicator_Invisible () pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rect (0, 0, 26, 20), pos); - ((FakeDriver)Application.Driver).SetBufferSize (10, 10); + ((FakeDriver)Application.Driver).SetBufferSize (10, 11); Application.Refresh (); Assert.True (textView.WordWrap); Assert.True (scrollBar.AutoHideScrollBars); - Assert.Equal (20, textView.Lines); + Assert.Equal (21, textView.Lines); + + // The length is one more for the cursor on the last column of a line Assert.Equal (7, textView.Maxlength); Assert.Equal (0, textView.LeftColumn); Assert.Equal (0, scrollBar.Position); @@ -913,18 +850,50 @@ public void Hosting_ShowBothScrollIndicator_Invisible () expected = @" ┌────────┐ │This ▲│ -│is the ┬│ +│is ┬│ +│the ││ │help ││ │text ┴│ │for ░│ │the ░│ │Second ░│ -│Step. ▼│ +│ Step. ▼│ +└────────┘ +"; + + pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); + Assert.Equal (new Rect (0, 0, 10, 11), pos); + + Assert.False (textView.ReadOnly); + textView.ReadOnly = true; + Application.Refresh (); + Assert.True (textView.WordWrap); + Assert.True (scrollBar.AutoHideScrollBars); + Assert.Equal (20, textView.Lines); + + // The length is one more for the cursor on the last column of a line + Assert.Equal (7, textView.Maxlength); + Assert.Equal (0, textView.LeftColumn); + Assert.Equal (0, scrollBar.Position); + Assert.Equal (0, scrollBar.OtherScrollBarView.Position); + Assert.True (scrollBar.ShowScrollIndicator); + + expected = @" +┌────────┐ +│This ▲│ +│is the ┬│ +│help ││ +│text ││ +│for ┴│ +│the ░│ +│Second ░│ +│Step. ░│ +│ ▼│ └────────┘ "; pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rect (0, 0, 10, 10), pos); + Assert.Equal (new Rect (0, 0, 10, 11), pos); } [Fact] @@ -934,8 +903,8 @@ public void Hosting_Two_Horizontal_ScrollBarView_Throws_ArgumentException () var top = new Toplevel (); var host = new View (); top.Add (host); - var v = new ScrollBarView (host, false); - var h = new ScrollBarView (host, false); + var v = new ScrollBarView { IsVertical = false }; + var h = new ScrollBarView { IsVertical = false }; Assert.Throws (() => v.OtherScrollBarView = h); Assert.Throws (() => h.OtherScrollBarView = v); @@ -948,8 +917,8 @@ public void Hosting_Two_Vertical_ScrollBarView_Throws_ArgumentException () var top = new Toplevel (); var host = new View (); top.Add (host); - var v = new ScrollBarView (host, true); - var h = new ScrollBarView (host, true); + var v = new ScrollBarView { IsVertical = true }; + var h = new ScrollBarView { IsVertical = true }; Assert.Throws (() => v.OtherScrollBarView = h); Assert.Throws (() => h.OtherScrollBarView = v); @@ -962,10 +931,10 @@ public void Internal_Tests () Toplevel top = Application.Top; Assert.Equal (new Rect (0, 0, 80, 25), top.Bounds); var view = new View { Width = Dim.Fill (), Height = Dim.Fill () }; + var sbv = new ScrollBarView { IsVertical = true, OtherScrollBarView = new ScrollBarView { IsVertical = false } }; + view.Add (sbv); top.Add (view); - var sbv = new ScrollBarView (view, true); - top.Add (sbv); - Assert.Equal (view, sbv.Host); + Assert.Equal (view, sbv.SuperView); sbv.Size = 40; sbv.Position = 0; sbv.OtherScrollBarView.Size = 100; @@ -1000,9 +969,9 @@ public void Internal_Tests () sbv.KeepContentAlwaysInViewport = false; sbv.OtherScrollBarView.KeepContentAlwaysInViewport = false; Assert.True (sbv.CanScroll (50, out max, sbv.IsVertical)); - Assert.Equal (39, max); + Assert.Equal (39, max); // Keep 1 row visible Assert.True (sbv.OtherScrollBarView.CanScroll (150, out max, sbv.OtherScrollBarView.IsVertical)); - Assert.Equal (99, max); + Assert.Equal (99, max); // Keep 1 column visible Assert.True (sbv.Visible); Assert.True (sbv.OtherScrollBarView.Visible); } @@ -1086,6 +1055,240 @@ public void OtherScrollBarView_Not_Null () Assert.Equal (_scrollBar.OtherScrollBarView.OtherScrollBarView, _scrollBar); } + [Fact] + public void ScrollBarType_IsBuiltIn_In_Padding () + { + var view = new View { ScrollBarType = ScrollBarType.None }; + Assert.Empty (view.Padding.Subviews); + + view = new View { ScrollBarType = ScrollBarType.Both }; + Assert.Equal (3, view.Padding.Subviews.Count); + + foreach (View sbv in view.Padding.Subviews) + { + if (sbv is not ScrollBarView) + { + Assert.True (sbv is ScrollBarView.ContentBottomRightCorner); + } + else + { + Assert.True (sbv is ScrollBarView); + } + } + + view = new View { ScrollBarType = ScrollBarType.Vertical }; + Assert.Single (view.Padding.Subviews); + Assert.True (view.Padding.Subviews [0] is ScrollBarView); + + view = new View { ScrollBarType = ScrollBarType.Horizontal }; + Assert.Single (view.Padding.Subviews); + Assert.True (view.Padding.Subviews [0] is ScrollBarView); + } + + [Fact] + public void ScrollBarType_IsBuiltIn_In_Padding_Does_Not_Throws_If_ScrollBarType_None () + { + Exception exception = Record.Exception (() => () => new View { ScrollBarType = ScrollBarType.None }); + Assert.Null (exception); + } + + [Fact] + [SetupFakeDriver] + public void ScrollBarType_IsBuiltIn_In_Padding_Thickness () + { + ((FakeDriver)Application.Driver).SetBufferSize (15, 11); + + var top = new View { Width = 15, Height = 11, ColorScheme = new ColorScheme (Attribute.Default) }; + + var view = new View + { + X = Pos.Center (), Y = Pos.Center (), Width = 9, Height = 6, ScrollBarType = ScrollBarType.Both, + Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", CanFocus = true + }; + view.TextFormatter.WordWrap = false; + view.TextFormatter.MultiLine = true; + string [] strings = view.Text.Split ("\n").ToArray (); + view.ScrollColsSize = strings.OrderByDescending (s => s.Length).First ().GetColumns (); + view.ScrollRowsSize = strings.Length; + + view.ColorScheme = new ColorScheme + { + Normal = new Attribute (Color.Green, Color.Red), + Focus = new Attribute (Color.Red, Color.Green) + }; + + view.Padding.ColorScheme = new ColorScheme + { + Normal = new Attribute (Color.Black, Color.Gray), + Focus = new Attribute (Color.White, Color.DarkGray) + }; + var view2 = new View { X = Pos.Center (), Y = Pos.Bottom (view) + 1, Text = "Test", CanFocus = true, AutoSize = true }; + view2.ColorScheme = view.ColorScheme; + top.Add (view, view2); + top.BeginInit (); + top.EndInit (); + top.FocusFirst (); + top.LayoutSubviews (); + top.Draw (); + Assert.True (view.HasFocus); + Assert.False (view2.HasFocus); + Assert.Equal (12, view.ScrollColsSize); + Assert.Equal (7, view.ScrollRowsSize); + Assert.Equal ("(0,0,8,5)", view.Bounds.ToString ()); + Assert.Equal ("(0,0,8,5)", view.ContentArea.ToString ()); + Assert.Equal ("(3,2,9,6)", view.Frame.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Margin.Bounds.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Margin.ContentArea.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Margin.Frame.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Border.Bounds.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Border.ContentArea.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Border.Frame.ToString ()); + Assert.Equal ("(0,0,8,5)", view.Padding.Bounds.ToString ()); + Assert.Equal ("(0,0,8,5)", view.Padding.ContentArea.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Padding.Frame.ToString ()); + Assert.Equal ("(Left=0,Top=0,Right=1,Bottom=1)", view.Padding.Thickness.ToString ()); + Assert.Equal ("{Width=8, Height=5}", view.TextFormatter.Size.ToString ()); + + TestHelpers.AssertDriverContentsWithFrameAre ( + @" + First Li▲ + Second L┬ + Third Li│ + Fourth L┴ + Fifth Li▼ + ◄├───┤░► + + Test ", + _output); + + Attribute [] attrs = + [ + Attribute.Default, + new Attribute (Color.Red, Color.Green), + new Attribute (Color.Green, Color.Red), + new Attribute (Color.White, Color.DarkGray), + new Attribute (Color.Black, Color.Gray) + ]; + + TestHelpers.AssertDriverAttributesAre ( + @" +000000000000000 +000000000000000 +000111111113000 +000111111113000 +000111111113000 +000111111113000 +000111111113000 +000333333333000 +000000000000000 +000002222000000 +000000000000000", + null, + attrs); + } + + [Fact] + [SetupFakeDriver] + public void ScrollBarType_IsBuiltIn_In_Padding_Thickness_Inside_Another_Container () + { + ((FakeDriver)Application.Driver).SetBufferSize (15, 11); + + var superTop = new View { Width = 15, Height = 11, ColorScheme = new ColorScheme (Attribute.Default) }; + + var view = new View + { + X = Pos.Center (), Y = Pos.Center (), Width = 9, Height = 6, ScrollBarType = ScrollBarType.Both, + Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", CanFocus = true + }; + view.TextFormatter.WordWrap = false; + view.TextFormatter.MultiLine = true; + string [] strings = view.Text.Split ("\n").ToArray (); + view.ScrollColsSize = strings.OrderByDescending (s => s.Length).First ().GetColumns (); + view.ScrollRowsSize = strings.Length; + + view.ColorScheme = new ColorScheme + { + Normal = new Attribute (Color.Green, Color.Red), + Focus = new Attribute (Color.Red, Color.Green) + }; + + view.Padding.ColorScheme = new ColorScheme + { + Normal = new Attribute (Color.Black, Color.Gray), + Focus = new Attribute (Color.White, Color.DarkGray) + }; + var view2 = new View { X = Pos.Center (), Y = Pos.Bottom (view) + 1, Text = "Test", CanFocus = true, AutoSize = true }; + view2.ColorScheme = view.ColorScheme; + + var top = new View + { Width = Dim.Fill (), Height = Dim.Fill (), ColorScheme = new ColorScheme { Normal = Attribute.Default }, BorderStyle = LineStyle.Single }; + top.Add (view, view2); + superTop.Add (top); + superTop.BeginInit (); + superTop.EndInit (); + superTop.FocusFirst (); + superTop.LayoutSubviews (); + superTop.Draw (); + Assert.True (view.HasFocus); + Assert.False (view2.HasFocus); + Assert.Equal (12, view.ScrollColsSize); + Assert.Equal (7, view.ScrollRowsSize); + Assert.Equal ("(0,0,8,5)", view.Bounds.ToString ()); + Assert.Equal ("(0,0,8,5)", view.ContentArea.ToString ()); + Assert.Equal ("(2,1,9,6)", view.Frame.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Margin.Bounds.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Margin.ContentArea.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Margin.Frame.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Border.Bounds.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Border.ContentArea.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Border.Frame.ToString ()); + Assert.Equal ("(0,0,8,5)", view.Padding.Bounds.ToString ()); + Assert.Equal ("(0,0,8,5)", view.Padding.ContentArea.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Padding.Frame.ToString ()); + Assert.Equal ("(Left=0,Top=0,Right=1,Bottom=1)", view.Padding.Thickness.ToString ()); + Assert.Equal ("{Width=8, Height=5}", view.TextFormatter.Size.ToString ()); + + TestHelpers.AssertDriverContentsWithFrameAre ( + @" +┌─────────────┐ +│ │ +│ First Li▲ │ +│ Second L┬ │ +│ Third Li│ │ +│ Fourth L┴ │ +│ Fifth Li▼ │ +│ ◄├───┤░► │ +│ │ +│ Test │ +└─────────────┘", + _output); + + Attribute [] attrs = + [ + Attribute.Default, + new Attribute (Color.Red, Color.Green), + new Attribute (Color.Green, Color.Red), + new Attribute (Color.White, Color.DarkGray), + new Attribute (Color.Black, Color.Gray) + ]; + + TestHelpers.AssertDriverAttributesAre ( + @" +000000000000000 +000000000000000 +000111111113000 +000111111113000 +000111111113000 +000111111113000 +000111111113000 +000333333333000 +000000000000000 +000002222000000 +000000000000000", + null, + attrs); + } + [Fact] [ScrollBarAutoInitShutdown] public void Scrolling_With_Default_Constructor_Do_Not_Scroll () @@ -1116,9 +1319,10 @@ public void ShowScrollIndicator_False_Must_Also_Set_Visible_To_False_To_Not_Resp var label = new Label { AutoSize = false, Width = 14, Height = 5, Text = text }; var btn = new Button { X = 14, Text = "Click Me!" }; btn.Clicked += (s, e) => clicked = true; - Application.Top.Add (label, btn); - var sbv = new ScrollBarView (label, true, false) { Size = 5 }; + var sbv = new ScrollBarView { IsVertical = true, Size = 5 }; + label.Add (sbv); + Application.Top.Add (label, btn); Application.Begin (Application.Top); Assert.Equal (5, sbv.Size); @@ -1156,6 +1360,8 @@ This is a test Assert.False (sbv.ShowScrollIndicator); Assert.True (sbv.Visible); Application.Top.Draw (); + + // Set the visibility to true doesn't ensure the scroll bar from showing Assert.False (sbv.Visible); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -1183,6 +1389,39 @@ This is a test Assert.Equal (5, sbv.Size); Assert.False (sbv.ShowScrollIndicator); Assert.False (sbv.Visible); + + // It's needed to set ShowScrollIndicator to true and AutoHideScrollBars to false forcing + // showing the scroll bar, otherwise AutoHideScrollBars will automatically control it + Assert.True (sbv.AutoHideScrollBars); + sbv.ShowScrollIndicator = true; + sbv.AutoHideScrollBars = false; + Application.Top.Draw (); + + TestHelpers.AssertDriverContentsWithFrameAre ( + @$" +This is a tes▲{ + CM.Glyphs.LeftBracket +} Click Me! { + CM.Glyphs.RightBracket +} +This is a tes┬ +This is a tes│ +This is a tes┴ +This is a tes▼ ", + _output + ); + + Application.OnMouseEvent ( + new MouseEventEventArgs ( + new MouseEvent { X = 15, Y = 0, Flags = MouseFlags.Button1Clicked } + ) + ); + + Assert.Null (Application.MouseGrabView); + Assert.True (clicked); + Assert.Equal (5, sbv.Size); + Assert.True (sbv.ShowScrollIndicator); + Assert.True (sbv.Visible); } [Fact] @@ -1200,8 +1439,6 @@ public void Vertical_Default_Draws_Correctly () Id = "sbv", Size = height * 2, - // BUGBUG: ScrollBarView should work if Host is null - Host = super, ShowScrollIndicator = true, IsVertical = true }; diff --git a/UnitTests/Views/ScrollViewTests.cs b/UnitTests/Views/ScrollViewTests.cs index 4b4dd60ffe..86c3bfa829 100644 --- a/UnitTests/Views/ScrollViewTests.cs +++ b/UnitTests/Views/ScrollViewTests.cs @@ -925,6 +925,8 @@ public void KeyBindings_Command () Assert.True (sv.KeepContentAlwaysInViewport); Assert.True (sv.AutoHideScrollBars); + Assert.True (sv.ShowVerticalScrollIndicator); + Assert.True (sv.ShowHorizontalScrollIndicator); Assert.Equal (new Point (0, 0), sv.ContentOffset); Assert.False (sv.OnKeyDown (new Key (KeyCode.CursorUp))); Assert.Equal (new Point (0, 0), sv.ContentOffset); @@ -936,10 +938,18 @@ public void KeyBindings_Command () Assert.Equal (new Point (0, 0), sv.ContentOffset); Assert.True (sv.OnKeyDown (new Key (KeyCode.PageDown))); Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.PageDown))); - Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new Key (KeyCode.PageDown))); + + // The other scroll bar is visible, so it need to scroll one more row + Assert.Equal (new Point (0, -11), sv.ContentOffset); Assert.False (sv.OnKeyDown (new Key (KeyCode.CursorDown))); - Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.Equal (new Point (0, -11), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new Key ((KeyCode)'v' | KeyCode.AltMask))); + + // Scrolled 10 rows and still is hiding one row + Assert.Equal (new Point (0, -1), sv.ContentOffset); + + // Pressing the same key again will set to 0 Assert.True (sv.OnKeyDown (new Key ((KeyCode)'v' | KeyCode.AltMask))); Assert.Equal (new Point (0, 0), sv.ContentOffset); Assert.True (sv.OnKeyDown (new Key (KeyCode.V | KeyCode.CtrlMask))); @@ -954,32 +964,38 @@ public void KeyBindings_Command () Assert.Equal (new Point (0, -10), sv.ContentOffset); Assert.True (sv.OnKeyDown (new Key (KeyCode.PageDown | KeyCode.CtrlMask))); Assert.Equal (new Point (-20, -10), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.CursorRight))); - Assert.Equal (new Point (-20, -10), sv.ContentOffset); + Assert.True (sv.OnKeyDown (new Key (KeyCode.CursorRight))); + + // The other scroll bar is visible, so it need to scroll one more column + Assert.Equal (new Point (-21, -10), sv.ContentOffset); Assert.True (sv.OnKeyDown (new Key (KeyCode.Home))); - Assert.Equal (new Point (-20, 0), sv.ContentOffset); + + // The other scroll bar is visible, so it need to scroll one more column + Assert.Equal (new Point (-21, 0), sv.ContentOffset); Assert.False (sv.OnKeyDown (new Key (KeyCode.Home))); - Assert.Equal (new Point (-20, 0), sv.ContentOffset); + Assert.Equal (new Point (-21, 0), sv.ContentOffset); Assert.True (sv.OnKeyDown (new Key (KeyCode.End))); - Assert.Equal (new Point (-20, -10), sv.ContentOffset); + Assert.Equal (new Point (-21, -11), sv.ContentOffset); Assert.False (sv.OnKeyDown (new Key (KeyCode.End))); - Assert.Equal (new Point (-20, -10), sv.ContentOffset); + Assert.Equal (new Point (-21, -11), sv.ContentOffset); Assert.True (sv.OnKeyDown (new Key (KeyCode.Home | KeyCode.CtrlMask))); - Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.Equal (new Point (0, -11), sv.ContentOffset); Assert.False (sv.OnKeyDown (new Key (KeyCode.Home | KeyCode.CtrlMask))); - Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.Equal (new Point (0, -11), sv.ContentOffset); Assert.True (sv.OnKeyDown (new Key (KeyCode.End | KeyCode.CtrlMask))); - Assert.Equal (new Point (-20, -10), sv.ContentOffset); + Assert.Equal (new Point (-21, -11), sv.ContentOffset); Assert.False (sv.OnKeyDown (new Key (KeyCode.End | KeyCode.CtrlMask))); - Assert.Equal (new Point (-20, -10), sv.ContentOffset); + Assert.Equal (new Point (-21, -11), sv.ContentOffset); Assert.True (sv.OnKeyDown (new Key (KeyCode.Home))); - Assert.Equal (new Point (-20, 0), sv.ContentOffset); + Assert.Equal (new Point (-21, 0), sv.ContentOffset); Assert.True (sv.OnKeyDown (new Key (KeyCode.Home | KeyCode.CtrlMask))); Assert.Equal (new Point (0, 0), sv.ContentOffset); sv.KeepContentAlwaysInViewport = false; Assert.False (sv.KeepContentAlwaysInViewport); Assert.True (sv.AutoHideScrollBars); + Assert.True (sv.ShowVerticalScrollIndicator); + Assert.True (sv.ShowHorizontalScrollIndicator); Assert.Equal (new Point (0, 0), sv.ContentOffset); Assert.False (sv.OnKeyDown (new Key (KeyCode.CursorUp))); Assert.Equal (new Point (0, 0), sv.ContentOffset); @@ -1062,8 +1078,8 @@ public void Remove_Added_View_Is_Allowed () private class CustomButton : FrameView { - private readonly Label labelFill; - private readonly Label labelText; + private readonly Label _labelFill; + private readonly Label _labelText; public CustomButton (string fill, string text, int width, int height) { @@ -1071,30 +1087,30 @@ public CustomButton (string fill, string text, int width, int height) Height = height; //labelFill = new Label { AutoSize = false, X = Pos.Center (), Y = Pos.Center (), Width = Dim.Fill (), Height = Dim.Fill (), Visible = false }; - labelFill = new Label { AutoSize = false, Width = Dim.Fill (), Height = Dim.Fill (), Visible = false }; - - labelFill.LayoutComplete += (s, e) => - { - var fillText = new StringBuilder (); - - for (var i = 0; i < labelFill.Bounds.Height; i++) - { - if (i > 0) - { - fillText.AppendLine (""); - } - - for (var j = 0; j < labelFill.Bounds.Width; j++) - { - fillText.Append (fill); - } - } - - labelFill.Text = fillText.ToString (); - }; - - labelText = new Label { X = Pos.Center (), Y = Pos.Center (), Text = text }; - Add (labelFill, labelText); + _labelFill = new Label { AutoSize = false, Width = Dim.Fill (), Height = Dim.Fill (), Visible = false }; + + _labelFill.LayoutComplete += (s, e) => + { + var fillText = new StringBuilder (); + + for (var i = 0; i < _labelFill.Bounds.Height; i++) + { + if (i > 0) + { + fillText.AppendLine (""); + } + + for (var j = 0; j < _labelFill.Bounds.Width; j++) + { + fillText.Append (fill); + } + } + + _labelFill.Text = fillText.ToString (); + }; + + _labelText = new Label { X = Pos.Center (), Y = Pos.Center (), Text = text }; + Add (_labelFill, _labelText); CanFocus = true; } @@ -1102,7 +1118,7 @@ public override bool OnEnter (View view) { Border.LineStyle = LineStyle.None; Border.Thickness = new Thickness (0); - labelFill.Visible = true; + _labelFill.Visible = true; view = this; return base.OnEnter (view); @@ -1112,7 +1128,7 @@ public override bool OnLeave (View view) { Border.LineStyle = LineStyle.Single; Border.Thickness = new Thickness (1); - labelFill.Visible = false; + _labelFill.Visible = false; if (view == null) { diff --git a/UnitTests/Views/TextViewTests.cs b/UnitTests/Views/TextViewTests.cs index ba8d74b886..540abd5fb8 100644 --- a/UnitTests/Views/TextViewTests.cs +++ b/UnitTests/Views/TextViewTests.cs @@ -8973,13 +8973,12 @@ This is TestHelpers.AssertDriverContentsWithFrameAre ( @" -This is -the first -line. -This is -the -second -line. +This is +the first +line. +This is +the second +line. ", _output ); From f1645215930b5da10681395a298c4d6d5615ce4c Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 17:18:27 +0000 Subject: [PATCH 024/130] Remove the hack BottomOffset and RightOffset used by the old scroll bar. --- Terminal.Gui/Views/TextView.cs | 77 ++++++---------------- UnitTests/Views/TextViewTests.cs | 108 +++++++++++++++++++------------ 2 files changed, 88 insertions(+), 97 deletions(-) diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 5b4596d86d..89b194d432 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -1953,7 +1953,6 @@ public class TextView : View private readonly HistoryText _historyText = new (); private bool _allowsReturn = true; private bool _allowsTab = true; - private int _bottomOffset, _rightOffset; private bool _clickWithSelecting; // The column we are tracking, or -1 if we are not tracking any column @@ -2593,25 +2592,6 @@ public bool AllowsTab /// public IAutocomplete Autocomplete { get; protected set; } = new TextViewAutocomplete (); - /// - /// The bottom offset needed to use a horizontal scrollbar or for another reason. This is only needed with the - /// keyboard navigation. - /// - public int BottomOffset - { - get => _bottomOffset; - set - { - if (CurrentRow == Lines - 1 && _bottomOffset > 0 && value == 0) - { - _topRow = Math.Max (_topRow - _bottomOffset, 0); - } - - _bottomOffset = value; - Adjust (); - } - } - /// public override bool CanFocus { @@ -2780,25 +2760,6 @@ public bool ReadOnly } } - /// - /// The right offset needed to use a vertical scrollbar or for another reason. This is only needed with the - /// keyboard navigation. - /// - public int RightOffset - { - get => _rightOffset; - set - { - if (!_wordWrap && CurrentColumn == GetCurrentLine ().Count && _rightOffset > 0 && value == 0) - { - _leftColumn = Math.Max (_leftColumn - _rightOffset, 0); - } - - _rightOffset = value; - Adjust (); - } - } - /// public override int ScrollLeftOffset { @@ -3456,7 +3417,7 @@ public override bool MouseEvent (MouseEvent ev) if (_model.Count > 0 && _shiftSelecting && Selecting) { - if (CurrentRow - _topRow + BottomOffset >= Bounds.Height - 1 && _model.Count + BottomOffset > _topRow + CurrentRow) + if (CurrentRow - _topRow >= Bounds.Height - 1 && _model.Count > _topRow + CurrentRow) { ScrollTo (_topRow + Bounds.Height); } @@ -3466,14 +3427,14 @@ public override bool MouseEvent (MouseEvent ev) } else if (ev.Y >= Bounds.Height) { - ScrollTo (_model.Count + BottomOffset); + ScrollTo (_model.Count); } else if (ev.Y < 0 && _topRow > 0) { ScrollTo (0); } - if (CurrentColumn - _leftColumn + RightOffset >= Bounds.Width - 1 && line.Count + RightOffset > _leftColumn + CurrentColumn) + if (CurrentColumn - _leftColumn >= Bounds.Width - 1 && line.Count > _leftColumn + CurrentColumn) { ScrollTo (_leftColumn + Bounds.Width, false); } @@ -3483,7 +3444,7 @@ public override bool MouseEvent (MouseEvent ev) } else if (ev.X >= Bounds.Width) { - ScrollTo (line.Count + RightOffset, false); + ScrollTo (line.Count, false); } else if (ev.X < 0 && _leftColumn > 0) { @@ -3650,8 +3611,8 @@ public override void OnDrawContent (Rect contentArea) SetNormalColor (); (int width, int height) offB = OffSetBackground (); - int right = Bounds.Width + offB.width + RightOffset; - int bottom = Bounds.Height + offB.height + BottomOffset; + int right = Bounds.Width + offB.width ; + int bottom = Bounds.Height + offB.height; var row = 0; for (int idxRow = _topRow; idxRow < _model.Count; idxRow++) @@ -3938,7 +3899,7 @@ public override void PositionCursor () int posX = CurrentColumn - _leftColumn; int posY = CurrentRow - _topRow; - if (posX > -1 && col >= posX && posX < Bounds.Width - RightOffset && _topRow <= CurrentRow && posY < Bounds.Height - BottomOffset) + if (posX > -1 && col >= posX && posX < Bounds.Width && _topRow <= CurrentRow && posY < Bounds.Height) { ResetCursorVisibility (); Move (col, CurrentRow - _topRow); @@ -4011,7 +3972,7 @@ public void ScrollTo (int idx, bool isRow = true) else if (!_wordWrap) { int maxlength = - _model.GetMaxVisibleLine (_topRow, _topRow + Bounds.Height + RightOffset, TabWidth); + _model.GetMaxVisibleLine (_topRow, _topRow + Bounds.Height, TabWidth); ScrollLeftOffset = _leftColumn = Math.Max (!_wordWrap && idx > maxlength - 1 ? maxlength - 1 : idx, 0); } @@ -4190,19 +4151,19 @@ private void Adjust () need = true; } else if (!_wordWrap - && (CurrentColumn - _leftColumn + 1 + RightOffset > Bounds.Width + offB.width || dSize.size + 1 + RightOffset >= Bounds.Width + offB.width)) + && (CurrentColumn - _leftColumn + 1 > Bounds.Width + offB.width || dSize.size + 1 >= Bounds.Width + offB.width)) { _leftColumn = TextModel.CalculateLeftColumn ( line, _leftColumn, CurrentColumn, - Bounds.Width + offB.width - RightOffset, + Bounds.Width + offB.width, TabWidth ); need = true; } else if ((_wordWrap && _leftColumn > 0) - || (dSize.size + RightOffset < Bounds.Width + offB.width && tSize.size + RightOffset < Bounds.Width + offB.width)) + || (dSize.size < Bounds.Width + offB.width && tSize.size < Bounds.Width + offB.width)) { if (_leftColumn > 0) { @@ -4216,9 +4177,9 @@ private void Adjust () _topRow = CurrentRow; need = true; } - else if (CurrentRow - _topRow + BottomOffset >= Bounds.Height + offB.height) + else if (CurrentRow - _topRow >= Bounds.Height + offB.height) { - _topRow = Math.Min (Math.Max (CurrentRow - Bounds.Height + 1 + BottomOffset, 0), CurrentRow); + _topRow = Math.Min (Math.Max (CurrentRow - Bounds.Height + 1, 0), CurrentRow); need = true; } else if (_topRow > 0 && CurrentRow < _topRow) @@ -4236,6 +4197,8 @@ private void Adjust () } SetNeedsDisplay (); + + SetScrollColsRowsSize (); } else { @@ -5412,7 +5375,7 @@ private void MoveDown () CurrentRow++; - if (CurrentRow + BottomOffset >= _topRow + Bounds.Height) + if (CurrentRow >= _topRow + Bounds.Height) { _topRow++; SetNeedsDisplay (); @@ -5916,9 +5879,9 @@ private void ProcessMouseClick (MouseEvent ev, out List line) r = GetCurrentLine (); int idx = TextModel.GetColFromX (r, _leftColumn, Math.Max (ev.X, 0), TabWidth); - if (idx - _leftColumn >= r.Count + RightOffset) + if (idx - _leftColumn >= r.Count) { - CurrentColumn = Math.Max (r.Count - _leftColumn + RightOffset - (ReadOnly ? 1 : 0), 0); + CurrentColumn = Math.Max (r.Count - _leftColumn - (ReadOnly ? 1 : 0), 0); } else { @@ -6486,7 +6449,9 @@ private string StringFromRunes (List cells) return StringExtensions.ToString (encoded); } - private void TextView_DrawAdornments (object? sender, DrawEventArgs e) + private void TextView_DrawAdornments (object? sender, DrawEventArgs e) { SetScrollColsRowsSize (); } + + private void SetScrollColsRowsSize () { if (ScrollBarType != ScrollBarType.None) { diff --git a/UnitTests/Views/TextViewTests.cs b/UnitTests/Views/TextViewTests.cs index 540abd5fb8..aca43d6f6f 100644 --- a/UnitTests/Views/TextViewTests.cs +++ b/UnitTests/Views/TextViewTests.cs @@ -106,38 +106,6 @@ public void BackTab_Test_Follow_By_Tab () Application.Run (); } - [Fact] - [TextViewTestsAutoInitShutdown] - public void BottomOffset_Sets_To_Zero_Adjust_TopRow () - { - var text = ""; - - for (var i = 0; i < 12; i++) - { - text += $"This is the line {i}\n"; - } - - var tv = new TextView { Width = 10, Height = 10, BottomOffset = 1 }; - tv.Text = text; - - tv.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.End)); - - Assert.Equal (4, tv.TopRow); - Assert.Equal (1, tv.BottomOffset); - - tv.BottomOffset = 0; - Assert.Equal (3, tv.TopRow); - Assert.Equal (0, tv.BottomOffset); - - tv.BottomOffset = 2; - Assert.Equal (5, tv.TopRow); - Assert.Equal (2, tv.BottomOffset); - - tv.BottomOffset = 0; - Assert.Equal (3, tv.TopRow); - Assert.Equal (0, tv.BottomOffset); - } - [Fact] [TextViewTestsAutoInitShutdown] public void CanFocus_False_Wont_Focus_With_Mouse () @@ -6923,7 +6891,7 @@ public void ReplaceAllText_Does_Not_Throw_Exception () [Fact] [TextViewTestsAutoInitShutdown] - public void RightOffset_Sets_To_Zero_Adjust_leftColumn () + public void ScrollBarType_IsBuiltIn_Always_Adjust_LeftColumn () { var text = ""; @@ -6932,25 +6900,83 @@ public void RightOffset_Sets_To_Zero_Adjust_leftColumn () text += $"{i.ToString () [^1]}"; } - var tv = new TextView { Width = 10, Height = 10, RightOffset = 1 }; + var tv = new TextView { Width = 10, Height = 10, ScrollBarType = ScrollBarType.Both }; tv.Text = text; + tv.BeginInit (); + tv.EndInit (); + + tv.NewKeyDownEvent (new Key (KeyCode.Space)); tv.NewKeyDownEvent (new Key (KeyCode.End)); Assert.Equal (4, tv.LeftColumn); - Assert.Equal (1, tv.RightOffset); + Assert.Equal (14, tv.Maxlength); + Assert.Equal (tv.LeftColumn, tv.Maxlength - tv.Bounds.Width); + + tv.NewKeyDownEvent (new Key (KeyCode.Backspace)); + tv.NewKeyDownEvent (new Key (KeyCode.End)); - tv.RightOffset = 0; Assert.Equal (3, tv.LeftColumn); - Assert.Equal (0, tv.RightOffset); + Assert.Equal (13, tv.Maxlength); + Assert.Equal (tv.LeftColumn, tv.Maxlength - tv.Bounds.Width); + + tv.NewKeyDownEvent (new Key (KeyCode.Space)); + tv.NewKeyDownEvent (new Key (KeyCode.Space)); - tv.RightOffset = 2; Assert.Equal (5, tv.LeftColumn); - Assert.Equal (2, tv.RightOffset); + Assert.Equal (15, tv.Maxlength); + Assert.Equal (tv.LeftColumn, tv.Maxlength - tv.Bounds.Width); + + tv.NewKeyDownEvent (new Key (KeyCode.Backspace)); + tv.NewKeyDownEvent (new Key (KeyCode.Backspace)); - tv.RightOffset = 0; Assert.Equal (3, tv.LeftColumn); - Assert.Equal (0, tv.RightOffset); + Assert.Equal (13, tv.Maxlength); + Assert.Equal (tv.LeftColumn, tv.Maxlength - tv.Bounds.Width); + } + + [Fact] + [TextViewTestsAutoInitShutdown] + public void ScrollBarType_IsBuiltIn_Always_Adjust_TopRow () + { + var text = ""; + + for (var i = 0; i < 12; i++) + { + text += $"This is the line {i}\n"; + } + + var tv = new TextView { Width = 10, Height = 10, ScrollBarType = ScrollBarType.Both }; + tv.Text = text; + + tv.BeginInit (); + tv.EndInit (); + + tv.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.End)); + + Assert.Equal (4, tv.TopRow); + Assert.Equal (13, tv.Lines); + Assert.Equal (tv.TopRow, tv.Lines - tv.Bounds.Height); + + tv.NewKeyDownEvent (new Key (KeyCode.Backspace)); + + Assert.Equal (3, tv.TopRow); + Assert.Equal (12, tv.Lines); + Assert.Equal (tv.TopRow, tv.Lines - tv.Bounds.Height); + + tv.NewKeyDownEvent (new Key (KeyCode.Enter)); + tv.NewKeyDownEvent (new Key (KeyCode.Enter)); + + Assert.Equal (5, tv.TopRow); + Assert.Equal (14, tv.Lines); + Assert.Equal (tv.TopRow, tv.Lines - tv.Bounds.Height); + + tv.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.AltMask)); + tv.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.AltMask)); + + Assert.Equal (3, tv.TopRow); + Assert.Equal (12, tv.Lines); + Assert.Equal (tv.TopRow, tv.Lines - tv.Bounds.Height); } [Fact] From 81246014fe32a7ca4f8ff02b34eef6d7ba4738cf Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 17:29:29 +0000 Subject: [PATCH 025/130] Rename to AddEventHandlersForScrollBars. --- Terminal.Gui/View/ViewScrollBar.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 93f0c252bf..1551ddecf9 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -81,7 +81,7 @@ public virtual ScrollBarType ScrollBarType } Padding.Add (_scrollBar); - AddHandlers (); + AddEventHandlersForScrollBars (); AddScrollKeyBindings (_scrollBar); if (_scrollBar.OtherScrollBarView != null) @@ -268,7 +268,7 @@ public virtual int ScrollTopOffset /// public bool UseNegativeBoundsLocation { get; set; } - private void AddHandlers () + private void AddEventHandlersForScrollBars () { if (_scrollBar == null) { From 1f47285266262d77bfecb25cc1f00acff00c6530 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 17:33:13 +0000 Subject: [PATCH 026/130] Replace '== null' to 'is null'. --- Terminal.Gui/View/ViewScrollBar.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 1551ddecf9..9253dd0cac 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -270,7 +270,7 @@ public virtual int ScrollTopOffset private void AddEventHandlersForScrollBars () { - if (_scrollBar == null) + if (_scrollBar is null) { return; } @@ -563,7 +563,7 @@ private void AddScrollKeyBindings (ScrollBarView scrollBar) private void DisposeScrollBar () { - if (_scrollBar == null) + if (_scrollBar is null) { return; } From 7fc326b6bca7634d456841721947d051dbce84d4 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 17:35:05 +0000 Subject: [PATCH 027/130] Replace to AddKeyBindingsForScrolling. --- Terminal.Gui/View/ViewScrollBar.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 9253dd0cac..b9a9deef7d 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -82,11 +82,11 @@ public virtual ScrollBarType ScrollBarType Padding.Add (_scrollBar); AddEventHandlersForScrollBars (); - AddScrollKeyBindings (_scrollBar); + AddKeyBindingsForScrolling (_scrollBar); if (_scrollBar.OtherScrollBarView != null) { - AddScrollKeyBindings (_scrollBar.OtherScrollBarView); + AddKeyBindingsForScrolling (_scrollBar.OtherScrollBarView); } SetNeedsDisplay (); @@ -283,7 +283,7 @@ private void AddEventHandlersForScrollBars () } } - private void AddScrollKeyBindings (ScrollBarView scrollBar) + private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) { if (scrollBar.IsVertical) { From 270229ef4db65af32d0123f854887c421a11b62d Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 18:16:11 +0000 Subject: [PATCH 028/130] Rename to KeepContentAlwaysInViewPort. --- Terminal.Gui/View/ViewScrollBar.cs | 4 ++-- Terminal.Gui/Views/ScrollBarView.cs | 30 +++++++++++++-------------- Terminal.Gui/Views/ScrollView.cs | 10 ++++----- UICatalog/Scenarios/Scrolling.cs | 2 +- UnitTests/Views/ScrollBarViewTests.cs | 8 +++---- UnitTests/Views/ScrollViewTests.cs | 12 +++++------ 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index b9a9deef7d..1cc285b886 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -137,8 +137,8 @@ public int ScrollColsSize /// Get or sets if the view-port is kept always visible in the area of this public bool ScrollKeepContentAlwaysInViewPort { - get => _scrollBar.KeepContentAlwaysInViewport; - set => _scrollBar.KeepContentAlwaysInViewport = value; + get => _scrollBar.KeepContentAlwaysInViewPort; + set => _scrollBar.KeepContentAlwaysInViewPort = value; } /// diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index badedb548d..64f0e414ea 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -76,7 +76,7 @@ public bool IsVertical } /// Get or sets if the view-port is kept always visible in the area of this - public bool KeepContentAlwaysInViewport + public bool KeepContentAlwaysInViewPort { get => _keepContentAlwaysInViewport; set @@ -437,15 +437,15 @@ public override void OnDrawContent (Rect contentArea) { bh -= 2; - int by1 = KeepContentAlwaysInViewport + int by1 = KeepContentAlwaysInViewPort ? _position * bh / Size : _position * bh / (Size + bh); - int by2 = KeepContentAlwaysInViewport + int by2 = KeepContentAlwaysInViewPort ? Math.Min ((_position + bh) * bh / Size + 1, bh - 1) : (_position + bh) * bh / (Size + bh); - if (KeepContentAlwaysInViewport && by1 == by2) + if (KeepContentAlwaysInViewPort && by1 == by2) { by1 = Math.Max (by1 - 1, 0); } @@ -530,15 +530,15 @@ public override void OnDrawContent (Rect contentArea) { bw -= 2; - int bx1 = KeepContentAlwaysInViewport + int bx1 = KeepContentAlwaysInViewPort ? _position * bw / Size : _position * bw / (Size + bw); - int bx2 = KeepContentAlwaysInViewport + int bx2 = KeepContentAlwaysInViewPort ? Math.Min ((_position + bw) * bw / Size + 1, bw - 1) : (_position + bw) * bw / (Size + bw); - if (KeepContentAlwaysInViewport && bx1 == bx2) + if (KeepContentAlwaysInViewPort && bx1 == bx2) { bx1 = Math.Max (bx1 - 1, 0); } @@ -657,12 +657,12 @@ private void AdjustContentInViewport (bool refresh = true) var pos = 0; - if (KeepContentAlwaysInViewport && !_vertical && _position + SuperView.Bounds.Width > _size + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0)) + if (KeepContentAlwaysInViewPort && !_vertical && _position + SuperView.Bounds.Width > _size + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0)) { pos = Math.Max (_size - SuperView.Bounds.Width + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0), 0); } - if (KeepContentAlwaysInViewport && _vertical && _position + SuperView.Bounds.Height > _size + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0)) + if (KeepContentAlwaysInViewPort && _vertical && _position + SuperView.Bounds.Height > _size + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0)) { pos = Math.Max (_size - SuperView.Bounds.Height + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0), 0); } @@ -672,9 +672,9 @@ private void AdjustContentInViewport (bool refresh = true) Position = pos; } - if (OtherScrollBarView is { } && OtherScrollBarView.KeepContentAlwaysInViewport != KeepContentAlwaysInViewport) + if (OtherScrollBarView is { } && OtherScrollBarView.KeepContentAlwaysInViewPort != KeepContentAlwaysInViewPort) { - OtherScrollBarView.KeepContentAlwaysInViewport = KeepContentAlwaysInViewport; + OtherScrollBarView.KeepContentAlwaysInViewPort = KeepContentAlwaysInViewPort; } if (pos == 0 && refresh) @@ -844,16 +844,16 @@ private int GetBarSize (bool isVertical) if (IsBuiltIn) { - return isVertical ? KeepContentAlwaysInViewport + return isVertical ? KeepContentAlwaysInViewPort ? SuperView.Bounds.Height : 0 : - KeepContentAlwaysInViewport ? SuperView.Bounds.Width : 0; + KeepContentAlwaysInViewPort ? SuperView.Bounds.Width : 0; } - return isVertical ? KeepContentAlwaysInViewport + return isVertical ? KeepContentAlwaysInViewPort ? SuperView.Bounds.Height - (_showBothScrollIndicator ? 1 : 0) : 0 : - KeepContentAlwaysInViewport ? SuperView.Bounds.Width - (_showBothScrollIndicator ? 1 : 0) : 0; + KeepContentAlwaysInViewPort ? SuperView.Bounds.Width - (_showBothScrollIndicator ? 1 : 0) : 0; } private void ManageScrollBarThickness () diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index 90d4945bf8..19aeabe751 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -193,15 +193,15 @@ public Size ContentSize } /// Get or sets if the view-port is kept always visible in the area of this - public bool KeepContentAlwaysInViewport + public bool KeepContentAlwaysInViewPort { - get => _horizontal?.KeepContentAlwaysInViewport ?? _vertical.KeepContentAlwaysInViewport; + get => _horizontal?.KeepContentAlwaysInViewPort ?? _vertical.KeepContentAlwaysInViewPort; set { - if (_horizontal.KeepContentAlwaysInViewport || _vertical.KeepContentAlwaysInViewport != value) + if (_horizontal.KeepContentAlwaysInViewPort || _vertical.KeepContentAlwaysInViewPort != value) { - _vertical.KeepContentAlwaysInViewport = value; - _horizontal.KeepContentAlwaysInViewport = value; + _vertical.KeepContentAlwaysInViewPort = value; + _horizontal.KeepContentAlwaysInViewPort = value; } } } diff --git a/UICatalog/Scenarios/Scrolling.cs b/UICatalog/Scenarios/Scrolling.cs index d38cbeb33a..387603ddc3 100644 --- a/UICatalog/Scenarios/Scrolling.cs +++ b/UICatalog/Scenarios/Scrolling.cs @@ -215,7 +215,7 @@ void Top_Loaded (object sender, EventArgs args) }; Win.Add (ahCheckBox); - keepCheckBox.Toggled += (s, e) => scrollView.KeepContentAlwaysInViewport = (bool)keepCheckBox.Checked; + keepCheckBox.Toggled += (s, e) => scrollView.KeepContentAlwaysInViewPort = (bool)keepCheckBox.Checked; Win.Add (keepCheckBox); //var scrollView2 = new ScrollView (new Rect (55, 2, 20, 8)) { diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index 3e1bde31c0..bf4ee90981 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -487,7 +487,7 @@ public void Source = new ListWrapper (source) }; win.Add (listView); - var newScrollBarView = new ScrollBarView { IsVertical = true, KeepContentAlwaysInViewport = true }; + var newScrollBarView = new ScrollBarView { IsVertical = true, KeepContentAlwaysInViewPort = true }; listView.Add (newScrollBarView); newScrollBarView.ChangedPosition += (s, e) => @@ -966,8 +966,8 @@ public void Internal_Tests () Assert.Equal (21, max); // 21+80=101 Assert.True (sbv.Visible); Assert.True (sbv.OtherScrollBarView.Visible); - sbv.KeepContentAlwaysInViewport = false; - sbv.OtherScrollBarView.KeepContentAlwaysInViewport = false; + sbv.KeepContentAlwaysInViewPort = false; + sbv.OtherScrollBarView.KeepContentAlwaysInViewPort = false; Assert.True (sbv.CanScroll (50, out max, sbv.IsVertical)); Assert.Equal (39, max); // Keep 1 row visible Assert.True (sbv.OtherScrollBarView.CanScroll (150, out max, sbv.OtherScrollBarView.IsVertical)); @@ -984,7 +984,7 @@ public void KeepContentAlwaysInViewport_False () AddHandlers (); - _scrollBar.KeepContentAlwaysInViewport = false; + _scrollBar.KeepContentAlwaysInViewPort = false; _scrollBar.Position = 50; Assert.Equal (_scrollBar.Position, _scrollBar.Size - 1); Assert.Equal (_scrollBar.Position, _hostView.Top); diff --git a/UnitTests/Views/ScrollViewTests.cs b/UnitTests/Views/ScrollViewTests.cs index 86c3bfa829..758eb128f8 100644 --- a/UnitTests/Views/ScrollViewTests.cs +++ b/UnitTests/Views/ScrollViewTests.cs @@ -183,7 +183,7 @@ public void Clear_Window_Inside_ScrollView () Width = 10, Height = 10, ContentSize = new Size (23, 23), - KeepContentAlwaysInViewport = false + KeepContentAlwaysInViewPort = false }; var bottomLabel = new Label { X = 15, Y = 15, Text = "At 15,15" }; Application.Top.Add (topLabel, sv, bottomLabel); @@ -344,7 +344,7 @@ public void Constructors_Defaults () Assert.Equal (Point.Empty, sv.ContentOffset); Assert.Equal (Size.Empty, sv.ContentSize); Assert.True (sv.AutoHideScrollBars); - Assert.True (sv.KeepContentAlwaysInViewport); + Assert.True (sv.KeepContentAlwaysInViewPort); sv = new ScrollView { X = 1, Y = 2, Width = 20, Height = 10 }; Assert.Equal (LayoutStyle.Absolute, sv.LayoutStyle); @@ -353,7 +353,7 @@ public void Constructors_Defaults () Assert.Equal (Point.Empty, sv.ContentOffset); Assert.Equal (Size.Empty, sv.ContentSize); Assert.True (sv.AutoHideScrollBars); - Assert.True (sv.KeepContentAlwaysInViewport); + Assert.True (sv.KeepContentAlwaysInViewPort); } [Fact] @@ -923,7 +923,7 @@ public void KeyBindings_Command () sv.BeginInit (); sv.EndInit (); - Assert.True (sv.KeepContentAlwaysInViewport); + Assert.True (sv.KeepContentAlwaysInViewPort); Assert.True (sv.AutoHideScrollBars); Assert.True (sv.ShowVerticalScrollIndicator); Assert.True (sv.ShowHorizontalScrollIndicator); @@ -991,8 +991,8 @@ public void KeyBindings_Command () Assert.True (sv.OnKeyDown (new Key (KeyCode.Home | KeyCode.CtrlMask))); Assert.Equal (new Point (0, 0), sv.ContentOffset); - sv.KeepContentAlwaysInViewport = false; - Assert.False (sv.KeepContentAlwaysInViewport); + sv.KeepContentAlwaysInViewPort = false; + Assert.False (sv.KeepContentAlwaysInViewPort); Assert.True (sv.AutoHideScrollBars); Assert.True (sv.ShowVerticalScrollIndicator); Assert.True (sv.ShowHorizontalScrollIndicator); From 77dcc5ec3e4469a610783b110bead2aaf20dcb52 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 19:32:19 +0000 Subject: [PATCH 029/130] Replace with "virtual space". --- Terminal.Gui/Views/ScrollBarView.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index 64f0e414ea..a0df0dcb55 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -160,7 +160,7 @@ public bool ShowScrollIndicator /// The size. /// /// The is typically the size of the virtual content. E.g. when a Scrollbar is part of a - /// the Size is set to the appropriate dimension of . + /// the Size is set to the appropriate dimension of virtual space. /// public int Size { From 9f7151355df99e61df36d287f06a3214dbe6d699 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 19:51:06 +0000 Subject: [PATCH 030/130] Remove VisibleChanged. --- Terminal.Gui/View/ViewScrollBar.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 1cc285b886..2cb6dc174b 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -570,12 +570,9 @@ private void DisposeScrollBar () _scrollBar.ChangedPosition -= ScrollBar_ChangedPosition; - //_scrollBar.VisibleChanged -= ScrollBar_VisibleChanged; - if (_scrollBar.OtherScrollBarView != null) + if (_scrollBar.OtherScrollBar is { }) { - _scrollBar.OtherScrollBarView.ChangedPosition -= OtherScrollBarView_ChangedPosition; - - //_scrollBar.OtherScrollBarView.VisibleChanged -= OtherScrollBarView_VisibleChanged; + _scrollBar.OtherScrollBar.ChangedPosition -= OtherScrollBar_ChangedPosition; } _scrollBar.RemoveAll (); From 845c8dca868b0cb67cc3a4ca700231442db44277 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 20:07:58 +0000 Subject: [PATCH 031/130] Revert "Remove VisibleChanged." This reverts commit 9f7151355df99e61df36d287f06a3214dbe6d699. --- Terminal.Gui/View/ViewScrollBar.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 2cb6dc174b..1cc285b886 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -570,9 +570,12 @@ private void DisposeScrollBar () _scrollBar.ChangedPosition -= ScrollBar_ChangedPosition; - if (_scrollBar.OtherScrollBar is { }) + //_scrollBar.VisibleChanged -= ScrollBar_VisibleChanged; + if (_scrollBar.OtherScrollBarView != null) { - _scrollBar.OtherScrollBar.ChangedPosition -= OtherScrollBar_ChangedPosition; + _scrollBar.OtherScrollBarView.ChangedPosition -= OtherScrollBarView_ChangedPosition; + + //_scrollBar.OtherScrollBarView.VisibleChanged -= OtherScrollBarView_VisibleChanged; } _scrollBar.RemoveAll (); From 2496f6eb5929508c01ec2a53578a659a47557575 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 20:13:14 +0000 Subject: [PATCH 032/130] Remove VisibleChanged. --- Terminal.Gui/View/ViewScrollBar.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 1cc285b886..e6dce09a50 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -570,12 +570,9 @@ private void DisposeScrollBar () _scrollBar.ChangedPosition -= ScrollBar_ChangedPosition; - //_scrollBar.VisibleChanged -= ScrollBar_VisibleChanged; if (_scrollBar.OtherScrollBarView != null) { _scrollBar.OtherScrollBarView.ChangedPosition -= OtherScrollBarView_ChangedPosition; - - //_scrollBar.OtherScrollBarView.VisibleChanged -= OtherScrollBarView_VisibleChanged; } _scrollBar.RemoveAll (); From 22db0d90443073d1b07aa979c1f4ea41ed85f895 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 20:34:26 +0000 Subject: [PATCH 033/130] Rename ScrollBarView to ScrollBar. --- Terminal.Gui/Drawing/Glyphs.cs | 4 +- Terminal.Gui/View/ViewScrollBar.cs | 108 ++--- .../Views/{ScrollBarView.cs => ScrollBar.cs} | 138 +++---- Terminal.Gui/Views/ScrollView.cs | 26 +- Terminal.Gui/Views/Wizard/WizardStep.cs | 22 +- UICatalog/Scenarios/Editor.cs | 2 +- UnitTests/Input/ResponderTests.cs | 10 +- ...crollBarViewTests.cs => ScrollBarTests.cs} | 370 +++++++++--------- UnitTests/Views/ScrollViewTests.cs | 4 +- 9 files changed, 342 insertions(+), 342 deletions(-) rename Terminal.Gui/Views/{ScrollBarView.cs => ScrollBar.cs} (87%) rename UnitTests/Views/{ScrollBarViewTests.cs => ScrollBarTests.cs} (80%) diff --git a/Terminal.Gui/Drawing/Glyphs.cs b/Terminal.Gui/Drawing/Glyphs.cs index 18d83de504..dec1074a31 100644 --- a/Terminal.Gui/Drawing/Glyphs.cs +++ b/Terminal.Gui/Drawing/Glyphs.cs @@ -76,10 +76,10 @@ public class GlyphDefinitions /// Continuous block meter segment (e.g. for ). public Rune ContinuousMeterSegment { get; set; } = (Rune)'█'; - /// Stipple pattern (e.g. for ). Default is Light Shade (U+2591) - ░. + /// Stipple pattern (e.g. for ). Default is Light Shade (U+2591) - ░. public Rune Stipple { get; set; } = (Rune)'░'; - /// Diamond (e.g. for . Default is Lozenge (U+25CA) - ◊. + /// Diamond (e.g. for . Default is Lozenge (U+25CA) - ◊. public Rune Diamond { get; set; } = (Rune)'◊'; /// Close. Default is Heavy Ballot X (U+2718) - ✘. diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index e6dce09a50..b707ca0024 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -1,7 +1,7 @@ namespace Terminal.Gui; /// -/// The scroll bar types used by this . +/// The scroll bar types used by this . /// public enum ScrollBarType { @@ -28,7 +28,7 @@ public enum ScrollBarType public partial class View { - private ScrollBarView _scrollBar; + private ScrollBar _scrollBar; private ScrollBarType _scrollBarType; private int _scrollColsSize; private int _scrollLeftOffset; @@ -62,16 +62,16 @@ public virtual ScrollBarType ScrollBarType switch (_scrollBarType) { case ScrollBarType.Vertical: - _scrollBar = new ScrollBarView { IsVertical = true }; + _scrollBar = new ScrollBar { IsVertical = true }; break; case ScrollBarType.Horizontal: - _scrollBar = new ScrollBarView { IsVertical = false }; + _scrollBar = new ScrollBar { IsVertical = false }; break; case ScrollBarType.Both: - _scrollBar = new ScrollBarView { IsVertical = true }; - _scrollBar.OtherScrollBarView = new ScrollBarView { IsVertical = false, OtherScrollBarView = _scrollBar }; + _scrollBar = new ScrollBar { IsVertical = true }; + _scrollBar.OtherScrollBar = new ScrollBar { IsVertical = false, OtherScrollBar = _scrollBar }; break; case ScrollBarType.None: @@ -84,9 +84,9 @@ public virtual ScrollBarType ScrollBarType AddEventHandlersForScrollBars (); AddKeyBindingsForScrolling (_scrollBar); - if (_scrollBar.OtherScrollBarView != null) + if (_scrollBar.OtherScrollBar != null) { - AddKeyBindingsForScrolling (_scrollBar.OtherScrollBarView); + AddKeyBindingsForScrolling (_scrollBar.OtherScrollBar); } SetNeedsDisplay (); @@ -110,13 +110,13 @@ public int ScrollColsSize switch (_scrollBar.IsVertical) { - case true when _scrollBar.OtherScrollBarView is { }: - if (_scrollBar.OtherScrollBarView.Size == _scrollColsSize) + case true when _scrollBar.OtherScrollBar is { }: + if (_scrollBar.OtherScrollBar.Size == _scrollColsSize) { return; } - _scrollBar.OtherScrollBarView.Size = _scrollColsSize; + _scrollBar.OtherScrollBar.Size = _scrollColsSize; break; case false: @@ -134,7 +134,7 @@ public int ScrollColsSize } } - /// Get or sets if the view-port is kept always visible in the area of this + /// Get or sets if the view-port is kept always visible in the area of this public bool ScrollKeepContentAlwaysInViewPort { get => _scrollBar.KeepContentAlwaysInViewPort; @@ -162,19 +162,19 @@ public virtual int ScrollLeftOffset { _scrollBar.Position = _scrollLeftOffset; } - else if (_scrollBar is { OtherScrollBarView.IsVertical: false } && _scrollBar?.OtherScrollBarView.Position != _scrollLeftOffset) + else if (_scrollBar is { OtherScrollBar.IsVertical: false } && _scrollBar?.OtherScrollBar.Position != _scrollLeftOffset) { - _scrollBar!.OtherScrollBarView.Position = _scrollLeftOffset; + _scrollBar!.OtherScrollBar.Position = _scrollLeftOffset; } } } } - /// Represent a vertical or horizontal ScrollBarView other than this. - public ScrollBarView ScrollOtherScrollBarView + /// Represent a vertical or horizontal ScrollBar other than this. + public ScrollBar ScrollOtherScrollBar { - get => _scrollBar.OtherScrollBarView; - set => _scrollBar.OtherScrollBarView = value; + get => _scrollBar.OtherScrollBar; + set => _scrollBar.OtherScrollBar = value; } /// The position, relative to , to set the scrollbar at. @@ -211,13 +211,13 @@ public int ScrollRowsSize _scrollBar.Size = _scrollRowsSize; break; - case false when _scrollBar.OtherScrollBarView is { }: - if (_scrollBar.OtherScrollBarView.Size == _scrollRowsSize) + case false when _scrollBar.OtherScrollBar is { }: + if (_scrollBar.OtherScrollBar.Size == _scrollRowsSize) { return; } - _scrollBar.OtherScrollBarView.Size = _scrollRowsSize; + _scrollBar.OtherScrollBar.Size = _scrollRowsSize; break; } @@ -255,9 +255,9 @@ public virtual int ScrollTopOffset { _scrollBar.Position = _scrollTopOffset; } - else if (_scrollBar is { OtherScrollBarView.IsVertical: true } && _scrollBar?.OtherScrollBarView.Position != _scrollTopOffset) + else if (_scrollBar is { OtherScrollBar.IsVertical: true } && _scrollBar?.OtherScrollBar.Position != _scrollTopOffset) { - _scrollBar!.OtherScrollBarView.Position = _scrollTopOffset; + _scrollBar!.OtherScrollBar.Position = _scrollTopOffset; } } } @@ -277,13 +277,13 @@ private void AddEventHandlersForScrollBars () _scrollBar.ChangedPosition += ScrollBar_ChangedPosition; - if (_scrollBar.OtherScrollBarView != null) + if (_scrollBar.OtherScrollBar != null) { - _scrollBar.OtherScrollBarView.ChangedPosition += OtherScrollBarView_ChangedPosition; + _scrollBar.OtherScrollBar.ChangedPosition += OtherScrollBar_ChangedPosition; } } - private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) + private void AddKeyBindingsForScrolling (ScrollBar scrollBar) { if (scrollBar.IsVertical) { @@ -299,9 +299,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: true }) + if (scrollBar.OtherScrollBar is { IsVertical: true }) { - scrollBar.OtherScrollBarView.Position++; + scrollBar.OtherScrollBar.Position++; return true; } @@ -320,9 +320,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: true }) + if (scrollBar.OtherScrollBar is { IsVertical: true }) { - scrollBar.OtherScrollBarView.Position--; + scrollBar.OtherScrollBar.Position--; return true; } @@ -341,9 +341,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: true }) + if (scrollBar.OtherScrollBar is { IsVertical: true }) { - scrollBar.OtherScrollBarView.Position = 0; + scrollBar.OtherScrollBar.Position = 0; return true; } @@ -362,9 +362,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: true }) + if (scrollBar.OtherScrollBar is { IsVertical: true }) { - scrollBar.OtherScrollBarView.Position = ScrollRowsSize; + scrollBar.OtherScrollBar.Position = ScrollRowsSize; return true; } @@ -383,9 +383,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: true }) + if (scrollBar.OtherScrollBar is { IsVertical: true }) { - scrollBar.OtherScrollBarView.Position += ContentArea.Height; + scrollBar.OtherScrollBar.Position += ContentArea.Height; return true; } @@ -404,9 +404,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: true }) + if (scrollBar.OtherScrollBar is { IsVertical: true }) { - scrollBar.OtherScrollBarView.Position -= ContentArea.Height; + scrollBar.OtherScrollBar.Position -= ContentArea.Height; return true; } @@ -436,9 +436,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: false }) + if (scrollBar.OtherScrollBar is { IsVertical: false }) { - scrollBar.OtherScrollBarView.Position--; + scrollBar.OtherScrollBar.Position--; return true; } @@ -457,9 +457,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: false }) + if (scrollBar.OtherScrollBar is { IsVertical: false }) { - scrollBar.OtherScrollBarView.Position++; + scrollBar.OtherScrollBar.Position++; return true; } @@ -478,9 +478,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: false }) + if (scrollBar.OtherScrollBar is { IsVertical: false }) { - scrollBar.OtherScrollBarView.Position = 0; + scrollBar.OtherScrollBar.Position = 0; return true; } @@ -499,9 +499,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: false }) + if (scrollBar.OtherScrollBar is { IsVertical: false }) { - scrollBar.OtherScrollBarView.Position = ScrollColsSize; + scrollBar.OtherScrollBar.Position = ScrollColsSize; return true; } @@ -520,9 +520,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: false }) + if (scrollBar.OtherScrollBar is { IsVertical: false }) { - scrollBar.OtherScrollBarView.Position += ContentArea.Width; + scrollBar.OtherScrollBar.Position += ContentArea.Width; return true; } @@ -541,9 +541,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: false }) + if (scrollBar.OtherScrollBar is { IsVertical: false }) { - scrollBar.OtherScrollBarView.Position -= ContentArea.Width; + scrollBar.OtherScrollBar.Position -= ContentArea.Width; return true; } @@ -570,20 +570,20 @@ private void DisposeScrollBar () _scrollBar.ChangedPosition -= ScrollBar_ChangedPosition; - if (_scrollBar.OtherScrollBarView != null) + if (_scrollBar.OtherScrollBar != null) { - _scrollBar.OtherScrollBarView.ChangedPosition -= OtherScrollBarView_ChangedPosition; + _scrollBar.OtherScrollBar.ChangedPosition -= OtherScrollBar_ChangedPosition; } _scrollBar.RemoveAll (); _scrollBar = null; } - private void OtherScrollBarView_ChangedPosition (object sender, EventArgs e) { SetBoundsByPosition (_scrollBar.OtherScrollBarView); } + private void OtherScrollBar_ChangedPosition (object sender, EventArgs e) { SetBoundsByPosition (_scrollBar.OtherScrollBar); } private void ScrollBar_ChangedPosition (object sender, EventArgs e) { SetBoundsByPosition (_scrollBar); } - private void SetBoundsByPosition (ScrollBarView scrollBar) + private void SetBoundsByPosition (ScrollBar scrollBar) { if (scrollBar.IsVertical) { diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBar.cs similarity index 87% rename from Terminal.Gui/Views/ScrollBarView.cs rename to Terminal.Gui/Views/ScrollBar.cs index a0df0dcb55..2c6f9b026f 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBar.cs @@ -1,5 +1,5 @@ // -// ScrollBarView.cs: ScrollBarView view. +// ScrollBar.cs: ScrollBar view. // // Authors: // Miguel de Icaza (miguel@gnome.org) @@ -7,7 +7,7 @@ namespace Terminal.Gui; -/// ScrollBarViews are views that display a 1-character scrollbar, either horizontal or vertical +/// ScrollBars are views that display a 1-character scrollbar, either horizontal or vertical /// /// /// The scrollbar is drawn to be a representation of the Size, assuming that the scroll position is set at @@ -15,13 +15,13 @@ namespace Terminal.Gui; /// /// If the region to display the scrollbar is larger than three characters, arrow indicators are drawn. /// -public class ScrollBarView : View +public class ScrollBar : View { private bool _autoHideScrollBars = true; private View _contentBottomRightCorner; private bool _keepContentAlwaysInViewport = true; private int _lastLocation = -1; - private ScrollBarView _otherScrollBarView; + private ScrollBar _otherScrollBar; private int _posBarOffset; private int _posBottomTee; private int _posLeftTee; @@ -32,18 +32,18 @@ public class ScrollBarView : View private bool _vertical; /// - /// Initializes a new instance of the class using + /// Initializes a new instance of the class using /// layout. /// - public ScrollBarView () + public ScrollBar () { ShowScrollIndicator = true; WantContinuousButtonPressed = true; ClearOnVisibleFalse = false; CanFocus = false; - Added += ScrollBarView_Added; - Initialized += ScrollBarView_Initialized; + Added += ScrollBar_Added; + Initialized += ScrollBar_Initialized; } /// If true the vertical/horizontal scroll bars won't be showed if it's not needed. @@ -75,7 +75,7 @@ public bool IsVertical } } - /// Get or sets if the view-port is kept always visible in the area of this + /// Get or sets if the view-port is kept always visible in the area of this public bool KeepContentAlwaysInViewPort { get => _keepContentAlwaysInViewport; @@ -90,25 +90,25 @@ public bool KeepContentAlwaysInViewPort } } - /// Represent a vertical or horizontal ScrollBarView other than this. - public ScrollBarView OtherScrollBarView + /// Represent a vertical or horizontal ScrollBar other than this. + public ScrollBar OtherScrollBar { - get => _otherScrollBarView; + get => _otherScrollBar; set { if (value is { } && ((value.IsVertical && _vertical) || (!value.IsVertical && !_vertical))) { throw new ArgumentException ( - $"There is already a {(_vertical ? "vertical" : "horizontal")} ScrollBarView." + $"There is already a {(_vertical ? "vertical" : "horizontal")} ScrollBar." ); } - _otherScrollBarView = value; - _otherScrollBarView._otherScrollBarView = this; + _otherScrollBar = value; + _otherScrollBar._otherScrollBar = this; - if (SuperView != null && _otherScrollBarView?.SuperView is null && !SuperView.Subviews.Contains (_otherScrollBarView)) + if (SuperView != null && _otherScrollBar?.SuperView is null && !SuperView.Subviews.Contains (_otherScrollBar)) { - SuperView.Add (_otherScrollBarView); + SuperView.Add (_otherScrollBar); } } } @@ -178,7 +178,7 @@ public int Size internal bool IsBuiltIn => SuperView is Adornment; - private bool _showBothScrollIndicator => OtherScrollBarView?._showScrollIndicator == true && _showScrollIndicator; + private bool _showBothScrollIndicator => OtherScrollBar?._showScrollIndicator == true && _showScrollIndicator; /// This event is raised when the position on the scrollbar has changed. public event EventHandler ChangedPosition; @@ -672,9 +672,9 @@ private void AdjustContentInViewport (bool refresh = true) Position = pos; } - if (OtherScrollBarView is { } && OtherScrollBarView.KeepContentAlwaysInViewPort != KeepContentAlwaysInViewPort) + if (OtherScrollBar is { } && OtherScrollBar.KeepContentAlwaysInViewPort != KeepContentAlwaysInViewPort) { - OtherScrollBarView.KeepContentAlwaysInViewPort = KeepContentAlwaysInViewPort; + OtherScrollBar.KeepContentAlwaysInViewPort = KeepContentAlwaysInViewPort; } if (pos == 0 && refresh) @@ -683,7 +683,7 @@ private void AdjustContentInViewport (bool refresh = true) } } - private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = false) + private bool CheckBothScrollBars (ScrollBar scrollBarView, bool pending = false) { int barsize = scrollBarView._vertical ? scrollBarView.Bounds.Height : scrollBarView.Bounds.Width; @@ -699,7 +699,7 @@ private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = fa scrollBarView.Visible = false; } } - else if (barsize > 0 && barsize == scrollBarView._size && scrollBarView.OtherScrollBarView is { } && pending) + else if (barsize > 0 && barsize == scrollBarView._size && scrollBarView.OtherScrollBar is { } && pending) { if (scrollBarView._showScrollIndicator) { @@ -711,32 +711,32 @@ private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = fa scrollBarView.Visible = false; } - if (scrollBarView.OtherScrollBarView is { } && scrollBarView._showBothScrollIndicator) + if (scrollBarView.OtherScrollBar is { } && scrollBarView._showBothScrollIndicator) { - scrollBarView.OtherScrollBarView.ShowScrollIndicator = false; + scrollBarView.OtherScrollBar.ShowScrollIndicator = false; } - if (scrollBarView.OtherScrollBarView.Visible) + if (scrollBarView.OtherScrollBar.Visible) { - scrollBarView.OtherScrollBarView.Visible = false; + scrollBarView.OtherScrollBar.Visible = false; } } - else if (barsize > 0 && barsize == _size && scrollBarView.OtherScrollBarView is { } && !pending) + else if (barsize > 0 && barsize == _size && scrollBarView.OtherScrollBar is { } && !pending) { pending = true; } else { - if (scrollBarView.OtherScrollBarView is { } && pending) + if (scrollBarView.OtherScrollBar is { } && pending) { if (!scrollBarView._showBothScrollIndicator) { - scrollBarView.OtherScrollBarView.ShowScrollIndicator = true; + scrollBarView.OtherScrollBar.ShowScrollIndicator = true; } - if (!scrollBarView.OtherScrollBarView.Visible) + if (!scrollBarView.OtherScrollBar.Visible) { - scrollBarView.OtherScrollBarView.Visible = true; + scrollBarView.OtherScrollBar.Visible = true; } } @@ -798,8 +798,8 @@ private void ContentBottomRightCorner_MouseClick (object sender, MouseEventEvent private void CreateBottomRightCorner (View host) { if (host != null - && ((_contentBottomRightCorner is null && OtherScrollBarView is null) - || (_contentBottomRightCorner is null && OtherScrollBarView is { } && OtherScrollBarView._contentBottomRightCorner is null))) + && ((_contentBottomRightCorner is null && OtherScrollBar is null) + || (_contentBottomRightCorner is null && OtherScrollBar is { } && OtherScrollBar._contentBottomRightCorner is null))) { if (IsBuiltIn && ((Adornment)host).Parent.ScrollBarType != ScrollBarType.Both) { @@ -827,11 +827,11 @@ private void CreateBottomRightCorner (View host) } else if (host != null && _contentBottomRightCorner == null - && OtherScrollBarView != null - && OtherScrollBarView._contentBottomRightCorner != null) + && OtherScrollBar != null + && OtherScrollBar._contentBottomRightCorner != null) { - _contentBottomRightCorner = OtherScrollBarView._contentBottomRightCorner; + _contentBottomRightCorner = OtherScrollBar._contentBottomRightCorner; } } @@ -873,13 +873,13 @@ private void ManageScrollBarThickness () 0, IsVertical ? ShowScrollIndicator ? 1 : 0 - : OtherScrollBarView?.IsVertical == true - ? OtherScrollBarView?.ShowScrollIndicator == true ? 1 : 0 + : OtherScrollBar?.IsVertical == true + ? OtherScrollBar?.ShowScrollIndicator == true ? 1 : 0 : 0, !IsVertical ? ShowScrollIndicator ? 1 : 0 - : OtherScrollBarView?.IsVertical == false - ? OtherScrollBarView?.ShowScrollIndicator == true ? 1 : 0 + : OtherScrollBar?.IsVertical == false + ? OtherScrollBar?.ShowScrollIndicator == true ? 1 : 0 : 0), _ => throw new ArgumentOutOfRangeException () }; @@ -891,9 +891,9 @@ private void Parent_EnabledChanged (object sender, EventArgs e) { Enabled = SuperView.Enabled; - if (_otherScrollBarView is { }) + if (_otherScrollBar is { }) { - _otherScrollBarView.Enabled = Enabled; + _otherScrollBar.Enabled = Enabled; } _contentBottomRightCorner.Enabled = Enabled; @@ -905,9 +905,9 @@ private void Parent_VisibleChanged (object sender, EventArgs e) { Visible = SuperView.Visible; - if (_otherScrollBarView is { }) + if (_otherScrollBar is { }) { - _otherScrollBarView.Visible = Visible; + _otherScrollBar.Visible = Visible; } _contentBottomRightCorner.Visible = Visible; @@ -918,7 +918,7 @@ private void Parent_VisibleChanged (object sender, EventArgs e) } } - private void ScrollBarView_Added (object sender, SuperViewChangedEventArgs e) + private void ScrollBar_Added (object sender, SuperViewChangedEventArgs e) { if (IsBuiltIn) { @@ -931,9 +931,9 @@ private void ScrollBarView_Added (object sender, SuperViewChangedEventArgs e) Y = IsVertical ? 0 : Pos.AnchorEnd (1); } - if (OtherScrollBarView is { SuperView: null } && !e.Parent.Subviews.Contains (OtherScrollBarView)) + if (OtherScrollBar is { SuperView: null } && !e.Parent.Subviews.Contains (OtherScrollBar)) { - e.Parent.Add (OtherScrollBarView); + e.Parent.Add (OtherScrollBar); } CreateBottomRightCorner (e.Parent); @@ -948,7 +948,7 @@ private void ScrollBarView_Added (object sender, SuperViewChangedEventArgs e) ManageScrollBarThickness (); } - private void ScrollBarView_Initialized (object sender, EventArgs e) + private void ScrollBar_Initialized (object sender, EventArgs e) { SetWidthHeight (); ShowHideScrollBars (); @@ -986,9 +986,9 @@ private void SetPosition (int newPosition) OnChangedPosition (); SetNeedsDisplay (); - OtherScrollBarView?.SetNeedsDisplay (); + OtherScrollBar?.SetNeedsDisplay (); _contentBottomRightCorner?.SetNeedsDisplay (); - OtherScrollBarView?._contentBottomRightCorner?.SetNeedsDisplay (); + OtherScrollBar?._contentBottomRightCorner?.SetNeedsDisplay (); } // BUGBUG: v2 - rationalize this with View.SetMinWidthHeight @@ -1004,10 +1004,10 @@ private void SetWidthHeight () Width = _vertical ? 1 : SuperView is Adornment ? Dim.Fill () : Dim.Fill (1); Height = _vertical ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) : 1; - _otherScrollBarView.Width = _otherScrollBarView._vertical ? 1 : + _otherScrollBar.Width = _otherScrollBar._vertical ? 1 : SuperView is Adornment ? Dim.Fill () : Dim.Fill (1); - _otherScrollBarView.Height = _otherScrollBarView._vertical + _otherScrollBar.Height = _otherScrollBar._vertical ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) : 1; } @@ -1016,11 +1016,11 @@ private void SetWidthHeight () Width = _vertical ? 1 : Dim.Fill (); Height = _vertical ? Dim.Fill () : 1; } - else if (_otherScrollBarView?._showScrollIndicator == true) + else if (_otherScrollBar?._showScrollIndicator == true) { - _otherScrollBarView.Width = _otherScrollBarView._vertical ? 1 : Dim.Fill (); + _otherScrollBar.Width = _otherScrollBar._vertical ? 1 : Dim.Fill (); - _otherScrollBarView.Height = _otherScrollBarView._vertical ? Dim.Fill () : 1; + _otherScrollBar.Height = _otherScrollBar._vertical ? Dim.Fill () : 1; } if (IsBuiltIn) @@ -1043,20 +1043,20 @@ private void ShowHideScrollBars (bool redraw = true) { bool pending = CheckBothScrollBars (this); - if (_otherScrollBarView is { }) + if (_otherScrollBar is { }) { - _otherScrollBarView.SetRelativeLayout (SuperView?.Bounds ?? Bounds); - CheckBothScrollBars (_otherScrollBarView, pending); + _otherScrollBar.SetRelativeLayout (SuperView?.Bounds ?? Bounds); + CheckBothScrollBars (_otherScrollBar, pending); } } SetWidthHeight (); SetRelativeLayout (SuperView?.Bounds ?? Bounds); - if (_otherScrollBarView is { }) + if (_otherScrollBar is { }) { - OtherScrollBarView.SetWidthHeight (); - OtherScrollBarView.SetRelativeLayout (SuperView?.Bounds ?? Bounds); + OtherScrollBar.SetWidthHeight (); + OtherScrollBar.SetRelativeLayout (SuperView?.Bounds ?? Bounds); } if (_showBothScrollIndicator) @@ -1065,9 +1065,9 @@ private void ShowHideScrollBars (bool redraw = true) { _contentBottomRightCorner.Visible = true; } - else if (_otherScrollBarView is { } && _otherScrollBarView._contentBottomRightCorner is { }) + else if (_otherScrollBar is { } && _otherScrollBar._contentBottomRightCorner is { }) { - _otherScrollBarView._contentBottomRightCorner.Visible = true; + _otherScrollBar._contentBottomRightCorner.Visible = true; } } else if (!_showScrollIndicator) @@ -1076,9 +1076,9 @@ private void ShowHideScrollBars (bool redraw = true) { _contentBottomRightCorner.Visible = false; } - else if (_otherScrollBarView is { } && _otherScrollBarView._contentBottomRightCorner is { }) + else if (_otherScrollBar is { } && _otherScrollBar._contentBottomRightCorner is { }) { - _otherScrollBarView._contentBottomRightCorner.Visible = false; + _otherScrollBar._contentBottomRightCorner.Visible = false; } if (Application.MouseGrabView is { } && Application.MouseGrabView == this) @@ -1090,9 +1090,9 @@ private void ShowHideScrollBars (bool redraw = true) { _contentBottomRightCorner.Visible = false; } - else if (_otherScrollBarView is { } && _otherScrollBarView._contentBottomRightCorner is { }) + else if (_otherScrollBar is { } && _otherScrollBar._contentBottomRightCorner is { }) { - _otherScrollBarView._contentBottomRightCorner.Visible = false; + _otherScrollBar._contentBottomRightCorner.Visible = false; } if (SuperView?.Visible == true && _showScrollIndicator && !Visible) @@ -1100,9 +1100,9 @@ private void ShowHideScrollBars (bool redraw = true) Visible = true; } - if (SuperView?.Visible == true && _otherScrollBarView?._showScrollIndicator == true && !_otherScrollBarView.Visible) + if (SuperView?.Visible == true && _otherScrollBar?._showScrollIndicator == true && !_otherScrollBar.Visible) { - _otherScrollBarView.Visible = true; + _otherScrollBar.Visible = true; } } diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index 19aeabe751..356f34807d 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -28,8 +28,8 @@ namespace Terminal.Gui; public class ScrollView : View { private readonly ContentView _contentView; - private readonly ScrollBarView _horizontal; - private readonly ScrollBarView _vertical; + private readonly ScrollBar _horizontal; + private readonly ScrollBar _vertical; private View _contentBottomRightCorner; private Point _contentOffset; private Size _contentSize; @@ -43,7 +43,7 @@ public ScrollView () _contentView = new ContentView (); base.Add (_contentView); - _vertical = new ScrollBarView + _vertical = new ScrollBar { X = Pos.AnchorEnd (1), Y = 0, @@ -52,7 +52,7 @@ public ScrollView () IsVertical = true }; - _horizontal = new ScrollBarView + _horizontal = new ScrollBar { X = 0, Y = Pos.AnchorEnd (1), @@ -60,11 +60,11 @@ public ScrollView () Size = 1, IsVertical = false }; - _vertical.OtherScrollBarView = _horizontal; - _horizontal.OtherScrollBarView = _vertical; + _vertical.OtherScrollBar = _horizontal; + _horizontal.OtherScrollBar = _vertical; // The _horizontal will be automatically added - // through the OtherScrollBarView property + // through the OtherScrollBar property base.Add (_vertical); CanFocus = true; @@ -220,7 +220,7 @@ public bool ShowHorizontalScrollIndicator if (value) { - _horizontal.OtherScrollBarView = _vertical; + _horizontal.OtherScrollBar = _vertical; if (!Subviews.Contains (_horizontal)) { @@ -229,7 +229,7 @@ public bool ShowHorizontalScrollIndicator _horizontal.ShowScrollIndicator = true; _horizontal.AutoHideScrollBars = AutoHideScrollBars; - _horizontal.OtherScrollBarView.ShowScrollIndicator = true; + _horizontal.OtherScrollBar.ShowScrollIndicator = true; _horizontal.MouseEnter += View_MouseEnter; _horizontal.MouseLeave += View_MouseLeave; } @@ -258,7 +258,7 @@ public bool ShowVerticalScrollIndicator if (value) { - _vertical.OtherScrollBarView = _horizontal; + _vertical.OtherScrollBar = _horizontal; if (!Subviews.Contains (_vertical)) { @@ -267,7 +267,7 @@ public bool ShowVerticalScrollIndicator _vertical.ShowScrollIndicator = true; _vertical.AutoHideScrollBars = AutoHideScrollBars; - _vertical.OtherScrollBarView.ShowScrollIndicator = true; + _vertical.OtherScrollBar.ShowScrollIndicator = true; _vertical.MouseEnter += View_MouseEnter; _vertical.MouseLeave += View_MouseLeave; } @@ -286,12 +286,12 @@ public bool ShowVerticalScrollIndicator /// The view to add to the scrollview. public override void Add (View view) { - if (view is ScrollBarView.ContentBottomRightCorner) + if (view is ScrollBar.ContentBottomRightCorner) { _contentBottomRightCorner = view; base.Add (view); } - else if (view is ScrollBarView) + else if (view is ScrollBar) { base.Add (view); } diff --git a/Terminal.Gui/Views/Wizard/WizardStep.cs b/Terminal.Gui/Views/Wizard/WizardStep.cs index 490307ee0b..a9c5fbd281 100644 --- a/Terminal.Gui/Views/Wizard/WizardStep.cs +++ b/Terminal.Gui/Views/Wizard/WizardStep.cs @@ -53,7 +53,7 @@ public WizardStep () base.Add (_helpTextView); // BUGBUG: v2 - Disabling scrolling for now - //var scrollBar = new ScrollBarView (helpTextView, true); + //var scrollBar = new ScrollBar (helpTextView, true); //scrollBar.ChangedPosition += (s,e) => { // helpTextView.TopRow = scrollBar.Position; @@ -63,10 +63,10 @@ public WizardStep () // helpTextView.SetNeedsDisplay (); //}; - //scrollBar.OtherScrollBarView.ChangedPosition += (s,e) => { - // helpTextView.LeftColumn = scrollBar.OtherScrollBarView.Position; - // if (helpTextView.LeftColumn != scrollBar.OtherScrollBarView.Position) { - // scrollBar.OtherScrollBarView.Position = helpTextView.LeftColumn; + //scrollBar.OtherScrollBar.ChangedPosition += (s,e) => { + // helpTextView.LeftColumn = scrollBar.OtherScrollBar.Position; + // if (helpTextView.LeftColumn != scrollBar.OtherScrollBar.Position) { + // scrollBar.OtherScrollBar.Position = helpTextView.LeftColumn; // } // helpTextView.SetNeedsDisplay (); //}; @@ -79,10 +79,10 @@ public WizardStep () // } //}; - //scrollBar.OtherScrollBarView.VisibleChanged += (s,e) => { - // if (scrollBar.OtherScrollBarView.Visible && helpTextView.BottomOffset == 0) { + //scrollBar.OtherScrollBar.VisibleChanged += (s,e) => { + // if (scrollBar.OtherScrollBar.Visible && helpTextView.BottomOffset == 0) { // helpTextView.BottomOffset = 1; - // } else if (!scrollBar.OtherScrollBarView.Visible && helpTextView.BottomOffset == 1) { + // } else if (!scrollBar.OtherScrollBar.Visible && helpTextView.BottomOffset == 1) { // helpTextView.BottomOffset = 0; // } //}; @@ -90,9 +90,9 @@ public WizardStep () //helpTextView.DrawContent += (s,e) => { // scrollBar.Size = helpTextView.Lines; // scrollBar.Position = helpTextView.TopRow; - // if (scrollBar.OtherScrollBarView is { }) { - // scrollBar.OtherScrollBarView.Size = helpTextView.Maxlength; - // scrollBar.OtherScrollBarView.Position = helpTextView.LeftColumn; + // if (scrollBar.OtherScrollBar is { }) { + // scrollBar.OtherScrollBar.Size = helpTextView.Maxlength; + // scrollBar.OtherScrollBar.Position = helpTextView.LeftColumn; // } // scrollBar.LayoutSubviews (); // scrollBar.Refresh (); diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index 6b46c70fc2..6e3c7eb2b5 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -193,7 +193,7 @@ public override void Init () ) } ), - new MenuBarItem ("_ScrollBarView", CreateKeepChecked ()), + new MenuBarItem ("_ScrollBar", CreateKeepChecked ()), new MenuBarItem ("_Cursor", CreateCursorRadio ()), new MenuBarItem ( "Forma_t", diff --git a/UnitTests/Input/ResponderTests.cs b/UnitTests/Input/ResponderTests.cs index 5bed852579..2aa197fcc5 100644 --- a/UnitTests/Input/ResponderTests.cs +++ b/UnitTests/Input/ResponderTests.cs @@ -158,10 +158,10 @@ public void IsOverridden_False_IfNotOverridden () [TestRespondersDisposed] public void IsOverridden_True_IfOverridden () { - // MouseEvent is defined on Responder IS overriden on ScrollBarView (but not View) + // MouseEvent is defined on Responder IS overriden on ScrollBar (but not View) Assert.True ( Responder.IsOverridden ( - new ScrollBarView { Text = "ScrollBarView overrides MouseEvent" }, + new ScrollBar { Text = "ScrollBar overrides MouseEvent" }, "MouseEvent" ) ); @@ -177,17 +177,17 @@ public void IsOverridden_True_IfOverridden () ) ); - // ScrollBarView overrides both MouseEvent (from Responder) and Redraw (from View) + // ScrollBar overrides both MouseEvent (from Responder) and Redraw (from View) Assert.True ( Responder.IsOverridden ( - new ScrollBarView { Text = "ScrollBarView overrides MouseEvent" }, + new ScrollBar { Text = "ScrollBar overrides MouseEvent" }, "MouseEvent" ) ); Assert.True ( Responder.IsOverridden ( - new ScrollBarView { Text = "ScrollBarView overrides OnDrawContent" }, + new ScrollBar { Text = "ScrollBar overrides OnDrawContent" }, "OnDrawContent" ) ); diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarTests.cs similarity index 80% rename from UnitTests/Views/ScrollBarViewTests.cs rename to UnitTests/Views/ScrollBarTests.cs index bf4ee90981..9eeb886d1e 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarTests.cs @@ -3,19 +3,19 @@ namespace Terminal.Gui.ViewsTests; -public class ScrollBarViewTests +public class ScrollBarTests { private static HostView _hostView; private readonly ITestOutputHelper _output; private bool _added; - private ScrollBarView _scrollBar; - public ScrollBarViewTests (ITestOutputHelper output) { _output = output; } + private ScrollBar _scrollBar; + public ScrollBarTests (ITestOutputHelper output) { _output = output; } [Fact] [ScrollBarAutoInitShutdown] public void AutoHideScrollBars_Check () { - Hosting_A_View_To_A_ScrollBarView (); + Hosting_A_View_To_A_ScrollBar (); AddHandlers (); @@ -30,16 +30,16 @@ public void AutoHideScrollBars_Check () _scrollBar.Height.ToString () ); Assert.Equal (24, _scrollBar.Bounds.Height); - Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); - Assert.True (_scrollBar.OtherScrollBarView.Visible); + Assert.True (_scrollBar.OtherScrollBar.ShowScrollIndicator); + Assert.True (_scrollBar.OtherScrollBar.Visible); Assert.Equal ( "Fill(1)", - _scrollBar.OtherScrollBarView.Width.ToString () + _scrollBar.OtherScrollBar.Width.ToString () ); - Assert.Equal (79, _scrollBar.OtherScrollBarView.Bounds.Width); - Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ()); - Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height); + Assert.Equal (79, _scrollBar.OtherScrollBar.Bounds.Width); + Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBar.Height.ToString ()); + Assert.Equal (1, _scrollBar.OtherScrollBar.Bounds.Height); _hostView.Lines = 10; _hostView.Draw (); @@ -53,16 +53,16 @@ public void AutoHideScrollBars_Check () _scrollBar.Height.ToString () ); Assert.Equal (24, _scrollBar.Bounds.Height); - Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); - Assert.True (_scrollBar.OtherScrollBarView.Visible); + Assert.True (_scrollBar.OtherScrollBar.ShowScrollIndicator); + Assert.True (_scrollBar.OtherScrollBar.Visible); Assert.Equal ( "Fill(0)", - _scrollBar.OtherScrollBarView.Width.ToString () + _scrollBar.OtherScrollBar.Width.ToString () ); - Assert.Equal (80, _scrollBar.OtherScrollBarView.Bounds.Width); - Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ()); - Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height); + Assert.Equal (80, _scrollBar.OtherScrollBar.Bounds.Width); + Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBar.Height.ToString ()); + Assert.Equal (1, _scrollBar.OtherScrollBar.Bounds.Height); _hostView.Cols = 60; _hostView.Draw (); @@ -76,16 +76,16 @@ public void AutoHideScrollBars_Check () _scrollBar.Height.ToString () ); Assert.Equal (24, _scrollBar.Bounds.Height); - Assert.False (_scrollBar.OtherScrollBarView.ShowScrollIndicator); - Assert.False (_scrollBar.OtherScrollBarView.Visible); + Assert.False (_scrollBar.OtherScrollBar.ShowScrollIndicator); + Assert.False (_scrollBar.OtherScrollBar.Visible); Assert.Equal ( "Fill(0)", - _scrollBar.OtherScrollBarView.Width.ToString () + _scrollBar.OtherScrollBar.Width.ToString () ); - Assert.Equal (80, _scrollBar.OtherScrollBarView.Bounds.Width); - Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ()); - Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height); + Assert.Equal (80, _scrollBar.OtherScrollBar.Bounds.Width); + Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBar.Height.ToString ()); + Assert.Equal (1, _scrollBar.OtherScrollBar.Bounds.Height); _hostView.Lines = 40; _hostView.Draw (); @@ -99,16 +99,16 @@ public void AutoHideScrollBars_Check () _scrollBar.Height.ToString () ); Assert.Equal (25, _scrollBar.Bounds.Height); - Assert.False (_scrollBar.OtherScrollBarView.ShowScrollIndicator); - Assert.False (_scrollBar.OtherScrollBarView.Visible); + Assert.False (_scrollBar.OtherScrollBar.ShowScrollIndicator); + Assert.False (_scrollBar.OtherScrollBar.Visible); Assert.Equal ( "Fill(0)", - _scrollBar.OtherScrollBarView.Width.ToString () + _scrollBar.OtherScrollBar.Width.ToString () ); - Assert.Equal (80, _scrollBar.OtherScrollBarView.Bounds.Width); - Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ()); - Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height); + Assert.Equal (80, _scrollBar.OtherScrollBar.Bounds.Width); + Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBar.Height.ToString ()); + Assert.Equal (1, _scrollBar.OtherScrollBar.Bounds.Height); _hostView.Cols = 120; _hostView.Draw (); @@ -122,16 +122,16 @@ public void AutoHideScrollBars_Check () _scrollBar.Height.ToString () ); Assert.Equal (24, _scrollBar.Bounds.Height); - Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); - Assert.True (_scrollBar.OtherScrollBarView.Visible); + Assert.True (_scrollBar.OtherScrollBar.ShowScrollIndicator); + Assert.True (_scrollBar.OtherScrollBar.Visible); Assert.Equal ( "Fill(1)", - _scrollBar.OtherScrollBarView.Width.ToString () + _scrollBar.OtherScrollBar.Width.ToString () ); - Assert.Equal (79, _scrollBar.OtherScrollBarView.Bounds.Width); - Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ()); - Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height); + Assert.Equal (79, _scrollBar.OtherScrollBar.Bounds.Width); + Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBar.Height.ToString ()); + Assert.Equal (1, _scrollBar.OtherScrollBar.Bounds.Height); } [Fact] @@ -144,7 +144,7 @@ public void Both_Default_Draws_Correctly () var super = new Window { Id = "super", Width = Dim.Fill (), Height = Dim.Fill () }; Application.Top.Add (super); - var horiz = new ScrollBarView + var horiz = new ScrollBar { Id = "horiz", Size = width * 2, @@ -154,14 +154,14 @@ public void Both_Default_Draws_Correctly () }; super.Add (horiz); - var vert = new ScrollBarView + var vert = new ScrollBar { Id = "vert", Size = height * 2, ShowScrollIndicator = true, IsVertical = true, - OtherScrollBarView = horiz + OtherScrollBar = horiz }; super.Add (vert); @@ -216,7 +216,7 @@ public void Both_Default_Draws_Correctly () [ScrollBarAutoInitShutdown] public void ChangedPosition_Negative_Value () { - Hosting_A_View_To_A_ScrollBarView (); + Hosting_A_View_To_A_ScrollBar (); AddHandlers (); @@ -224,16 +224,16 @@ public void ChangedPosition_Negative_Value () Assert.Equal (0, _scrollBar.Position); Assert.Equal (_scrollBar.Position, _hostView.Top); - _scrollBar.OtherScrollBarView.Position = -50; - Assert.Equal (0, _scrollBar.OtherScrollBarView.Position); - Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); + _scrollBar.OtherScrollBar.Position = -50; + Assert.Equal (0, _scrollBar.OtherScrollBar.Position); + Assert.Equal (_scrollBar.OtherScrollBar.Position, _hostView.Left); } [Fact] [ScrollBarAutoInitShutdown] public void ChangedPosition_Scrolling () { - Hosting_A_View_To_A_ScrollBarView (); + Hosting_A_View_To_A_ScrollBar (); AddHandlers (); @@ -249,16 +249,16 @@ public void ChangedPosition_Scrolling () Assert.Equal (_scrollBar.Position, _hostView.Top); } - for (var i = 0; i < _scrollBar.OtherScrollBarView.Size; i++) + for (var i = 0; i < _scrollBar.OtherScrollBar.Size; i++) { - _scrollBar.OtherScrollBarView.Position += i; - Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); + _scrollBar.OtherScrollBar.Position += i; + Assert.Equal (_scrollBar.OtherScrollBar.Position, _hostView.Left); } - for (int i = _scrollBar.OtherScrollBarView.Size - 1; i >= 0; i--) + for (int i = _scrollBar.OtherScrollBar.Size - 1; i >= 0; i--) { - _scrollBar.OtherScrollBarView.Position -= 1; - Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); + _scrollBar.OtherScrollBar.Position -= 1; + Assert.Equal (_scrollBar.OtherScrollBar.Position, _hostView.Left); } } @@ -266,15 +266,15 @@ public void ChangedPosition_Scrolling () [ScrollBarAutoInitShutdown] public void ChangedPosition_Update_The_Hosted_View () { - Hosting_A_View_To_A_ScrollBarView (); + Hosting_A_View_To_A_ScrollBar (); AddHandlers (); _scrollBar.Position = 2; Assert.Equal (_scrollBar.Position, _hostView.Top); - _scrollBar.OtherScrollBarView.Position = 5; - Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); + _scrollBar.OtherScrollBar.Position = 5; + Assert.Equal (_scrollBar.OtherScrollBar.Position, _hostView.Left); } [Fact] @@ -286,7 +286,7 @@ public void ClearOnVisibleFalse_Gets_Sets () var label = new Label { Text = text }; Application.Top.Add (label); - var sbv = new ScrollBarView { IsVertical = true, Size = 100, ClearOnVisibleFalse = false }; + var sbv = new ScrollBar { IsVertical = true, Size = 100, ClearOnVisibleFalse = false }; label.Add (sbv); Application.Begin (Application.Top); @@ -411,42 +411,42 @@ public void Assert.True (listView.ScrollKeepContentAlwaysInViewPort); - var newScrollBarView = listView.Padding.Subviews [0] as ScrollBarView; + var newScrollBar = listView.Padding.Subviews [0] as ScrollBar; - newScrollBarView!.ChangedPosition += (s, e) => + newScrollBar!.ChangedPosition += (s, e) => { - listView.LeftItem = newScrollBarView.Position; + listView.LeftItem = newScrollBar.Position; - if (listView.LeftItem != newScrollBarView.Position) + if (listView.LeftItem != newScrollBar.Position) { - newScrollBarView.Position = listView.LeftItem; + newScrollBar.Position = listView.LeftItem; } - Assert.Equal (newScrollBarView.Position, listView.LeftItem); + Assert.Equal (newScrollBar.Position, listView.LeftItem); listView.SetNeedsDisplay (); }; listView.DrawContent += (s, e) => { - newScrollBarView.Size = listView.MaxLength; - Assert.Equal (newScrollBarView.Size, listView.MaxLength); - newScrollBarView.Position = listView.LeftItem; - Assert.Equal (newScrollBarView.Position, listView.LeftItem); - newScrollBarView.Refresh (); + newScrollBar.Size = listView.MaxLength; + Assert.Equal (newScrollBar.Size, listView.MaxLength); + newScrollBar.Position = listView.LeftItem; + Assert.Equal (newScrollBar.Position, listView.LeftItem); + newScrollBar.Refresh (); }; top.Ready += (s, e) => { - newScrollBarView.Position = 100; + newScrollBar.Position = 100; Assert.Equal ( - newScrollBarView.Position, - newScrollBarView.Size + newScrollBar.Position, + newScrollBar.Size - listView.LeftItem + (listView.LeftItem - listView.Bounds.Width)); - Assert.Equal (newScrollBarView.Position, listView.LeftItem); + Assert.Equal (newScrollBar.Position, listView.LeftItem); - Assert.Equal (92, newScrollBarView.Position); + Assert.Equal (92, newScrollBar.Position); Assert.Equal (92, listView.LeftItem); Application.RequestStop (); }; @@ -487,43 +487,43 @@ public void Source = new ListWrapper (source) }; win.Add (listView); - var newScrollBarView = new ScrollBarView { IsVertical = true, KeepContentAlwaysInViewPort = true }; - listView.Add (newScrollBarView); + var newScrollBar = new ScrollBar { IsVertical = true, KeepContentAlwaysInViewPort = true }; + listView.Add (newScrollBar); - newScrollBarView.ChangedPosition += (s, e) => + newScrollBar.ChangedPosition += (s, e) => { - listView.TopItem = newScrollBarView.Position; + listView.TopItem = newScrollBar.Position; - if (listView.TopItem != newScrollBarView.Position) + if (listView.TopItem != newScrollBar.Position) { - newScrollBarView.Position = listView.TopItem; + newScrollBar.Position = listView.TopItem; } - Assert.Equal (newScrollBarView.Position, listView.TopItem); + Assert.Equal (newScrollBar.Position, listView.TopItem); listView.SetNeedsDisplay (); }; listView.DrawContent += (s, e) => { - newScrollBarView.Size = listView.Source.Count; - Assert.Equal (newScrollBarView.Size, listView.Source.Count); - newScrollBarView.Position = listView.TopItem; - Assert.Equal (newScrollBarView.Position, listView.TopItem); - newScrollBarView.Refresh (); + newScrollBar.Size = listView.Source.Count; + Assert.Equal (newScrollBar.Size, listView.Source.Count); + newScrollBar.Position = listView.TopItem; + Assert.Equal (newScrollBar.Position, listView.TopItem); + newScrollBar.Refresh (); }; top.Ready += (s, e) => { - newScrollBarView.Position = 45; + newScrollBar.Position = 45; Assert.Equal ( - newScrollBarView.Position, - newScrollBarView.Size + newScrollBar.Position, + newScrollBar.Size - listView.TopItem + (listView.TopItem - listView.Bounds.Height) ); - Assert.Equal (newScrollBarView.Position, listView.TopItem); - Assert.Equal (27, newScrollBarView.Position); + Assert.Equal (newScrollBar.Position, listView.TopItem); + Assert.Equal (27, newScrollBar.Position); Assert.Equal (27, listView.TopItem); Application.RequestStop (); }; @@ -543,22 +543,22 @@ public void ContentBottomRightCorner_Not_Redraw_If_Both_Size_Equal_To_Zero () var text = "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test"; var label = new Label { Text = text }; - var sbv = new ScrollBarView { X = Pos.AnchorEnd (1), IsVertical = true, Size = 100 }; - sbv.OtherScrollBarView = new ScrollBarView { Y = Pos.AnchorEnd (1), IsVertical = false, Size = 100, OtherScrollBarView = sbv }; - label.Add (sbv, sbv.OtherScrollBarView); + var sbv = new ScrollBar { X = Pos.AnchorEnd (1), IsVertical = true, Size = 100 }; + sbv.OtherScrollBar = new ScrollBar { Y = Pos.AnchorEnd (1), IsVertical = false, Size = 100, OtherScrollBar = sbv }; + label.Add (sbv, sbv.OtherScrollBar); Application.Top.Add (label); Application.Begin (Application.Top); Assert.Equal (100, sbv.Size); - Assert.Equal (100, sbv.OtherScrollBarView.Size); + Assert.Equal (100, sbv.OtherScrollBar.Size); Assert.True (sbv.ShowScrollIndicator); - Assert.True (sbv.OtherScrollBarView.ShowScrollIndicator); + Assert.True (sbv.OtherScrollBar.ShowScrollIndicator); Assert.True (sbv.Visible); - Assert.True (sbv.OtherScrollBarView.Visible); + Assert.True (sbv.OtherScrollBar.Visible); View contentBottomRightCorner = - label.Subviews.First (v => v is ScrollBarView.ContentBottomRightCorner); - Assert.True (contentBottomRightCorner is ScrollBarView.ContentBottomRightCorner); + label.Subviews.First (v => v is ScrollBar.ContentBottomRightCorner); + Assert.True (contentBottomRightCorner is ScrollBar.ContentBottomRightCorner); Assert.True (contentBottomRightCorner.Visible); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -574,13 +574,13 @@ This is a tes▼ ); sbv.Size = 0; - sbv.OtherScrollBarView.Size = 0; + sbv.OtherScrollBar.Size = 0; Assert.Equal (0, sbv.Size); - Assert.Equal (0, sbv.OtherScrollBarView.Size); + Assert.Equal (0, sbv.OtherScrollBar.Size); Assert.False (sbv.ShowScrollIndicator); - Assert.False (sbv.OtherScrollBarView.ShowScrollIndicator); + Assert.False (sbv.OtherScrollBar.ShowScrollIndicator); Assert.False (sbv.Visible); - Assert.False (sbv.OtherScrollBarView.Visible); + Assert.False (sbv.OtherScrollBar.Visible); Application.Top.Draw (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -596,13 +596,13 @@ This is a test ); sbv.Size = 50; - sbv.OtherScrollBarView.Size = 50; + sbv.OtherScrollBar.Size = 50; Assert.Equal (50, sbv.Size); - Assert.Equal (50, sbv.OtherScrollBarView.Size); + Assert.Equal (50, sbv.OtherScrollBar.Size); Assert.True (sbv.ShowScrollIndicator); - Assert.True (sbv.OtherScrollBarView.ShowScrollIndicator); + Assert.True (sbv.OtherScrollBar.ShowScrollIndicator); Assert.True (sbv.Visible); - Assert.True (sbv.OtherScrollBarView.Visible); + Assert.True (sbv.OtherScrollBar.Visible); Application.Top.Draw (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -626,13 +626,13 @@ public void ContentBottomRightCorner_Not_Redraw_If_One_Size_Equal_To_Zero () "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test"; var label = new Label { Text = text }; - var sbv = new ScrollBarView { X = Pos.AnchorEnd (1), IsVertical = true, Size = 100 }; + var sbv = new ScrollBar { X = Pos.AnchorEnd (1), IsVertical = true, Size = 100 }; label.Add (sbv); Application.Top.Add (label); Application.Begin (Application.Top); Assert.Equal (100, sbv.Size); - Assert.Null (sbv.OtherScrollBarView); + Assert.Null (sbv.OtherScrollBar); Assert.True (sbv.ShowScrollIndicator); Assert.True (sbv.Visible); @@ -669,9 +669,9 @@ This is a test [Fact] [ScrollBarAutoInitShutdown] - public void DrawContent_Update_The_ScrollBarView_Position () + public void DrawContent_Update_The_ScrollBar_Position () { - Hosting_A_View_To_A_ScrollBarView (); + Hosting_A_View_To_A_ScrollBar (); AddHandlers (); @@ -681,7 +681,7 @@ public void DrawContent_Update_The_ScrollBarView_Position () _hostView.Left = 6; _hostView.Draw (); - Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); + Assert.Equal (_scrollBar.OtherScrollBar.Position, _hostView.Left); } [Fact] @@ -694,7 +694,7 @@ public void Horizontal_Default_Draws_Correctly () var super = new Window { Id = "super", Width = Dim.Fill (), Height = Dim.Fill () }; Application.Top.Add (super); - var sbv = new ScrollBarView { Id = "sbv", Size = width * 2, ShowScrollIndicator = true }; + var sbv = new ScrollBar { Id = "sbv", Size = width * 2, ShowScrollIndicator = true }; super.Add (sbv); Application.Begin (Application.Top); ((FakeDriver)Application.Driver).SetBufferSize (width, height); @@ -708,22 +708,22 @@ public void Horizontal_Default_Draws_Correctly () [Fact] [ScrollBarAutoInitShutdown] - public void Hosting_A_View_To_A_ScrollBarView () + public void Hosting_A_View_To_A_ScrollBar () { RemoveHandlers (); - _scrollBar = new ScrollBarView { IsVertical = true, OtherScrollBarView = new ScrollBarView { IsVertical = false } }; + _scrollBar = new ScrollBar { IsVertical = true, OtherScrollBar = new ScrollBar { IsVertical = false } }; _hostView.Add (_scrollBar); Application.Begin (Application.Top); Assert.True (_scrollBar.IsVertical); - Assert.False (_scrollBar.OtherScrollBarView.IsVertical); + Assert.False (_scrollBar.OtherScrollBar.IsVertical); Assert.Equal (_scrollBar.Position, _hostView.Top); Assert.NotEqual (_scrollBar.Size, _hostView.Lines); - Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); - Assert.NotEqual (_scrollBar.OtherScrollBarView.Size, _hostView.Cols); + Assert.Equal (_scrollBar.OtherScrollBar.Position, _hostView.Left); + Assert.NotEqual (_scrollBar.OtherScrollBar.Size, _hostView.Cols); AddHandlers (); _hostView.SuperView.LayoutSubviews (); @@ -731,8 +731,8 @@ public void Hosting_A_View_To_A_ScrollBarView () Assert.Equal (_scrollBar.Position, _hostView.Top); Assert.Equal (_scrollBar.Size, _hostView.Lines); - Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); - Assert.Equal (_scrollBar.OtherScrollBarView.Size, _hostView.Cols); + Assert.Equal (_scrollBar.OtherScrollBar.Position, _hostView.Left); + Assert.Equal (_scrollBar.OtherScrollBar.Size, _hostView.Cols); } [Fact] @@ -755,17 +755,17 @@ public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () Application.Begin (Application.Top); ((FakeDriver)Application.Driver).SetBufferSize (45, 20); - var scrollBar = textView.Padding.Subviews [0] as ScrollBarView; + var scrollBar = textView.Padding.Subviews [0] as ScrollBar; Assert.True (scrollBar.AutoHideScrollBars); Assert.False (scrollBar.ShowScrollIndicator); - Assert.False (scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.False (scrollBar.OtherScrollBar.ShowScrollIndicator); Assert.Equal (5, textView.Lines); // The length is one more for the cursor on the last column of the line Assert.Equal (43, textView.Maxlength); Assert.Equal (0, textView.LeftColumn); Assert.Equal (0, scrollBar.Position); - Assert.Equal (0, scrollBar.OtherScrollBarView.Position); + Assert.Equal (0, scrollBar.OtherScrollBar.Position); var expected = @" ┌───────────────────────────────────────────┐ @@ -805,7 +805,7 @@ public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () Assert.Equal (23, textView.Maxlength); Assert.Equal (0, textView.LeftColumn); Assert.Equal (0, scrollBar.Position); - Assert.Equal (0, scrollBar.OtherScrollBarView.Position); + Assert.Equal (0, scrollBar.OtherScrollBar.Position); expected = @" ┌────────────────────────┐ @@ -844,7 +844,7 @@ public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () Assert.Equal (7, textView.Maxlength); Assert.Equal (0, textView.LeftColumn); Assert.Equal (0, scrollBar.Position); - Assert.Equal (0, scrollBar.OtherScrollBarView.Position); + Assert.Equal (0, scrollBar.OtherScrollBar.Position); Assert.True (scrollBar.ShowScrollIndicator); expected = @" @@ -875,7 +875,7 @@ public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () Assert.Equal (7, textView.Maxlength); Assert.Equal (0, textView.LeftColumn); Assert.Equal (0, scrollBar.Position); - Assert.Equal (0, scrollBar.OtherScrollBarView.Position); + Assert.Equal (0, scrollBar.OtherScrollBar.Position); Assert.True (scrollBar.ShowScrollIndicator); expected = @" @@ -898,30 +898,30 @@ public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () [Fact] [ScrollBarAutoInitShutdown] - public void Hosting_Two_Horizontal_ScrollBarView_Throws_ArgumentException () + public void Hosting_Two_Horizontal_ScrollBar_Throws_ArgumentException () { var top = new Toplevel (); var host = new View (); top.Add (host); - var v = new ScrollBarView { IsVertical = false }; - var h = new ScrollBarView { IsVertical = false }; + var v = new ScrollBar { IsVertical = false }; + var h = new ScrollBar { IsVertical = false }; - Assert.Throws (() => v.OtherScrollBarView = h); - Assert.Throws (() => h.OtherScrollBarView = v); + Assert.Throws (() => v.OtherScrollBar = h); + Assert.Throws (() => h.OtherScrollBar = v); } [Fact] [ScrollBarAutoInitShutdown] - public void Hosting_Two_Vertical_ScrollBarView_Throws_ArgumentException () + public void Hosting_Two_Vertical_ScrollBar_Throws_ArgumentException () { var top = new Toplevel (); var host = new View (); top.Add (host); - var v = new ScrollBarView { IsVertical = true }; - var h = new ScrollBarView { IsVertical = true }; + var v = new ScrollBar { IsVertical = true }; + var h = new ScrollBar { IsVertical = true }; - Assert.Throws (() => v.OtherScrollBarView = h); - Assert.Throws (() => h.OtherScrollBarView = v); + Assert.Throws (() => v.OtherScrollBar = h); + Assert.Throws (() => h.OtherScrollBar = v); } [Fact] @@ -931,56 +931,56 @@ public void Internal_Tests () Toplevel top = Application.Top; Assert.Equal (new Rect (0, 0, 80, 25), top.Bounds); var view = new View { Width = Dim.Fill (), Height = Dim.Fill () }; - var sbv = new ScrollBarView { IsVertical = true, OtherScrollBarView = new ScrollBarView { IsVertical = false } }; + var sbv = new ScrollBar { IsVertical = true, OtherScrollBar = new ScrollBar { IsVertical = false } }; view.Add (sbv); top.Add (view); Assert.Equal (view, sbv.SuperView); sbv.Size = 40; sbv.Position = 0; - sbv.OtherScrollBarView.Size = 100; - sbv.OtherScrollBarView.Position = 0; + sbv.OtherScrollBar.Size = 100; + sbv.OtherScrollBar.Position = 0; // Host bounds is not empty. Assert.True (sbv.CanScroll (10, out int max, sbv.IsVertical)); Assert.Equal (10, max); - Assert.True (sbv.OtherScrollBarView.CanScroll (10, out max, sbv.OtherScrollBarView.IsVertical)); + Assert.True (sbv.OtherScrollBar.CanScroll (10, out max, sbv.OtherScrollBar.IsVertical)); Assert.Equal (10, max); Application.Begin (top); // They are visible so they are drawn. Assert.True (sbv.Visible); - Assert.True (sbv.OtherScrollBarView.Visible); + Assert.True (sbv.OtherScrollBar.Visible); top.LayoutSubviews (); // Now the host bounds is not empty. Assert.True (sbv.CanScroll (10, out max, sbv.IsVertical)); Assert.Equal (10, max); - Assert.True (sbv.OtherScrollBarView.CanScroll (10, out max, sbv.OtherScrollBarView.IsVertical)); + Assert.True (sbv.OtherScrollBar.CanScroll (10, out max, sbv.OtherScrollBar.IsVertical)); Assert.Equal (10, max); Assert.True (sbv.CanScroll (50, out max, sbv.IsVertical)); Assert.Equal (40, sbv.Size); Assert.Equal (16, max); // 16+25=41 - Assert.True (sbv.OtherScrollBarView.CanScroll (150, out max, sbv.OtherScrollBarView.IsVertical)); - Assert.Equal (100, sbv.OtherScrollBarView.Size); + Assert.True (sbv.OtherScrollBar.CanScroll (150, out max, sbv.OtherScrollBar.IsVertical)); + Assert.Equal (100, sbv.OtherScrollBar.Size); Assert.Equal (21, max); // 21+80=101 Assert.True (sbv.Visible); - Assert.True (sbv.OtherScrollBarView.Visible); + Assert.True (sbv.OtherScrollBar.Visible); sbv.KeepContentAlwaysInViewPort = false; - sbv.OtherScrollBarView.KeepContentAlwaysInViewPort = false; + sbv.OtherScrollBar.KeepContentAlwaysInViewPort = false; Assert.True (sbv.CanScroll (50, out max, sbv.IsVertical)); Assert.Equal (39, max); // Keep 1 row visible - Assert.True (sbv.OtherScrollBarView.CanScroll (150, out max, sbv.OtherScrollBarView.IsVertical)); + Assert.True (sbv.OtherScrollBar.CanScroll (150, out max, sbv.OtherScrollBar.IsVertical)); Assert.Equal (99, max); // Keep 1 column visible Assert.True (sbv.Visible); - Assert.True (sbv.OtherScrollBarView.Visible); + Assert.True (sbv.OtherScrollBar.Visible); } [Fact] [ScrollBarAutoInitShutdown] public void KeepContentAlwaysInViewport_False () { - Hosting_A_View_To_A_ScrollBarView (); + Hosting_A_View_To_A_ScrollBar (); AddHandlers (); @@ -991,10 +991,10 @@ public void KeepContentAlwaysInViewport_False () Assert.Equal (29, _scrollBar.Position); Assert.Equal (29, _hostView.Top); - _scrollBar.OtherScrollBarView.Position = 150; - Assert.Equal (_scrollBar.OtherScrollBarView.Position, _scrollBar.OtherScrollBarView.Size - 1); - Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); - Assert.Equal (99, _scrollBar.OtherScrollBarView.Position); + _scrollBar.OtherScrollBar.Position = 150; + Assert.Equal (_scrollBar.OtherScrollBar.Position, _scrollBar.OtherScrollBar.Size - 1); + Assert.Equal (_scrollBar.OtherScrollBar.Position, _hostView.Left); + Assert.Equal (99, _scrollBar.OtherScrollBar.Position); Assert.Equal (99, _hostView.Left); } @@ -1002,20 +1002,20 @@ public void KeepContentAlwaysInViewport_False () [ScrollBarAutoInitShutdown] public void KeepContentAlwaysInViewport_True () { - Hosting_A_View_To_A_ScrollBarView (); + Hosting_A_View_To_A_ScrollBar (); AddHandlers (); Assert.Equal (80, _hostView.Bounds.Width); Assert.Equal (25, _hostView.Bounds.Height); - Assert.Equal (79, _scrollBar.OtherScrollBarView.Bounds.Width); + Assert.Equal (79, _scrollBar.OtherScrollBar.Bounds.Width); Assert.Equal (24, _scrollBar.Bounds.Height); Assert.Equal (30, _scrollBar.Size); - Assert.Equal (100, _scrollBar.OtherScrollBarView.Size); + Assert.Equal (100, _scrollBar.OtherScrollBar.Size); Assert.True (_scrollBar.ShowScrollIndicator); - Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.True (_scrollBar.OtherScrollBar.ShowScrollIndicator); Assert.True (_scrollBar.Visible); - Assert.True (_scrollBar.OtherScrollBarView.Visible); + Assert.True (_scrollBar.OtherScrollBar.Visible); _scrollBar.Position = 50; Assert.Equal (_scrollBar.Position, _scrollBar.Size - _scrollBar.Bounds.Height); @@ -1023,36 +1023,36 @@ public void KeepContentAlwaysInViewport_True () Assert.Equal (6, _scrollBar.Position); Assert.Equal (6, _hostView.Top); Assert.True (_scrollBar.ShowScrollIndicator); - Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.True (_scrollBar.OtherScrollBar.ShowScrollIndicator); Assert.True (_scrollBar.Visible); - Assert.True (_scrollBar.OtherScrollBarView.Visible); + Assert.True (_scrollBar.OtherScrollBar.Visible); - _scrollBar.OtherScrollBarView.Position = 150; + _scrollBar.OtherScrollBar.Position = 150; Assert.Equal ( - _scrollBar.OtherScrollBarView.Position, - _scrollBar.OtherScrollBarView.Size - _scrollBar.OtherScrollBarView.Bounds.Width + _scrollBar.OtherScrollBar.Position, + _scrollBar.OtherScrollBar.Size - _scrollBar.OtherScrollBar.Bounds.Width ); - Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); - Assert.Equal (21, _scrollBar.OtherScrollBarView.Position); + Assert.Equal (_scrollBar.OtherScrollBar.Position, _hostView.Left); + Assert.Equal (21, _scrollBar.OtherScrollBar.Position); Assert.Equal (21, _hostView.Left); Assert.True (_scrollBar.ShowScrollIndicator); - Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.True (_scrollBar.OtherScrollBar.ShowScrollIndicator); Assert.True (_scrollBar.Visible); - Assert.True (_scrollBar.OtherScrollBarView.Visible); + Assert.True (_scrollBar.OtherScrollBar.Visible); } [Fact] [ScrollBarAutoInitShutdown] - public void OtherScrollBarView_Not_Null () + public void OtherScrollBar_Not_Null () { - Hosting_A_View_To_A_ScrollBarView (); + Hosting_A_View_To_A_ScrollBar (); AddHandlers (); - Assert.NotNull (_scrollBar.OtherScrollBarView); - Assert.NotEqual (_scrollBar, _scrollBar.OtherScrollBarView); - Assert.Equal (_scrollBar.OtherScrollBarView.OtherScrollBarView, _scrollBar); + Assert.NotNull (_scrollBar.OtherScrollBar); + Assert.NotEqual (_scrollBar, _scrollBar.OtherScrollBar); + Assert.Equal (_scrollBar.OtherScrollBar.OtherScrollBar, _scrollBar); } [Fact] @@ -1066,23 +1066,23 @@ public void ScrollBarType_IsBuiltIn_In_Padding () foreach (View sbv in view.Padding.Subviews) { - if (sbv is not ScrollBarView) + if (sbv is not ScrollBar) { - Assert.True (sbv is ScrollBarView.ContentBottomRightCorner); + Assert.True (sbv is ScrollBar.ContentBottomRightCorner); } else { - Assert.True (sbv is ScrollBarView); + Assert.True (sbv is ScrollBar); } } view = new View { ScrollBarType = ScrollBarType.Vertical }; Assert.Single (view.Padding.Subviews); - Assert.True (view.Padding.Subviews [0] is ScrollBarView); + Assert.True (view.Padding.Subviews [0] is ScrollBar); view = new View { ScrollBarType = ScrollBarType.Horizontal }; Assert.Single (view.Padding.Subviews); - Assert.True (view.Padding.Subviews [0] is ScrollBarView); + Assert.True (view.Padding.Subviews [0] is ScrollBar); } [Fact] @@ -1293,7 +1293,7 @@ public void ScrollBarType_IsBuiltIn_In_Padding_Thickness_Inside_Another_Containe [ScrollBarAutoInitShutdown] public void Scrolling_With_Default_Constructor_Do_Not_Scroll () { - var sbv = new ScrollBarView { Position = 1 }; + var sbv = new ScrollBar { Position = 1 }; Assert.Equal (1, sbv.Position); Assert.NotEqual (0, sbv.Position); } @@ -1302,12 +1302,12 @@ public void Scrolling_With_Default_Constructor_Do_Not_Scroll () [ScrollBarAutoInitShutdown] public void ShowScrollIndicator_Check () { - Hosting_A_View_To_A_ScrollBarView (); + Hosting_A_View_To_A_ScrollBar (); AddHandlers (); Assert.True (_scrollBar.ShowScrollIndicator); - Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.True (_scrollBar.OtherScrollBar.ShowScrollIndicator); } [Fact] @@ -1320,13 +1320,13 @@ public void ShowScrollIndicator_False_Must_Also_Set_Visible_To_False_To_Not_Resp var btn = new Button { X = 14, Text = "Click Me!" }; btn.Clicked += (s, e) => clicked = true; - var sbv = new ScrollBarView { IsVertical = true, Size = 5 }; + var sbv = new ScrollBar { IsVertical = true, Size = 5 }; label.Add (sbv); Application.Top.Add (label, btn); Application.Begin (Application.Top); Assert.Equal (5, sbv.Size); - Assert.Null (sbv.OtherScrollBarView); + Assert.Null (sbv.OtherScrollBar); Assert.False (sbv.ShowScrollIndicator); Assert.False (sbv.Visible); @@ -1434,7 +1434,7 @@ public void Vertical_Default_Draws_Correctly () var super = new Window { Id = "super", Width = Dim.Fill (), Height = Dim.Fill () }; Application.Top.Add (super); - var sbv = new ScrollBarView + var sbv = new ScrollBar { Id = "sbv", Size = height * 2, @@ -1495,8 +1495,8 @@ private void _hostView_DrawContent (object sender, DrawEventArgs e) { _scrollBar.Size = _hostView.Lines; _scrollBar.Position = _hostView.Top; - _scrollBar.OtherScrollBarView.Size = _hostView.Cols; - _scrollBar.OtherScrollBarView.Position = _hostView.Left; + _scrollBar.OtherScrollBar.Size = _hostView.Cols; + _scrollBar.OtherScrollBar.Position = _hostView.Left; _scrollBar.Refresh (); } @@ -1512,13 +1512,13 @@ private void _scrollBar_ChangedPosition (object sender, EventArgs e) _hostView.SetNeedsDisplay (); } - private void _scrollBar_OtherScrollBarView_ChangedPosition (object sender, EventArgs e) + private void _scrollBar_OtherScrollBar_ChangedPosition (object sender, EventArgs e) { - _hostView.Left = _scrollBar.OtherScrollBarView.Position; + _hostView.Left = _scrollBar.OtherScrollBar.Position; - if (_hostView.Left != _scrollBar.OtherScrollBarView.Position) + if (_hostView.Left != _scrollBar.OtherScrollBar.Position) { - _scrollBar.OtherScrollBarView.Position = _hostView.Left; + _scrollBar.OtherScrollBar.Position = _hostView.Left; } _hostView.SetNeedsDisplay (); @@ -1530,7 +1530,7 @@ private void AddHandlers () { _hostView.DrawContent += _hostView_DrawContent; _scrollBar.ChangedPosition += _scrollBar_ChangedPosition; - _scrollBar.OtherScrollBarView.ChangedPosition += _scrollBar_OtherScrollBarView_ChangedPosition; + _scrollBar.OtherScrollBar.ChangedPosition += _scrollBar_OtherScrollBar_ChangedPosition; } _added = true; @@ -1542,7 +1542,7 @@ private void RemoveHandlers () { _hostView.DrawContent -= _hostView_DrawContent; _scrollBar.ChangedPosition -= _scrollBar_ChangedPosition; - _scrollBar.OtherScrollBarView.ChangedPosition -= _scrollBar_OtherScrollBarView_ChangedPosition; + _scrollBar.OtherScrollBar.ChangedPosition -= _scrollBar_OtherScrollBar_ChangedPosition; } _added = false; diff --git a/UnitTests/Views/ScrollViewTests.cs b/UnitTests/Views/ScrollViewTests.cs index 758eb128f8..ea13dd7996 100644 --- a/UnitTests/Views/ScrollViewTests.cs +++ b/UnitTests/Views/ScrollViewTests.cs @@ -405,8 +405,8 @@ public void ContentBottomRightCorner_Draw () top.Draw (); - View contentBottomRightCorner = sv.Subviews.First (v => v is ScrollBarView.ContentBottomRightCorner); - Assert.True (contentBottomRightCorner is ScrollBarView.ContentBottomRightCorner); + View contentBottomRightCorner = sv.Subviews.First (v => v is ScrollBar.ContentBottomRightCorner); + Assert.True (contentBottomRightCorner is ScrollBar.ContentBottomRightCorner); Assert.True (contentBottomRightCorner.Visible); TestHelpers.AssertDriverContentsWithFrameAre ( From 97402ea3dbd8bd9b921265dd12dea2a15b24fe43 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 21:04:48 +0000 Subject: [PATCH 034/130] Add scroll bar to the WizardStep. --- Terminal.Gui/Views/Wizard/WizardStep.cs | 47 +------------------------ 1 file changed, 1 insertion(+), 46 deletions(-) diff --git a/Terminal.Gui/Views/Wizard/WizardStep.cs b/Terminal.Gui/Views/Wizard/WizardStep.cs index a9c5fbd281..78a6a47fb3 100644 --- a/Terminal.Gui/Views/Wizard/WizardStep.cs +++ b/Terminal.Gui/Views/Wizard/WizardStep.cs @@ -50,54 +50,9 @@ public WizardStep () _helpTextView.ReadOnly = true; _helpTextView.WordWrap = true; + _helpTextView.ScrollBarType = ScrollBarType.Both; base.Add (_helpTextView); - // BUGBUG: v2 - Disabling scrolling for now - //var scrollBar = new ScrollBar (helpTextView, true); - - //scrollBar.ChangedPosition += (s,e) => { - // helpTextView.TopRow = scrollBar.Position; - // if (helpTextView.TopRow != scrollBar.Position) { - // scrollBar.Position = helpTextView.TopRow; - // } - // helpTextView.SetNeedsDisplay (); - //}; - - //scrollBar.OtherScrollBar.ChangedPosition += (s,e) => { - // helpTextView.LeftColumn = scrollBar.OtherScrollBar.Position; - // if (helpTextView.LeftColumn != scrollBar.OtherScrollBar.Position) { - // scrollBar.OtherScrollBar.Position = helpTextView.LeftColumn; - // } - // helpTextView.SetNeedsDisplay (); - //}; - - //scrollBar.VisibleChanged += (s,e) => { - // if (scrollBar.Visible && helpTextView.RightOffset == 0) { - // helpTextView.RightOffset = 1; - // } else if (!scrollBar.Visible && helpTextView.RightOffset == 1) { - // helpTextView.RightOffset = 0; - // } - //}; - - //scrollBar.OtherScrollBar.VisibleChanged += (s,e) => { - // if (scrollBar.OtherScrollBar.Visible && helpTextView.BottomOffset == 0) { - // helpTextView.BottomOffset = 1; - // } else if (!scrollBar.OtherScrollBar.Visible && helpTextView.BottomOffset == 1) { - // helpTextView.BottomOffset = 0; - // } - //}; - - //helpTextView.DrawContent += (s,e) => { - // scrollBar.Size = helpTextView.Lines; - // scrollBar.Position = helpTextView.TopRow; - // if (scrollBar.OtherScrollBar is { }) { - // scrollBar.OtherScrollBar.Size = helpTextView.Maxlength; - // scrollBar.OtherScrollBar.Position = helpTextView.LeftColumn; - // } - // scrollBar.LayoutSubviews (); - // scrollBar.Refresh (); - //}; - //base.Add (scrollBar); ShowHide (); } From 2d385b51ae2213311f31ef6dcb69852b3ec7e728 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 21:12:09 +0000 Subject: [PATCH 035/130] Make IsBuiltIn as private. --- Terminal.Gui/Views/ScrollBar.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Terminal.Gui/Views/ScrollBar.cs b/Terminal.Gui/Views/ScrollBar.cs index 2c6f9b026f..79cec42d75 100644 --- a/Terminal.Gui/Views/ScrollBar.cs +++ b/Terminal.Gui/Views/ScrollBar.cs @@ -176,10 +176,10 @@ public int Size } } - internal bool IsBuiltIn => SuperView is Adornment; - private bool _showBothScrollIndicator => OtherScrollBar?._showScrollIndicator == true && _showScrollIndicator; + private bool IsBuiltIn => SuperView is Adornment; + /// This event is raised when the position on the scrollbar has changed. public event EventHandler ChangedPosition; @@ -1005,11 +1005,11 @@ private void SetWidthHeight () Height = _vertical ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) : 1; _otherScrollBar.Width = _otherScrollBar._vertical ? 1 : - SuperView is Adornment ? Dim.Fill () : Dim.Fill (1); + SuperView is Adornment ? Dim.Fill () : Dim.Fill (1); _otherScrollBar.Height = _otherScrollBar._vertical - ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) - : 1; + ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) + : 1; } else if (_showScrollIndicator) { From 5e3be5fe5cd2df05dea91ccbb9b552d4cdb18021 Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 21 Feb 2024 23:33:11 +0000 Subject: [PATCH 036/130] Decouples the scroll bar from the adornments. --- Terminal.Gui/View/ViewScrollBar.cs | 41 ++++--- UICatalog/Scenarios/CsvEditor.cs | 2 +- UICatalog/Scenarios/Editor.cs | 4 +- UICatalog/Scenarios/ListColumns.cs | 4 +- UICatalog/Scenarios/ListViewWithSelection.cs | 4 +- UICatalog/Scenarios/ListsAndCombos.cs | 8 +- UICatalog/Scenarios/ProcessTable.cs | 3 +- UICatalog/Scenarios/TableEditor.cs | 3 +- UICatalog/Scenarios/TreeViewFileSystem.cs | 3 +- UICatalog/Scenarios/Wizards.cs | 4 +- UICatalog/UICatalog.cs | 8 +- UnitTests/Views/ScrollBarTests.cs | 119 +++++++++++++++++-- UnitTests/Views/TextViewTests.cs | 6 +- 13 files changed, 159 insertions(+), 50 deletions(-) diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index b707ca0024..27ee281063 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -51,27 +51,30 @@ public virtual ScrollBarType ScrollBarType get => _scrollBarType; set { - if (_scrollBar is { } && _scrollBarType == value) + View view = this is Adornment adornment ? adornment.Parent : this; + + if (view._scrollBar is { } && view._scrollBarType == value) { return; } - _scrollBarType = value; - DisposeScrollBar (); + view._scrollBarType = value; + view.DisposeScrollBar (); + - switch (_scrollBarType) + switch (view._scrollBarType) { case ScrollBarType.Vertical: - _scrollBar = new ScrollBar { IsVertical = true }; + view._scrollBar = new ScrollBar { IsVertical = true }; break; case ScrollBarType.Horizontal: - _scrollBar = new ScrollBar { IsVertical = false }; + view._scrollBar = new ScrollBar { IsVertical = false }; break; case ScrollBarType.Both: - _scrollBar = new ScrollBar { IsVertical = true }; - _scrollBar.OtherScrollBar = new ScrollBar { IsVertical = false, OtherScrollBar = _scrollBar }; + view._scrollBar = new ScrollBar { IsVertical = true }; + view._scrollBar.OtherScrollBar = new ScrollBar { IsVertical = false, OtherScrollBar = view._scrollBar }; break; case ScrollBarType.None: @@ -80,16 +83,16 @@ public virtual ScrollBarType ScrollBarType throw new ArgumentOutOfRangeException (); } - Padding.Add (_scrollBar); - AddEventHandlersForScrollBars (); - AddKeyBindingsForScrolling (_scrollBar); + Add (view._scrollBar); + view.AddEventHandlersForScrollBars (view._scrollBar); + view.AddKeyBindingsForScrolling (view._scrollBar); - if (_scrollBar.OtherScrollBar != null) + if (view._scrollBar.OtherScrollBar != null) { - AddKeyBindingsForScrolling (_scrollBar.OtherScrollBar); + view.AddKeyBindingsForScrolling (view._scrollBar.OtherScrollBar); } - SetNeedsDisplay (); + view.SetNeedsDisplay (); } } @@ -268,18 +271,18 @@ public virtual int ScrollTopOffset /// public bool UseNegativeBoundsLocation { get; set; } - private void AddEventHandlersForScrollBars () + private void AddEventHandlersForScrollBars (ScrollBar scrollBar) { - if (_scrollBar is null) + if (scrollBar is null) { return; } - _scrollBar.ChangedPosition += ScrollBar_ChangedPosition; + scrollBar.ChangedPosition += ScrollBar_ChangedPosition; - if (_scrollBar.OtherScrollBar != null) + if (scrollBar.OtherScrollBar != null) { - _scrollBar.OtherScrollBar.ChangedPosition += OtherScrollBar_ChangedPosition; + scrollBar.OtherScrollBar.ChangedPosition += OtherScrollBar_ChangedPosition; } } diff --git a/UICatalog/Scenarios/CsvEditor.cs b/UICatalog/Scenarios/CsvEditor.cs index 4ea27f2646..498c5a0384 100644 --- a/UICatalog/Scenarios/CsvEditor.cs +++ b/UICatalog/Scenarios/CsvEditor.cs @@ -605,7 +605,7 @@ private void SetFormat () private void SetTable (DataTable dataTable) { _tableView.Table = new DataTableSource (_currentTable = dataTable); } - private void SetupScrollBar () { _tableView.ScrollBarType = ScrollBarType.Both; } + private void SetupScrollBar () { _tableView.Padding.ScrollBarType = ScrollBarType.Both; } private void Sort (bool asc) { diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index 6e3c7eb2b5..274c2ee0fb 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -57,9 +57,9 @@ public override void Init () X = 0, Y = 0, Width = Dim.Fill (), - Height = Dim.Fill (), - ScrollBarType = ScrollBarType.Both + Height = Dim.Fill () }; + _textView.Padding.ScrollBarType = ScrollBarType.Both; CreateDemoFile (_fileName); diff --git a/UICatalog/Scenarios/ListColumns.cs b/UICatalog/Scenarios/ListColumns.cs index 2f8701e3ed..ce5867d732 100644 --- a/UICatalog/Scenarios/ListColumns.cs +++ b/UICatalog/Scenarios/ListColumns.cs @@ -65,9 +65,9 @@ public override void Setup () ShowHorizontalHeaderUnderline = false, ShowHorizontalBottomline = false, ExpandLastColumn = false - }, - ScrollBarType = ScrollBarType.Both + } }; + _listColView.Padding.ScrollBarType = ScrollBarType.Both; var listColStyle = new ListColumnStyle (); var menu = new MenuBar diff --git a/UICatalog/Scenarios/ListViewWithSelection.cs b/UICatalog/Scenarios/ListViewWithSelection.cs index d18a945dea..d9a9ebdaf9 100644 --- a/UICatalog/Scenarios/ListViewWithSelection.cs +++ b/UICatalog/Scenarios/ListViewWithSelection.cs @@ -48,9 +48,9 @@ public override void Setup () Height = Dim.Fill (), Width = Dim.Fill (1), AllowsMarking = false, - AllowsMultipleSelection = false, - ScrollBarType = ScrollBarType.Both + AllowsMultipleSelection = false }; + _listView.Padding.ScrollBarType = ScrollBarType.Both; _listView.RowRender += ListView_RowRender; Win.Add (_listView); diff --git a/UICatalog/Scenarios/ListsAndCombos.cs b/UICatalog/Scenarios/ListsAndCombos.cs index c00bdd8cec..e0d3dcd6de 100644 --- a/UICatalog/Scenarios/ListsAndCombos.cs +++ b/UICatalog/Scenarios/ListsAndCombos.cs @@ -47,9 +47,9 @@ public override void Setup () Y = Pos.Bottom (lbListView) + 1, Height = Dim.Fill (2), Width = Dim.Percent (40), - Source = new ListWrapper (items), - ScrollBarType = ScrollBarType.Both + Source = new ListWrapper (items) }; + listview.Padding.ScrollBarType = ScrollBarType.Both; listview.SelectedItemChanged += (s, e) => lbListView.Text = items [listview.SelectedItem]; Win.Add (lbListView, listview); @@ -68,9 +68,9 @@ public override void Setup () X = Pos.Right (listview) + 1, Y = Pos.Bottom (lbListView) + 1, Height = Dim.Fill (2), - Width = Dim.Percent (40), - ScrollBarType = ScrollBarType.Both + Width = Dim.Percent (40) }; + comboBox.Padding.ScrollBarType = ScrollBarType.Both; comboBox.SetSource (items); comboBox.SelectedItemChanged += (s, text) => lbComboBox.Text = text.Value.ToString (); diff --git a/UICatalog/Scenarios/ProcessTable.cs b/UICatalog/Scenarios/ProcessTable.cs index 3ec4515c6f..8c3b297038 100644 --- a/UICatalog/Scenarios/ProcessTable.cs +++ b/UICatalog/Scenarios/ProcessTable.cs @@ -17,7 +17,8 @@ public override void Setup () Win.Y = 1; // menu Win.Height = Dim.Fill (1); // status bar - tableView = new TableView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill (), ScrollBarType = ScrollBarType.Both }; + tableView = new TableView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () }; + tableView.Padding.ScrollBarType = ScrollBarType.Both; // First time CreateProcessTable (); diff --git a/UICatalog/Scenarios/TableEditor.cs b/UICatalog/Scenarios/TableEditor.cs index f8620dc8f9..0302c91909 100644 --- a/UICatalog/Scenarios/TableEditor.cs +++ b/UICatalog/Scenarios/TableEditor.cs @@ -433,7 +433,8 @@ public override void Setup () Win.Y = 1; // menu Win.Height = Dim.Fill (1); // status bar - _tableView = new TableView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill (1), ScrollBarType = ScrollBarType.Both }; + _tableView = new TableView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill (1) }; + _tableView.Padding.ScrollBarType = ScrollBarType.Both; var menu = new MenuBar { diff --git a/UICatalog/Scenarios/TreeViewFileSystem.cs b/UICatalog/Scenarios/TreeViewFileSystem.cs index b790ae4e11..379090a083 100644 --- a/UICatalog/Scenarios/TreeViewFileSystem.cs +++ b/UICatalog/Scenarios/TreeViewFileSystem.cs @@ -174,7 +174,8 @@ public override void Setup () }; Application.Top.Add (menu); - _treeViewFiles = new TreeView { X = 0, Y = 0, Width = Dim.Percent (50), Height = Dim.Fill (), ScrollBarType = ScrollBarType.Both }; + _treeViewFiles = new TreeView { X = 0, Y = 0, Width = Dim.Percent (50), Height = Dim.Fill () }; + _treeViewFiles.Padding.ScrollBarType = ScrollBarType.Both; _treeViewFiles.DrawLine += TreeViewFiles_DrawLine; _detailsFrame = new DetailsFrame (_iconProvider) diff --git a/UICatalog/Scenarios/Wizards.cs b/UICatalog/Scenarios/Wizards.cs index b4f15b936c..7216ef2173 100644 --- a/UICatalog/Scenarios/Wizards.cs +++ b/UICatalog/Scenarios/Wizards.cs @@ -259,9 +259,9 @@ void Top_Loaded (object sender, EventArgs args) Height = Dim.Fill (1), WordWrap = true, AllowsTab = false, - ColorScheme = Colors.ColorSchemes ["Base"], - ScrollBarType = ScrollBarType.Both + ColorScheme = Colors.ColorSchemes ["Base"] }; + someText.Padding.ScrollBarType = ScrollBarType.Both; var help = "This is helpful."; fourthStep.Add (someText); diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index df99e945c3..ed648f0daa 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -498,9 +498,9 @@ public UICatalogTopLevel () Title = "Categories", BorderStyle = LineStyle.Single, SuperViewRendersLineCanvas = true, - Source = new ListWrapper (_categories), - ScrollBarType = ScrollBarType.Both + Source = new ListWrapper (_categories) }; + CategoryList.Padding.ScrollBarType = ScrollBarType.Both; CategoryList.OpenSelectedItem += (s, a) => { ScenarioList!.SetFocus (); }; CategoryList.SelectedItemChanged += CategoryView_SelectedChanged; @@ -518,9 +518,9 @@ public UICatalogTopLevel () CanFocus = true, Title = "Scenarios", BorderStyle = LineStyle.Single, - SuperViewRendersLineCanvas = true, - ScrollBarType = ScrollBarType.Both + SuperViewRendersLineCanvas = true }; + ScenarioList.Padding.ScrollBarType = ScrollBarType.Both; // TableView provides many options for table headers. For simplicity we turn all // of these off. By enabling FullRowSelect and turning off headers, TableView looks just diff --git a/UnitTests/Views/ScrollBarTests.cs b/UnitTests/Views/ScrollBarTests.cs index 9eeb886d1e..62a1a960b7 100644 --- a/UnitTests/Views/ScrollBarTests.cs +++ b/UnitTests/Views/ScrollBarTests.cs @@ -404,9 +404,9 @@ public void Y = 0, Width = Dim.Fill (), Height = Dim.Fill (), - Source = new ListWrapper (source), - ScrollBarType = ScrollBarType.Horizontal + Source = new ListWrapper (source) }; + listView.Padding.ScrollBarType = ScrollBarType.Horizontal; win.Add (listView); Assert.True (listView.ScrollKeepContentAlwaysInViewPort); @@ -744,9 +744,9 @@ public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () Width = Dim.Fill (), Height = Dim.Fill (), Text = - "This is the help text for the Second Step.\n\nPress the button to see a message box.\n\nEnter name too.", - ScrollBarType = ScrollBarType.Both + "This is the help text for the Second Step.\n\nPress the button to see a message box.\n\nEnter name too." }; + textView.Padding.ScrollBarType = ScrollBarType.Both; var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () }; win.Add (textView); @@ -1061,7 +1061,8 @@ public void ScrollBarType_IsBuiltIn_In_Padding () var view = new View { ScrollBarType = ScrollBarType.None }; Assert.Empty (view.Padding.Subviews); - view = new View { ScrollBarType = ScrollBarType.Both }; + view = new View (); + view.Padding.ScrollBarType = ScrollBarType.Both; Assert.Equal (3, view.Padding.Subviews.Count); foreach (View sbv in view.Padding.Subviews) @@ -1076,11 +1077,13 @@ public void ScrollBarType_IsBuiltIn_In_Padding () } } - view = new View { ScrollBarType = ScrollBarType.Vertical }; + view = new View (); + view.Padding.ScrollBarType = ScrollBarType.Vertical; Assert.Single (view.Padding.Subviews); Assert.True (view.Padding.Subviews [0] is ScrollBar); - view = new View { ScrollBarType = ScrollBarType.Horizontal }; + view = new View (); + view.Padding.ScrollBarType = ScrollBarType.Horizontal; Assert.Single (view.Padding.Subviews); Assert.True (view.Padding.Subviews [0] is ScrollBar); } @@ -1102,9 +1105,10 @@ public void ScrollBarType_IsBuiltIn_In_Padding_Thickness () var view = new View { - X = Pos.Center (), Y = Pos.Center (), Width = 9, Height = 6, ScrollBarType = ScrollBarType.Both, + X = Pos.Center (), Y = Pos.Center (), Width = 9, Height = 6, Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", CanFocus = true }; + view.Padding.ScrollBarType = ScrollBarType.Both; view.TextFormatter.WordWrap = false; view.TextFormatter.MultiLine = true; string [] strings = view.Text.Split ("\n").ToArray (); @@ -1197,9 +1201,10 @@ public void ScrollBarType_IsBuiltIn_In_Padding_Thickness_Inside_Another_Containe var view = new View { - X = Pos.Center (), Y = Pos.Center (), Width = 9, Height = 6, ScrollBarType = ScrollBarType.Both, + X = Pos.Center (), Y = Pos.Center (), Width = 9, Height = 6, Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", CanFocus = true }; + view.Padding.ScrollBarType = ScrollBarType.Both; view.TextFormatter.WordWrap = false; view.TextFormatter.MultiLine = true; string [] strings = view.Text.Split ("\n").ToArray (); @@ -1284,6 +1289,102 @@ public void ScrollBarType_IsBuiltIn_In_Padding_Thickness_Inside_Another_Containe 000333333333000 000000000000000 000002222000000 +000000000000000", + null, + attrs); + } + + [Fact] + [SetupFakeDriver] + public void ScrollBarType_IsBuiltIn_In_Parent_Inside_Another_Container () + { + ((FakeDriver)Application.Driver).SetBufferSize (15, 11); + + var superTop = new View { Width = 15, Height = 11, ColorScheme = new ColorScheme (Attribute.Default) }; + + var view = new View + { + X = Pos.Center (), Y = Pos.Center (), Width = 9, Height = 6, + Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", CanFocus = true, + ScrollBarType = ScrollBarType.Both + }; + view.TextFormatter.WordWrap = false; + view.TextFormatter.MultiLine = true; + string [] strings = view.Text.Split ("\n").ToArray (); + view.ScrollColsSize = strings.OrderByDescending (s => s.Length).First ().GetColumns (); + view.ScrollRowsSize = strings.Length; + + view.ColorScheme = new ColorScheme + { + Normal = new Attribute (Color.Green, Color.Red), + Focus = new Attribute (Color.Red, Color.Green) + }; + + var view2 = new View { X = Pos.Center (), Y = Pos.Bottom (view) + 1, Text = "Test", CanFocus = true, AutoSize = true }; + view2.ColorScheme = view.ColorScheme; + + var top = new View + { Width = Dim.Fill (), Height = Dim.Fill (), ColorScheme = new ColorScheme { Normal = Attribute.Default }, BorderStyle = LineStyle.Single }; + top.Add (view, view2); + superTop.Add (top); + superTop.BeginInit (); + superTop.EndInit (); + superTop.FocusFirst (); + superTop.LayoutSubviews (); + superTop.Draw (); + Assert.True (view.HasFocus); + Assert.False (view2.HasFocus); + Assert.Equal (12, view.ScrollColsSize); + Assert.Equal (7, view.ScrollRowsSize); + Assert.Equal ("(0,0,9,6)", view.Bounds.ToString ()); + Assert.Equal ("(0,0,9,6)", view.ContentArea.ToString ()); + Assert.Equal ("(2,1,9,6)", view.Frame.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Margin.Bounds.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Margin.ContentArea.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Margin.Frame.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Border.Bounds.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Border.ContentArea.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Border.Frame.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Padding.Bounds.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Padding.ContentArea.ToString ()); + Assert.Equal ("(0,0,9,6)", view.Padding.Frame.ToString ()); + Assert.Equal ("(Left=0,Top=0,Right=0,Bottom=0)", view.Padding.Thickness.ToString ()); + Assert.Equal ("{Width=9, Height=6}", view.TextFormatter.Size.ToString ()); + + TestHelpers.AssertDriverContentsWithFrameAre ( + @" +┌─────────────┐ +│ │ +│ First Li▲ │ +│ Second L┬ │ +│ Third Li│ │ +│ Fourth L┴ │ +│ Fifth Li▼ │ +│ ◄├───┤░► │ +│ │ +│ Test │ +└─────────────┘", + _output); + + Attribute [] attrs = + [ + Attribute.Default, + new Attribute (Color.Red, Color.Green), + new Attribute (Color.Green, Color.Red) + ]; + + TestHelpers.AssertDriverAttributesAre ( + @" +000000000000000 +000000000000000 +000111111111000 +000111111111000 +000111111111000 +000111111111000 +000111111111000 +000111111111000 +000000000000000 +000002222000000 000000000000000", null, attrs); diff --git a/UnitTests/Views/TextViewTests.cs b/UnitTests/Views/TextViewTests.cs index aca43d6f6f..e94e53a3b0 100644 --- a/UnitTests/Views/TextViewTests.cs +++ b/UnitTests/Views/TextViewTests.cs @@ -6900,7 +6900,8 @@ public void ScrollBarType_IsBuiltIn_Always_Adjust_LeftColumn () text += $"{i.ToString () [^1]}"; } - var tv = new TextView { Width = 10, Height = 10, ScrollBarType = ScrollBarType.Both }; + var tv = new TextView { Width = 10, Height = 10 }; + tv.Padding.ScrollBarType = ScrollBarType.Both; tv.Text = text; tv.BeginInit (); @@ -6946,7 +6947,8 @@ public void ScrollBarType_IsBuiltIn_Always_Adjust_TopRow () text += $"This is the line {i}\n"; } - var tv = new TextView { Width = 10, Height = 10, ScrollBarType = ScrollBarType.Both }; + var tv = new TextView { Width = 10, Height = 10 }; + tv.Padding.ScrollBarType = ScrollBarType.Both; tv.Text = text; tv.BeginInit (); From 2cd5faf027aeab8e56d4c4914e287d961c551323 Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 22 Feb 2024 00:13:49 +0000 Subject: [PATCH 037/130] Rename to ScrollBars. --- UICatalog/Scenarios/{ScrollBarBuiltIn.cs => ScrollBars.cs} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename UICatalog/Scenarios/{ScrollBarBuiltIn.cs => ScrollBars.cs} (97%) diff --git a/UICatalog/Scenarios/ScrollBarBuiltIn.cs b/UICatalog/Scenarios/ScrollBars.cs similarity index 97% rename from UICatalog/Scenarios/ScrollBarBuiltIn.cs rename to UICatalog/Scenarios/ScrollBars.cs index 6c1a16b999..47edaedd76 100644 --- a/UICatalog/Scenarios/ScrollBarBuiltIn.cs +++ b/UICatalog/Scenarios/ScrollBars.cs @@ -5,7 +5,7 @@ namespace UICatalog.Scenarios; [ScenarioMetadata ("ScrollBar BuiltIn", "Demonstrates the scroll bar built-in the Padding Adornment.")] [ScenarioCategory ("Controls")] -public class ScrollBarBuiltIn : Scenario +public class ScrollBars : Scenario { public override void Init () { From f8738e1738b9a76552e929e60d980829c0526152 Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 22 Feb 2024 09:15:10 +0000 Subject: [PATCH 038/130] Rename to AdornmentSubViewHandledMouseEvent. --- Terminal.Gui/Application.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Terminal.Gui/Application.cs b/Terminal.Gui/Application.cs index 6d3a69362c..66e3ed1d62 100644 --- a/Terminal.Gui/Application.cs +++ b/Terminal.Gui/Application.cs @@ -1575,7 +1575,7 @@ bool AdornmentHandledMouseEvent (Adornment adornment) { view = View.FindDeepestView (view?.Padding, screenX, screenY, out _, out _); - if (view is { } && AdornmentViewHandledMouseEvent ()) + if (view is { } && AdornmentSubViewHandledMouseEvent ()) { return; } @@ -1590,7 +1590,7 @@ bool AdornmentHandledMouseEvent (Adornment adornment) // TODO: This is a temporary hack to work around the fact that // drag handling is handled in Toplevel (See Issue #2537) - if (AdornmentViewHandledMouseEvent ()) + if (AdornmentSubViewHandledMouseEvent ()) { return; } @@ -1649,7 +1649,7 @@ bool AdornmentHandledMouseEvent (Adornment adornment) } } - bool AdornmentViewHandledMouseEvent () + bool AdornmentSubViewHandledMouseEvent () { var me = new MouseEvent { From 511df4bd7259805567212c554d604d2952cd8fd6 Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 22 Feb 2024 09:49:08 +0000 Subject: [PATCH 039/130] Decouple FrameToScreen from the Adornment base-class. --- Terminal.Gui/View/Adornment/Adornment.cs | 16 ---------------- Terminal.Gui/View/Adornment/Border.cs | 11 +++++++++++ Terminal.Gui/View/Adornment/Padding.cs | 11 +++++++++++ 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Terminal.Gui/View/Adornment/Adornment.cs b/Terminal.Gui/View/Adornment/Adornment.cs index 9865ea0947..bf627ee80c 100644 --- a/Terminal.Gui/View/Adornment/Adornment.cs +++ b/Terminal.Gui/View/Adornment/Adornment.cs @@ -112,22 +112,6 @@ public override Rect FrameToScreen () ret.Location = Parent?.FrameToScreen ().Location ?? ret.Location; - switch (this) - { - case Gui.Margin: - break; - case Gui.Border: - ret.X += Parent != null ? Parent.Margin.Thickness.Left : 0; - ret.Y += Parent != null ? Parent.Margin.Thickness.Top : 0; - - break; - case Gui.Padding: - ret.X += Parent != null ? Parent.Margin.Thickness.Left + Parent.Border.Thickness.Left : 0; - ret.Y += Parent != null ? Parent.Margin.Thickness.Top + Parent.Border.Thickness.Top : 0; - - break; - } - // We now have coordinates relative to our View. If our View's SuperView has // a SuperView, keep going... return ret; diff --git a/Terminal.Gui/View/Adornment/Border.cs b/Terminal.Gui/View/Adornment/Border.cs index cc5973fa15..c16c2b0603 100644 --- a/Terminal.Gui/View/Adornment/Border.cs +++ b/Terminal.Gui/View/Adornment/Border.cs @@ -212,6 +212,17 @@ public void DrawTitle (Rect region, string title) } } + /// + public override Rect FrameToScreen () + { + Rect ret = base.FrameToScreen (); + + ret.X += Parent?.Margin.Thickness.Left ?? 0; + ret.Y += Parent?.Margin.Thickness.Top ?? 0; + + return ret; + } + /// public override void OnDrawContent (Rect contentArea) { diff --git a/Terminal.Gui/View/Adornment/Padding.cs b/Terminal.Gui/View/Adornment/Padding.cs index 7909ff77eb..5b09339dde 100644 --- a/Terminal.Gui/View/Adornment/Padding.cs +++ b/Terminal.Gui/View/Adornment/Padding.cs @@ -38,4 +38,15 @@ public override ColorScheme ColorScheme Parent?.SetNeedsDisplay (); } } + + /// + public override Rect FrameToScreen () + { + Rect ret = base.FrameToScreen (); + + ret.X += Parent != null ? Parent.Margin.Thickness.Left + Parent.Border.Thickness.Left : 0; + ret.Y += Parent != null ? Parent.Margin.Thickness.Top + Parent.Border.Thickness.Top : 0; + + return ret; + } } From 53b3e81427da9e1255151fd93308fd79af5766d9 Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 22 Feb 2024 11:52:46 +0000 Subject: [PATCH 040/130] Fix broken scroll bar in the ComboBox list. --- Terminal.Gui/Views/ComboBox.cs | 4 ++-- UICatalog/Scenarios/ListsAndCombos.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 37b655d12c..9e79521129 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -139,8 +139,8 @@ public bool ReadOnly /// public override ScrollBarType ScrollBarType { - get => _listview.ScrollBarType; - set => _listview.ScrollBarType = value; + get => _listview.Padding.ScrollBarType; + set => _listview.Padding.ScrollBarType = value; } /// Current search text diff --git a/UICatalog/Scenarios/ListsAndCombos.cs b/UICatalog/Scenarios/ListsAndCombos.cs index e0d3dcd6de..1ca9095e46 100644 --- a/UICatalog/Scenarios/ListsAndCombos.cs +++ b/UICatalog/Scenarios/ListsAndCombos.cs @@ -70,7 +70,7 @@ public override void Setup () Height = Dim.Fill (2), Width = Dim.Percent (40) }; - comboBox.Padding.ScrollBarType = ScrollBarType.Both; + comboBox.ScrollBarType = ScrollBarType.Both; comboBox.SetSource (items); comboBox.SelectedItemChanged += (s, text) => lbComboBox.Text = text.Value.ToString (); From a04a555b145a4cc489d617bf0b99706577978bb0 Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 22 Feb 2024 23:43:41 +0000 Subject: [PATCH 041/130] Fix merge errors. --- UnitTests/Views/ScrollBarTests.cs | 2 +- UnitTests/Views/ScrollViewTests.cs | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/UnitTests/Views/ScrollBarTests.cs b/UnitTests/Views/ScrollBarTests.cs index 62a1a960b7..37acb9e94d 100644 --- a/UnitTests/Views/ScrollBarTests.cs +++ b/UnitTests/Views/ScrollBarTests.cs @@ -1419,7 +1419,7 @@ public void ShowScrollIndicator_False_Must_Also_Set_Visible_To_False_To_Not_Resp var text = "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test"; var label = new Label { AutoSize = false, Width = 14, Height = 5, Text = text }; var btn = new Button { X = 14, Text = "Click Me!" }; - btn.Clicked += (s, e) => clicked = true; + btn.Accept += (s, e) => clicked = true; var sbv = new ScrollBar { IsVertical = true, Size = 5 }; label.Add (sbv); diff --git a/UnitTests/Views/ScrollViewTests.cs b/UnitTests/Views/ScrollViewTests.cs index b4f4aa85a6..3d2cba0f58 100644 --- a/UnitTests/Views/ScrollViewTests.cs +++ b/UnitTests/Views/ScrollViewTests.cs @@ -938,19 +938,19 @@ public void KeyBindings_Command () Assert.Equal (new Point (0, 0), sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.PageDown)); Assert.Equal (new Point (0, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.PageDown))); + Assert.True (sv.OnKeyDown (Key.PageDown)); // The other scroll bar is visible, so it need to scroll one more row Assert.Equal (new Point (0, -11), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.CursorDown))); + Assert.False (sv.OnKeyDown (Key.CursorDown)); Assert.Equal (new Point (0, -11), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key ((KeyCode)'v' | KeyCode.AltMask))); + Assert.True (sv.OnKeyDown (Key.V.WithAlt)); // Scrolled 10 rows and still is hiding one row Assert.Equal (new Point (0, -1), sv.ContentOffset); // Pressing the same key again will set to 0 - Assert.True (sv.OnKeyDown (new Key ((KeyCode)'v' | KeyCode.AltMask))); + Assert.True (sv.OnKeyDown (Key.V.WithAlt)); Assert.Equal (new Point (0, 0), sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.V.WithCtrl)); Assert.Equal (new Point (0, -10), sv.ContentOffset); @@ -964,19 +964,19 @@ public void KeyBindings_Command () Assert.Equal (new Point (0, -10), sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.PageDown.WithCtrl)); Assert.Equal (new Point (-20, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.CursorRight))); + Assert.True (sv.OnKeyDown (Key.CursorRight)); // The other scroll bar is visible, so it need to scroll one more column Assert.Equal (new Point (-21, -10), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.Home))); + Assert.True (sv.OnKeyDown (Key.Home)); // The other scroll bar is visible, so it need to scroll one more column Assert.Equal (new Point (-21, 0), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.Home))); + Assert.False (sv.OnKeyDown (Key.Home)); Assert.Equal (new Point (-21, 0), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.End))); + Assert.True (sv.OnKeyDown (Key.End)); Assert.Equal (new Point (-21, -11), sv.ContentOffset); - Assert.False (sv.OnKeyDown (new Key (KeyCode.End))); + Assert.False (sv.OnKeyDown (Key.End)); Assert.Equal (new Point (-21, -11), sv.ContentOffset); Assert.True (sv.OnKeyDown (new Key (KeyCode.Home | KeyCode.CtrlMask))); Assert.Equal (new Point (0, -11), sv.ContentOffset); @@ -986,7 +986,7 @@ public void KeyBindings_Command () Assert.Equal (new Point (-21, -11), sv.ContentOffset); Assert.False (sv.OnKeyDown (new Key (KeyCode.End | KeyCode.CtrlMask))); Assert.Equal (new Point (-21, -11), sv.ContentOffset); - Assert.True (sv.OnKeyDown (new Key (KeyCode.Home))); + Assert.True (sv.OnKeyDown (Key.Home)); Assert.Equal (new Point (-21, 0), sv.ContentOffset); Assert.True (sv.OnKeyDown (new Key (KeyCode.Home | KeyCode.CtrlMask))); Assert.Equal (new Point (0, 0), sv.ContentOffset); From 566c675653e1c5eadfe3ac8d3cf82069229e5918 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 23 Feb 2024 00:35:51 +0000 Subject: [PATCH 042/130] Fix merge errors. --- Terminal.Gui/Types/Rectangle.cs | 12 +- Terminal.Gui/View/Adornment/Adornment.cs | 2 +- Terminal.Gui/View/Adornment/Border.cs | 6 +- Terminal.Gui/View/Adornment/Padding.cs | 4 +- Terminal.Gui/View/Layout/ViewLayout.cs | 6 +- Terminal.Gui/View/View.cs | 4 +- Terminal.Gui/View/ViewDrawing.cs | 14 +- Terminal.Gui/Views/Line.cs | 2 +- Terminal.Gui/Views/TableView/TableView.cs | 2 +- Terminal.Gui/Views/TextView.cs | 12 +- UICatalog/Scenarios/Clipping.cs | 2 +- UICatalog/Scenarios/Scrolling.cs | 6 +- .../ConsoleDrivers/ConsoleDriverTests.cs | 4 +- UnitTests/View/Adornment/AdornmentTests.cs | 144 +++++++++--------- UnitTests/View/Adornment/BorderTests.cs | 28 ++-- UnitTests/View/Layout/LayoutTests.cs | 22 +-- UnitTests/View/Text/AutoSizeTrueTests.cs | 50 +++--- UnitTests/View/ViewTests.cs | 2 +- UnitTests/Views/MenuBarTests.cs | 4 +- UnitTests/Views/ScrollBarTests.cs | 84 +++++----- UnitTests/Views/WindowTests.cs | 2 +- 21 files changed, 206 insertions(+), 206 deletions(-) diff --git a/Terminal.Gui/Types/Rectangle.cs b/Terminal.Gui/Types/Rectangle.cs index 61e1ae1e36..f9a3ba99b0 100644 --- a/Terminal.Gui/Types/Rectangle.cs +++ b/Terminal.Gui/Types/Rectangle.cs @@ -22,7 +22,7 @@ public struct Rectangle /// Gets or sets the y-coordinate of the upper-left corner of this Rectangle structure. public int Y; - /// Gets or sets the width of this Rect structure. + /// Gets or sets the width of this Rectangle structure. public int Width { get => width; @@ -73,9 +73,9 @@ int bottom ); } - /// Produces a new Rect by inflating an existing Rect by the specified coordinate values. + /// Produces a new Rectangle by inflating an existing Rectangle by the specified coordinate values. /// - /// Produces a new Rect by inflating an existing Rect by the specified coordinate values. The rectangle is + /// Produces a new Rectangle by inflating an existing Rectangle by the specified coordinate values. The rectangle is /// enlarged in both directions along an axis. /// public static Rectangle Inflate (Rectangle rect, int x, int y) @@ -86,7 +86,7 @@ public static Rectangle Inflate (Rectangle rect, int x, int y) return r; } - /// Inflates an existing Rect by the specified coordinate values. + /// Inflates an existing Rectangle by the specified coordinate values. /// /// This method enlarges this rectangle, not a copy of it. The rectangle is enlarged in both directions along an /// axis. @@ -101,7 +101,7 @@ public void Inflate (int width, int height) Y -= height; } - /// Inflates an existing Rect by the specified Sizwe. + /// Inflates an existing Rectangle by the specified Sizwe. /// /// This method enlarges this rectangle, not a copy of it. The rectangle is enlarged in both directions along an /// axis. @@ -139,7 +139,7 @@ public static Rectangle Union (Rectangle a, Rectangle b) //int x2 = Math.Max (a.X + a.Width, b.X + b.Width); //int y1 = Math.Min (a.Y, b.Y);oS //int y2 = Math.Max (a.Y + a.Height, b.Y + b.Height); - //return new Rect (x1, y1, x2 - x1, y2 - y1); + //return new Rectangle (x1, y1, x2 - x1, y2 - y1); int x1 = Math.Min (a.X, b.X); int x2 = Math.Max (a.X + Math.Abs (a.Width), b.X + Math.Abs (b.Width)); diff --git a/Terminal.Gui/View/Adornment/Adornment.cs b/Terminal.Gui/View/Adornment/Adornment.cs index eae086bbb0..0fe7140b1f 100644 --- a/Terminal.Gui/View/Adornment/Adornment.cs +++ b/Terminal.Gui/View/Adornment/Adornment.cs @@ -40,7 +40,7 @@ public override Rectangle Bounds /// /// Gets the rectangle that describes the inner area of the Adornment. The Location is always (0,0). /// - public override Rect ContentArea => Thickness?.GetInside (new Rect (Point.Empty, Frame.Size)) ?? new Rect (Point.Empty, Frame.Size); + public override Rectangle ContentArea => Thickness?.GetInside (new Rectangle (Point.Empty, Frame.Size)) ?? new Rectangle (Point.Empty, Frame.Size); /// The Parent of this Adornment (the View this Adornment surrounds). /// diff --git a/Terminal.Gui/View/Adornment/Border.cs b/Terminal.Gui/View/Adornment/Border.cs index 36d98ae793..45f72d5909 100644 --- a/Terminal.Gui/View/Adornment/Border.cs +++ b/Terminal.Gui/View/Adornment/Border.cs @@ -194,9 +194,9 @@ public void DrawFrame (Rectangle region, bool clear) } /// - public override Rect FrameToScreen () + public override Rectangle FrameToScreen () { - Rect ret = base.FrameToScreen (); + Rectangle ret = base.FrameToScreen (); ret.X += Parent?.Margin.Thickness.Left ?? 0; ret.Y += Parent?.Margin.Thickness.Top ?? 0; @@ -205,7 +205,7 @@ public override Rect FrameToScreen () } /// - public override void OnDrawContent (Rect contentArea) + public override void OnDrawContent (Rectangle contentArea) { base.OnDrawContent (contentArea); diff --git a/Terminal.Gui/View/Adornment/Padding.cs b/Terminal.Gui/View/Adornment/Padding.cs index 5b09339dde..4c2270f54b 100644 --- a/Terminal.Gui/View/Adornment/Padding.cs +++ b/Terminal.Gui/View/Adornment/Padding.cs @@ -40,9 +40,9 @@ public override ColorScheme ColorScheme } /// - public override Rect FrameToScreen () + public override Rectangle FrameToScreen () { - Rect ret = base.FrameToScreen (); + Rectangle ret = base.FrameToScreen (); ret.X += Parent != null ? Parent.Margin.Thickness.Left + Parent.Border.Thickness.Left : 0; ret.Y += Parent != null ? Parent.Margin.Thickness.Top + Parent.Border.Thickness.Top : 0; diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 5d07233d25..a6cf32eba2 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -237,13 +237,13 @@ public virtual Rectangle Bounds /// The content area represent the View-relative rectangle used for this view. The area inside the view where subviews /// and content are presented. The Location is always (0,0). It will be mainly used for clipping a region. /// - public virtual Rect ContentArea + public virtual Rectangle ContentArea { get { if (Margin == null || Border == null || Padding == null) { - return new Rect (default (Point), Frame.Size); + return new Rectangle (default (Point), Frame.Size); } int width = Math.Max ( @@ -254,7 +254,7 @@ public virtual Rect ContentArea 0, Frame.Size.Height - Margin.Thickness.Vertical - Border.Thickness.Vertical - Padding.Thickness.Vertical); - return new Rect (Point.Empty, new Size (width, height)); + return new Rectangle (Point.Empty, new Size (width, height)); } } diff --git a/Terminal.Gui/View/View.cs b/Terminal.Gui/View/View.cs index f5e315f808..04fea12247 100644 --- a/Terminal.Gui/View/View.cs +++ b/Terminal.Gui/View/View.cs @@ -49,9 +49,9 @@ namespace Terminal.Gui; /// . /// /// -/// To create a View using Absolute layout, call a constructor that takes a Rect parameter to specify the +/// To create a View using Absolute layout, call a constructor that takes a Rectangle parameter to specify the /// absolute position and size or simply set ). To create a View using Computed layout use -/// a constructor that does not take a Rect parameter and set the X, Y, Width and Height properties on the view to +/// a constructor that does not take a Rectangle parameter and set the X, Y, Width and Height properties on the view to /// non-absolute values. Both approaches use coordinates that are relative to the of the /// the View is added to. /// diff --git a/Terminal.Gui/View/ViewDrawing.cs b/Terminal.Gui/View/ViewDrawing.cs index a6eca1ff48..2721a77096 100644 --- a/Terminal.Gui/View/ViewDrawing.cs +++ b/Terminal.Gui/View/ViewDrawing.cs @@ -129,7 +129,7 @@ public Rectangle ClipToBounds () } Rectangle previous = Driver.Clip; - Driver.Clip = Rect.Intersect (previous, BoundsToScreen (ContentArea)); + Driver.Clip = Rectangle.Intersect (previous, BoundsToScreen (ContentArea)); return previous; } @@ -203,7 +203,7 @@ public void Draw () /// /// Will be invoked before any subviews added with have been drawn. /// - /// Rect provides the view-relative rectangle describing the currently visible viewport into the + /// Rectangle provides the view-relative rectangle describing the currently visible viewport into the /// . /// /// @@ -213,7 +213,7 @@ public void Draw () /// /// Will be invoked before any subviews added with have been drawn. /// - /// Rect provides the view-relative rectangle describing the currently visible viewport into the + /// Rectangle provides the view-relative rectangle describing the currently visible viewport into the /// . /// /// @@ -223,7 +223,7 @@ public void Draw () /// /// Will be invoked after any subviews removed with have been completed drawing. /// - /// Rect provides the view-relative rectangle describing the currently visible viewport into the + /// Rectangle provides the view-relative rectangle describing the currently visible viewport into the /// . /// /// @@ -622,11 +622,11 @@ protected void ClearNeedsDisplay () if (Margin is { }) { - Margin._needsDisplayRect = Rect.Empty; + Margin._needsDisplayRect = Rectangle.Empty; Margin.SubViewNeedsDisplay = false; - Border._needsDisplayRect = Rect.Empty; + Border._needsDisplayRect = Rectangle.Empty; Border.SubViewNeedsDisplay = false; - Padding._needsDisplayRect = Rect.Empty; + Padding._needsDisplayRect = Rectangle.Empty; Padding.SubViewNeedsDisplay = false; } } diff --git a/Terminal.Gui/Views/Line.cs b/Terminal.Gui/Views/Line.cs index 6e1a5a06ad..122e5cb19a 100644 --- a/Terminal.Gui/Views/Line.cs +++ b/Terminal.Gui/Views/Line.cs @@ -30,7 +30,7 @@ public override bool OnDrawAdornments () return true; } - //public override void OnDrawContentComplete (Rect contentArea) + //public override void OnDrawContentComplete (Rectangle contentArea) //{ // var screenBounds = ViewToScreen (Frame); diff --git a/Terminal.Gui/Views/TableView/TableView.cs b/Terminal.Gui/Views/TableView/TableView.cs index 9ce2a9a4c2..066e402ccc 100644 --- a/Terminal.Gui/Views/TableView/TableView.cs +++ b/Terminal.Gui/Views/TableView/TableView.cs @@ -1544,7 +1544,7 @@ private TableSelection CreateTableSelection (int pt1X, int pt1Y, int pt2X, int p int left = Math.Max (Math.Min (pt1X, pt2X), 0); int right = Math.Max (Math.Max (pt1X, pt2X), 0); - // Rect class is inclusive of Top Left but exclusive of Bottom Right so extend by 1 + // Rectangle class is inclusive of Top Left but exclusive of Bottom Right so extend by 1 return new TableSelection (new Point (pt1X, pt1Y), new Rectangle (left, top, right - left + 1, bot - top + 1)) { IsToggled = toggle diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index e5f3bec9cd..cf517748af 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -3854,7 +3854,7 @@ public override void PositionCursor () // BUGBUG: customized rect aren't supported now because the Redraw isn't using the Intersect method. //var minRow = Math.Min (Math.Max (Math.Min (selectionStartRow, currentRow) - topRow, 0), Bounds.Height); //var maxRow = Math.Min (Math.Max (Math.Max (selectionStartRow, currentRow) - topRow, 0), Bounds.Height); - //SetNeedsDisplay (new Rect (0, minRow, Bounds.Width, maxRow)); + //SetNeedsDisplay (new Rectangle (0, minRow, Bounds.Width, maxRow)); SetNeedsDisplay (); } @@ -4312,7 +4312,7 @@ private void ClearRegion () else { // BUGBUG: customized rect aren't supported now because the Redraw isn't using the Intersect method. - //SetNeedsDisplay (new Rect (0, startRow - topRow, Bounds.Width, startRow - topRow + 1)); + //SetNeedsDisplay (new Rectangle (0, startRow - topRow, Bounds.Width, startRow - topRow + 1)); SetNeedsDisplay (); } @@ -4408,7 +4408,7 @@ private bool DeleteTextBackwards () else { // BUGBUG: customized rect aren't supported now because the Redraw isn't using the Intersect method. - //SetNeedsDisplay (new Rect (0, currentRow - topRow, 1, Bounds.Width)); + //SetNeedsDisplay (new Rectangle (0, currentRow - topRow, 1, Bounds.Width)); SetNeedsDisplay (); } } @@ -4818,7 +4818,7 @@ private void Insert (RuneCell cell) if (!_wrapNeeded) { // BUGBUG: customized rect aren't supported now because the Redraw isn't using the Intersect method. - //SetNeedsDisplay (new Rect (0, prow, Math.Max (Bounds.Width, 0), Math.Max (prow + 1, 0))); + //SetNeedsDisplay (new Rectangle (0, prow, Math.Max (Bounds.Width, 0), Math.Max (prow + 1, 0))); SetNeedsDisplay (); } } @@ -4867,7 +4867,7 @@ private void InsertAllText (string text) else { // BUGBUG: customized rect aren't supported now because the Redraw isn't using the Intersect method. - //SetNeedsDisplay (new Rect (0, currentRow - topRow, Bounds.Width, Math.Max (currentRow - topRow + 1, 0))); + //SetNeedsDisplay (new Rectangle (0, currentRow - topRow, Bounds.Width, Math.Max (currentRow - topRow + 1, 0))); SetNeedsDisplay (); } @@ -6184,7 +6184,7 @@ private bool ProcessReturn () else { // BUGBUG: customized rect aren't supported now because the Redraw isn't using the Intersect method. - //SetNeedsDisplay (new Rect (0, currentRow - topRow, 2, Bounds.Height)); + //SetNeedsDisplay (new Rectangle (0, currentRow - topRow, 2, Bounds.Height)); SetNeedsDisplay (); } diff --git a/UICatalog/Scenarios/Clipping.cs b/UICatalog/Scenarios/Clipping.cs index e13eceeb63..353054837b 100644 --- a/UICatalog/Scenarios/Clipping.cs +++ b/UICatalog/Scenarios/Clipping.cs @@ -20,7 +20,7 @@ public override void Setup () //Win.Height = Dim.Fill () - 2; var label = new Label { - X = 0, Y = 0, Text = "ScrollView (new Rect (3, 3, 50, 20)) with a 200, 100 ContentSize..." + X = 0, Y = 0, Text = "ScrollView (new Rectangle (3, 3, 50, 20)) with a 200, 100 ContentSize..." }; Application.Top.Add (label); diff --git a/UICatalog/Scenarios/Scrolling.cs b/UICatalog/Scenarios/Scrolling.cs index 7e30b24004..0d93ff9e58 100644 --- a/UICatalog/Scenarios/Scrolling.cs +++ b/UICatalog/Scenarios/Scrolling.cs @@ -218,13 +218,13 @@ void Top_Loaded (object sender, EventArgs args) keepCheckBox.Toggled += (s, e) => scrollView.KeepContentAlwaysInViewPort = (bool)keepCheckBox.Checked; Win.Add (keepCheckBox); - //var scrollView2 = new ScrollView (new Rect (55, 2, 20, 8)) { + //var scrollView2 = new ScrollView (new Rectangle (55, 2, 20, 8)) { // ContentSize = new Size (20, 50), // //ContentOffset = new Point (0, 0), // ShowVerticalScrollIndicator = true, // ShowHorizontalScrollIndicator = true //}; - //var filler = new Filler (new Rect (0, 0, 60, 40)); + //var filler = new Filler (new Rectangle (0, 0, 60, 40)); //scrollView2.Add (filler); //scrollView2.DrawContent += (s,e) => { // scrollView2.ContentSize = filler.GetContentSize (); @@ -232,7 +232,7 @@ void Top_Loaded (object sender, EventArgs args) //Win.Add (scrollView2); //// This is just to debug the visuals of the scrollview when small - //var scrollView3 = new ScrollView (new Rect (55, 15, 3, 3)) { + //var scrollView3 = new ScrollView (new Rectangle (55, 15, 3, 3)) { // ContentSize = new Size (100, 100), // ShowVerticalScrollIndicator = true, // ShowHorizontalScrollIndicator = true diff --git a/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs b/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs index 1ac22ef4b4..68a2a419f4 100644 --- a/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs +++ b/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs @@ -254,7 +254,7 @@ public void TerminalResized_Simulation (Type driverType) //"; // var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - // Assert.Equal (new Rect (0, 0, 20, 8), pos); + // Assert.Equal (new Rectangle (0, 0, 20, 8), pos); // Assert.True (dlg.ProcessKey (new (Key.Tab))); // dlg.Draw (); @@ -271,7 +271,7 @@ public void TerminalResized_Simulation (Type driverType) //"; // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - // Assert.Equal (new Rect (0, 0, 20, 8), pos); + // Assert.Equal (new Rectangle (0, 0, 20, 8), pos); // win.RequestStop (); // }); diff --git a/UnitTests/View/Adornment/AdornmentTests.cs b/UnitTests/View/Adornment/AdornmentTests.cs index 2bda7b5d57..c84e139705 100644 --- a/UnitTests/View/Adornment/AdornmentTests.cs +++ b/UnitTests/View/Adornment/AdornmentTests.cs @@ -18,24 +18,24 @@ public void BoundsToScreen_All_Adornments_With_Thickness () parent.BeginInit (); parent.EndInit (); - Assert.Equal (new Rect (1, 2, 10, 10), parent.Frame); - Assert.Equal (new Rect (0, 0, 4, 4), parent.Bounds); - Assert.Equal (new Rect (0, 0, 10, 10), parent.Margin.Frame); - Assert.Equal (new Rect (1, 1, 8, 8), parent.Margin.Bounds); - Assert.Equal (new Rect (1, 1, 8, 8), parent.Border.Frame); - Assert.Equal (new Rect (1, 1, 6, 6), parent.Border.Bounds); - Assert.Equal (new Rect (2, 2, 6, 6), parent.Padding.Frame); - Assert.Equal (new Rect (1, 1, 4, 4), parent.Padding.Bounds); + Assert.Equal (new Rectangle (1, 2, 10, 10), parent.Frame); + Assert.Equal (new Rectangle (0, 0, 4, 4), parent.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Margin.Frame); + Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Margin.Bounds); + Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Border.Frame); + Assert.Equal (new Rectangle (1, 1, 6, 6), parent.Border.Bounds); + Assert.Equal (new Rectangle (2, 2, 6, 6), parent.Padding.Frame); + Assert.Equal (new Rectangle (1, 1, 4, 4), parent.Padding.Bounds); Assert.Null (parent.Margin.SuperView); - Rect boundsAsScreen = parent.BoundsToScreen (parent.Bounds); - Assert.Equal (new Rect (4, 5, 4, 4), boundsAsScreen); + Rectangle boundsAsScreen = parent.BoundsToScreen (parent.Bounds); + Assert.Equal (new Rectangle (4, 5, 4, 4), boundsAsScreen); boundsAsScreen = parent.Margin.BoundsToScreen (parent.Margin.Bounds); - Assert.Equal (new Rect (2, 3, 8, 8), boundsAsScreen); + Assert.Equal (new Rectangle (2, 3, 8, 8), boundsAsScreen); boundsAsScreen = parent.Border.BoundsToScreen (parent.Border.Bounds); - Assert.Equal (new Rect (2, 3, 6, 6), boundsAsScreen); + Assert.Equal (new Rectangle (2, 3, 6, 6), boundsAsScreen); boundsAsScreen = parent.Padding.BoundsToScreen (parent.Padding.Bounds); - Assert.Equal (new Rect (2, 3, 4, 4), boundsAsScreen); + Assert.Equal (new Rectangle (2, 3, 4, 4), boundsAsScreen); } [Fact] @@ -56,13 +56,13 @@ public void BoundsToScreen_Uses_Parent_Not_SuperView () Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Padding.Bounds); Assert.Null (parent.Margin.SuperView); - Rect boundsAsScreen = parent.BoundsToScreen (new Rect (1, 2, 5, 5)); + Rectangle boundsAsScreen = parent.BoundsToScreen (new Rectangle (1, 2, 5, 5)); Assert.Equal (new Rectangle (2, 4, 5, 5), boundsAsScreen); - boundsAsScreen = parent.Margin.BoundsToScreen (new Rect (1, 2, 5, 5)); + boundsAsScreen = parent.Margin.BoundsToScreen (new Rectangle (1, 2, 5, 5)); Assert.Equal (new Rectangle (2, 4, 5, 5), boundsAsScreen); - boundsAsScreen = parent.Border.BoundsToScreen (new Rect (1, 2, 5, 5)); + boundsAsScreen = parent.Border.BoundsToScreen (new Rectangle (1, 2, 5, 5)); Assert.Equal (new Rectangle (2, 4, 5, 5), boundsAsScreen); - boundsAsScreen = parent.Padding.BoundsToScreen (new Rect (1, 2, 5, 5)); + boundsAsScreen = parent.Padding.BoundsToScreen (new Rectangle (1, 2, 5, 5)); Assert.Equal (new Rectangle (2, 4, 5, 5), boundsAsScreen); } @@ -106,18 +106,18 @@ public void Draw_Centered_View_With_Thickness_One_On_All_Adornments () top.EndInit (); top.Draw (); - Assert.Equal ("(0,0,10,9)", parent.Margin.Frame.ToString ()); - Assert.Equal ("(1,1,8,7)", parent.Border.Frame.ToString ()); - Assert.Equal ("(2,2,6,5)", parent.Padding.Frame.ToString ()); - Assert.Equal ("(5,1,10,9)", parent.Frame.ToString ()); - Assert.Equal ("(1,1,8,7)", parent.Margin.Bounds.ToString ()); - Assert.Equal ("(1,1,6,5)", parent.Border.Bounds.ToString ()); - Assert.Equal ("(1,1,4,3)", parent.Padding.Bounds.ToString ()); - Assert.Equal ("(0,0,4,3)", parent.Bounds.ToString ()); - Assert.Equal ("(1,1,8,7)", parent.Margin.ContentArea.ToString ()); - Assert.Equal ("(1,1,6,5)", parent.Border.ContentArea.ToString ()); - Assert.Equal ("(1,1,4,3)", parent.Padding.ContentArea.ToString ()); - Assert.Equal ("(0,0,4,3)", parent.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=10,Height=9}", parent.Margin.Frame.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Border.Frame.ToString ()); + Assert.Equal ("{X=2,Y=2,Width=6,Height=5}", parent.Padding.Frame.ToString ()); + Assert.Equal ("{X=5,Y=1,Width=10,Height=9}", parent.Frame.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Margin.Bounds.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=6,Height=5}", parent.Border.Bounds.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=4,Height=3}", parent.Padding.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=4,Height=3}", parent.Bounds.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Margin.ContentArea.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=6,Height=5}", parent.Border.ContentArea.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=4,Height=3}", parent.Padding.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=4,Height=3}", parent.ContentArea.ToString ()); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -189,22 +189,22 @@ public void Draw_Centered_View_With_Thickness_One_On_All_Adornments_Inside_Anoth superTop.EndInit (); superTop.Draw (); - Assert.Equal ("(0,0,20,11)", top.Margin.Frame.ToString ()); - Assert.Equal ("(0,0,20,11)", top.Border.Frame.ToString ()); - Assert.Equal ("(1,1,18,9)", top.Padding.Frame.ToString ()); - Assert.Equal ("(0,0,20,11)", top.Frame.ToString ()); - Assert.Equal ("(0,0,10,9)", parent.Margin.Frame.ToString ()); - Assert.Equal ("(1,1,8,7)", parent.Border.Frame.ToString ()); - Assert.Equal ("(2,2,6,5)", parent.Padding.Frame.ToString ()); - Assert.Equal ("(4,0,10,9)", parent.Frame.ToString ()); - Assert.Equal ("(1,1,8,7)", parent.Margin.Bounds.ToString ()); - Assert.Equal ("(1,1,6,5)", parent.Border.Bounds.ToString ()); - Assert.Equal ("(1,1,4,3)", parent.Padding.Bounds.ToString ()); - Assert.Equal ("(0,0,4,3)", parent.Bounds.ToString ()); - Assert.Equal ("(1,1,8,7)", parent.Margin.ContentArea.ToString ()); - Assert.Equal ("(1,1,6,5)", parent.Border.ContentArea.ToString ()); - Assert.Equal ("(1,1,4,3)", parent.Padding.ContentArea.ToString ()); - Assert.Equal ("(0,0,4,3)", parent.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=20,Height=11}", top.Margin.Frame.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=20,Height=11}", top.Border.Frame.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=18,Height=9}", top.Padding.Frame.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=20,Height=11}", top.Frame.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=10,Height=9}", parent.Margin.Frame.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Border.Frame.ToString ()); + Assert.Equal ("{X=2,Y=2,Width=6,Height=5}", parent.Padding.Frame.ToString ()); + Assert.Equal ("{X=4,Y=0,Width=10,Height=9}", parent.Frame.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Margin.Bounds.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=6,Height=5}", parent.Border.Bounds.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=4,Height=3}", parent.Padding.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=4,Height=3}", parent.Bounds.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Margin.ContentArea.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=6,Height=5}", parent.Border.ContentArea.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=4,Height=3}", parent.Padding.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=4,Height=3}", parent.ContentArea.ToString ()); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -249,20 +249,20 @@ public void FrameToScreen_All_Adornments_With_Thickness () parent.BeginInit (); parent.EndInit (); - Assert.Equal (new Rect (1, 2, 10, 10), parent.Frame); - Assert.Equal (new Rect (0, 0, 4, 4), parent.Bounds); - Assert.Equal (new Rect (0, 0, 10, 10), parent.Margin.Frame); - Assert.Equal (new Rect (1, 1, 8, 8), parent.Margin.Bounds); - Assert.Equal (new Rect (1, 1, 8, 8), parent.Border.Frame); - Assert.Equal (new Rect (1, 1, 6, 6), parent.Border.Bounds); - Assert.Equal (new Rect (2, 2, 6, 6), parent.Padding.Frame); - Assert.Equal (new Rect (1, 1, 4, 4), parent.Padding.Bounds); + Assert.Equal (new Rectangle (1, 2, 10, 10), parent.Frame); + Assert.Equal (new Rectangle (0, 0, 4, 4), parent.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Margin.Frame); + Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Margin.Bounds); + Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Border.Frame); + Assert.Equal (new Rectangle (1, 1, 6, 6), parent.Border.Bounds); + Assert.Equal (new Rectangle (2, 2, 6, 6), parent.Padding.Frame); + Assert.Equal (new Rectangle (1, 1, 4, 4), parent.Padding.Bounds); Assert.Null (parent.Margin.SuperView); - Assert.Equal (new Rect (1, 2, 10, 10), parent.FrameToScreen ()); - Assert.Equal (new Rect (1, 2, 10, 10), parent.Margin.FrameToScreen ()); - Assert.Equal (new Rect (2, 3, 8, 8), parent.Border.FrameToScreen ()); - Assert.Equal (new Rect (3, 4, 6, 6), parent.Padding.FrameToScreen ()); + Assert.Equal (new Rectangle (1, 2, 10, 10), parent.FrameToScreen ()); + Assert.Equal (new Rectangle (1, 2, 10, 10), parent.Margin.FrameToScreen ()); + Assert.Equal (new Rectangle (2, 3, 8, 8), parent.Border.FrameToScreen ()); + Assert.Equal (new Rectangle (3, 4, 6, 6), parent.Padding.FrameToScreen ()); } [Fact] @@ -278,23 +278,23 @@ public void FrameToScreen_All_Adornments_With_Thickness_With_SuperView () parent.BeginInit (); parent.EndInit (); - Assert.Equal (new Rect (0, 0, 12, 12), top.Frame); - Assert.Equal (new Rect (0, 0, 12, 12), top.Bounds); - Assert.Equal (new Rect (1, 2, 10, 10), parent.Frame); - Assert.Equal (new Rect (0, 0, 4, 4), parent.Bounds); - Assert.Equal (new Rect (0, 0, 10, 10), parent.Margin.Frame); - Assert.Equal (new Rect (1, 1, 8, 8), parent.Margin.Bounds); - Assert.Equal (new Rect (1, 1, 8, 8), parent.Border.Frame); - Assert.Equal (new Rect (1, 1, 6, 6), parent.Border.Bounds); - Assert.Equal (new Rect (2, 2, 6, 6), parent.Padding.Frame); - Assert.Equal (new Rect (1, 1, 4, 4), parent.Padding.Bounds); + Assert.Equal (new Rectangle (0, 0, 12, 12), top.Frame); + Assert.Equal (new Rectangle (0, 0, 12, 12), top.Bounds); + Assert.Equal (new Rectangle (1, 2, 10, 10), parent.Frame); + Assert.Equal (new Rectangle (0, 0, 4, 4), parent.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Margin.Frame); + Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Margin.Bounds); + Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Border.Frame); + Assert.Equal (new Rectangle (1, 1, 6, 6), parent.Border.Bounds); + Assert.Equal (new Rectangle (2, 2, 6, 6), parent.Padding.Frame); + Assert.Equal (new Rectangle (1, 1, 4, 4), parent.Padding.Bounds); Assert.Null (parent.Margin.SuperView); - Assert.Equal (new Rect (0, 0, 12, 12), top.FrameToScreen ()); - Assert.Equal (new Rect (1, 2, 10, 10), parent.FrameToScreen ()); - Assert.Equal (new Rect (1, 2, 10, 10), parent.Margin.FrameToScreen ()); - Assert.Equal (new Rect (2, 3, 8, 8), parent.Border.FrameToScreen ()); - Assert.Equal (new Rect (3, 4, 6, 6), parent.Padding.FrameToScreen ()); + Assert.Equal (new Rectangle (0, 0, 12, 12), top.FrameToScreen ()); + Assert.Equal (new Rectangle (1, 2, 10, 10), parent.FrameToScreen ()); + Assert.Equal (new Rectangle (1, 2, 10, 10), parent.Margin.FrameToScreen ()); + Assert.Equal (new Rectangle (2, 3, 8, 8), parent.Border.FrameToScreen ()); + Assert.Equal (new Rectangle (3, 4, 6, 6), parent.Padding.FrameToScreen ()); } [Theory] diff --git a/UnitTests/View/Adornment/BorderTests.cs b/UnitTests/View/Adornment/BorderTests.cs index 89f76538c9..208e8ada2a 100644 --- a/UnitTests/View/Adornment/BorderTests.cs +++ b/UnitTests/View/Adornment/BorderTests.cs @@ -487,19 +487,19 @@ public void Border_With_Title_Size_Height (int height) switch (height) { case 0: - //Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 0), subview.Frame); expected = @" "; break; case 1: - //Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 0), subview.Frame); expected = @" ────────────────────"; break; case 2: - //Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 1), subview.Frame); expected = @" ┌┤1234├────────────┐ └──────────────────┘ @@ -507,7 +507,7 @@ public void Border_With_Title_Size_Height (int height) break; case 3: - //Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 2), subview.Frame); expected = @" ┌┤1234├────────────┐ │ │ @@ -548,7 +548,7 @@ public void Border_With_Title_Size_Width (int width) switch (width) { case 1: - //Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 0), subview.Frame); expected = @" │ │ @@ -556,7 +556,7 @@ public void Border_With_Title_Size_Width (int width) break; case 2: - //Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 1), subview.Frame); expected = @" ┌┐ ││ @@ -564,7 +564,7 @@ public void Border_With_Title_Size_Width (int width) break; case 3: - //Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 2), subview.Frame); expected = @" ┌─┐ │ │ @@ -573,7 +573,7 @@ public void Border_With_Title_Size_Width (int width) break; case 4: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 3), subview.Frame); expected = @" ┌┤├┐ │ │ @@ -581,7 +581,7 @@ public void Border_With_Title_Size_Width (int width) break; case 5: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 3), subview.Frame); expected = @" ┌┤1├┐ │ │ @@ -589,7 +589,7 @@ public void Border_With_Title_Size_Width (int width) break; case 6: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 3), subview.Frame); expected = @" ┌┤12├┐ │ │ @@ -597,7 +597,7 @@ public void Border_With_Title_Size_Width (int width) break; case 7: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 3), subview.Frame); expected = @" ┌┤123├┐ │ │ @@ -605,7 +605,7 @@ public void Border_With_Title_Size_Width (int width) break; case 8: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 3), subview.Frame); expected = @" ┌┤1234├┐ │ │ @@ -613,7 +613,7 @@ public void Border_With_Title_Size_Width (int width) break; case 9: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 3), subview.Frame); expected = @" ┌┤1234├─┐ │ │ @@ -621,7 +621,7 @@ public void Border_With_Title_Size_Width (int width) break; case 10: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 3), subview.Frame); expected = @" ┌┤1234├──┐ │ │ diff --git a/UnitTests/View/Layout/LayoutTests.cs b/UnitTests/View/Layout/LayoutTests.cs index 6065d2dee0..eaadf87b4a 100644 --- a/UnitTests/View/Layout/LayoutTests.cs +++ b/UnitTests/View/Layout/LayoutTests.cs @@ -45,13 +45,13 @@ public void Dim_CenteredSubView_85_Percent_Height (int height) switch (height) { case 1: - //Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 0), subview.Frame); expected = @" ────────────────────"; break; case 2: - //Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 1), subview.Frame); expected = @" ┌──────────────────┐ └──────────────────┘ @@ -59,7 +59,7 @@ public void Dim_CenteredSubView_85_Percent_Height (int height) break; case 3: - //Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 2), subview.Frame); expected = @" ┌──────────────────┐ │ │ @@ -68,7 +68,7 @@ public void Dim_CenteredSubView_85_Percent_Height (int height) break; case 4: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 3), subview.Frame); expected = @" ┌──────────────────┐ │ ─────────────── │ @@ -77,7 +77,7 @@ public void Dim_CenteredSubView_85_Percent_Height (int height) break; case 5: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 3), subview.Frame); expected = @" ┌──────────────────┐ │ ┌─────────────┐ │ @@ -87,7 +87,7 @@ public void Dim_CenteredSubView_85_Percent_Height (int height) break; case 6: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 3), subview.Frame); expected = @" ┌──────────────────┐ │ ┌─────────────┐ │ @@ -98,7 +98,7 @@ public void Dim_CenteredSubView_85_Percent_Height (int height) break; case 7: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 3), subview.Frame); expected = @" ┌──────────────────┐ │ ┌─────────────┐ │ @@ -110,7 +110,7 @@ public void Dim_CenteredSubView_85_Percent_Height (int height) break; case 8: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 3), subview.Frame); expected = @" ┌──────────────────┐ │ ┌─────────────┐ │ @@ -123,7 +123,7 @@ public void Dim_CenteredSubView_85_Percent_Height (int height) break; case 9: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 3), subview.Frame); expected = @" ┌──────────────────┐ │ │ @@ -137,7 +137,7 @@ public void Dim_CenteredSubView_85_Percent_Height (int height) break; case 10: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new Rectangle (0, 0, 17, 3), subview.Frame); expected = @" ┌──────────────────┐ │ │ @@ -337,7 +337,7 @@ public void DimFill_SizedCorrectly () //view.SetNeedsLayout (); Application.Top.LayoutSubviews (); - //view.SetRelativeLayout (new Rect (0, 0, 32, 5)); + //view.SetRelativeLayout (new Rectangle (0, 0, 32, 5)); Assert.Equal (32, view.Frame.Width); Assert.Equal (5, view.Frame.Height); } diff --git a/UnitTests/View/Text/AutoSizeTrueTests.cs b/UnitTests/View/Text/AutoSizeTrueTests.cs index 85494e1511..5b438de6f5 100644 --- a/UnitTests/View/Text/AutoSizeTrueTests.cs +++ b/UnitTests/View/Text/AutoSizeTrueTests.cs @@ -760,11 +760,11 @@ public void AutoSize_Dim_Subtract_Operator_With_Text () // Assert.Equal (5, text.Length); // Assert.False (label.AutoSize); - // Assert.Equal (new Rect (0, 0, 0, 1), label.Frame); + // Assert.Equal (new Rectangle (0, 0, 0, 1), label.Frame); // Assert.Equal (new Size (3, 1), label.TextFormatter.Size); // Assert.Equal (new List { "Lab" }, label.TextFormatter.Lines); - // Assert.Equal (new Rect (0, 0, 10, 4), win.Frame); - // Assert.Equal (new Rect (0, 0, 10, 4), Application.Top.Frame); + // Assert.Equal (new Rectangle (0, 0, 10, 4), win.Frame); + // Assert.Equal (new Rectangle (0, 0, 10, 4), Application.Top.Frame); // var expected = @" //┌────────┐ //│Lab │ @@ -773,7 +773,7 @@ public void AutoSize_Dim_Subtract_Operator_With_Text () //"; // var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rect (0, 0, 10, 4), pos); + // Assert.Equal (new Rectangle (0, 0, 10, 4), pos); // text = "0123456789"; // Assert.Equal (10, text.Length); @@ -781,7 +781,7 @@ public void AutoSize_Dim_Subtract_Operator_With_Text () // Application.Refresh (); // Assert.False (label.AutoSize); - // Assert.Equal (new Rect (0, 0, 0, 1), label.Frame); + // Assert.Equal (new Rectangle (0, 0, 0, 1), label.Frame); // Assert.Equal (new Size (0, 1), label.TextFormatter.Size); // Assert.Equal (new List { string.Empty }, label.TextFormatter.Lines); // expected = @" @@ -792,7 +792,7 @@ public void AutoSize_Dim_Subtract_Operator_With_Text () //"; // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rect (0, 0, 10, 4), pos); + // Assert.Equal (new Rectangle (0, 0, 10, 4), pos); // } [Fact] @@ -2363,10 +2363,10 @@ public void GetCurrentWidth_TrySetWidth () // var rs = Application.Begin (Application.Top); // ((FakeDriver)Application.Driver).SetBufferSize (22, 22); - // Assert.Equal (new Rect (0, 0, 22, 22), win.Frame); - // Assert.Equal (new Rect (0, 0, 22, 22), win.Margin.Frame); - // Assert.Equal (new Rect (0, 0, 22, 22), win.Border.Frame); - // Assert.Equal (new Rect (1, 1, 20, 20), win.Padding.Frame); + // Assert.Equal (new Rectangle (0, 0, 22, 22), win.Frame); + // Assert.Equal (new Rectangle (0, 0, 22, 22), win.Margin.Frame); + // Assert.Equal (new Rectangle (0, 0, 22, 22), win.Border.Frame); + // Assert.Equal (new Rectangle (1, 1, 20, 20), win.Padding.Frame); // Assert.False (view.AutoSize); // Assert.Equal (TextDirection.LeftRight_TopBottom, view.TextDirection); // Assert.Equal (Rect.Empty, view.Frame); @@ -2400,7 +2400,7 @@ public void GetCurrentWidth_TrySetWidth () //"; // var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rect (0, 0, 22, 22), pos); + // Assert.Equal (new Rectangle (0, 0, 22, 22), pos); // view.Text = "Hello World"; // view.Width = 11; @@ -2408,7 +2408,7 @@ public void GetCurrentWidth_TrySetWidth () // win.LayoutSubviews (); // Application.Refresh (); - // Assert.Equal (new Rect (0, 0, 11, 1), view.Frame); + // Assert.Equal (new Rectangle (0, 0, 11, 1), view.Frame); // Assert.Equal ("Absolute(0)", view.X.ToString ()); // Assert.Equal ("Absolute(0)", view.Y.ToString ()); // Assert.Equal ("Absolute(11)", view.Width.ToString ()); @@ -2439,13 +2439,13 @@ public void GetCurrentWidth_TrySetWidth () //"; // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rect (0, 0, 22, 22), pos); + // Assert.Equal (new Rectangle (0, 0, 22, 22), pos); // view.AutoSize = true; // view.Text = "Hello Worlds"; // Application.Refresh (); - // Assert.Equal (new Rect (0, 0, 12, 1), view.Frame); + // Assert.Equal (new Rectangle (0, 0, 12, 1), view.Frame); // Assert.Equal ("Absolute(0)", view.X.ToString ()); // Assert.Equal ("Absolute(0)", view.Y.ToString ()); // Assert.Equal ("Absolute(11)", view.Width.ToString ()); @@ -2476,12 +2476,12 @@ public void GetCurrentWidth_TrySetWidth () //"; // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rect (0, 0, 22, 22), pos); + // Assert.Equal (new Rectangle (0, 0, 22, 22), pos); // view.TextDirection = TextDirection.TopBottom_LeftRight; // Application.Refresh (); - // Assert.Equal (new Rect (0, 0, 11, 12), view.Frame); + // Assert.Equal (new Rectangle (0, 0, 11, 12), view.Frame); // Assert.Equal ("Absolute(0)", view.X.ToString ()); // Assert.Equal ("Absolute(0)", view.Y.ToString ()); // Assert.Equal ("Absolute(11)", view.Width.ToString ()); @@ -2512,13 +2512,13 @@ public void GetCurrentWidth_TrySetWidth () //"; // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rect (0, 0, 22, 22), pos); + // Assert.Equal (new Rectangle (0, 0, 22, 22), pos); // view.AutoSize = false; // view.Height = 1; // Application.Refresh (); - // Assert.Equal (new Rect (0, 0, 11, 1), view.Frame); + // Assert.Equal (new Rectangle (0, 0, 11, 1), view.Frame); // Assert.Equal ("Absolute(0)", view.X.ToString ()); // Assert.Equal ("Absolute(0)", view.Y.ToString ()); // Assert.Equal ("Absolute(11)", view.Width.ToString ()); @@ -2549,12 +2549,12 @@ public void GetCurrentWidth_TrySetWidth () //"; // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rect (0, 0, 22, 22), pos); + // Assert.Equal (new Rectangle (0, 0, 22, 22), pos); // view.PreserveTrailingSpaces = true; // Application.Refresh (); - // Assert.Equal (new Rect (0, 0, 11, 1), view.Frame); + // Assert.Equal (new Rectangle (0, 0, 11, 1), view.Frame); // Assert.Equal ("Absolute(0)", view.X.ToString ()); // Assert.Equal ("Absolute(0)", view.Y.ToString ()); // Assert.Equal ("Absolute(11)", view.Width.ToString ()); @@ -2585,7 +2585,7 @@ public void GetCurrentWidth_TrySetWidth () //"; // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rect (0, 0, 22, 22), pos); + // Assert.Equal (new Rectangle (0, 0, 22, 22), pos); // view.PreserveTrailingSpaces = false; // var f = view.Frame; @@ -2594,7 +2594,7 @@ public void GetCurrentWidth_TrySetWidth () // view.TextDirection = TextDirection.TopBottom_LeftRight; // Application.Refresh (); - // Assert.Equal (new Rect (0, 0, 1, 11), view.Frame); + // Assert.Equal (new Rectangle (0, 0, 1, 11), view.Frame); // Assert.Equal ("Absolute(0)", view.X.ToString ()); // Assert.Equal ("Absolute(0)", view.Y.ToString ()); // Assert.Equal ("Absolute(1)", view.Width.ToString ()); @@ -2625,12 +2625,12 @@ public void GetCurrentWidth_TrySetWidth () //"; // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rect (0, 0, 22, 22), pos); + // Assert.Equal (new Rectangle (0, 0, 22, 22), pos); // view.AutoSize = true; // Application.Refresh (); - // Assert.Equal (new Rect (0, 0, 1, 12), view.Frame); + // Assert.Equal (new Rectangle (0, 0, 1, 12), view.Frame); // Assert.Equal ("Absolute(0)", view.X.ToString ()); // Assert.Equal ("Absolute(0)", view.Y.ToString ()); // Assert.Equal ("Absolute(1)", view.Width.ToString ()); @@ -2661,7 +2661,7 @@ public void GetCurrentWidth_TrySetWidth () //"; // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rect (0, 0, 22, 22), pos); + // Assert.Equal (new Rectangle (0, 0, 22, 22), pos); // Application.End (rs); // } diff --git a/UnitTests/View/ViewTests.cs b/UnitTests/View/ViewTests.cs index a5ef315b4a..fa8702bc34 100644 --- a/UnitTests/View/ViewTests.cs +++ b/UnitTests/View/ViewTests.cs @@ -773,7 +773,7 @@ public void New_Initializes () Assert.Equal (TextDirection.LeftRight_TopBottom, r.TextDirection); r.Dispose (); - // Rect with values + // Rectangle with values r = new View { Frame = new Rectangle (1, 2, 3, 4) }; Assert.NotNull (r); Assert.Equal (LayoutStyle.Absolute, r.LayoutStyle); diff --git a/UnitTests/Views/MenuBarTests.cs b/UnitTests/Views/MenuBarTests.cs index cdca63cbd0..016b12b4d4 100644 --- a/UnitTests/Views/MenuBarTests.cs +++ b/UnitTests/Views/MenuBarTests.cs @@ -1008,7 +1008,7 @@ File Edit "; var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Assert.Equal (new Rect (1, 0, 11, 1), pos); + Assert.Equal (new Rectangle (1, 0, 11, 1), pos); Assert.True (Application.Top.ProcessKeyDown (new KeyEventArgs (Key.N))); Application.MainLoop.RunIteration (); @@ -1036,7 +1036,7 @@ File Edit "; pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Assert.Equal (new Rect (1, 0, 11, 1), pos); + Assert.Equal (new Rectangle (1, 0, 11, 1), pos); Assert.True (Application.Top.ProcessKeyDown (new KeyEventArgs (Key.CursorRight))); Assert.True (Application.Top.ProcessKeyDown (new KeyEventArgs (Key.C))); diff --git a/UnitTests/Views/ScrollBarTests.cs b/UnitTests/Views/ScrollBarTests.cs index 37acb9e94d..2c9d0d5ad1 100644 --- a/UnitTests/Views/ScrollBarTests.cs +++ b/UnitTests/Views/ScrollBarTests.cs @@ -790,8 +790,8 @@ public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () └───────────────────────────────────────────┘ "; - Rect pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rect (0, 0, 45, 20), pos); + Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); + Assert.Equal (new Rectangle (0, 0, 45, 20), pos); textView.WordWrap = true; ((FakeDriver)Application.Driver).SetBufferSize (26, 20); @@ -831,7 +831,7 @@ public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () "; pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rect (0, 0, 26, 20), pos); + Assert.Equal (new Rectangle (0, 0, 26, 20), pos); ((FakeDriver)Application.Driver).SetBufferSize (10, 11); Application.Refresh (); @@ -862,7 +862,7 @@ public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () "; pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rect (0, 0, 10, 11), pos); + Assert.Equal (new Rectangle (0, 0, 10, 11), pos); Assert.False (textView.ReadOnly); textView.ReadOnly = true; @@ -893,7 +893,7 @@ public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () "; pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rect (0, 0, 10, 11), pos); + Assert.Equal (new Rectangle (0, 0, 10, 11), pos); } [Fact] @@ -929,7 +929,7 @@ public void Hosting_Two_Vertical_ScrollBar_Throws_ArgumentException () public void Internal_Tests () { Toplevel top = Application.Top; - Assert.Equal (new Rect (0, 0, 80, 25), top.Bounds); + Assert.Equal (new Rectangle (0, 0, 80, 25), top.Bounds); var view = new View { Width = Dim.Fill (), Height = Dim.Fill () }; var sbv = new ScrollBar { IsVertical = true, OtherScrollBar = new ScrollBar { IsVertical = false } }; view.Add (sbv); @@ -1138,18 +1138,18 @@ public void ScrollBarType_IsBuiltIn_In_Padding_Thickness () Assert.False (view2.HasFocus); Assert.Equal (12, view.ScrollColsSize); Assert.Equal (7, view.ScrollRowsSize); - Assert.Equal ("(0,0,8,5)", view.Bounds.ToString ()); - Assert.Equal ("(0,0,8,5)", view.ContentArea.ToString ()); - Assert.Equal ("(3,2,9,6)", view.Frame.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Margin.Bounds.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Margin.ContentArea.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Margin.Frame.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Border.Bounds.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Border.ContentArea.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Border.Frame.ToString ()); - Assert.Equal ("(0,0,8,5)", view.Padding.Bounds.ToString ()); - Assert.Equal ("(0,0,8,5)", view.Padding.ContentArea.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Padding.Frame.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.ContentArea.ToString ()); + Assert.Equal ("{X=3,Y=2,Width=9,Height=6}", view.Frame.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.Frame.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Frame.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Padding.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Padding.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.Frame.ToString ()); Assert.Equal ("(Left=0,Top=0,Right=1,Bottom=1)", view.Padding.Thickness.ToString ()); Assert.Equal ("{Width=8, Height=5}", view.TextFormatter.Size.ToString ()); @@ -1238,18 +1238,18 @@ public void ScrollBarType_IsBuiltIn_In_Padding_Thickness_Inside_Another_Containe Assert.False (view2.HasFocus); Assert.Equal (12, view.ScrollColsSize); Assert.Equal (7, view.ScrollRowsSize); - Assert.Equal ("(0,0,8,5)", view.Bounds.ToString ()); - Assert.Equal ("(0,0,8,5)", view.ContentArea.ToString ()); - Assert.Equal ("(2,1,9,6)", view.Frame.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Margin.Bounds.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Margin.ContentArea.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Margin.Frame.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Border.Bounds.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Border.ContentArea.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Border.Frame.ToString ()); - Assert.Equal ("(0,0,8,5)", view.Padding.Bounds.ToString ()); - Assert.Equal ("(0,0,8,5)", view.Padding.ContentArea.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Padding.Frame.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.ContentArea.ToString ()); + Assert.Equal ("{X=2,Y=1,Width=9,Height=6}", view.Frame.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.Frame.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Frame.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Padding.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Padding.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.Frame.ToString ()); Assert.Equal ("(Left=0,Top=0,Right=1,Bottom=1)", view.Padding.Thickness.ToString ()); Assert.Equal ("{Width=8, Height=5}", view.TextFormatter.Size.ToString ()); @@ -1336,18 +1336,18 @@ public void ScrollBarType_IsBuiltIn_In_Parent_Inside_Another_Container () Assert.False (view2.HasFocus); Assert.Equal (12, view.ScrollColsSize); Assert.Equal (7, view.ScrollRowsSize); - Assert.Equal ("(0,0,9,6)", view.Bounds.ToString ()); - Assert.Equal ("(0,0,9,6)", view.ContentArea.ToString ()); - Assert.Equal ("(2,1,9,6)", view.Frame.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Margin.Bounds.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Margin.ContentArea.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Margin.Frame.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Border.Bounds.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Border.ContentArea.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Border.Frame.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Padding.Bounds.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Padding.ContentArea.ToString ()); - Assert.Equal ("(0,0,9,6)", view.Padding.Frame.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.ContentArea.ToString ()); + Assert.Equal ("{X=2,Y=1,Width=9,Height=6}", view.Frame.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.Frame.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Frame.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.Frame.ToString ()); Assert.Equal ("(Left=0,Top=0,Right=0,Bottom=0)", view.Padding.Thickness.ToString ()); Assert.Equal ("{Width=9, Height=6}", view.TextFormatter.Size.ToString ()); diff --git a/UnitTests/Views/WindowTests.cs b/UnitTests/Views/WindowTests.cs index 95e7d1af21..57fc532186 100644 --- a/UnitTests/Views/WindowTests.cs +++ b/UnitTests/Views/WindowTests.cs @@ -185,7 +185,7 @@ public void New_Initializes () Assert.Null (windowWithFrameRectEmpty.MostFocused); Assert.Equal (TextDirection.LeftRight_TopBottom, windowWithFrameRectEmpty.TextDirection); - // Rect with values + // Rectangle with values using var windowWithFrame1234 = new Window ( ); windowWithFrame1234.Frame = new (1, 2, 3, 4); windowWithFrame1234.Title = "title"; From 33861c3bb11ea7d44ef25bf747bec23b5cadc13f Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 24 Feb 2024 02:04:21 +0000 Subject: [PATCH 043/130] Add ContentOffset property. --- Terminal.Gui/View/Layout/ViewLayout.cs | 34 ++++--- Terminal.Gui/View/ViewScrollBar.cs | 7 +- Terminal.Gui/Views/ScrollBar.cs | 126 ++++++++++++++++++------- 3 files changed, 114 insertions(+), 53 deletions(-) diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index a6cf32eba2..ff69ce6ca9 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -190,13 +190,17 @@ public virtual Rectangle Bounds - Margin.Thickness.Horizontal - Border.Thickness.Horizontal - Padding.Thickness.Horizontal - - _bounds.Location.X); + - ContentOffset.X); int height = Math.Max ( 0, - Frame.Size.Height - Margin.Thickness.Vertical - Border.Thickness.Vertical - Padding.Thickness.Vertical - _bounds.Location.Y); + Frame.Size.Height + - Margin.Thickness.Vertical + - Border.Thickness.Vertical + - Padding.Thickness.Vertical + - ContentOffset.Y); - return new Rectangle (_bounds.Location, new Size (width, height)); + return new Rectangle (ContentOffset, new Size (width, height)); } set { @@ -210,12 +214,6 @@ public virtual Rectangle Bounds ); } #endif // DEBUG - if (ScrollBarType != ScrollBarType.None && UseNegativeBoundsLocation) - { - _bounds = value; - - return; - } Frame = new Rectangle ( Frame.Location, @@ -258,6 +256,11 @@ public virtual Rectangle ContentArea } } + /// + /// Represent the content offset if is true. + /// + public Point ContentOffset { get; set; } + /// Gets or sets the absolute location and dimension of the view. /// /// The rectangle describing absolute location and dimension of the view, in coordinates relative to the @@ -272,7 +275,8 @@ public virtual Rectangle ContentArea /// This causes to be . /// /// Altering the Frame will eventually (when the view hierarchy is next laid out via see - /// cref="LayoutSubviews"/>) cause and + /// cref="LayoutSubviews"/>) cause and + /// /// methods to be called. /// /// @@ -472,7 +476,8 @@ public Dim Width /// /// /// If set to a relative value (e.g. ) the value is indeterminate until the view has been - /// initialized ( is true) and has been called. + /// initialized ( is true) and has been + /// called. /// /// /// Changing this property will eventually (when the view is next drawn) cause the @@ -499,7 +504,8 @@ public Pos X /// /// /// If set to a relative value (e.g. ) the value is indeterminate until the view has been - /// initialized ( is true) and has been called. + /// initialized ( is true) and has been + /// called. /// /// /// Changing this property will eventually (when the view is next drawn) cause the @@ -986,8 +992,8 @@ internal void OnResizeNeeded () // First try SuperView.Bounds, then Application.Top, then Driver.Bounds. // Finally, if none of those are valid, use int.MaxValue (for Unit tests). Rectangle relativeBounds = SuperView is { IsInitialized: true } ? SuperView.Bounds : - Application.Top is { } && Application.Top.IsInitialized ? Application.Top.Bounds : - Application.Driver?.Bounds ?? new Rectangle (0, 0, int.MaxValue, int.MaxValue); + Application.Top is { } && Application.Top.IsInitialized ? Application.Top.Bounds : + Application.Driver?.Bounds ?? new Rectangle (0, 0, int.MaxValue, int.MaxValue); SetRelativeLayout (relativeBounds); // TODO: Determine what, if any of the below is actually needed here. diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 27ee281063..11608d9d88 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -61,7 +61,6 @@ public virtual ScrollBarType ScrollBarType view._scrollBarType = value; view.DisposeScrollBar (); - switch (view._scrollBarType) { case ScrollBarType.Vertical: @@ -592,8 +591,7 @@ private void SetBoundsByPosition (ScrollBar scrollBar) { if (UseNegativeBoundsLocation) { - Bounds = Bounds with { Y = -scrollBar.Position }; - Bounds = Bounds with { Height = Math.Min (Bounds.Height + scrollBar.Position, ScrollRowsSize) }; + ContentOffset = new Point (Bounds.X, -scrollBar.Position); if (Bounds.Y != -scrollBar.Position) { @@ -612,8 +610,7 @@ private void SetBoundsByPosition (ScrollBar scrollBar) { if (UseNegativeBoundsLocation) { - Bounds = Bounds with { X = -scrollBar.Position }; - Bounds = Bounds with { Width = Math.Min (Bounds.Width + scrollBar.Position, ScrollColsSize) }; + ContentOffset = new Point (-scrollBar.Position, Bounds.Y); if (Bounds.X != -scrollBar.Position) { diff --git a/Terminal.Gui/Views/ScrollBar.cs b/Terminal.Gui/Views/ScrollBar.cs index 2784c03682..5a198c6fba 100644 --- a/Terminal.Gui/Views/ScrollBar.cs +++ b/Terminal.Gui/Views/ScrollBar.cs @@ -17,6 +17,7 @@ namespace Terminal.Gui; /// public class ScrollBar : View { + private static Point _superViewContentOffset; private bool _autoHideScrollBars = true; private View _contentBottomRightCorner; private bool _keepContentAlwaysInViewport = true; @@ -164,7 +165,7 @@ public bool ShowScrollIndicator /// public int Size { - get => _size; + get => _size - (IsVertical ? _superViewContentOffset.Y : _superViewContentOffset.X); set { _size = value; @@ -631,7 +632,7 @@ public override bool OnMouseLeave (MouseEvent mouseEvent) // param n is the new position and the max is the positive/negative value that can be scrolled for the new position internal bool CanScroll (int n, out int maxToScroll, bool isVertical = false) { - if (SuperView is null || SuperView?.Bounds.IsEmpty == true) + if (GetSuperViewBounds ().IsEmpty) { maxToScroll = 0; @@ -639,13 +640,13 @@ internal bool CanScroll (int n, out int maxToScroll, bool isVertical = false) } int barSize = GetBarSize (isVertical); - int newPosition = Math.Max (Math.Min (_size - barSize, n), 0); + int newPosition = Math.Max (Math.Min (Size - barSize, n), 0); - maxToScroll = _size > barSize + newPosition + maxToScroll = Size > barSize + newPosition ? newPosition - _position - : _size - (barSize + _position) - (barSize == 0 && _showBothScrollIndicator ? 1 : 0); + : Size - (barSize + _position) - (barSize == 0 && _showBothScrollIndicator ? 1 : 0); - return _size >= barSize + newPosition && maxToScroll != 0; + return Size >= barSize + newPosition && maxToScroll != 0; } private void AdjustContentInViewport (bool refresh = true) @@ -656,15 +657,16 @@ private void AdjustContentInViewport (bool refresh = true) } var pos = 0; + Rectangle bounds = GetSuperViewBounds (); - if (KeepContentAlwaysInViewPort && !_vertical && _position + SuperView.Bounds.Width > _size + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0)) + if (KeepContentAlwaysInViewPort && !_vertical && _position + bounds.Width > Size + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0)) { - pos = Math.Max (_size - SuperView.Bounds.Width + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0), 0); + pos = Math.Max (Size - bounds.Width + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0), 0); } - if (KeepContentAlwaysInViewPort && _vertical && _position + SuperView.Bounds.Height > _size + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0)) + if (KeepContentAlwaysInViewPort && _vertical && _position + bounds.Height > Size + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0)) { - pos = Math.Max (_size - SuperView.Bounds.Height + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0), 0); + pos = Math.Max (Size - bounds.Height + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0), 0); } if (pos != 0) @@ -687,7 +689,7 @@ private bool CheckBothScrollBars (ScrollBar scrollBarView, bool pending = false) { int barsize = scrollBarView._vertical ? scrollBarView.Bounds.Height : scrollBarView.Bounds.Width; - if (barsize == 0 || barsize >= scrollBarView._size) + if (barsize == 0 || barsize >= scrollBarView.Size) { if (scrollBarView._showScrollIndicator) { @@ -699,7 +701,7 @@ private bool CheckBothScrollBars (ScrollBar scrollBarView, bool pending = false) scrollBarView.Visible = false; } } - else if (barsize > 0 && barsize == scrollBarView._size && scrollBarView.OtherScrollBar is { } && pending) + else if (barsize > 0 && barsize == scrollBarView.Size && scrollBarView.OtherScrollBar is { } && pending) { if (scrollBarView._showScrollIndicator) { @@ -721,7 +723,7 @@ private bool CheckBothScrollBars (ScrollBar scrollBarView, bool pending = false) scrollBarView.OtherScrollBar.Visible = false; } } - else if (barsize > 0 && barsize == _size && scrollBarView.OtherScrollBar is { } && !pending) + else if (barsize > 0 && barsize == Size && scrollBarView.OtherScrollBar is { } && !pending) { pending = true; } @@ -837,7 +839,9 @@ private void CreateBottomRightCorner (View host) private int GetBarSize (bool isVertical) { - if (SuperView is null || SuperView?.Bounds.IsEmpty == true) + Rectangle bounds = GetSuperViewBounds (); + + if (bounds.IsEmpty) { return 0; } @@ -845,15 +849,25 @@ private int GetBarSize (bool isVertical) if (IsBuiltIn) { return isVertical ? KeepContentAlwaysInViewPort - ? SuperView.Bounds.Height + ? bounds.Height : 0 : - KeepContentAlwaysInViewPort ? SuperView.Bounds.Width : 0; + KeepContentAlwaysInViewPort ? bounds.Width : 0; } return isVertical ? KeepContentAlwaysInViewPort - ? SuperView.Bounds.Height - (_showBothScrollIndicator ? 1 : 0) + ? bounds.Height - (_showBothScrollIndicator ? 1 : 0) : 0 : - KeepContentAlwaysInViewPort ? SuperView.Bounds.Width - (_showBothScrollIndicator ? 1 : 0) : 0; + KeepContentAlwaysInViewPort ? bounds.Width - (_showBothScrollIndicator ? 1 : 0) : 0; + } + + private Rectangle GetSuperViewBounds () + { + if (SuperView is null) + { + return Rectangle.Empty; + } + + return new Rectangle (Point.Empty, new Size (SuperView.Bounds.Width + SuperView.ContentOffset.X, SuperView.Bounds.Height + SuperView.ContentOffset.Y)); } private void ManageScrollBarThickness () @@ -991,7 +1005,6 @@ private void SetPosition (int newPosition) OtherScrollBar?._contentBottomRightCorner?.SetNeedsDisplay (); } - // BUGBUG: v2 - rationalize this with View.SetMinWidthHeight private void SetWidthHeight () { if (!IsInitialized) @@ -1001,26 +1014,71 @@ private void SetWidthHeight () if (_showBothScrollIndicator) { - Width = _vertical ? 1 : SuperView is Adornment ? Dim.Fill () : Dim.Fill (1); - Height = _vertical ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) : 1; + if (SuperView is { UseNegativeBoundsLocation: true }) + { + Rectangle bounds = GetSuperViewBounds (); + + X = _vertical ? bounds.Right - 1 : bounds.Left; + Y = _vertical ? bounds.Top : bounds.Bottom - 1; + Width = _vertical ? 1 : SuperView is Adornment ? Dim.Fill () : bounds.Width - 1; + Height = _vertical ? SuperView is Adornment ? Dim.Fill () : bounds.Height - 1 : 1; + + _otherScrollBar.X = _otherScrollBar._vertical ? bounds.Right - 1 : bounds.Left; + _otherScrollBar.Y = _otherScrollBar._vertical ? bounds.Top : bounds.Bottom - 1; + + _otherScrollBar.Width = _otherScrollBar._vertical ? 1 : + SuperView is Adornment ? Dim.Fill () : bounds.Width - 1; + + _otherScrollBar.Height = _otherScrollBar._vertical + ? SuperView is Adornment ? Dim.Fill () : bounds.Height - 1 + : 1; + } + else + { + Width = _vertical ? 1 : SuperView is Adornment ? Dim.Fill () : Dim.Fill (1); + Height = _vertical ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) : 1; - _otherScrollBar.Width = _otherScrollBar._vertical ? 1 : - SuperView is Adornment ? Dim.Fill () : Dim.Fill (1); + _otherScrollBar.Width = _otherScrollBar._vertical ? 1 : + SuperView is Adornment ? Dim.Fill () : Dim.Fill (1); - _otherScrollBar.Height = _otherScrollBar._vertical - ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) - : 1; + _otherScrollBar.Height = _otherScrollBar._vertical + ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) + : 1; + } } else if (_showScrollIndicator) { - Width = _vertical ? 1 : Dim.Fill (); - Height = _vertical ? Dim.Fill () : 1; + if (SuperView is { UseNegativeBoundsLocation: true }) + { + Rectangle bounds = GetSuperViewBounds (); + + X = _vertical ? bounds.Right - 1 : bounds.Left; + Y = _vertical ? bounds.Top : bounds.Bottom - 1; + Width = _vertical ? 1 : bounds.Width; + Height = _vertical ? bounds.Height : 1; + } + else + { + Width = _vertical ? 1 : Dim.Fill (); + Height = _vertical ? Dim.Fill () : 1; + } } else if (_otherScrollBar?._showScrollIndicator == true) { - _otherScrollBar.Width = _otherScrollBar._vertical ? 1 : Dim.Fill (); + if (SuperView is { UseNegativeBoundsLocation: true }) + { + Rectangle bounds = GetSuperViewBounds (); - _otherScrollBar.Height = _otherScrollBar._vertical ? Dim.Fill () : 1; + _otherScrollBar.X = _otherScrollBar._vertical ? bounds.Right - 1 : bounds.Left; + _otherScrollBar.Y = _otherScrollBar._vertical ? bounds.Top : bounds.Bottom - 1; + _otherScrollBar.Width = _otherScrollBar._vertical ? 1 : bounds.Width; + _otherScrollBar.Height = _otherScrollBar._vertical ? bounds.Height : 1; + } + else + { + _otherScrollBar.Width = _otherScrollBar._vertical ? 1 : Dim.Fill (); + _otherScrollBar.Height = _otherScrollBar._vertical ? Dim.Fill () : 1; + } } if (IsBuiltIn) @@ -1037,7 +1095,7 @@ private void ShowHideScrollBars (bool redraw = true) return; } - SetRelativeLayout (SuperView?.Bounds ?? Bounds); + SetRelativeLayout (GetSuperViewBounds ()); if (AutoHideScrollBars) { @@ -1045,18 +1103,18 @@ private void ShowHideScrollBars (bool redraw = true) if (_otherScrollBar is { }) { - _otherScrollBar.SetRelativeLayout (SuperView?.Bounds ?? Bounds); + _otherScrollBar.SetRelativeLayout (GetSuperViewBounds ()); CheckBothScrollBars (_otherScrollBar, pending); } } SetWidthHeight (); - SetRelativeLayout (SuperView?.Bounds ?? Bounds); + SetRelativeLayout (GetSuperViewBounds ()); if (_otherScrollBar is { }) { OtherScrollBar.SetWidthHeight (); - OtherScrollBar.SetRelativeLayout (SuperView?.Bounds ?? Bounds); + OtherScrollBar.SetRelativeLayout (GetSuperViewBounds ()); } if (_showBothScrollIndicator) From 64b7f2e7a98266a306e6ca0fd37db6888b4b2d52 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 24 Feb 2024 02:06:18 +0000 Subject: [PATCH 044/130] Allow all adornments handle mouse events on subviews. --- Terminal.Gui/Application.cs | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/Terminal.Gui/Application.cs b/Terminal.Gui/Application.cs index 7d1aaf7a4f..2c7608f9eb 100644 --- a/Terminal.Gui/Application.cs +++ b/Terminal.Gui/Application.cs @@ -1573,9 +1573,9 @@ bool AdornmentHandledMouseEvent (Adornment adornment) // TODO: Debate whether inside-out or outside-in is the right strategy if (AdornmentHandledMouseEvent (view?.Padding)) { - view = View.FindDeepestView (view?.Padding, screenX, screenY, out _, out _); + view = View.FindDeepestView (view?.Padding, screenX, screenY, out int newX, out int newY); - if (view is { } && AdornmentSubViewHandledMouseEvent ()) + if (view is { } && AdornmentSubViewHandledMouseEvent (newX, newY)) { return; } @@ -1585,12 +1585,23 @@ bool AdornmentHandledMouseEvent (Adornment adornment) if (AdornmentHandledMouseEvent (view?.Border)) { - if (view is Toplevel) + View previousView = view; + + view = View.FindDeepestView (view?.Border, screenX, screenY, out int newX, out int newY); + + if (view is { } && AdornmentSubViewHandledMouseEvent (newX, newY)) + { + return; + } + + view = previousView; + + if (previousView is Toplevel) { // TODO: This is a temporary hack to work around the fact that // drag handling is handled in Toplevel (See Issue #2537) - if (AdornmentSubViewHandledMouseEvent ()) + if (AdornmentSubViewHandledMouseEvent (screenX, screenY)) { return; } @@ -1601,6 +1612,13 @@ bool AdornmentHandledMouseEvent (Adornment adornment) if (AdornmentHandledMouseEvent (view?.Margin)) { + view = View.FindDeepestView (view?.Margin, screenX, screenY, out int newX, out int newY); + + if (view is { } && AdornmentSubViewHandledMouseEvent (newX, newY)) + { + return; + } + return; } @@ -1649,15 +1667,15 @@ bool AdornmentHandledMouseEvent (Adornment adornment) } } - bool AdornmentSubViewHandledMouseEvent () + bool AdornmentSubViewHandledMouseEvent (int x, int y) { var me = new MouseEvent { - X = screenX, - Y = screenY, + X = x, + Y = y, Flags = a.MouseEvent.Flags, - OfX = screenX, - OfY = screenY, + OfX = screenX - x, + OfY = screenY - y, View = view }; From 294b0ebee695fa301f84263450d0ead067d45ff2 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 24 Feb 2024 02:07:45 +0000 Subject: [PATCH 045/130] Testing ScrollBar on all adornments and content area. --- UICatalog/Scenarios/ScrollBars.cs | 90 ++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 19 deletions(-) diff --git a/UICatalog/Scenarios/ScrollBars.cs b/UICatalog/Scenarios/ScrollBars.cs index 47edaedd76..f9f902d539 100644 --- a/UICatalog/Scenarios/ScrollBars.cs +++ b/UICatalog/Scenarios/ScrollBars.cs @@ -3,7 +3,7 @@ namespace UICatalog.Scenarios; -[ScenarioMetadata ("ScrollBar BuiltIn", "Demonstrates the scroll bar built-in the Padding Adornment.")] +[ScenarioMetadata ("ScrollBars", "Demonstrates the scroll bar built-in the Padding Adornment.")] [ScenarioCategory ("Controls")] public class ScrollBars : Scenario { @@ -15,34 +15,86 @@ public override void Init () public override void Setup () { - var view = new View + var text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line"; + + var win = new Window (); + + var viewOnMargin = new View + { + X = 0, Y = Pos.Center (), Width = 12, Height = 6, + Text = text, + UseNegativeBoundsLocation = true + }; + viewOnMargin.Margin.ScrollBarType = ScrollBarType.Both; + SetViewProperties (viewOnMargin); + win.Add (viewOnMargin); + + win.Add (new Label { X = 0, Y = Pos.Top (viewOnMargin) - 2, Text = "On Margin:" }); + + var viewOnContentArea = new View { - X = Pos.Center (), Y = Pos.Center (), Width = 15, Height = 8, ScrollBarType = ScrollBarType.Both, - Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", + X = Pos.AnchorEnd () - 15, Y = Pos.Center (), Width = 15, Height = 8, + Text = text, + UseNegativeBoundsLocation = true, + ScrollBarType = ScrollBarType.Both + }; + viewOnContentArea.Margin.Thickness = new Thickness (1); + viewOnContentArea.Margin.ColorScheme = Colors.ColorSchemes ["Dialog"]; + viewOnContentArea.BorderStyle = LineStyle.Single; + SetViewProperties (viewOnContentArea); + win.Add (viewOnContentArea); + + win.Add (new Label { X = Pos.Left (viewOnContentArea), Y = Pos.Top (viewOnContentArea) - 2, Text = "On ContentArea:" }); + + var viewOnPadding = new View + { + X = Pos.Left (viewOnContentArea) - 30, Y = Pos.Center (), Width = 15, Height = 8, + Text = text, UseNegativeBoundsLocation = true }; + viewOnPadding.Padding.ScrollBarType = ScrollBarType.Both; + viewOnPadding.Margin.Thickness = new Thickness (1); + viewOnPadding.Margin.ColorScheme = Colors.ColorSchemes ["Dialog"]; + viewOnPadding.BorderStyle = LineStyle.Single; + viewOnPadding.Padding.ColorScheme = Colors.ColorSchemes ["Menu"]; + SetViewProperties (viewOnPadding); + win.Add (viewOnPadding); + + win.Add (new Label { X = Pos.Left (viewOnPadding), Y = Pos.Top (viewOnPadding) - 2, Text = "On Padding:" }); + + var viewOnBorder = new View + { + X = Pos.Left (viewOnPadding) - 30, Y = Pos.Center (), Width = 13, Height = 8, + Text = text, + UseNegativeBoundsLocation = true, + BorderStyle = LineStyle.None + }; + viewOnBorder.Border.ScrollBarType = ScrollBarType.Both; + viewOnBorder.Margin.Thickness = new Thickness (1); + viewOnBorder.Margin.ColorScheme = Colors.ColorSchemes ["Dialog"]; + SetViewProperties (viewOnBorder); + win.Add (viewOnBorder); + + win.Add (new Label { X = Pos.Left (viewOnBorder), Y = Pos.Top (viewOnBorder) - 2, Text = "On Border:" }); + + var btn = new Button { X = Pos.Center (), Y = Pos.Bottom (viewOnContentArea) + 1, Text = "Test" }; + win.Add (btn); + + viewOnBorder.TabIndex = 1; + viewOnPadding.TabIndex = 2; + viewOnContentArea.TabIndex = 3; + + Application.Top.Add (win); + } - //var view = new View - //{ - // X = 5, Y = 5, Width = 9, Height = 6, ScrollBarType = ScrollBarType.Both, - // Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", UseNegativeBoundsLocation = true - //}; + private void SetViewProperties (View view) + { view.TextFormatter.WordWrap = false; view.TextFormatter.MultiLine = true; view.TextFormatter.FillRemaining = true; view.CanFocus = true; - view.Padding.ColorScheme = Colors.ColorSchemes ["Menu"]; string [] strings = view.Text.Split ("\n").ToArray (); view.ScrollColsSize = strings.OrderByDescending (s => s.Length).First ().GetColumns (); view.ScrollRowsSize = strings.Length; - view.Margin.Thickness = new Thickness (1); - view.Margin.ColorScheme = Colors.ColorSchemes ["Dialog"]; - view.BorderStyle = LineStyle.Single; - var win = new Window (); - win.Add (view); - - var btn = new Button { X = Pos.Center (), Y = Pos.Bottom (view), Text = "Test" }; - win.Add (btn); - Application.Top.Add (win); } } From c7839280f280e189e9688e5c03298ec0ce691f39 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 24 Feb 2024 02:08:57 +0000 Subject: [PATCH 046/130] Add more unit tests and fixes. --- UnitTests/Views/ScrollBarTests.cs | 107 +++++++++++++++++++++++------- UnitTests/Views/ToplevelTests.cs | 70 +++++++++---------- 2 files changed, 117 insertions(+), 60 deletions(-) diff --git a/UnitTests/Views/ScrollBarTests.cs b/UnitTests/Views/ScrollBarTests.cs index 2c9d0d5ad1..5227700814 100644 --- a/UnitTests/Views/ScrollBarTests.cs +++ b/UnitTests/Views/ScrollBarTests.cs @@ -414,17 +414,17 @@ public void var newScrollBar = listView.Padding.Subviews [0] as ScrollBar; newScrollBar!.ChangedPosition += (s, e) => - { - listView.LeftItem = newScrollBar.Position; + { + listView.LeftItem = newScrollBar.Position; - if (listView.LeftItem != newScrollBar.Position) - { - newScrollBar.Position = listView.LeftItem; - } + if (listView.LeftItem != newScrollBar.Position) + { + newScrollBar.Position = listView.LeftItem; + } - Assert.Equal (newScrollBar.Position, listView.LeftItem); - listView.SetNeedsDisplay (); - }; + Assert.Equal (newScrollBar.Position, listView.LeftItem); + listView.SetNeedsDisplay (); + }; listView.DrawContent += (s, e) => { @@ -491,17 +491,17 @@ public void listView.Add (newScrollBar); newScrollBar.ChangedPosition += (s, e) => - { - listView.TopItem = newScrollBar.Position; + { + listView.TopItem = newScrollBar.Position; - if (listView.TopItem != newScrollBar.Position) - { - newScrollBar.Position = listView.TopItem; - } + if (listView.TopItem != newScrollBar.Position) + { + newScrollBar.Position = listView.TopItem; + } - Assert.Equal (newScrollBar.Position, listView.TopItem); - listView.SetNeedsDisplay (); - }; + Assert.Equal (newScrollBar.Position, listView.TopItem); + listView.SetNeedsDisplay (); + }; listView.DrawContent += (s, e) => { @@ -1097,7 +1097,7 @@ public void ScrollBarType_IsBuiltIn_In_Padding_Does_Not_Throws_If_ScrollBarType_ [Fact] [SetupFakeDriver] - public void ScrollBarType_IsBuiltIn_In_Padding_Thickness () + public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Padding_Thickness () { ((FakeDriver)Application.Driver).SetBufferSize (15, 11); @@ -1106,7 +1106,8 @@ public void ScrollBarType_IsBuiltIn_In_Padding_Thickness () var view = new View { X = Pos.Center (), Y = Pos.Center (), Width = 9, Height = 6, - Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", CanFocus = true + Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", CanFocus = true, + UseNegativeBoundsLocation = true }; view.Padding.ScrollBarType = ScrollBarType.Both; view.TextFormatter.WordWrap = false; @@ -1189,11 +1190,27 @@ Fifth Li▼ 000000000000000", null, attrs); + + Assert.True (view.Padding.OnInvokingKeyBindings (new Key (KeyCode.End))); + Assert.True (view.Padding.OnInvokingKeyBindings (new Key (KeyCode.End | KeyCode.ShiftMask))); + top.Draw (); + + TestHelpers.AssertDriverContentsWithFrameAre ( + @" + d Line ▲ + th Line ┬ + h Line │ + h Line ┴ + nth Line▼ + ◄░░├──┤► + + Test ", + _output); } [Fact] [SetupFakeDriver] - public void ScrollBarType_IsBuiltIn_In_Padding_Thickness_Inside_Another_Container () + public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Padding_Thickness_Inside_Another_Container () { ((FakeDriver)Application.Driver).SetBufferSize (15, 11); @@ -1202,7 +1219,8 @@ public void ScrollBarType_IsBuiltIn_In_Padding_Thickness_Inside_Another_Containe var view = new View { X = Pos.Center (), Y = Pos.Center (), Width = 9, Height = 6, - Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", CanFocus = true + Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", CanFocus = true, + UseNegativeBoundsLocation = true }; view.Padding.ScrollBarType = ScrollBarType.Both; view.TextFormatter.WordWrap = false; @@ -1292,11 +1310,30 @@ public void ScrollBarType_IsBuiltIn_In_Padding_Thickness_Inside_Another_Containe 000000000000000", null, attrs); + + Assert.True (view.Padding.OnInvokingKeyBindings (new Key (KeyCode.End))); + Assert.True (view.Padding.OnInvokingKeyBindings (new Key (KeyCode.End | KeyCode.ShiftMask))); + top.Draw (); + + TestHelpers.AssertDriverContentsWithFrameAre ( + @" +┌─────────────┐ +│ │ +│ d Line ▲ │ +│ th Line ┬ │ +│ h Line │ │ +│ h Line ┴ │ +│ nth Line▼ │ +│ ◄░░├──┤► │ +│ │ +│ Test │ +└─────────────┘", + _output); } - [Fact] + [Fact] [SetupFakeDriver] - public void ScrollBarType_IsBuiltIn_In_Parent_Inside_Another_Container () + public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Parent_Inside_Another_Container () { ((FakeDriver)Application.Driver).SetBufferSize (15, 11); @@ -1306,7 +1343,8 @@ public void ScrollBarType_IsBuiltIn_In_Parent_Inside_Another_Container () { X = Pos.Center (), Y = Pos.Center (), Width = 9, Height = 6, Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", CanFocus = true, - ScrollBarType = ScrollBarType.Both + ScrollBarType = ScrollBarType.Both, + UseNegativeBoundsLocation = true }; view.TextFormatter.WordWrap = false; view.TextFormatter.MultiLine = true; @@ -1388,6 +1426,25 @@ public void ScrollBarType_IsBuiltIn_In_Parent_Inside_Another_Container () 000000000000000", null, attrs); + + Assert.True (view.OnInvokingKeyBindings (Key.End)); + Assert.True (view.OnInvokingKeyBindings (Key.End.WithShift)); + top.Draw (); + + TestHelpers.AssertDriverContentsWithFrameAre ( + @" +┌─────────────┐ +│ │ +│ d Line ▲ │ +│ th Line ┬ │ +│ h Line │ │ +│ h Line ┴ │ +│ nth Line▼ │ +│ ◄░░├──┤► │ +│ │ +│ Test │ +└─────────────┘", + _output); } [Fact] diff --git a/UnitTests/Views/ToplevelTests.cs b/UnitTests/Views/ToplevelTests.cs index 84b8182516..5707a485cc 100644 --- a/UnitTests/Views/ToplevelTests.cs +++ b/UnitTests/Views/ToplevelTests.cs @@ -1504,7 +1504,7 @@ public void Toplevel_Inside_ScrollView_MouseGrabView () new MouseEvent { X = 5, Y = 5, Flags = MouseFlags.Button1Released } ) ); - Assert.Null (Application.MouseGrabView); + Assert.Equal (scrollView, Application.MouseGrabView); Application.OnMouseEvent ( new MouseEventEventArgs ( @@ -1807,40 +1807,40 @@ public void Draw_A_Top_Subview_On_A_Window () testWindow.Add (btnPopup); btnPopup.Accept += (s, e) => - { - Rectangle viewToScreen = btnPopup.BoundsToScreen (top.Frame); - - var viewAddedToTop = new View - { - Text = "viewAddedToTop", - X = 1, - Y = viewToScreen.Y + 1, - Width = 18, - Height = 16, - BorderStyle = LineStyle.Single - }; - Assert.Equal (testWindow, Application.Current); - Application.Current.DrawContentComplete += testWindow_DrawContentComplete; - top.Add (viewAddedToTop); - - void testWindow_DrawContentComplete (object sender, DrawEventArgs e) - { - Assert.Equal (new Rectangle (1, 3, 18, 16), viewAddedToTop.Frame); - - Rectangle savedClip = Application.Driver.Clip; - Application.Driver.Clip = top.Frame; - viewAddedToTop.Draw (); - top.Move (2, 15); - View.Driver.AddStr ("One"); - top.Move (2, 16); - View.Driver.AddStr ("Two"); - top.Move (2, 17); - View.Driver.AddStr ("Three"); - Application.Driver.Clip = savedClip; - - Application.Current.DrawContentComplete -= testWindow_DrawContentComplete; - } - }; + { + Rectangle viewToScreen = btnPopup.BoundsToScreen (top.Frame); + + var viewAddedToTop = new View + { + Text = "viewAddedToTop", + X = 1, + Y = viewToScreen.Y + 1, + Width = 18, + Height = 16, + BorderStyle = LineStyle.Single + }; + Assert.Equal (testWindow, Application.Current); + Application.Current.DrawContentComplete += testWindow_DrawContentComplete; + top.Add (viewAddedToTop); + + void testWindow_DrawContentComplete (object sender, DrawEventArgs e) + { + Assert.Equal (new Rectangle (1, 3, 18, 16), viewAddedToTop.Frame); + + Rectangle savedClip = Application.Driver.Clip; + Application.Driver.Clip = top.Frame; + viewAddedToTop.Draw (); + top.Move (2, 15); + View.Driver.AddStr ("One"); + top.Move (2, 16); + View.Driver.AddStr ("Two"); + top.Move (2, 17); + View.Driver.AddStr ("Three"); + Application.Driver.Clip = savedClip; + + Application.Current.DrawContentComplete -= testWindow_DrawContentComplete; + } + }; RunState rs = Application.Begin (testWindow); Assert.Equal (new Rectangle (2, 1, 15, 10), testWindow.Frame); From 383fc16ab84830ec1ca14794e1285eb4f97d5e1f Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 24 Feb 2024 18:52:11 +0000 Subject: [PATCH 047/130] Fix issue ScrollBar not be ungrab if the mouse is over another view. --- Terminal.Gui/Application.cs | 18 ++++++++++++++++-- Terminal.Gui/Views/ScrollBar.cs | 2 ++ UnitTests/Views/ScrollBarTests.cs | 26 ++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/Application.cs b/Terminal.Gui/Application.cs index 2c7608f9eb..e151abb47b 100644 --- a/Terminal.Gui/Application.cs +++ b/Terminal.Gui/Application.cs @@ -1512,14 +1512,28 @@ public static void OnMouseEvent (MouseEventEventArgs a) }; } - if (OutsideRect (new Point (nme.X, nme.Y), MouseGrabView.Bounds)) + if (OutsideRect (new Point (nme.X, nme.Y), MouseGrabView.Bounds) || (view is { } && view != MouseGrabView)) { // The mouse has moved outside the bounds of the view that // grabbed the mouse, so we tell the view that last got // OnMouseEnter the mouse is leaving // BUGBUG: That sentence makes no sense. Either I'm missing something // or this logic is flawed. - _mouseEnteredView?.OnMouseLeave (a.MouseEvent); + // We cannot trust the bounds because they may be the same as the bounds of + // other views, and therefore it is more accurate to trust the view itself + if (view is { }) + { + View parent = view is Adornment adornment ? adornment.Parent : view; + + if (parent.OnMouseEnter (a.MouseEvent)) + { + MouseGrabView?.OnMouseLeave (a.MouseEvent); + } + } + else + { + _mouseEnteredView?.OnMouseLeave (a.MouseEvent); + } } //System.Diagnostics.Debug.WriteLine ($"{nme.Flags};{nme.X};{nme.Y};{MouseGrabView}"); diff --git a/Terminal.Gui/Views/ScrollBar.cs b/Terminal.Gui/Views/ScrollBar.cs index 5a198c6fba..1922e6eb81 100644 --- a/Terminal.Gui/Views/ScrollBar.cs +++ b/Terminal.Gui/Views/ScrollBar.cs @@ -958,6 +958,8 @@ private void ScrollBar_Added (object sender, SuperViewChangedEventArgs e) parent.EnabledChanged += Parent_EnabledChanged; parent.VisibleChanged += Parent_VisibleChanged; parent.DrawAdornments += Parent_DrawAdornments; + parent.MouseEnter += (s, e) => OnMouseEnter (e.MouseEvent); + parent.MouseLeave += (s, e) => OnMouseLeave (e.MouseEvent); ManageScrollBarThickness (); } diff --git a/UnitTests/Views/ScrollBarTests.cs b/UnitTests/Views/ScrollBarTests.cs index 5227700814..f0d05b4c93 100644 --- a/UnitTests/Views/ScrollBarTests.cs +++ b/UnitTests/Views/ScrollBarTests.cs @@ -1055,6 +1055,32 @@ public void OtherScrollBar_Not_Null () Assert.Equal (_scrollBar.OtherScrollBar.OtherScrollBar, _scrollBar); } + [Fact] + [SetupFakeDriver] + public void ScrollBar_Ungrab_Mouse_If_The_Mouse_Is_On_Another_View () + { + var top = new Toplevel { Id = "top", Width = 10, Height = 10 }; + var viewLeft = new View { Id = "left", Width = 5, Height = 5, ScrollBarType = ScrollBarType.Vertical, ScrollRowsSize = 20, CanFocus = true }; + + var viewRight = new View + { Id = "right", X = Pos.Right (viewLeft), Width = 5, Height = 6, ScrollBarType = ScrollBarType.Vertical, ScrollRowsSize = 20, CanFocus = true }; + top.Add (viewLeft, viewRight); + Application.Begin (top); + + Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent { X = 1, Y = 0, Flags = MouseFlags.WheeledDown })); + + View firstGrabbed = Application.MouseGrabView; + Assert.IsType (firstGrabbed); + Assert.Equal (new Rectangle (4, 0, 1, 5), firstGrabbed.Frame); + + Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent { X = 7, Y = 0, Flags = MouseFlags.WheeledDown })); + + View secondGrabbed = Application.MouseGrabView; + Assert.IsType (firstGrabbed); + Assert.Equal (new Rectangle (4, 0, 1, 6), secondGrabbed.Frame); + Assert.NotEqual (firstGrabbed, secondGrabbed); + } + [Fact] public void ScrollBarType_IsBuiltIn_In_Padding () { From 930260acc86dc68543fef98226ab467f5034ff1b Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 24 Feb 2024 20:13:35 +0000 Subject: [PATCH 048/130] Decouples BoundsToScreen method from Adornments by make the GetAdornmentsThickness virtual. --- Terminal.Gui/View/Adornment/Border.cs | 72 +++++++++++++--------- Terminal.Gui/View/Adornment/Margin.cs | 3 + Terminal.Gui/View/Adornment/Padding.cs | 11 ++++ Terminal.Gui/View/Layout/ViewLayout.cs | 21 ++----- UnitTests/View/Adornment/AdornmentTests.cs | 15 +++++ 5 files changed, 76 insertions(+), 46 deletions(-) diff --git a/Terminal.Gui/View/Adornment/Border.cs b/Terminal.Gui/View/Adornment/Border.cs index 45f72d5909..86d10aab8d 100644 --- a/Terminal.Gui/View/Adornment/Border.cs +++ b/Terminal.Gui/View/Adornment/Border.cs @@ -192,7 +192,7 @@ public void DrawFrame (Rectangle region, bool clear) Driver.Clip = savedClip; } - + /// public override Rectangle FrameToScreen () { @@ -204,6 +204,17 @@ public override Rectangle FrameToScreen () return ret; } + /// + public override Thickness GetAdornmentsThickness () + { + int left = Parent.Margin.Thickness.Left; + int top = Parent.Margin.Thickness.Top; + int right = Parent.Margin.Thickness.Right; + int bottom = Parent.Margin.Thickness.Bottom; + + return new Thickness (left, top, right, bottom); + } + /// public override void OnDrawContent (Rectangle contentArea) { @@ -225,38 +236,39 @@ public override void OnDrawContent (Rectangle contentArea) // For Border // ...thickness extends outward (border/title is always as far in as possible) var borderBounds = new Rectangle ( - screenBounds.X + Math.Max (0, Thickness.Left - 1), - screenBounds.Y + Math.Max (0, Thickness.Top - 1), - Math.Max ( - 0, - screenBounds.Width - - Math.Max ( - 0, - Math.Max (0, Thickness.Left - 1) - + Math.Max (0, Thickness.Right - 1) - ) - ), - Math.Max ( - 0, - screenBounds.Height - - Math.Max ( - 0, - Math.Max (0, Thickness.Top - 1) - + Math.Max (0, Thickness.Bottom - 1) - ) - ) - ); + screenBounds.X + Math.Max (0, Thickness.Left - 1), + screenBounds.Y + Math.Max (0, Thickness.Top - 1), + Math.Max ( + 0, + screenBounds.Width + - Math.Max ( + 0, + Math.Max (0, Thickness.Left - 1) + + Math.Max (0, Thickness.Right - 1) + ) + ), + Math.Max ( + 0, + screenBounds.Height + - Math.Max ( + 0, + Math.Max (0, Thickness.Top - 1) + + Math.Max (0, Thickness.Bottom - 1) + ) + ) + ); int topTitleLineY = borderBounds.Y; int titleY = borderBounds.Y; var titleBarsLength = 0; // the little vertical thingies - int maxTitleWidth = Math.Max (0, + int maxTitleWidth = Math.Max ( + 0, Math.Min ( - Parent.TitleTextFormatter.FormatAndGetSize ().Width, - Math.Min (screenBounds.Width - 4, borderBounds.Width - 4) - ) - ); + Parent.TitleTextFormatter.FormatAndGetSize ().Width, + Math.Min (screenBounds.Width - 4, borderBounds.Width - 4) + ) + ); Parent.TitleTextFormatter.Size = new Size (maxTitleWidth, 1); int sideLineLength = borderBounds.Height; @@ -296,7 +308,8 @@ public override void OnDrawContent (Rectangle contentArea) if (canDrawBorder && Thickness.Top > 0 && maxTitleWidth > 0 && !string.IsNullOrEmpty (Parent?.Title)) { - Parent.TitleTextFormatter.Draw (new (borderBounds.X + 2, titleY, maxTitleWidth, 1), + Parent.TitleTextFormatter.Draw ( + new Rectangle (borderBounds.X + 2, titleY, maxTitleWidth, 1), Parent.HasFocus ? Parent.GetFocusColor () : Parent.GetNormalColor (), Parent.HasFocus ? Parent.GetFocusColor () : Parent.GetHotNormalColor ()); } @@ -475,7 +488,8 @@ public override void OnDrawContent (Rectangle contentArea) // Redraw title if (drawTop && maxTitleWidth > 0 && !string.IsNullOrEmpty (Parent?.Title)) { - Parent.TitleTextFormatter.Draw (new (borderBounds.X + 2, titleY, maxTitleWidth, 1), + Parent.TitleTextFormatter.Draw ( + new Rectangle (borderBounds.X + 2, titleY, maxTitleWidth, 1), Parent.HasFocus ? Parent.GetFocusColor () : Parent.GetNormalColor (), Parent.HasFocus ? Parent.GetFocusColor () : Parent.GetNormalColor ()); } diff --git a/Terminal.Gui/View/Adornment/Margin.cs b/Terminal.Gui/View/Adornment/Margin.cs index ca2142fc00..aa7d7ef302 100644 --- a/Terminal.Gui/View/Adornment/Margin.cs +++ b/Terminal.Gui/View/Adornment/Margin.cs @@ -38,4 +38,7 @@ public override ColorScheme ColorScheme Parent?.SetNeedsDisplay (); } } + + /// + public override Thickness GetAdornmentsThickness () { return Thickness.Empty; } } diff --git a/Terminal.Gui/View/Adornment/Padding.cs b/Terminal.Gui/View/Adornment/Padding.cs index 4c2270f54b..e5521c1b5f 100644 --- a/Terminal.Gui/View/Adornment/Padding.cs +++ b/Terminal.Gui/View/Adornment/Padding.cs @@ -49,4 +49,15 @@ public override Rectangle FrameToScreen () return ret; } + + /// + public override Thickness GetAdornmentsThickness () + { + int left = Parent.Margin.Thickness.Left + Parent.Border.Thickness.Left; + int top = Parent.Margin.Thickness.Top + Parent.Border.Thickness.Top; + int right = Parent.Margin.Thickness.Right + Parent.Border.Thickness.Right; + int bottom = Parent.Margin.Thickness.Bottom + Parent.Border.Thickness.Bottom; + + return new Thickness (left, top, right, bottom); + } } diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index ff69ce6ca9..6e774f3a42 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -570,23 +570,10 @@ public virtual void BoundsToScreen (int x, int y, out int rx, out int ry, bool c if (super is Adornment adornment) { boundsOffset = super.FrameToScreen ().Location; - View parent = adornment.Parent; + Thickness thickness = adornment.GetAdornmentsThickness (); - switch (super) - { - case Gui.Margin: - break; - case Gui.Border: - boundsOffset.X -= parent.Margin.Thickness.Left; - boundsOffset.Y -= parent.Margin.Thickness.Top; - - break; - case Gui.Padding: - boundsOffset.X -= parent.Margin.Thickness.Left + parent.Border.Thickness.Left; - boundsOffset.Y -= parent.Margin.Thickness.Top + parent.Border.Thickness.Top; - - break; - } + boundsOffset.X -= thickness.Left; + boundsOffset.Y -= thickness.Top; } else { @@ -684,7 +671,7 @@ public virtual Rectangle FrameToScreen () /// Gets the thickness describing the sum of the Adornments' thicknesses. /// /// A thickness that describes the sum of the Adornments' thicknesses. - public Thickness GetAdornmentsThickness () + public virtual Thickness GetAdornmentsThickness () { int left = Margin.Thickness.Left + Border.Thickness.Left + Padding.Thickness.Left; int top = Margin.Thickness.Top + Border.Thickness.Top + Padding.Thickness.Top; diff --git a/UnitTests/View/Adornment/AdornmentTests.cs b/UnitTests/View/Adornment/AdornmentTests.cs index c84e139705..0dbd051cb3 100644 --- a/UnitTests/View/Adornment/AdornmentTests.cs +++ b/UnitTests/View/Adornment/AdornmentTests.cs @@ -387,6 +387,21 @@ public void GetAdornmentsThickness () view.Dispose (); } + [Fact] + public void GetAdornmentsThickness_On_Adornments () + { + var view = new View { Width = 10, Height = 10 }; + view.Margin.Thickness = new Thickness (1); + view.Border.Thickness = new Thickness (1); + view.Padding.Thickness = new Thickness (1); + + Assert.Equal (new Thickness (3, 3, 3, 3), view.GetAdornmentsThickness ()); + Assert.Equal (Thickness.Empty, view.Margin.GetAdornmentsThickness ()); + Assert.Equal (new Thickness (1), view.Border.GetAdornmentsThickness ()); + Assert.Equal (new Thickness (2), view.Padding.GetAdornmentsThickness ()); + view.Dispose (); + } + [Fact] public void Setting_Bounds_Throws () { From 743baa7663a8dfab699185e6c8d7fb412e52ba4d Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 24 Feb 2024 20:52:57 +0000 Subject: [PATCH 049/130] Rename ScrollBar to ScrollBarView. --- Terminal.Gui/Drawing/Glyphs.cs | 4 +- Terminal.Gui/View/ViewScrollBar.cs | 22 +++---- .../Views/{ScrollBar.cs => ScrollBarView.cs} | 14 ++--- Terminal.Gui/Views/ScrollView.cs | 12 ++-- UnitTests/Input/ResponderTests.cs | 6 +- ...crollBarTests.cs => ScrollBarViewTests.cs} | 62 +++++++++---------- UnitTests/Views/ScrollViewTests.cs | 4 +- 7 files changed, 62 insertions(+), 62 deletions(-) rename Terminal.Gui/Views/{ScrollBar.cs => ScrollBarView.cs} (99%) rename UnitTests/Views/{ScrollBarTests.cs => ScrollBarViewTests.cs} (96%) diff --git a/Terminal.Gui/Drawing/Glyphs.cs b/Terminal.Gui/Drawing/Glyphs.cs index dec1074a31..18d83de504 100644 --- a/Terminal.Gui/Drawing/Glyphs.cs +++ b/Terminal.Gui/Drawing/Glyphs.cs @@ -76,10 +76,10 @@ public class GlyphDefinitions /// Continuous block meter segment (e.g. for ). public Rune ContinuousMeterSegment { get; set; } = (Rune)'█'; - /// Stipple pattern (e.g. for ). Default is Light Shade (U+2591) - ░. + /// Stipple pattern (e.g. for ). Default is Light Shade (U+2591) - ░. public Rune Stipple { get; set; } = (Rune)'░'; - /// Diamond (e.g. for . Default is Lozenge (U+25CA) - ◊. + /// Diamond (e.g. for . Default is Lozenge (U+25CA) - ◊. public Rune Diamond { get; set; } = (Rune)'◊'; /// Close. Default is Heavy Ballot X (U+2718) - ✘. diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 11608d9d88..47c1bf56b0 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -1,7 +1,7 @@ namespace Terminal.Gui; /// -/// The scroll bar types used by this . +/// The scroll bar types used by this . /// public enum ScrollBarType { @@ -28,7 +28,7 @@ public enum ScrollBarType public partial class View { - private ScrollBar _scrollBar; + private ScrollBarView _scrollBar; private ScrollBarType _scrollBarType; private int _scrollColsSize; private int _scrollLeftOffset; @@ -64,16 +64,16 @@ public virtual ScrollBarType ScrollBarType switch (view._scrollBarType) { case ScrollBarType.Vertical: - view._scrollBar = new ScrollBar { IsVertical = true }; + view._scrollBar = new ScrollBarView { IsVertical = true }; break; case ScrollBarType.Horizontal: - view._scrollBar = new ScrollBar { IsVertical = false }; + view._scrollBar = new ScrollBarView { IsVertical = false }; break; case ScrollBarType.Both: - view._scrollBar = new ScrollBar { IsVertical = true }; - view._scrollBar.OtherScrollBar = new ScrollBar { IsVertical = false, OtherScrollBar = view._scrollBar }; + view._scrollBar = new ScrollBarView { IsVertical = true }; + view._scrollBar.OtherScrollBar = new ScrollBarView { IsVertical = false, OtherScrollBar = view._scrollBar }; break; case ScrollBarType.None: @@ -136,7 +136,7 @@ public int ScrollColsSize } } - /// Get or sets if the view-port is kept always visible in the area of this + /// Get or sets if the view-port is kept always visible in the area of this public bool ScrollKeepContentAlwaysInViewPort { get => _scrollBar.KeepContentAlwaysInViewPort; @@ -173,7 +173,7 @@ public virtual int ScrollLeftOffset } /// Represent a vertical or horizontal ScrollBar other than this. - public ScrollBar ScrollOtherScrollBar + public ScrollBarView ScrollOtherScrollBar { get => _scrollBar.OtherScrollBar; set => _scrollBar.OtherScrollBar = value; @@ -270,7 +270,7 @@ public virtual int ScrollTopOffset /// public bool UseNegativeBoundsLocation { get; set; } - private void AddEventHandlersForScrollBars (ScrollBar scrollBar) + private void AddEventHandlersForScrollBars (ScrollBarView scrollBar) { if (scrollBar is null) { @@ -285,7 +285,7 @@ private void AddEventHandlersForScrollBars (ScrollBar scrollBar) } } - private void AddKeyBindingsForScrolling (ScrollBar scrollBar) + private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) { if (scrollBar.IsVertical) { @@ -585,7 +585,7 @@ private void DisposeScrollBar () private void ScrollBar_ChangedPosition (object sender, EventArgs e) { SetBoundsByPosition (_scrollBar); } - private void SetBoundsByPosition (ScrollBar scrollBar) + private void SetBoundsByPosition (ScrollBarView scrollBar) { if (scrollBar.IsVertical) { diff --git a/Terminal.Gui/Views/ScrollBar.cs b/Terminal.Gui/Views/ScrollBarView.cs similarity index 99% rename from Terminal.Gui/Views/ScrollBar.cs rename to Terminal.Gui/Views/ScrollBarView.cs index 1922e6eb81..f2543d615d 100644 --- a/Terminal.Gui/Views/ScrollBar.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -15,14 +15,14 @@ namespace Terminal.Gui; /// /// If the region to display the scrollbar is larger than three characters, arrow indicators are drawn. /// -public class ScrollBar : View +public class ScrollBarView : View { private static Point _superViewContentOffset; private bool _autoHideScrollBars = true; private View _contentBottomRightCorner; private bool _keepContentAlwaysInViewport = true; private int _lastLocation = -1; - private ScrollBar _otherScrollBar; + private ScrollBarView _otherScrollBar; private int _posBarOffset; private int _posBottomTee; private int _posLeftTee; @@ -33,10 +33,10 @@ public class ScrollBar : View private bool _vertical; /// - /// Initializes a new instance of the class using + /// Initializes a new instance of the class using /// layout. /// - public ScrollBar () + public ScrollBarView () { ShowScrollIndicator = true; WantContinuousButtonPressed = true; @@ -76,7 +76,7 @@ public bool IsVertical } } - /// Get or sets if the view-port is kept always visible in the area of this + /// Get or sets if the view-port is kept always visible in the area of this public bool KeepContentAlwaysInViewPort { get => _keepContentAlwaysInViewport; @@ -92,7 +92,7 @@ public bool KeepContentAlwaysInViewPort } /// Represent a vertical or horizontal ScrollBar other than this. - public ScrollBar OtherScrollBar + public ScrollBarView OtherScrollBar { get => _otherScrollBar; set @@ -685,7 +685,7 @@ private void AdjustContentInViewport (bool refresh = true) } } - private bool CheckBothScrollBars (ScrollBar scrollBarView, bool pending = false) + private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = false) { int barsize = scrollBarView._vertical ? scrollBarView.Bounds.Height : scrollBarView.Bounds.Width; diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index 20c059f6c3..9e834e7d37 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -28,8 +28,8 @@ namespace Terminal.Gui; public class ScrollView : View { private readonly ContentView _contentView; - private readonly ScrollBar _horizontal; - private readonly ScrollBar _vertical; + private readonly ScrollBarView _horizontal; + private readonly ScrollBarView _vertical; private View _contentBottomRightCorner; private Point _contentOffset; private Size _contentSize; @@ -43,7 +43,7 @@ public ScrollView () _contentView = new ContentView (); base.Add (_contentView); - _vertical = new ScrollBar + _vertical = new ScrollBarView { X = Pos.AnchorEnd (1), Y = 0, @@ -52,7 +52,7 @@ public ScrollView () IsVertical = true }; - _horizontal = new ScrollBar + _horizontal = new ScrollBarView { X = 0, Y = Pos.AnchorEnd (1), @@ -286,12 +286,12 @@ public bool ShowVerticalScrollIndicator /// The view to add to the scrollview. public override void Add (View view) { - if (view is ScrollBar.ContentBottomRightCorner) + if (view is ScrollBarView.ContentBottomRightCorner) { _contentBottomRightCorner = view; base.Add (view); } - else if (view is ScrollBar) + else if (view is ScrollBarView) { base.Add (view); } diff --git a/UnitTests/Input/ResponderTests.cs b/UnitTests/Input/ResponderTests.cs index 2aa197fcc5..d5fac8f009 100644 --- a/UnitTests/Input/ResponderTests.cs +++ b/UnitTests/Input/ResponderTests.cs @@ -161,7 +161,7 @@ public void IsOverridden_True_IfOverridden () // MouseEvent is defined on Responder IS overriden on ScrollBar (but not View) Assert.True ( Responder.IsOverridden ( - new ScrollBar { Text = "ScrollBar overrides MouseEvent" }, + new ScrollBarView { Text = "ScrollBar overrides MouseEvent" }, "MouseEvent" ) ); @@ -180,14 +180,14 @@ public void IsOverridden_True_IfOverridden () // ScrollBar overrides both MouseEvent (from Responder) and Redraw (from View) Assert.True ( Responder.IsOverridden ( - new ScrollBar { Text = "ScrollBar overrides MouseEvent" }, + new ScrollBarView { Text = "ScrollBar overrides MouseEvent" }, "MouseEvent" ) ); Assert.True ( Responder.IsOverridden ( - new ScrollBar { Text = "ScrollBar overrides OnDrawContent" }, + new ScrollBarView { Text = "ScrollBar overrides OnDrawContent" }, "OnDrawContent" ) ); diff --git a/UnitTests/Views/ScrollBarTests.cs b/UnitTests/Views/ScrollBarViewTests.cs similarity index 96% rename from UnitTests/Views/ScrollBarTests.cs rename to UnitTests/Views/ScrollBarViewTests.cs index f0d05b4c93..d1c910c5a8 100644 --- a/UnitTests/Views/ScrollBarTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -3,13 +3,13 @@ namespace Terminal.Gui.ViewsTests; -public class ScrollBarTests +public class ScrollBarViewTests { private static HostView _hostView; private readonly ITestOutputHelper _output; private bool _added; - private ScrollBar _scrollBar; - public ScrollBarTests (ITestOutputHelper output) { _output = output; } + private ScrollBarView _scrollBar; + public ScrollBarViewTests (ITestOutputHelper output) { _output = output; } [Fact] [ScrollBarAutoInitShutdown] @@ -144,7 +144,7 @@ public void Both_Default_Draws_Correctly () var super = new Window { Id = "super", Width = Dim.Fill (), Height = Dim.Fill () }; Application.Top.Add (super); - var horiz = new ScrollBar + var horiz = new ScrollBarView { Id = "horiz", Size = width * 2, @@ -154,7 +154,7 @@ public void Both_Default_Draws_Correctly () }; super.Add (horiz); - var vert = new ScrollBar + var vert = new ScrollBarView { Id = "vert", Size = height * 2, @@ -286,7 +286,7 @@ public void ClearOnVisibleFalse_Gets_Sets () var label = new Label { Text = text }; Application.Top.Add (label); - var sbv = new ScrollBar { IsVertical = true, Size = 100, ClearOnVisibleFalse = false }; + var sbv = new ScrollBarView { IsVertical = true, Size = 100, ClearOnVisibleFalse = false }; label.Add (sbv); Application.Begin (Application.Top); @@ -411,7 +411,7 @@ public void Assert.True (listView.ScrollKeepContentAlwaysInViewPort); - var newScrollBar = listView.Padding.Subviews [0] as ScrollBar; + var newScrollBar = listView.Padding.Subviews [0] as ScrollBarView; newScrollBar!.ChangedPosition += (s, e) => { @@ -487,7 +487,7 @@ public void Source = new ListWrapper (source) }; win.Add (listView); - var newScrollBar = new ScrollBar { IsVertical = true, KeepContentAlwaysInViewPort = true }; + var newScrollBar = new ScrollBarView { IsVertical = true, KeepContentAlwaysInViewPort = true }; listView.Add (newScrollBar); newScrollBar.ChangedPosition += (s, e) => @@ -543,8 +543,8 @@ public void ContentBottomRightCorner_Not_Redraw_If_Both_Size_Equal_To_Zero () var text = "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test"; var label = new Label { Text = text }; - var sbv = new ScrollBar { X = Pos.AnchorEnd (1), IsVertical = true, Size = 100 }; - sbv.OtherScrollBar = new ScrollBar { Y = Pos.AnchorEnd (1), IsVertical = false, Size = 100, OtherScrollBar = sbv }; + var sbv = new ScrollBarView { X = Pos.AnchorEnd (1), IsVertical = true, Size = 100 }; + sbv.OtherScrollBar = new ScrollBarView { Y = Pos.AnchorEnd (1), IsVertical = false, Size = 100, OtherScrollBar = sbv }; label.Add (sbv, sbv.OtherScrollBar); Application.Top.Add (label); Application.Begin (Application.Top); @@ -557,8 +557,8 @@ public void ContentBottomRightCorner_Not_Redraw_If_Both_Size_Equal_To_Zero () Assert.True (sbv.OtherScrollBar.Visible); View contentBottomRightCorner = - label.Subviews.First (v => v is ScrollBar.ContentBottomRightCorner); - Assert.True (contentBottomRightCorner is ScrollBar.ContentBottomRightCorner); + label.Subviews.First (v => v is ScrollBarView.ContentBottomRightCorner); + Assert.True (contentBottomRightCorner is ScrollBarView.ContentBottomRightCorner); Assert.True (contentBottomRightCorner.Visible); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -626,7 +626,7 @@ public void ContentBottomRightCorner_Not_Redraw_If_One_Size_Equal_To_Zero () "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test"; var label = new Label { Text = text }; - var sbv = new ScrollBar { X = Pos.AnchorEnd (1), IsVertical = true, Size = 100 }; + var sbv = new ScrollBarView { X = Pos.AnchorEnd (1), IsVertical = true, Size = 100 }; label.Add (sbv); Application.Top.Add (label); Application.Begin (Application.Top); @@ -694,7 +694,7 @@ public void Horizontal_Default_Draws_Correctly () var super = new Window { Id = "super", Width = Dim.Fill (), Height = Dim.Fill () }; Application.Top.Add (super); - var sbv = new ScrollBar { Id = "sbv", Size = width * 2, ShowScrollIndicator = true }; + var sbv = new ScrollBarView { Id = "sbv", Size = width * 2, ShowScrollIndicator = true }; super.Add (sbv); Application.Begin (Application.Top); ((FakeDriver)Application.Driver).SetBufferSize (width, height); @@ -712,7 +712,7 @@ public void Hosting_A_View_To_A_ScrollBar () { RemoveHandlers (); - _scrollBar = new ScrollBar { IsVertical = true, OtherScrollBar = new ScrollBar { IsVertical = false } }; + _scrollBar = new ScrollBarView { IsVertical = true, OtherScrollBar = new ScrollBarView { IsVertical = false } }; _hostView.Add (_scrollBar); Application.Begin (Application.Top); @@ -755,7 +755,7 @@ public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () Application.Begin (Application.Top); ((FakeDriver)Application.Driver).SetBufferSize (45, 20); - var scrollBar = textView.Padding.Subviews [0] as ScrollBar; + var scrollBar = textView.Padding.Subviews [0] as ScrollBarView; Assert.True (scrollBar.AutoHideScrollBars); Assert.False (scrollBar.ShowScrollIndicator); Assert.False (scrollBar.OtherScrollBar.ShowScrollIndicator); @@ -903,8 +903,8 @@ public void Hosting_Two_Horizontal_ScrollBar_Throws_ArgumentException () var top = new Toplevel (); var host = new View (); top.Add (host); - var v = new ScrollBar { IsVertical = false }; - var h = new ScrollBar { IsVertical = false }; + var v = new ScrollBarView { IsVertical = false }; + var h = new ScrollBarView { IsVertical = false }; Assert.Throws (() => v.OtherScrollBar = h); Assert.Throws (() => h.OtherScrollBar = v); @@ -917,8 +917,8 @@ public void Hosting_Two_Vertical_ScrollBar_Throws_ArgumentException () var top = new Toplevel (); var host = new View (); top.Add (host); - var v = new ScrollBar { IsVertical = true }; - var h = new ScrollBar { IsVertical = true }; + var v = new ScrollBarView { IsVertical = true }; + var h = new ScrollBarView { IsVertical = true }; Assert.Throws (() => v.OtherScrollBar = h); Assert.Throws (() => h.OtherScrollBar = v); @@ -931,7 +931,7 @@ public void Internal_Tests () Toplevel top = Application.Top; Assert.Equal (new Rectangle (0, 0, 80, 25), top.Bounds); var view = new View { Width = Dim.Fill (), Height = Dim.Fill () }; - var sbv = new ScrollBar { IsVertical = true, OtherScrollBar = new ScrollBar { IsVertical = false } }; + var sbv = new ScrollBarView { IsVertical = true, OtherScrollBar = new ScrollBarView { IsVertical = false } }; view.Add (sbv); top.Add (view); Assert.Equal (view, sbv.SuperView); @@ -1070,13 +1070,13 @@ public void ScrollBar_Ungrab_Mouse_If_The_Mouse_Is_On_Another_View () Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent { X = 1, Y = 0, Flags = MouseFlags.WheeledDown })); View firstGrabbed = Application.MouseGrabView; - Assert.IsType (firstGrabbed); + Assert.IsType (firstGrabbed); Assert.Equal (new Rectangle (4, 0, 1, 5), firstGrabbed.Frame); Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent { X = 7, Y = 0, Flags = MouseFlags.WheeledDown })); View secondGrabbed = Application.MouseGrabView; - Assert.IsType (firstGrabbed); + Assert.IsType (firstGrabbed); Assert.Equal (new Rectangle (4, 0, 1, 6), secondGrabbed.Frame); Assert.NotEqual (firstGrabbed, secondGrabbed); } @@ -1093,25 +1093,25 @@ public void ScrollBarType_IsBuiltIn_In_Padding () foreach (View sbv in view.Padding.Subviews) { - if (sbv is not ScrollBar) + if (sbv is not ScrollBarView) { - Assert.True (sbv is ScrollBar.ContentBottomRightCorner); + Assert.True (sbv is ScrollBarView.ContentBottomRightCorner); } else { - Assert.True (sbv is ScrollBar); + Assert.True (sbv is ScrollBarView); } } view = new View (); view.Padding.ScrollBarType = ScrollBarType.Vertical; Assert.Single (view.Padding.Subviews); - Assert.True (view.Padding.Subviews [0] is ScrollBar); + Assert.True (view.Padding.Subviews [0] is ScrollBarView); view = new View (); view.Padding.ScrollBarType = ScrollBarType.Horizontal; Assert.Single (view.Padding.Subviews); - Assert.True (view.Padding.Subviews [0] is ScrollBar); + Assert.True (view.Padding.Subviews [0] is ScrollBarView); } [Fact] @@ -1477,7 +1477,7 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Parent_Inside_A [ScrollBarAutoInitShutdown] public void Scrolling_With_Default_Constructor_Do_Not_Scroll () { - var sbv = new ScrollBar { Position = 1 }; + var sbv = new ScrollBarView { Position = 1 }; Assert.Equal (1, sbv.Position); Assert.NotEqual (0, sbv.Position); } @@ -1504,7 +1504,7 @@ public void ShowScrollIndicator_False_Must_Also_Set_Visible_To_False_To_Not_Resp var btn = new Button { X = 14, Text = "Click Me!" }; btn.Accept += (s, e) => clicked = true; - var sbv = new ScrollBar { IsVertical = true, Size = 5 }; + var sbv = new ScrollBarView { IsVertical = true, Size = 5 }; label.Add (sbv); Application.Top.Add (label, btn); Application.Begin (Application.Top); @@ -1618,7 +1618,7 @@ public void Vertical_Default_Draws_Correctly () var super = new Window { Id = "super", Width = Dim.Fill (), Height = Dim.Fill () }; Application.Top.Add (super); - var sbv = new ScrollBar + var sbv = new ScrollBarView { Id = "sbv", Size = height * 2, diff --git a/UnitTests/Views/ScrollViewTests.cs b/UnitTests/Views/ScrollViewTests.cs index cbe940efa7..43326be59c 100644 --- a/UnitTests/Views/ScrollViewTests.cs +++ b/UnitTests/Views/ScrollViewTests.cs @@ -405,8 +405,8 @@ public void ContentBottomRightCorner_Draw () top.Draw (); - View contentBottomRightCorner = sv.Subviews.First (v => v is ScrollBar.ContentBottomRightCorner); - Assert.True (contentBottomRightCorner is ScrollBar.ContentBottomRightCorner); + View contentBottomRightCorner = sv.Subviews.First (v => v is ScrollBarView.ContentBottomRightCorner); + Assert.True (contentBottomRightCorner is ScrollBarView.ContentBottomRightCorner); Assert.True (contentBottomRightCorner.Visible); TestHelpers.AssertDriverContentsWithFrameAre ( From 6196b043c797f13aaaf97b3527e5042d3482f784 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 24 Feb 2024 21:15:23 +0000 Subject: [PATCH 050/130] Resolving reverted conflicts. --- Terminal.Gui/View/ViewScrollBar.cs | 92 +++---- Terminal.Gui/Views/ScrollBarView.cs | 152 ++++++------ Terminal.Gui/Views/ScrollView.cs | 14 +- UICatalog/Scenarios/Editor.cs | 2 +- UnitTests/Input/ResponderTests.cs | 10 +- UnitTests/Views/ScrollBarViewTests.cs | 342 +++++++++++++------------- 6 files changed, 306 insertions(+), 306 deletions(-) diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 47c1bf56b0..1e3ad6e51c 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -73,7 +73,7 @@ public virtual ScrollBarType ScrollBarType break; case ScrollBarType.Both: view._scrollBar = new ScrollBarView { IsVertical = true }; - view._scrollBar.OtherScrollBar = new ScrollBarView { IsVertical = false, OtherScrollBar = view._scrollBar }; + view._scrollBar.OtherScrollBarView = new ScrollBarView { IsVertical = false, OtherScrollBarView = view._scrollBar }; break; case ScrollBarType.None: @@ -86,9 +86,9 @@ public virtual ScrollBarType ScrollBarType view.AddEventHandlersForScrollBars (view._scrollBar); view.AddKeyBindingsForScrolling (view._scrollBar); - if (view._scrollBar.OtherScrollBar != null) + if (view._scrollBar.OtherScrollBarView != null) { - view.AddKeyBindingsForScrolling (view._scrollBar.OtherScrollBar); + view.AddKeyBindingsForScrolling (view._scrollBar.OtherScrollBarView); } view.SetNeedsDisplay (); @@ -112,13 +112,13 @@ public int ScrollColsSize switch (_scrollBar.IsVertical) { - case true when _scrollBar.OtherScrollBar is { }: - if (_scrollBar.OtherScrollBar.Size == _scrollColsSize) + case true when _scrollBar.OtherScrollBarView is { }: + if (_scrollBar.OtherScrollBarView.Size == _scrollColsSize) { return; } - _scrollBar.OtherScrollBar.Size = _scrollColsSize; + _scrollBar.OtherScrollBarView.Size = _scrollColsSize; break; case false: @@ -164,19 +164,19 @@ public virtual int ScrollLeftOffset { _scrollBar.Position = _scrollLeftOffset; } - else if (_scrollBar is { OtherScrollBar.IsVertical: false } && _scrollBar?.OtherScrollBar.Position != _scrollLeftOffset) + else if (_scrollBar is { OtherScrollBarView.IsVertical: false } && _scrollBar?.OtherScrollBarView.Position != _scrollLeftOffset) { - _scrollBar!.OtherScrollBar.Position = _scrollLeftOffset; + _scrollBar!.OtherScrollBarView.Position = _scrollLeftOffset; } } } } - /// Represent a vertical or horizontal ScrollBar other than this. - public ScrollBarView ScrollOtherScrollBar + /// Represent a vertical or horizontal ScrollBarView other than this. + public ScrollBarView ScrollOtherScrollBarView { - get => _scrollBar.OtherScrollBar; - set => _scrollBar.OtherScrollBar = value; + get => _scrollBar.OtherScrollBarView; + set => _scrollBar.OtherScrollBarView = value; } /// The position, relative to , to set the scrollbar at. @@ -213,13 +213,13 @@ public int ScrollRowsSize _scrollBar.Size = _scrollRowsSize; break; - case false when _scrollBar.OtherScrollBar is { }: - if (_scrollBar.OtherScrollBar.Size == _scrollRowsSize) + case false when _scrollBar.OtherScrollBarView is { }: + if (_scrollBar.OtherScrollBarView.Size == _scrollRowsSize) { return; } - _scrollBar.OtherScrollBar.Size = _scrollRowsSize; + _scrollBar.OtherScrollBarView.Size = _scrollRowsSize; break; } @@ -257,9 +257,9 @@ public virtual int ScrollTopOffset { _scrollBar.Position = _scrollTopOffset; } - else if (_scrollBar is { OtherScrollBar.IsVertical: true } && _scrollBar?.OtherScrollBar.Position != _scrollTopOffset) + else if (_scrollBar is { OtherScrollBarView.IsVertical: true } && _scrollBar?.OtherScrollBarView.Position != _scrollTopOffset) { - _scrollBar!.OtherScrollBar.Position = _scrollTopOffset; + _scrollBar!.OtherScrollBarView.Position = _scrollTopOffset; } } } @@ -279,9 +279,9 @@ private void AddEventHandlersForScrollBars (ScrollBarView scrollBar) scrollBar.ChangedPosition += ScrollBar_ChangedPosition; - if (scrollBar.OtherScrollBar != null) + if (_scrollBar.OtherScrollBarView != null) { - scrollBar.OtherScrollBar.ChangedPosition += OtherScrollBar_ChangedPosition; + _scrollBar.OtherScrollBarView.ChangedPosition += OtherScrollBarView_ChangedPosition; } } @@ -301,9 +301,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBar is { IsVertical: true }) + if (scrollBar.OtherScrollBarView is { IsVertical: true }) { - scrollBar.OtherScrollBar.Position++; + scrollBar.OtherScrollBarView.Position++; return true; } @@ -322,9 +322,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBar is { IsVertical: true }) + if (scrollBar.OtherScrollBarView is { IsVertical: true }) { - scrollBar.OtherScrollBar.Position--; + scrollBar.OtherScrollBarView.Position--; return true; } @@ -343,9 +343,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBar is { IsVertical: true }) + if (scrollBar.OtherScrollBarView is { IsVertical: true }) { - scrollBar.OtherScrollBar.Position = 0; + scrollBar.OtherScrollBarView.Position = 0; return true; } @@ -364,9 +364,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBar is { IsVertical: true }) + if (scrollBar.OtherScrollBarView is { IsVertical: true }) { - scrollBar.OtherScrollBar.Position = ScrollRowsSize; + scrollBar.OtherScrollBarView.Position = ScrollRowsSize; return true; } @@ -385,9 +385,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBar is { IsVertical: true }) + if (scrollBar.OtherScrollBarView is { IsVertical: true }) { - scrollBar.OtherScrollBar.Position += ContentArea.Height; + scrollBar.OtherScrollBarView.Position += ContentArea.Height; return true; } @@ -406,9 +406,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBar is { IsVertical: true }) + if (scrollBar.OtherScrollBarView is { IsVertical: true }) { - scrollBar.OtherScrollBar.Position -= ContentArea.Height; + scrollBar.OtherScrollBarView.Position -= ContentArea.Height; return true; } @@ -438,9 +438,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBar is { IsVertical: false }) + if (scrollBar.OtherScrollBarView is { IsVertical: false }) { - scrollBar.OtherScrollBar.Position--; + scrollBar.OtherScrollBarView.Position--; return true; } @@ -459,9 +459,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBar is { IsVertical: false }) + if (scrollBar.OtherScrollBarView is { IsVertical: false }) { - scrollBar.OtherScrollBar.Position++; + scrollBar.OtherScrollBarView.Position++; return true; } @@ -480,9 +480,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBar is { IsVertical: false }) + if (scrollBar.OtherScrollBarView is { IsVertical: false }) { - scrollBar.OtherScrollBar.Position = 0; + scrollBar.OtherScrollBarView.Position = 0; return true; } @@ -501,9 +501,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBar is { IsVertical: false }) + if (scrollBar.OtherScrollBarView is { IsVertical: false }) { - scrollBar.OtherScrollBar.Position = ScrollColsSize; + scrollBar.OtherScrollBarView.Position = ScrollColsSize; return true; } @@ -522,9 +522,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBar is { IsVertical: false }) + if (scrollBar.OtherScrollBarView is { IsVertical: false }) { - scrollBar.OtherScrollBar.Position += ContentArea.Width; + scrollBar.OtherScrollBarView.Position += ContentArea.Width; return true; } @@ -543,9 +543,9 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBar is { IsVertical: false }) + if (scrollBar.OtherScrollBarView is { IsVertical: false }) { - scrollBar.OtherScrollBar.Position -= ContentArea.Width; + scrollBar.OtherScrollBarView.Position -= ContentArea.Width; return true; } @@ -572,16 +572,16 @@ private void DisposeScrollBar () _scrollBar.ChangedPosition -= ScrollBar_ChangedPosition; - if (_scrollBar.OtherScrollBar != null) + if (_scrollBar.OtherScrollBarView != null) { - _scrollBar.OtherScrollBar.ChangedPosition -= OtherScrollBar_ChangedPosition; + _scrollBar.OtherScrollBarView.ChangedPosition -= OtherScrollBarView_ChangedPosition; } _scrollBar.RemoveAll (); _scrollBar = null; } - private void OtherScrollBar_ChangedPosition (object sender, EventArgs e) { SetBoundsByPosition (_scrollBar.OtherScrollBar); } + private void OtherScrollBarView_ChangedPosition (object sender, EventArgs e) { SetBoundsByPosition (_scrollBar.OtherScrollBarView); } private void ScrollBar_ChangedPosition (object sender, EventArgs e) { SetBoundsByPosition (_scrollBar); } diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index f2543d615d..e24e85d411 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -1,5 +1,5 @@ // -// ScrollBar.cs: ScrollBar view. +// ScrollBarView.cs: ScrollBarView view. // // Authors: // Miguel de Icaza (miguel@gnome.org) @@ -7,7 +7,7 @@ namespace Terminal.Gui; -/// ScrollBars are views that display a 1-character scrollbar, either horizontal or vertical +/// ScrollBarViews are views that display a 1-character scrollbar, either horizontal or vertical /// /// /// The scrollbar is drawn to be a representation of the Size, assuming that the scroll position is set at @@ -22,7 +22,7 @@ public class ScrollBarView : View private View _contentBottomRightCorner; private bool _keepContentAlwaysInViewport = true; private int _lastLocation = -1; - private ScrollBarView _otherScrollBar; + private ScrollBarView _otherScrollBarView; private int _posBarOffset; private int _posBottomTee; private int _posLeftTee; @@ -33,7 +33,7 @@ public class ScrollBarView : View private bool _vertical; /// - /// Initializes a new instance of the class using + /// Initializes a new instance of the class using /// layout. /// public ScrollBarView () @@ -43,8 +43,8 @@ public ScrollBarView () ClearOnVisibleFalse = false; CanFocus = false; - Added += ScrollBar_Added; - Initialized += ScrollBar_Initialized; + Added += ScrollBarView_Added; + Initialized += ScrollBarView_Initialized; } /// If true the vertical/horizontal scroll bars won't be showed if it's not needed. @@ -91,25 +91,25 @@ public bool KeepContentAlwaysInViewPort } } - /// Represent a vertical or horizontal ScrollBar other than this. - public ScrollBarView OtherScrollBar + /// Represent a vertical or horizontal ScrollBarView other than this. + public ScrollBarView OtherScrollBarView { - get => _otherScrollBar; + get => _otherScrollBarView; set { if (value is { } && ((value.IsVertical && _vertical) || (!value.IsVertical && !_vertical))) { throw new ArgumentException ( - $"There is already a {(_vertical ? "vertical" : "horizontal")} ScrollBar." + $"There is already a {(_vertical ? "vertical" : "horizontal")} ScrollBarView." ); } - _otherScrollBar = value; - _otherScrollBar._otherScrollBar = this; + _otherScrollBarView = value; + _otherScrollBarView._otherScrollBarView = this; - if (SuperView != null && _otherScrollBar?.SuperView is null && !SuperView.Subviews.Contains (_otherScrollBar)) + if (SuperView != null && _otherScrollBarView?.SuperView is null && !SuperView.Subviews.Contains (_otherScrollBarView)) { - SuperView.Add (_otherScrollBar); + SuperView.Add (_otherScrollBarView); } } } @@ -177,7 +177,7 @@ public int Size } } - private bool _showBothScrollIndicator => OtherScrollBar?._showScrollIndicator == true && _showScrollIndicator; + private bool _showBothScrollIndicator => OtherScrollBarView?._showScrollIndicator == true && _showScrollIndicator; private bool IsBuiltIn => SuperView is Adornment; @@ -674,9 +674,9 @@ private void AdjustContentInViewport (bool refresh = true) Position = pos; } - if (OtherScrollBar is { } && OtherScrollBar.KeepContentAlwaysInViewPort != KeepContentAlwaysInViewPort) + if (OtherScrollBarView is { } && OtherScrollBarView.KeepContentAlwaysInViewPort != KeepContentAlwaysInViewPort) { - OtherScrollBar.KeepContentAlwaysInViewPort = KeepContentAlwaysInViewPort; + OtherScrollBarView.KeepContentAlwaysInViewPort = KeepContentAlwaysInViewPort; } if (pos == 0 && refresh) @@ -701,7 +701,7 @@ private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = fa scrollBarView.Visible = false; } } - else if (barsize > 0 && barsize == scrollBarView.Size && scrollBarView.OtherScrollBar is { } && pending) + else if (barsize > 0 && barsize == scrollBarView.Size && scrollBarView.OtherScrollBarView is { } && pending) { if (scrollBarView._showScrollIndicator) { @@ -713,32 +713,32 @@ private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = fa scrollBarView.Visible = false; } - if (scrollBarView.OtherScrollBar is { } && scrollBarView._showBothScrollIndicator) + if (scrollBarView.OtherScrollBarView is { } && scrollBarView._showBothScrollIndicator) { - scrollBarView.OtherScrollBar.ShowScrollIndicator = false; + scrollBarView.OtherScrollBarView.ShowScrollIndicator = false; } - if (scrollBarView.OtherScrollBar.Visible) + if (scrollBarView.OtherScrollBarView.Visible) { - scrollBarView.OtherScrollBar.Visible = false; + scrollBarView.OtherScrollBarView.Visible = false; } } - else if (barsize > 0 && barsize == Size && scrollBarView.OtherScrollBar is { } && !pending) + else if (barsize > 0 && barsize == Size && scrollBarView.OtherScrollBarView is { } && !pending) { pending = true; } else { - if (scrollBarView.OtherScrollBar is { } && pending) + if (scrollBarView.OtherScrollBarView is { } && pending) { if (!scrollBarView._showBothScrollIndicator) { - scrollBarView.OtherScrollBar.ShowScrollIndicator = true; + scrollBarView.OtherScrollBarView.ShowScrollIndicator = true; } - if (!scrollBarView.OtherScrollBar.Visible) + if (!scrollBarView.OtherScrollBarView.Visible) { - scrollBarView.OtherScrollBar.Visible = true; + scrollBarView.OtherScrollBarView.Visible = true; } } @@ -800,8 +800,8 @@ private void ContentBottomRightCorner_MouseClick (object sender, MouseEventEvent private void CreateBottomRightCorner (View host) { if (host != null - && ((_contentBottomRightCorner is null && OtherScrollBar is null) - || (_contentBottomRightCorner is null && OtherScrollBar is { } && OtherScrollBar._contentBottomRightCorner is null))) + && ((_contentBottomRightCorner is null && OtherScrollBarView is null) + || (_contentBottomRightCorner is null && OtherScrollBarView is { } && OtherScrollBarView._contentBottomRightCorner is null))) { if (IsBuiltIn && ((Adornment)host).Parent.ScrollBarType != ScrollBarType.Both) { @@ -829,11 +829,11 @@ private void CreateBottomRightCorner (View host) } else if (host != null && _contentBottomRightCorner == null - && OtherScrollBar != null - && OtherScrollBar._contentBottomRightCorner != null) + && OtherScrollBarView != null + && OtherScrollBarView._contentBottomRightCorner != null) { - _contentBottomRightCorner = OtherScrollBar._contentBottomRightCorner; + _contentBottomRightCorner = OtherScrollBarView._contentBottomRightCorner; } } @@ -887,13 +887,13 @@ private void ManageScrollBarThickness () 0, IsVertical ? ShowScrollIndicator ? 1 : 0 - : OtherScrollBar?.IsVertical == true - ? OtherScrollBar?.ShowScrollIndicator == true ? 1 : 0 + : OtherScrollBarView?.IsVertical == true + ? OtherScrollBarView?.ShowScrollIndicator == true ? 1 : 0 : 0, !IsVertical ? ShowScrollIndicator ? 1 : 0 - : OtherScrollBar?.IsVertical == false - ? OtherScrollBar?.ShowScrollIndicator == true ? 1 : 0 + : OtherScrollBarView?.IsVertical == false + ? OtherScrollBarView?.ShowScrollIndicator == true ? 1 : 0 : 0), _ => throw new ArgumentOutOfRangeException () }; @@ -905,9 +905,9 @@ private void Parent_EnabledChanged (object sender, EventArgs e) { Enabled = SuperView.Enabled; - if (_otherScrollBar is { }) + if (_otherScrollBarView is { }) { - _otherScrollBar.Enabled = Enabled; + _otherScrollBarView.Enabled = Enabled; } _contentBottomRightCorner.Enabled = Enabled; @@ -919,9 +919,9 @@ private void Parent_VisibleChanged (object sender, EventArgs e) { Visible = SuperView.Visible; - if (_otherScrollBar is { }) + if (_otherScrollBarView is { }) { - _otherScrollBar.Visible = Visible; + _otherScrollBarView.Visible = Visible; } _contentBottomRightCorner.Visible = Visible; @@ -932,7 +932,7 @@ private void Parent_VisibleChanged (object sender, EventArgs e) } } - private void ScrollBar_Added (object sender, SuperViewChangedEventArgs e) + private void ScrollBarView_Added (object sender, SuperViewChangedEventArgs e) { if (IsBuiltIn) { @@ -945,9 +945,9 @@ private void ScrollBar_Added (object sender, SuperViewChangedEventArgs e) Y = IsVertical ? 0 : Pos.AnchorEnd (1); } - if (OtherScrollBar is { SuperView: null } && !e.Parent.Subviews.Contains (OtherScrollBar)) + if (OtherScrollBarView is { SuperView: null } && !e.Parent.Subviews.Contains (OtherScrollBarView)) { - e.Parent.Add (OtherScrollBar); + e.Parent.Add (OtherScrollBarView); } CreateBottomRightCorner (e.Parent); @@ -964,7 +964,7 @@ private void ScrollBar_Added (object sender, SuperViewChangedEventArgs e) ManageScrollBarThickness (); } - private void ScrollBar_Initialized (object sender, EventArgs e) + private void ScrollBarView_Initialized (object sender, EventArgs e) { SetWidthHeight (); ShowHideScrollBars (); @@ -1002,9 +1002,9 @@ private void SetPosition (int newPosition) OnChangedPosition (); SetNeedsDisplay (); - OtherScrollBar?.SetNeedsDisplay (); + OtherScrollBarView?.SetNeedsDisplay (); _contentBottomRightCorner?.SetNeedsDisplay (); - OtherScrollBar?._contentBottomRightCorner?.SetNeedsDisplay (); + OtherScrollBarView?._contentBottomRightCorner?.SetNeedsDisplay (); } private void SetWidthHeight () @@ -1025,25 +1025,25 @@ private void SetWidthHeight () Width = _vertical ? 1 : SuperView is Adornment ? Dim.Fill () : bounds.Width - 1; Height = _vertical ? SuperView is Adornment ? Dim.Fill () : bounds.Height - 1 : 1; - _otherScrollBar.X = _otherScrollBar._vertical ? bounds.Right - 1 : bounds.Left; - _otherScrollBar.Y = _otherScrollBar._vertical ? bounds.Top : bounds.Bottom - 1; + _otherScrollBarView.X = _otherScrollBarView._vertical ? bounds.Right - 1 : bounds.Left; + _otherScrollBarView.Y = _otherScrollBarView._vertical ? bounds.Top : bounds.Bottom - 1; - _otherScrollBar.Width = _otherScrollBar._vertical ? 1 : - SuperView is Adornment ? Dim.Fill () : bounds.Width - 1; + _otherScrollBarView.Width = _otherScrollBarView._vertical ? 1 : + SuperView is Adornment ? Dim.Fill () : bounds.Width - 1; - _otherScrollBar.Height = _otherScrollBar._vertical - ? SuperView is Adornment ? Dim.Fill () : bounds.Height - 1 - : 1; + _otherScrollBarView.Height = _otherScrollBarView._vertical + ? SuperView is Adornment ? Dim.Fill () : bounds.Height - 1 + : 1; } else { Width = _vertical ? 1 : SuperView is Adornment ? Dim.Fill () : Dim.Fill (1); Height = _vertical ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) : 1; - _otherScrollBar.Width = _otherScrollBar._vertical ? 1 : + _otherScrollBarView.Width = _otherScrollBarView._vertical ? 1 : SuperView is Adornment ? Dim.Fill () : Dim.Fill (1); - _otherScrollBar.Height = _otherScrollBar._vertical + _otherScrollBarView.Height = _otherScrollBarView._vertical ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) : 1; } @@ -1065,21 +1065,21 @@ private void SetWidthHeight () Height = _vertical ? Dim.Fill () : 1; } } - else if (_otherScrollBar?._showScrollIndicator == true) + else if (_otherScrollBarView?._showScrollIndicator == true) { if (SuperView is { UseNegativeBoundsLocation: true }) { Rectangle bounds = GetSuperViewBounds (); - _otherScrollBar.X = _otherScrollBar._vertical ? bounds.Right - 1 : bounds.Left; - _otherScrollBar.Y = _otherScrollBar._vertical ? bounds.Top : bounds.Bottom - 1; - _otherScrollBar.Width = _otherScrollBar._vertical ? 1 : bounds.Width; - _otherScrollBar.Height = _otherScrollBar._vertical ? bounds.Height : 1; + _otherScrollBarView.X = _otherScrollBarView._vertical ? bounds.Right - 1 : bounds.Left; + _otherScrollBarView.Y = _otherScrollBarView._vertical ? bounds.Top : bounds.Bottom - 1; + _otherScrollBarView.Width = _otherScrollBarView._vertical ? 1 : bounds.Width; + _otherScrollBarView.Height = _otherScrollBarView._vertical ? bounds.Height : 1; } else { - _otherScrollBar.Width = _otherScrollBar._vertical ? 1 : Dim.Fill (); - _otherScrollBar.Height = _otherScrollBar._vertical ? Dim.Fill () : 1; + _otherScrollBarView.Width = _otherScrollBarView._vertical ? 1 : Dim.Fill(); + _otherScrollBarView.Height = _otherScrollBarView._vertical ? Dim.Fill () : 1; } } @@ -1103,20 +1103,20 @@ private void ShowHideScrollBars (bool redraw = true) { bool pending = CheckBothScrollBars (this); - if (_otherScrollBar is { }) + if (_otherScrollBarView is { }) { - _otherScrollBar.SetRelativeLayout (GetSuperViewBounds ()); - CheckBothScrollBars (_otherScrollBar, pending); + _otherScrollBarView.SetRelativeLayout (GetSuperViewBounds ()); + CheckBothScrollBars (_otherScrollBarView, pending); } } SetWidthHeight (); SetRelativeLayout (GetSuperViewBounds ()); - if (_otherScrollBar is { }) + if (_otherScrollBarView is { }) { - OtherScrollBar.SetWidthHeight (); - OtherScrollBar.SetRelativeLayout (GetSuperViewBounds ()); + OtherScrollBarView.SetWidthHeight (); + OtherScrollBarView.SetRelativeLayout (GetSuperViewBounds ()); } if (_showBothScrollIndicator) @@ -1125,9 +1125,9 @@ private void ShowHideScrollBars (bool redraw = true) { _contentBottomRightCorner.Visible = true; } - else if (_otherScrollBar is { } && _otherScrollBar._contentBottomRightCorner is { }) + else if (_otherScrollBarView is { } && _otherScrollBarView._contentBottomRightCorner is { }) { - _otherScrollBar._contentBottomRightCorner.Visible = true; + _otherScrollBarView._contentBottomRightCorner.Visible = true; } } else if (!_showScrollIndicator) @@ -1136,9 +1136,9 @@ private void ShowHideScrollBars (bool redraw = true) { _contentBottomRightCorner.Visible = false; } - else if (_otherScrollBar is { } && _otherScrollBar._contentBottomRightCorner is { }) + else if (_otherScrollBarView is { } && _otherScrollBarView._contentBottomRightCorner is { }) { - _otherScrollBar._contentBottomRightCorner.Visible = false; + _otherScrollBarView._contentBottomRightCorner.Visible = false; } if (Application.MouseGrabView is { } && Application.MouseGrabView == this) @@ -1150,9 +1150,9 @@ private void ShowHideScrollBars (bool redraw = true) { _contentBottomRightCorner.Visible = false; } - else if (_otherScrollBar is { } && _otherScrollBar._contentBottomRightCorner is { }) + else if (_otherScrollBarView is { } && _otherScrollBarView._contentBottomRightCorner is { }) { - _otherScrollBar._contentBottomRightCorner.Visible = false; + _otherScrollBarView._contentBottomRightCorner.Visible = false; } if (SuperView?.Visible == true && _showScrollIndicator && !Visible) @@ -1160,9 +1160,9 @@ private void ShowHideScrollBars (bool redraw = true) Visible = true; } - if (SuperView?.Visible == true && _otherScrollBar?._showScrollIndicator == true && !_otherScrollBar.Visible) + if (SuperView?.Visible == true && _otherScrollBarView?._showScrollIndicator == true && !_otherScrollBarView.Visible) { - _otherScrollBar.Visible = true; + _otherScrollBarView.Visible = true; } } diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index 9e834e7d37..4e8c70cc99 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -60,11 +60,11 @@ public ScrollView () Size = 1, IsVertical = false }; - _vertical.OtherScrollBar = _horizontal; - _horizontal.OtherScrollBar = _vertical; + _vertical.OtherScrollBarView = _horizontal; + _horizontal.OtherScrollBarView = _vertical; // The _horizontal will be automatically added - // through the OtherScrollBar property + // through the OtherScrollBarView property base.Add (_vertical); CanFocus = true; @@ -220,7 +220,7 @@ public bool ShowHorizontalScrollIndicator if (value) { - _horizontal.OtherScrollBar = _vertical; + _horizontal.OtherScrollBarView = _vertical; if (!Subviews.Contains (_horizontal)) { @@ -229,7 +229,7 @@ public bool ShowHorizontalScrollIndicator _horizontal.ShowScrollIndicator = true; _horizontal.AutoHideScrollBars = AutoHideScrollBars; - _horizontal.OtherScrollBar.ShowScrollIndicator = true; + _horizontal.OtherScrollBarView.ShowScrollIndicator = true; _horizontal.MouseEnter += View_MouseEnter; _horizontal.MouseLeave += View_MouseLeave; } @@ -258,7 +258,7 @@ public bool ShowVerticalScrollIndicator if (value) { - _vertical.OtherScrollBar = _horizontal; + _vertical.OtherScrollBarView = _horizontal; if (!Subviews.Contains (_vertical)) { @@ -267,7 +267,7 @@ public bool ShowVerticalScrollIndicator _vertical.ShowScrollIndicator = true; _vertical.AutoHideScrollBars = AutoHideScrollBars; - _vertical.OtherScrollBar.ShowScrollIndicator = true; + _vertical.OtherScrollBarView.ShowScrollIndicator = true; _vertical.MouseEnter += View_MouseEnter; _vertical.MouseLeave += View_MouseLeave; } diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index 6ade34726b..1dbb724c9c 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -193,7 +193,7 @@ public override void Init () ) } ), - new MenuBarItem ("_ScrollBar", CreateKeepChecked ()), + new MenuBarItem ("_ScrollBarView", CreateKeepChecked ()), new MenuBarItem ("_Cursor", CreateCursorRadio ()), new MenuBarItem ( "Forma_t", diff --git a/UnitTests/Input/ResponderTests.cs b/UnitTests/Input/ResponderTests.cs index d5fac8f009..5bed852579 100644 --- a/UnitTests/Input/ResponderTests.cs +++ b/UnitTests/Input/ResponderTests.cs @@ -158,10 +158,10 @@ public void IsOverridden_False_IfNotOverridden () [TestRespondersDisposed] public void IsOverridden_True_IfOverridden () { - // MouseEvent is defined on Responder IS overriden on ScrollBar (but not View) + // MouseEvent is defined on Responder IS overriden on ScrollBarView (but not View) Assert.True ( Responder.IsOverridden ( - new ScrollBarView { Text = "ScrollBar overrides MouseEvent" }, + new ScrollBarView { Text = "ScrollBarView overrides MouseEvent" }, "MouseEvent" ) ); @@ -177,17 +177,17 @@ public void IsOverridden_True_IfOverridden () ) ); - // ScrollBar overrides both MouseEvent (from Responder) and Redraw (from View) + // ScrollBarView overrides both MouseEvent (from Responder) and Redraw (from View) Assert.True ( Responder.IsOverridden ( - new ScrollBarView { Text = "ScrollBar overrides MouseEvent" }, + new ScrollBarView { Text = "ScrollBarView overrides MouseEvent" }, "MouseEvent" ) ); Assert.True ( Responder.IsOverridden ( - new ScrollBarView { Text = "ScrollBar overrides OnDrawContent" }, + new ScrollBarView { Text = "ScrollBarView overrides OnDrawContent" }, "OnDrawContent" ) ); diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index d1c910c5a8..3c609038bd 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -15,7 +15,7 @@ public class ScrollBarViewTests [ScrollBarAutoInitShutdown] public void AutoHideScrollBars_Check () { - Hosting_A_View_To_A_ScrollBar (); + Hosting_A_View_To_A_ScrollBarView (); AddHandlers (); @@ -30,16 +30,16 @@ public void AutoHideScrollBars_Check () _scrollBar.Height.ToString () ); Assert.Equal (24, _scrollBar.Bounds.Height); - Assert.True (_scrollBar.OtherScrollBar.ShowScrollIndicator); - Assert.True (_scrollBar.OtherScrollBar.Visible); + Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.True (_scrollBar.OtherScrollBarView.Visible); Assert.Equal ( "Fill(1)", - _scrollBar.OtherScrollBar.Width.ToString () + _scrollBar.OtherScrollBarView.Width.ToString () ); - Assert.Equal (79, _scrollBar.OtherScrollBar.Bounds.Width); - Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBar.Height.ToString ()); - Assert.Equal (1, _scrollBar.OtherScrollBar.Bounds.Height); + Assert.Equal (79, _scrollBar.OtherScrollBarView.Bounds.Width); + Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ()); + Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height); _hostView.Lines = 10; _hostView.Draw (); @@ -53,16 +53,16 @@ public void AutoHideScrollBars_Check () _scrollBar.Height.ToString () ); Assert.Equal (24, _scrollBar.Bounds.Height); - Assert.True (_scrollBar.OtherScrollBar.ShowScrollIndicator); - Assert.True (_scrollBar.OtherScrollBar.Visible); + Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.True (_scrollBar.OtherScrollBarView.Visible); Assert.Equal ( "Fill(0)", - _scrollBar.OtherScrollBar.Width.ToString () + _scrollBar.OtherScrollBarView.Width.ToString () ); - Assert.Equal (80, _scrollBar.OtherScrollBar.Bounds.Width); - Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBar.Height.ToString ()); - Assert.Equal (1, _scrollBar.OtherScrollBar.Bounds.Height); + Assert.Equal (80, _scrollBar.OtherScrollBarView.Bounds.Width); + Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ()); + Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height); _hostView.Cols = 60; _hostView.Draw (); @@ -76,16 +76,16 @@ public void AutoHideScrollBars_Check () _scrollBar.Height.ToString () ); Assert.Equal (24, _scrollBar.Bounds.Height); - Assert.False (_scrollBar.OtherScrollBar.ShowScrollIndicator); - Assert.False (_scrollBar.OtherScrollBar.Visible); + Assert.False (_scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.False (_scrollBar.OtherScrollBarView.Visible); Assert.Equal ( "Fill(0)", - _scrollBar.OtherScrollBar.Width.ToString () + _scrollBar.OtherScrollBarView.Width.ToString () ); - Assert.Equal (80, _scrollBar.OtherScrollBar.Bounds.Width); - Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBar.Height.ToString ()); - Assert.Equal (1, _scrollBar.OtherScrollBar.Bounds.Height); + Assert.Equal (80, _scrollBar.OtherScrollBarView.Bounds.Width); + Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ()); + Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height); _hostView.Lines = 40; _hostView.Draw (); @@ -99,16 +99,16 @@ public void AutoHideScrollBars_Check () _scrollBar.Height.ToString () ); Assert.Equal (25, _scrollBar.Bounds.Height); - Assert.False (_scrollBar.OtherScrollBar.ShowScrollIndicator); - Assert.False (_scrollBar.OtherScrollBar.Visible); + Assert.False (_scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.False (_scrollBar.OtherScrollBarView.Visible); Assert.Equal ( "Fill(0)", - _scrollBar.OtherScrollBar.Width.ToString () + _scrollBar.OtherScrollBarView.Width.ToString () ); - Assert.Equal (80, _scrollBar.OtherScrollBar.Bounds.Width); - Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBar.Height.ToString ()); - Assert.Equal (1, _scrollBar.OtherScrollBar.Bounds.Height); + Assert.Equal (80, _scrollBar.OtherScrollBarView.Bounds.Width); + Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ()); + Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height); _hostView.Cols = 120; _hostView.Draw (); @@ -122,16 +122,16 @@ public void AutoHideScrollBars_Check () _scrollBar.Height.ToString () ); Assert.Equal (24, _scrollBar.Bounds.Height); - Assert.True (_scrollBar.OtherScrollBar.ShowScrollIndicator); - Assert.True (_scrollBar.OtherScrollBar.Visible); + Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.True (_scrollBar.OtherScrollBarView.Visible); Assert.Equal ( "Fill(1)", - _scrollBar.OtherScrollBar.Width.ToString () + _scrollBar.OtherScrollBarView.Width.ToString () ); - Assert.Equal (79, _scrollBar.OtherScrollBar.Bounds.Width); - Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBar.Height.ToString ()); - Assert.Equal (1, _scrollBar.OtherScrollBar.Bounds.Height); + Assert.Equal (79, _scrollBar.OtherScrollBarView.Bounds.Width); + Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ()); + Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height); } [Fact] @@ -161,7 +161,7 @@ public void Both_Default_Draws_Correctly () ShowScrollIndicator = true, IsVertical = true, - OtherScrollBar = horiz + OtherScrollBarView = horiz }; super.Add (vert); @@ -216,7 +216,7 @@ public void Both_Default_Draws_Correctly () [ScrollBarAutoInitShutdown] public void ChangedPosition_Negative_Value () { - Hosting_A_View_To_A_ScrollBar (); + Hosting_A_View_To_A_ScrollBarView (); AddHandlers (); @@ -224,16 +224,16 @@ public void ChangedPosition_Negative_Value () Assert.Equal (0, _scrollBar.Position); Assert.Equal (_scrollBar.Position, _hostView.Top); - _scrollBar.OtherScrollBar.Position = -50; - Assert.Equal (0, _scrollBar.OtherScrollBar.Position); - Assert.Equal (_scrollBar.OtherScrollBar.Position, _hostView.Left); + _scrollBar.OtherScrollBarView.Position = -50; + Assert.Equal (0, _scrollBar.OtherScrollBarView.Position); + Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); } [Fact] [ScrollBarAutoInitShutdown] public void ChangedPosition_Scrolling () { - Hosting_A_View_To_A_ScrollBar (); + Hosting_A_View_To_A_ScrollBarView (); AddHandlers (); @@ -249,16 +249,16 @@ public void ChangedPosition_Scrolling () Assert.Equal (_scrollBar.Position, _hostView.Top); } - for (var i = 0; i < _scrollBar.OtherScrollBar.Size; i++) + for (var i = 0; i < _scrollBar.OtherScrollBarView.Size; i++) { - _scrollBar.OtherScrollBar.Position += i; - Assert.Equal (_scrollBar.OtherScrollBar.Position, _hostView.Left); + _scrollBar.OtherScrollBarView.Position += i; + Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); } - for (int i = _scrollBar.OtherScrollBar.Size - 1; i >= 0; i--) + for (int i = _scrollBar.OtherScrollBarView.Size - 1; i >= 0; i--) { - _scrollBar.OtherScrollBar.Position -= 1; - Assert.Equal (_scrollBar.OtherScrollBar.Position, _hostView.Left); + _scrollBar.OtherScrollBarView.Position -= 1; + Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); } } @@ -266,15 +266,15 @@ public void ChangedPosition_Scrolling () [ScrollBarAutoInitShutdown] public void ChangedPosition_Update_The_Hosted_View () { - Hosting_A_View_To_A_ScrollBar (); + Hosting_A_View_To_A_ScrollBarView (); AddHandlers (); _scrollBar.Position = 2; Assert.Equal (_scrollBar.Position, _hostView.Top); - _scrollBar.OtherScrollBar.Position = 5; - Assert.Equal (_scrollBar.OtherScrollBar.Position, _hostView.Left); + _scrollBar.OtherScrollBarView.Position = 5; + Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); } [Fact] @@ -411,42 +411,42 @@ public void Assert.True (listView.ScrollKeepContentAlwaysInViewPort); - var newScrollBar = listView.Padding.Subviews [0] as ScrollBarView; + var newScrollBarView = listView.Padding.Subviews [0] as ScrollBarView; - newScrollBar!.ChangedPosition += (s, e) => - { - listView.LeftItem = newScrollBar.Position; - - if (listView.LeftItem != newScrollBar.Position) + newScrollBarView!.ChangedPosition += (s, e) => { - newScrollBar.Position = listView.LeftItem; - } + listView.LeftItem = newScrollBarView.Position; + + if (listView.LeftItem != newScrollBarView.Position) + { + newScrollBarView.Position = listView.LeftItem; + } - Assert.Equal (newScrollBar.Position, listView.LeftItem); - listView.SetNeedsDisplay (); - }; + Assert.Equal (newScrollBarView.Position, listView.LeftItem); + listView.SetNeedsDisplay (); + }; listView.DrawContent += (s, e) => { - newScrollBar.Size = listView.MaxLength; - Assert.Equal (newScrollBar.Size, listView.MaxLength); - newScrollBar.Position = listView.LeftItem; - Assert.Equal (newScrollBar.Position, listView.LeftItem); - newScrollBar.Refresh (); + newScrollBarView.Size = listView.MaxLength; + Assert.Equal (newScrollBarView.Size, listView.MaxLength); + newScrollBarView.Position = listView.LeftItem; + Assert.Equal (newScrollBarView.Position, listView.LeftItem); + newScrollBarView.Refresh (); }; top.Ready += (s, e) => { - newScrollBar.Position = 100; + newScrollBarView.Position = 100; Assert.Equal ( - newScrollBar.Position, - newScrollBar.Size + newScrollBarView.Position, + newScrollBarView.Size - listView.LeftItem + (listView.LeftItem - listView.Bounds.Width)); - Assert.Equal (newScrollBar.Position, listView.LeftItem); + Assert.Equal (newScrollBarView.Position, listView.LeftItem); - Assert.Equal (92, newScrollBar.Position); + Assert.Equal (92, newScrollBarView.Position); Assert.Equal (92, listView.LeftItem); Application.RequestStop (); }; @@ -487,43 +487,43 @@ public void Source = new ListWrapper (source) }; win.Add (listView); - var newScrollBar = new ScrollBarView { IsVertical = true, KeepContentAlwaysInViewPort = true }; - listView.Add (newScrollBar); + var newScrollBarView = new ScrollBarView { IsVertical = true, KeepContentAlwaysInViewPort = true }; + listView.Add (newScrollBarView); - newScrollBar.ChangedPosition += (s, e) => - { - listView.TopItem = newScrollBar.Position; - - if (listView.TopItem != newScrollBar.Position) + newScrollBarView.ChangedPosition += (s, e) => { - newScrollBar.Position = listView.TopItem; - } + listView.TopItem = newScrollBarView.Position; + + if (listView.TopItem != newScrollBarView.Position) + { + newScrollBarView.Position = listView.TopItem; + } - Assert.Equal (newScrollBar.Position, listView.TopItem); - listView.SetNeedsDisplay (); - }; + Assert.Equal (newScrollBarView.Position, listView.TopItem); + listView.SetNeedsDisplay (); + }; listView.DrawContent += (s, e) => { - newScrollBar.Size = listView.Source.Count; - Assert.Equal (newScrollBar.Size, listView.Source.Count); - newScrollBar.Position = listView.TopItem; - Assert.Equal (newScrollBar.Position, listView.TopItem); - newScrollBar.Refresh (); + newScrollBarView.Size = listView.Source.Count; + Assert.Equal (newScrollBarView.Size, listView.Source.Count); + newScrollBarView.Position = listView.TopItem; + Assert.Equal (newScrollBarView.Position, listView.TopItem); + newScrollBarView.Refresh (); }; top.Ready += (s, e) => { - newScrollBar.Position = 45; + newScrollBarView.Position = 45; Assert.Equal ( - newScrollBar.Position, - newScrollBar.Size + newScrollBarView.Position, + newScrollBarView.Size - listView.TopItem + (listView.TopItem - listView.Bounds.Height) ); - Assert.Equal (newScrollBar.Position, listView.TopItem); - Assert.Equal (27, newScrollBar.Position); + Assert.Equal (newScrollBarView.Position, listView.TopItem); + Assert.Equal (27, newScrollBarView.Position); Assert.Equal (27, listView.TopItem); Application.RequestStop (); }; @@ -544,17 +544,17 @@ public void ContentBottomRightCorner_Not_Redraw_If_Both_Size_Equal_To_Zero () "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test"; var label = new Label { Text = text }; var sbv = new ScrollBarView { X = Pos.AnchorEnd (1), IsVertical = true, Size = 100 }; - sbv.OtherScrollBar = new ScrollBarView { Y = Pos.AnchorEnd (1), IsVertical = false, Size = 100, OtherScrollBar = sbv }; - label.Add (sbv, sbv.OtherScrollBar); + sbv.OtherScrollBarView = new ScrollBarView { Y = Pos.AnchorEnd (1), IsVertical = false, Size = 100, OtherScrollBarView = sbv }; + label.Add (sbv, sbv.OtherScrollBarView); Application.Top.Add (label); Application.Begin (Application.Top); Assert.Equal (100, sbv.Size); - Assert.Equal (100, sbv.OtherScrollBar.Size); + Assert.Equal (100, sbv.OtherScrollBarView.Size); Assert.True (sbv.ShowScrollIndicator); - Assert.True (sbv.OtherScrollBar.ShowScrollIndicator); + Assert.True (sbv.OtherScrollBarView.ShowScrollIndicator); Assert.True (sbv.Visible); - Assert.True (sbv.OtherScrollBar.Visible); + Assert.True (sbv.OtherScrollBarView.Visible); View contentBottomRightCorner = label.Subviews.First (v => v is ScrollBarView.ContentBottomRightCorner); @@ -574,13 +574,13 @@ This is a tes▼ ); sbv.Size = 0; - sbv.OtherScrollBar.Size = 0; + sbv.OtherScrollBarView.Size = 0; Assert.Equal (0, sbv.Size); - Assert.Equal (0, sbv.OtherScrollBar.Size); + Assert.Equal (0, sbv.OtherScrollBarView.Size); Assert.False (sbv.ShowScrollIndicator); - Assert.False (sbv.OtherScrollBar.ShowScrollIndicator); + Assert.False (sbv.OtherScrollBarView.ShowScrollIndicator); Assert.False (sbv.Visible); - Assert.False (sbv.OtherScrollBar.Visible); + Assert.False (sbv.OtherScrollBarView.Visible); Application.Top.Draw (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -596,13 +596,13 @@ This is a test ); sbv.Size = 50; - sbv.OtherScrollBar.Size = 50; + sbv.OtherScrollBarView.Size = 50; Assert.Equal (50, sbv.Size); - Assert.Equal (50, sbv.OtherScrollBar.Size); + Assert.Equal (50, sbv.OtherScrollBarView.Size); Assert.True (sbv.ShowScrollIndicator); - Assert.True (sbv.OtherScrollBar.ShowScrollIndicator); + Assert.True (sbv.OtherScrollBarView.ShowScrollIndicator); Assert.True (sbv.Visible); - Assert.True (sbv.OtherScrollBar.Visible); + Assert.True (sbv.OtherScrollBarView.Visible); Application.Top.Draw (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -632,7 +632,7 @@ public void ContentBottomRightCorner_Not_Redraw_If_One_Size_Equal_To_Zero () Application.Begin (Application.Top); Assert.Equal (100, sbv.Size); - Assert.Null (sbv.OtherScrollBar); + Assert.Null (sbv.OtherScrollBarView); Assert.True (sbv.ShowScrollIndicator); Assert.True (sbv.Visible); @@ -669,9 +669,9 @@ This is a test [Fact] [ScrollBarAutoInitShutdown] - public void DrawContent_Update_The_ScrollBar_Position () + public void DrawContent_Update_The_ScrollBarView_Position () { - Hosting_A_View_To_A_ScrollBar (); + Hosting_A_View_To_A_ScrollBarView (); AddHandlers (); @@ -681,7 +681,7 @@ public void DrawContent_Update_The_ScrollBar_Position () _hostView.Left = 6; _hostView.Draw (); - Assert.Equal (_scrollBar.OtherScrollBar.Position, _hostView.Left); + Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); } [Fact] @@ -708,22 +708,22 @@ public void Horizontal_Default_Draws_Correctly () [Fact] [ScrollBarAutoInitShutdown] - public void Hosting_A_View_To_A_ScrollBar () + public void Hosting_A_View_To_A_ScrollBarView () { RemoveHandlers (); - _scrollBar = new ScrollBarView { IsVertical = true, OtherScrollBar = new ScrollBarView { IsVertical = false } }; + _scrollBar = new ScrollBarView { IsVertical = true, OtherScrollBarView = new ScrollBarView { IsVertical = false } }; _hostView.Add (_scrollBar); Application.Begin (Application.Top); Assert.True (_scrollBar.IsVertical); - Assert.False (_scrollBar.OtherScrollBar.IsVertical); + Assert.False (_scrollBar.OtherScrollBarView.IsVertical); Assert.Equal (_scrollBar.Position, _hostView.Top); Assert.NotEqual (_scrollBar.Size, _hostView.Lines); - Assert.Equal (_scrollBar.OtherScrollBar.Position, _hostView.Left); - Assert.NotEqual (_scrollBar.OtherScrollBar.Size, _hostView.Cols); + Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); + Assert.NotEqual (_scrollBar.OtherScrollBarView.Size, _hostView.Cols); AddHandlers (); _hostView.SuperView.LayoutSubviews (); @@ -731,8 +731,8 @@ public void Hosting_A_View_To_A_ScrollBar () Assert.Equal (_scrollBar.Position, _hostView.Top); Assert.Equal (_scrollBar.Size, _hostView.Lines); - Assert.Equal (_scrollBar.OtherScrollBar.Position, _hostView.Left); - Assert.Equal (_scrollBar.OtherScrollBar.Size, _hostView.Cols); + Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); + Assert.Equal (_scrollBar.OtherScrollBarView.Size, _hostView.Cols); } [Fact] @@ -758,14 +758,14 @@ public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () var scrollBar = textView.Padding.Subviews [0] as ScrollBarView; Assert.True (scrollBar.AutoHideScrollBars); Assert.False (scrollBar.ShowScrollIndicator); - Assert.False (scrollBar.OtherScrollBar.ShowScrollIndicator); + Assert.False (scrollBar.OtherScrollBarView.ShowScrollIndicator); Assert.Equal (5, textView.Lines); // The length is one more for the cursor on the last column of the line Assert.Equal (43, textView.Maxlength); Assert.Equal (0, textView.LeftColumn); Assert.Equal (0, scrollBar.Position); - Assert.Equal (0, scrollBar.OtherScrollBar.Position); + Assert.Equal (0, scrollBar.OtherScrollBarView.Position); var expected = @" ┌───────────────────────────────────────────┐ @@ -805,7 +805,7 @@ public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () Assert.Equal (23, textView.Maxlength); Assert.Equal (0, textView.LeftColumn); Assert.Equal (0, scrollBar.Position); - Assert.Equal (0, scrollBar.OtherScrollBar.Position); + Assert.Equal (0, scrollBar.OtherScrollBarView.Position); expected = @" ┌────────────────────────┐ @@ -844,7 +844,7 @@ public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () Assert.Equal (7, textView.Maxlength); Assert.Equal (0, textView.LeftColumn); Assert.Equal (0, scrollBar.Position); - Assert.Equal (0, scrollBar.OtherScrollBar.Position); + Assert.Equal (0, scrollBar.OtherScrollBarView.Position); Assert.True (scrollBar.ShowScrollIndicator); expected = @" @@ -875,7 +875,7 @@ public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () Assert.Equal (7, textView.Maxlength); Assert.Equal (0, textView.LeftColumn); Assert.Equal (0, scrollBar.Position); - Assert.Equal (0, scrollBar.OtherScrollBar.Position); + Assert.Equal (0, scrollBar.OtherScrollBarView.Position); Assert.True (scrollBar.ShowScrollIndicator); expected = @" @@ -898,7 +898,7 @@ public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () [Fact] [ScrollBarAutoInitShutdown] - public void Hosting_Two_Horizontal_ScrollBar_Throws_ArgumentException () + public void Hosting_Two_Horizontal_ScrollBarView_Throws_ArgumentException () { var top = new Toplevel (); var host = new View (); @@ -906,13 +906,13 @@ public void Hosting_Two_Horizontal_ScrollBar_Throws_ArgumentException () var v = new ScrollBarView { IsVertical = false }; var h = new ScrollBarView { IsVertical = false }; - Assert.Throws (() => v.OtherScrollBar = h); - Assert.Throws (() => h.OtherScrollBar = v); + Assert.Throws (() => v.OtherScrollBarView = h); + Assert.Throws (() => h.OtherScrollBarView = v); } [Fact] [ScrollBarAutoInitShutdown] - public void Hosting_Two_Vertical_ScrollBar_Throws_ArgumentException () + public void Hosting_Two_Vertical_ScrollBarView_Throws_ArgumentException () { var top = new Toplevel (); var host = new View (); @@ -920,8 +920,8 @@ public void Hosting_Two_Vertical_ScrollBar_Throws_ArgumentException () var v = new ScrollBarView { IsVertical = true }; var h = new ScrollBarView { IsVertical = true }; - Assert.Throws (() => v.OtherScrollBar = h); - Assert.Throws (() => h.OtherScrollBar = v); + Assert.Throws (() => v.OtherScrollBarView = h); + Assert.Throws (() => h.OtherScrollBarView = v); } [Fact] @@ -931,56 +931,56 @@ public void Internal_Tests () Toplevel top = Application.Top; Assert.Equal (new Rectangle (0, 0, 80, 25), top.Bounds); var view = new View { Width = Dim.Fill (), Height = Dim.Fill () }; - var sbv = new ScrollBarView { IsVertical = true, OtherScrollBar = new ScrollBarView { IsVertical = false } }; + var sbv = new ScrollBarView { IsVertical = true, OtherScrollBarView = new ScrollBarView { IsVertical = false } }; view.Add (sbv); top.Add (view); Assert.Equal (view, sbv.SuperView); sbv.Size = 40; sbv.Position = 0; - sbv.OtherScrollBar.Size = 100; - sbv.OtherScrollBar.Position = 0; + sbv.OtherScrollBarView.Size = 100; + sbv.OtherScrollBarView.Position = 0; // Host bounds is not empty. Assert.True (sbv.CanScroll (10, out int max, sbv.IsVertical)); Assert.Equal (10, max); - Assert.True (sbv.OtherScrollBar.CanScroll (10, out max, sbv.OtherScrollBar.IsVertical)); + Assert.True (sbv.OtherScrollBarView.CanScroll (10, out max, sbv.OtherScrollBarView.IsVertical)); Assert.Equal (10, max); Application.Begin (top); // They are visible so they are drawn. Assert.True (sbv.Visible); - Assert.True (sbv.OtherScrollBar.Visible); + Assert.True (sbv.OtherScrollBarView.Visible); top.LayoutSubviews (); // Now the host bounds is not empty. Assert.True (sbv.CanScroll (10, out max, sbv.IsVertical)); Assert.Equal (10, max); - Assert.True (sbv.OtherScrollBar.CanScroll (10, out max, sbv.OtherScrollBar.IsVertical)); + Assert.True (sbv.OtherScrollBarView.CanScroll (10, out max, sbv.OtherScrollBarView.IsVertical)); Assert.Equal (10, max); Assert.True (sbv.CanScroll (50, out max, sbv.IsVertical)); Assert.Equal (40, sbv.Size); Assert.Equal (16, max); // 16+25=41 - Assert.True (sbv.OtherScrollBar.CanScroll (150, out max, sbv.OtherScrollBar.IsVertical)); - Assert.Equal (100, sbv.OtherScrollBar.Size); + Assert.True (sbv.OtherScrollBarView.CanScroll (150, out max, sbv.OtherScrollBarView.IsVertical)); + Assert.Equal (100, sbv.OtherScrollBarView.Size); Assert.Equal (21, max); // 21+80=101 Assert.True (sbv.Visible); - Assert.True (sbv.OtherScrollBar.Visible); + Assert.True (sbv.OtherScrollBarView.Visible); sbv.KeepContentAlwaysInViewPort = false; - sbv.OtherScrollBar.KeepContentAlwaysInViewPort = false; + sbv.OtherScrollBarView.KeepContentAlwaysInViewPort = false; Assert.True (sbv.CanScroll (50, out max, sbv.IsVertical)); Assert.Equal (39, max); // Keep 1 row visible - Assert.True (sbv.OtherScrollBar.CanScroll (150, out max, sbv.OtherScrollBar.IsVertical)); + Assert.True (sbv.OtherScrollBarView.CanScroll (150, out max, sbv.OtherScrollBarView.IsVertical)); Assert.Equal (99, max); // Keep 1 column visible Assert.True (sbv.Visible); - Assert.True (sbv.OtherScrollBar.Visible); + Assert.True (sbv.OtherScrollBarView.Visible); } [Fact] [ScrollBarAutoInitShutdown] public void KeepContentAlwaysInViewport_False () { - Hosting_A_View_To_A_ScrollBar (); + Hosting_A_View_To_A_ScrollBarView (); AddHandlers (); @@ -991,10 +991,10 @@ public void KeepContentAlwaysInViewport_False () Assert.Equal (29, _scrollBar.Position); Assert.Equal (29, _hostView.Top); - _scrollBar.OtherScrollBar.Position = 150; - Assert.Equal (_scrollBar.OtherScrollBar.Position, _scrollBar.OtherScrollBar.Size - 1); - Assert.Equal (_scrollBar.OtherScrollBar.Position, _hostView.Left); - Assert.Equal (99, _scrollBar.OtherScrollBar.Position); + _scrollBar.OtherScrollBarView.Position = 150; + Assert.Equal (_scrollBar.OtherScrollBarView.Position, _scrollBar.OtherScrollBarView.Size - 1); + Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); + Assert.Equal (99, _scrollBar.OtherScrollBarView.Position); Assert.Equal (99, _hostView.Left); } @@ -1002,20 +1002,20 @@ public void KeepContentAlwaysInViewport_False () [ScrollBarAutoInitShutdown] public void KeepContentAlwaysInViewport_True () { - Hosting_A_View_To_A_ScrollBar (); + Hosting_A_View_To_A_ScrollBarView (); AddHandlers (); Assert.Equal (80, _hostView.Bounds.Width); Assert.Equal (25, _hostView.Bounds.Height); - Assert.Equal (79, _scrollBar.OtherScrollBar.Bounds.Width); + Assert.Equal (79, _scrollBar.OtherScrollBarView.Bounds.Width); Assert.Equal (24, _scrollBar.Bounds.Height); Assert.Equal (30, _scrollBar.Size); - Assert.Equal (100, _scrollBar.OtherScrollBar.Size); + Assert.Equal (100, _scrollBar.OtherScrollBarView.Size); Assert.True (_scrollBar.ShowScrollIndicator); - Assert.True (_scrollBar.OtherScrollBar.ShowScrollIndicator); + Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); Assert.True (_scrollBar.Visible); - Assert.True (_scrollBar.OtherScrollBar.Visible); + Assert.True (_scrollBar.OtherScrollBarView.Visible); _scrollBar.Position = 50; Assert.Equal (_scrollBar.Position, _scrollBar.Size - _scrollBar.Bounds.Height); @@ -1023,36 +1023,36 @@ public void KeepContentAlwaysInViewport_True () Assert.Equal (6, _scrollBar.Position); Assert.Equal (6, _hostView.Top); Assert.True (_scrollBar.ShowScrollIndicator); - Assert.True (_scrollBar.OtherScrollBar.ShowScrollIndicator); + Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); Assert.True (_scrollBar.Visible); - Assert.True (_scrollBar.OtherScrollBar.Visible); + Assert.True (_scrollBar.OtherScrollBarView.Visible); - _scrollBar.OtherScrollBar.Position = 150; + _scrollBar.OtherScrollBarView.Position = 150; Assert.Equal ( - _scrollBar.OtherScrollBar.Position, - _scrollBar.OtherScrollBar.Size - _scrollBar.OtherScrollBar.Bounds.Width + _scrollBar.OtherScrollBarView.Position, + _scrollBar.OtherScrollBarView.Size - _scrollBar.OtherScrollBarView.Bounds.Width ); - Assert.Equal (_scrollBar.OtherScrollBar.Position, _hostView.Left); - Assert.Equal (21, _scrollBar.OtherScrollBar.Position); + Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); + Assert.Equal (21, _scrollBar.OtherScrollBarView.Position); Assert.Equal (21, _hostView.Left); Assert.True (_scrollBar.ShowScrollIndicator); - Assert.True (_scrollBar.OtherScrollBar.ShowScrollIndicator); + Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); Assert.True (_scrollBar.Visible); - Assert.True (_scrollBar.OtherScrollBar.Visible); + Assert.True (_scrollBar.OtherScrollBarView.Visible); } [Fact] [ScrollBarAutoInitShutdown] - public void OtherScrollBar_Not_Null () + public void OtherScrollBarView_Not_Null () { - Hosting_A_View_To_A_ScrollBar (); + Hosting_A_View_To_A_ScrollBarView (); AddHandlers (); - Assert.NotNull (_scrollBar.OtherScrollBar); - Assert.NotEqual (_scrollBar, _scrollBar.OtherScrollBar); - Assert.Equal (_scrollBar.OtherScrollBar.OtherScrollBar, _scrollBar); + Assert.NotNull (_scrollBar.OtherScrollBarView); + Assert.NotEqual (_scrollBar, _scrollBar.OtherScrollBarView); + Assert.Equal (_scrollBar.OtherScrollBarView.OtherScrollBarView, _scrollBar); } [Fact] @@ -1486,12 +1486,12 @@ public void Scrolling_With_Default_Constructor_Do_Not_Scroll () [ScrollBarAutoInitShutdown] public void ShowScrollIndicator_Check () { - Hosting_A_View_To_A_ScrollBar (); + Hosting_A_View_To_A_ScrollBarView (); AddHandlers (); Assert.True (_scrollBar.ShowScrollIndicator); - Assert.True (_scrollBar.OtherScrollBar.ShowScrollIndicator); + Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); } [Fact] @@ -1510,7 +1510,7 @@ public void ShowScrollIndicator_False_Must_Also_Set_Visible_To_False_To_Not_Resp Application.Begin (Application.Top); Assert.Equal (5, sbv.Size); - Assert.Null (sbv.OtherScrollBar); + Assert.Null (sbv.OtherScrollBarView); Assert.False (sbv.ShowScrollIndicator); Assert.False (sbv.Visible); @@ -1679,8 +1679,8 @@ private void _hostView_DrawContent (object sender, DrawEventArgs e) { _scrollBar.Size = _hostView.Lines; _scrollBar.Position = _hostView.Top; - _scrollBar.OtherScrollBar.Size = _hostView.Cols; - _scrollBar.OtherScrollBar.Position = _hostView.Left; + _scrollBar.OtherScrollBarView.Size = _hostView.Cols; + _scrollBar.OtherScrollBarView.Position = _hostView.Left; _scrollBar.Refresh (); } @@ -1696,13 +1696,13 @@ private void _scrollBar_ChangedPosition (object sender, EventArgs e) _hostView.SetNeedsDisplay (); } - private void _scrollBar_OtherScrollBar_ChangedPosition (object sender, EventArgs e) + private void _scrollBar_OtherScrollBarView_ChangedPosition (object sender, EventArgs e) { - _hostView.Left = _scrollBar.OtherScrollBar.Position; + _hostView.Left = _scrollBar.OtherScrollBarView.Position; - if (_hostView.Left != _scrollBar.OtherScrollBar.Position) + if (_hostView.Left != _scrollBar.OtherScrollBarView.Position) { - _scrollBar.OtherScrollBar.Position = _hostView.Left; + _scrollBar.OtherScrollBarView.Position = _hostView.Left; } _hostView.SetNeedsDisplay (); @@ -1714,7 +1714,7 @@ private void AddHandlers () { _hostView.DrawContent += _hostView_DrawContent; _scrollBar.ChangedPosition += _scrollBar_ChangedPosition; - _scrollBar.OtherScrollBar.ChangedPosition += _scrollBar_OtherScrollBar_ChangedPosition; + _scrollBar.OtherScrollBarView.ChangedPosition += _scrollBar_OtherScrollBarView_ChangedPosition; } _added = true; @@ -1726,7 +1726,7 @@ private void RemoveHandlers () { _hostView.DrawContent -= _hostView_DrawContent; _scrollBar.ChangedPosition -= _scrollBar_ChangedPosition; - _scrollBar.OtherScrollBar.ChangedPosition -= _scrollBar_OtherScrollBar_ChangedPosition; + _scrollBar.OtherScrollBarView.ChangedPosition -= _scrollBar_OtherScrollBarView_ChangedPosition; } _added = false; From 9d401ffc0563c11a02d325ef9fc28aaa76d6bfdb Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 24 Feb 2024 22:11:20 +0000 Subject: [PATCH 051/130] Rename to UseContentOffset. --- Terminal.Gui/View/Layout/ViewLayout.cs | 2 +- Terminal.Gui/View/ViewScrollBar.cs | 10 +++++----- Terminal.Gui/Views/ScrollBarView.cs | 6 +++--- UICatalog/Scenarios/ScrollBars.cs | 8 ++++---- UnitTests/Views/ScrollBarViewTests.cs | 6 +++--- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 6e774f3a42..012815807d 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -257,7 +257,7 @@ public virtual Rectangle ContentArea } /// - /// Represent the content offset if is true. + /// Represent the content offset if is true. /// public Point ContentOffset { get; set; } diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 1e3ad6e51c..3646a8a391 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -151,7 +151,7 @@ public virtual int ScrollLeftOffset get => _scrollLeftOffset; set { - if (!UseNegativeBoundsLocation) + if (!UseContentOffset) { _scrollLeftOffset = value; @@ -244,7 +244,7 @@ public virtual int ScrollTopOffset get => _scrollTopOffset; set { - if (!UseNegativeBoundsLocation) + if (!UseContentOffset) { _scrollTopOffset = value; @@ -268,7 +268,7 @@ public virtual int ScrollTopOffset /// /// Determines if negative bounds location is allowed for scrolling the . /// - public bool UseNegativeBoundsLocation { get; set; } + public bool UseContentOffset { get; set; } private void AddEventHandlersForScrollBars (ScrollBarView scrollBar) { @@ -589,7 +589,7 @@ private void SetBoundsByPosition (ScrollBarView scrollBar) { if (scrollBar.IsVertical) { - if (UseNegativeBoundsLocation) + if (UseContentOffset) { ContentOffset = new Point (Bounds.X, -scrollBar.Position); @@ -608,7 +608,7 @@ private void SetBoundsByPosition (ScrollBarView scrollBar) } else { - if (UseNegativeBoundsLocation) + if (UseContentOffset) { ContentOffset = new Point (-scrollBar.Position, Bounds.Y); diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index e24e85d411..968441cc79 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -1016,7 +1016,7 @@ private void SetWidthHeight () if (_showBothScrollIndicator) { - if (SuperView is { UseNegativeBoundsLocation: true }) + if (SuperView is { UseContentOffset: true }) { Rectangle bounds = GetSuperViewBounds (); @@ -1050,7 +1050,7 @@ private void SetWidthHeight () } else if (_showScrollIndicator) { - if (SuperView is { UseNegativeBoundsLocation: true }) + if (SuperView is { UseContentOffset: true }) { Rectangle bounds = GetSuperViewBounds (); @@ -1067,7 +1067,7 @@ private void SetWidthHeight () } else if (_otherScrollBarView?._showScrollIndicator == true) { - if (SuperView is { UseNegativeBoundsLocation: true }) + if (SuperView is { UseContentOffset: true }) { Rectangle bounds = GetSuperViewBounds (); diff --git a/UICatalog/Scenarios/ScrollBars.cs b/UICatalog/Scenarios/ScrollBars.cs index f9f902d539..15722f2f60 100644 --- a/UICatalog/Scenarios/ScrollBars.cs +++ b/UICatalog/Scenarios/ScrollBars.cs @@ -23,7 +23,7 @@ public override void Setup () { X = 0, Y = Pos.Center (), Width = 12, Height = 6, Text = text, - UseNegativeBoundsLocation = true + UseContentOffset = true }; viewOnMargin.Margin.ScrollBarType = ScrollBarType.Both; SetViewProperties (viewOnMargin); @@ -35,7 +35,7 @@ public override void Setup () { X = Pos.AnchorEnd () - 15, Y = Pos.Center (), Width = 15, Height = 8, Text = text, - UseNegativeBoundsLocation = true, + UseContentOffset = true, ScrollBarType = ScrollBarType.Both }; viewOnContentArea.Margin.Thickness = new Thickness (1); @@ -50,7 +50,7 @@ public override void Setup () { X = Pos.Left (viewOnContentArea) - 30, Y = Pos.Center (), Width = 15, Height = 8, Text = text, - UseNegativeBoundsLocation = true + UseContentOffset = true }; viewOnPadding.Padding.ScrollBarType = ScrollBarType.Both; viewOnPadding.Margin.Thickness = new Thickness (1); @@ -66,7 +66,7 @@ public override void Setup () { X = Pos.Left (viewOnPadding) - 30, Y = Pos.Center (), Width = 13, Height = 8, Text = text, - UseNegativeBoundsLocation = true, + UseContentOffset = true, BorderStyle = LineStyle.None }; viewOnBorder.Border.ScrollBarType = ScrollBarType.Both; diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index 3c609038bd..8598fa07b3 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -1133,7 +1133,7 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Padding_Thickne { X = Pos.Center (), Y = Pos.Center (), Width = 9, Height = 6, Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", CanFocus = true, - UseNegativeBoundsLocation = true + UseContentOffset = true }; view.Padding.ScrollBarType = ScrollBarType.Both; view.TextFormatter.WordWrap = false; @@ -1246,7 +1246,7 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Padding_Thickne { X = Pos.Center (), Y = Pos.Center (), Width = 9, Height = 6, Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", CanFocus = true, - UseNegativeBoundsLocation = true + UseContentOffset = true }; view.Padding.ScrollBarType = ScrollBarType.Both; view.TextFormatter.WordWrap = false; @@ -1370,7 +1370,7 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Parent_Inside_A X = Pos.Center (), Y = Pos.Center (), Width = 9, Height = 6, Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", CanFocus = true, ScrollBarType = ScrollBarType.Both, - UseNegativeBoundsLocation = true + UseContentOffset = true }; view.TextFormatter.WordWrap = false; view.TextFormatter.MultiLine = true; From 9f5b4999bac85b7190d1f13e0df915e021c535d0 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 24 Feb 2024 22:43:24 +0000 Subject: [PATCH 052/130] Rename to GetVisibleContentArea as method. --- Terminal.Gui/View/Adornment/Adornment.cs | 13 +++--- Terminal.Gui/View/Layout/ViewLayout.cs | 50 +++++++++++----------- Terminal.Gui/View/ViewDrawing.cs | 2 +- Terminal.Gui/View/ViewScrollBar.cs | 18 ++++---- UnitTests/View/Adornment/AdornmentTests.cs | 16 +++---- UnitTests/Views/ScrollBarViewTests.cs | 24 +++++------ 6 files changed, 63 insertions(+), 60 deletions(-) diff --git a/Terminal.Gui/View/Adornment/Adornment.cs b/Terminal.Gui/View/Adornment/Adornment.cs index 0fe7140b1f..b2f4ec99fc 100644 --- a/Terminal.Gui/View/Adornment/Adornment.cs +++ b/Terminal.Gui/View/Adornment/Adornment.cs @@ -37,11 +37,6 @@ public override Rectangle Bounds set => throw new InvalidOperationException ("It makes no sense to set Bounds of a Thickness."); } - /// - /// Gets the rectangle that describes the inner area of the Adornment. The Location is always (0,0). - /// - public override Rectangle ContentArea => Thickness?.GetInside (new Rectangle (Point.Empty, Frame.Size)) ?? new Rectangle (Point.Empty, Frame.Size); - /// The Parent of this Adornment (the View this Adornment surrounds). /// /// Adornments are distinguished from typical View classes in that they are not sub-views, but have a parent/child @@ -117,6 +112,14 @@ public override Rectangle FrameToScreen () return ret; } + /// + /// Gets the rectangle that describes the inner area of the Adornment. The Location is always (0,0). + /// + public override Rectangle GetVisibleContentArea () + { + return Thickness?.GetInside (new Rectangle (Point.Empty, Frame.Size)) ?? new Rectangle (Point.Empty, Frame.Size); + } + /// Does nothing for Adornment /// public override bool OnDrawAdornments () { return false; } diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 012815807d..e818a1a570 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -231,31 +231,6 @@ public virtual Rectangle Bounds } } - /// - /// The content area represent the View-relative rectangle used for this view. The area inside the view where subviews - /// and content are presented. The Location is always (0,0). It will be mainly used for clipping a region. - /// - public virtual Rectangle ContentArea - { - get - { - if (Margin == null || Border == null || Padding == null) - { - return new Rectangle (default (Point), Frame.Size); - } - - int width = Math.Max ( - 0, - Frame.Size.Width - Margin.Thickness.Horizontal - Border.Thickness.Horizontal - Padding.Thickness.Horizontal); - - int height = Math.Max ( - 0, - Frame.Size.Height - Margin.Thickness.Vertical - Border.Thickness.Vertical - Padding.Thickness.Vertical); - - return new Rectangle (Point.Empty, new Size (width, height)); - } - } - /// /// Represent the content offset if is true. /// @@ -693,6 +668,31 @@ public Point GetBoundsOffset () ); } + /// + /// Get the visible content area represent the View-relative rectangle used for this view. The area inside the view + /// where subviews + /// and content are presented. The Location is always (0,0). It will be mainly used for clipping a region. + /// + public virtual Rectangle GetVisibleContentArea () + { + { + if (Margin == null || Border == null || Padding == null) + { + return new Rectangle (default (Point), Frame.Size); + } + + int width = Math.Max ( + 0, + Frame.Size.Width - Margin.Thickness.Horizontal - Border.Thickness.Horizontal - Padding.Thickness.Horizontal); + + int height = Math.Max ( + 0, + Frame.Size.Height - Margin.Thickness.Vertical - Border.Thickness.Vertical - Padding.Thickness.Vertical); + + return new Rectangle (Point.Empty, new Size (width, height)); + } + } + /// Fired after the View's method has completed. /// /// Subscribe to this event to perform tasks when the has been resized or the layout has diff --git a/Terminal.Gui/View/ViewDrawing.cs b/Terminal.Gui/View/ViewDrawing.cs index 2721a77096..303150e87d 100644 --- a/Terminal.Gui/View/ViewDrawing.cs +++ b/Terminal.Gui/View/ViewDrawing.cs @@ -129,7 +129,7 @@ public Rectangle ClipToBounds () } Rectangle previous = Driver.Clip; - Driver.Clip = Rectangle.Intersect (previous, BoundsToScreen (ContentArea)); + Driver.Clip = Rectangle.Intersect (previous, BoundsToScreen (GetVisibleContentArea ())); return previous; } diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 3646a8a391..4f4890fdd4 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -266,7 +266,7 @@ public virtual int ScrollTopOffset } /// - /// Determines if negative bounds location is allowed for scrolling the . + /// Determines if negative bounds location is allowed for scrolling the . /// public bool UseContentOffset { get; set; } @@ -380,14 +380,14 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) { if (scrollBar.IsVertical) { - scrollBar.Position += ContentArea.Height; + scrollBar.Position += GetVisibleContentArea().Height; return true; } if (scrollBar.OtherScrollBarView is { IsVertical: true }) { - scrollBar.OtherScrollBarView.Position += ContentArea.Height; + scrollBar.OtherScrollBarView.Position += GetVisibleContentArea().Height; return true; } @@ -401,14 +401,14 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) { if (scrollBar.IsVertical) { - scrollBar.Position -= ContentArea.Height; + scrollBar.Position -= GetVisibleContentArea().Height; return true; } if (scrollBar.OtherScrollBarView is { IsVertical: true }) { - scrollBar.OtherScrollBarView.Position -= ContentArea.Height; + scrollBar.OtherScrollBarView.Position -= GetVisibleContentArea().Height; return true; } @@ -517,14 +517,14 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) { if (!scrollBar.IsVertical) { - scrollBar.Position += ContentArea.Width; + scrollBar.Position += GetVisibleContentArea().Width; return true; } if (scrollBar.OtherScrollBarView is { IsVertical: false }) { - scrollBar.OtherScrollBarView.Position += ContentArea.Width; + scrollBar.OtherScrollBarView.Position += GetVisibleContentArea().Width; return true; } @@ -538,14 +538,14 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) { if (!scrollBar.IsVertical) { - scrollBar.Position -= ContentArea.Width; + scrollBar.Position -= GetVisibleContentArea().Width; return true; } if (scrollBar.OtherScrollBarView is { IsVertical: false }) { - scrollBar.OtherScrollBarView.Position -= ContentArea.Width; + scrollBar.OtherScrollBarView.Position -= GetVisibleContentArea ().Width; return true; } diff --git a/UnitTests/View/Adornment/AdornmentTests.cs b/UnitTests/View/Adornment/AdornmentTests.cs index 0dbd051cb3..c60b4a7a62 100644 --- a/UnitTests/View/Adornment/AdornmentTests.cs +++ b/UnitTests/View/Adornment/AdornmentTests.cs @@ -114,10 +114,10 @@ public void Draw_Centered_View_With_Thickness_One_On_All_Adornments () Assert.Equal ("{X=1,Y=1,Width=6,Height=5}", parent.Border.Bounds.ToString ()); Assert.Equal ("{X=1,Y=1,Width=4,Height=3}", parent.Padding.Bounds.ToString ()); Assert.Equal ("{X=0,Y=0,Width=4,Height=3}", parent.Bounds.ToString ()); - Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Margin.ContentArea.ToString ()); - Assert.Equal ("{X=1,Y=1,Width=6,Height=5}", parent.Border.ContentArea.ToString ()); - Assert.Equal ("{X=1,Y=1,Width=4,Height=3}", parent.Padding.ContentArea.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=4,Height=3}", parent.ContentArea.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Margin.GetVisibleContentArea ().ToString ()); + Assert.Equal ("{X=1,Y=1,Width=6,Height=5}", parent.Border.GetVisibleContentArea ().ToString ()); + Assert.Equal ("{X=1,Y=1,Width=4,Height=3}", parent.Padding.GetVisibleContentArea ().ToString ()); + Assert.Equal ("{X=0,Y=0,Width=4,Height=3}", parent.GetVisibleContentArea ().ToString ()); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -201,10 +201,10 @@ public void Draw_Centered_View_With_Thickness_One_On_All_Adornments_Inside_Anoth Assert.Equal ("{X=1,Y=1,Width=6,Height=5}", parent.Border.Bounds.ToString ()); Assert.Equal ("{X=1,Y=1,Width=4,Height=3}", parent.Padding.Bounds.ToString ()); Assert.Equal ("{X=0,Y=0,Width=4,Height=3}", parent.Bounds.ToString ()); - Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Margin.ContentArea.ToString ()); - Assert.Equal ("{X=1,Y=1,Width=6,Height=5}", parent.Border.ContentArea.ToString ()); - Assert.Equal ("{X=1,Y=1,Width=4,Height=3}", parent.Padding.ContentArea.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=4,Height=3}", parent.ContentArea.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Margin.GetVisibleContentArea ().ToString ()); + Assert.Equal ("{X=1,Y=1,Width=6,Height=5}", parent.Border.GetVisibleContentArea ().ToString ()); + Assert.Equal ("{X=1,Y=1,Width=4,Height=3}", parent.Padding.GetVisibleContentArea ().ToString ()); + Assert.Equal ("{X=0,Y=0,Width=4,Height=3}", parent.GetVisibleContentArea ().ToString ()); TestHelpers.AssertDriverContentsWithFrameAre ( @" diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index 8598fa07b3..8e4bf878fc 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -1166,16 +1166,16 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Padding_Thickne Assert.Equal (12, view.ScrollColsSize); Assert.Equal (7, view.ScrollRowsSize); Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Bounds.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=3,Y=2,Width=9,Height=6}", view.Frame.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.Bounds.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.Frame.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Bounds.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Frame.ToString ()); Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Padding.Bounds.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Padding.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Padding.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.Frame.ToString ()); Assert.Equal ("(Left=0,Top=0,Right=1,Bottom=1)", view.Padding.Thickness.ToString ()); Assert.Equal ("{Width=8, Height=5}", view.TextFormatter.Size.ToString ()); @@ -1283,16 +1283,16 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Padding_Thickne Assert.Equal (12, view.ScrollColsSize); Assert.Equal (7, view.ScrollRowsSize); Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Bounds.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=2,Y=1,Width=9,Height=6}", view.Frame.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.Bounds.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.Frame.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Bounds.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Frame.ToString ()); Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Padding.Bounds.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Padding.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Padding.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.Frame.ToString ()); Assert.Equal ("(Left=0,Top=0,Right=1,Bottom=1)", view.Padding.Thickness.ToString ()); Assert.Equal ("{Width=8, Height=5}", view.TextFormatter.Size.ToString ()); @@ -1401,16 +1401,16 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Parent_Inside_A Assert.Equal (12, view.ScrollColsSize); Assert.Equal (7, view.ScrollRowsSize); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Bounds.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=2,Y=1,Width=9,Height=6}", view.Frame.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.Bounds.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.Frame.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Bounds.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Frame.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.Bounds.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.Frame.ToString ()); Assert.Equal ("(Left=0,Top=0,Right=0,Bottom=0)", view.Padding.Thickness.ToString ()); Assert.Equal ("{Width=9, Height=6}", view.TextFormatter.Size.ToString ()); From c80964c735a9de7cca395b123dae31be94da98de Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 25 Feb 2024 01:16:08 +0000 Subject: [PATCH 053/130] Rename Bounds to ContentArea. --- Terminal.Gui/Application.cs | 4 +- .../Text/Autocomplete/AppendAutocomplete.cs | 2 +- .../Text/Autocomplete/PopupAutocomplete.cs | 38 +- Terminal.Gui/Text/TextFormatter.cs | 33 +- Terminal.Gui/View/Adornment/Adornment.cs | 4 +- Terminal.Gui/View/Layout/ViewLayout.cs | 51 +- Terminal.Gui/View/View.cs | 9 +- Terminal.Gui/View/ViewDrawing.cs | 45 +- Terminal.Gui/View/ViewScrollBar.cs | 26 +- Terminal.Gui/View/ViewText.cs | 62 +- Terminal.Gui/Views/ColorPicker.cs | 6 +- Terminal.Gui/Views/ComboBox.cs | 30 +- Terminal.Gui/Views/Dialog.cs | 8 +- Terminal.Gui/Views/FileDialog.cs | 30 +- Terminal.Gui/Views/GraphView/Annotations.cs | 14 +- Terminal.Gui/Views/GraphView/Axis.cs | 30 +- Terminal.Gui/Views/GraphView/GraphView.cs | 16 +- Terminal.Gui/Views/GraphView/Series.cs | 2 +- Terminal.Gui/Views/HexView.cs | 6 +- Terminal.Gui/Views/Line.cs | 2 +- Terminal.Gui/Views/LineView.cs | 2 +- Terminal.Gui/Views/ListView.cs | 29 +- Terminal.Gui/Views/Menu/Menu.cs | 13 +- Terminal.Gui/Views/MessageBox.cs | 10 +- Terminal.Gui/Views/ProgressBar.cs | 16 +- Terminal.Gui/Views/ScrollBarView.cs | 48 +- Terminal.Gui/Views/ScrollView.cs | 22 +- Terminal.Gui/Views/Slider.cs | 64 +- Terminal.Gui/Views/TabView.cs | 14 +- .../Views/TableView/ListTableSource.cs | 8 +- Terminal.Gui/Views/TableView/TableView.cs | 52 +- Terminal.Gui/Views/TextField.cs | 15 +- Terminal.Gui/Views/TextValidateField.cs | 8 +- Terminal.Gui/Views/TextView.cs | 117 ++-- Terminal.Gui/Views/TileView.cs | 50 +- Terminal.Gui/Views/Toplevel.cs | 10 +- Terminal.Gui/Views/TreeView/TreeView.cs | 29 +- UICatalog/Scenarios/ASCIICustomButton.cs | 4 +- UICatalog/Scenarios/Animation.cs | 6 +- .../Scenarios/BackgroundWorkerCollection.cs | 10 +- UICatalog/Scenarios/CharacterMap.cs | 55 +- UICatalog/Scenarios/ComputedLayout.cs | 68 +- UICatalog/Scenarios/Editor.cs | 4 +- UICatalog/Scenarios/GraphViewExample.cs | 4 +- UICatalog/Scenarios/ProgressBarStyles.cs | 130 ++-- UICatalog/Scenarios/Scrolling.cs | 28 +- UICatalog/Scenarios/Snake.cs | 2 +- UICatalog/Scenarios/ViewExperiments.cs | 6 +- UICatalog/Scenarios/VkeyPacketSimulator.cs | 32 +- UnitTests/Drawing/LineCanvasTests.cs | 6 +- UnitTests/View/Adornment/AdornmentTests.cs | 72 +- UnitTests/View/DrawTests.cs | 148 ++-- UnitTests/View/Layout/AbsoluteLayoutTests.cs | 48 +- UnitTests/View/Layout/DimTests.cs | 95 +-- UnitTests/View/Layout/PosTests.cs | 8 +- .../View/Layout/SetRelativeLayoutTests.cs | 16 +- UnitTests/View/SubviewTests.cs | 13 +- UnitTests/View/Text/AutoSizeFalseTests.cs | 6 +- UnitTests/View/Text/AutoSizeTrueTests.cs | 653 +++++++++--------- UnitTests/View/ViewTests.cs | 220 +++--- UnitTests/Views/ButtonTests.cs | 126 ++-- UnitTests/Views/ComboBoxTests.cs | 36 +- UnitTests/Views/GraphViewTests.cs | 46 +- UnitTests/Views/LabelTests.cs | 171 +++-- UnitTests/Views/ScrollBarViewTests.cs | 82 +-- UnitTests/Views/ScrollViewTests.cs | 10 +- UnitTests/Views/StatusBarTests.cs | 4 +- UnitTests/Views/TableViewTests.cs | 84 +-- UnitTests/Views/TextValidateFieldTests.cs | 2 +- UnitTests/Views/TextViewTests.cs | 40 +- UnitTests/Views/ToplevelTests.cs | 2 +- UnitTests/Views/TreeTableSourceTests.cs | 2 +- UnitTests/Views/TreeViewTests.cs | 188 ++--- UnitTests/Views/WindowTests.cs | 31 +- 74 files changed, 1703 insertions(+), 1680 deletions(-) diff --git a/Terminal.Gui/Application.cs b/Terminal.Gui/Application.cs index e151abb47b..04f297bcf6 100644 --- a/Terminal.Gui/Application.cs +++ b/Terminal.Gui/Application.cs @@ -1512,7 +1512,7 @@ public static void OnMouseEvent (MouseEventEventArgs a) }; } - if (OutsideRect (new Point (nme.X, nme.Y), MouseGrabView.Bounds) || (view is { } && view != MouseGrabView)) + if (OutsideRect (new Point (nme.X, nme.Y), MouseGrabView.ContentArea) || (view is { } && view != MouseGrabView)) { // The mouse has moved outside the bounds of the view that // grabbed the mouse, so we tell the view that last got @@ -1636,7 +1636,7 @@ bool AdornmentHandledMouseEvent (Adornment adornment) return; } - Rectangle bounds = view.BoundsToScreen (view.Bounds); + Rectangle bounds = view.BoundsToScreen (view.ContentArea); if (bounds.Contains (a.MouseEvent.X, a.MouseEvent.Y)) { diff --git a/Terminal.Gui/Text/Autocomplete/AppendAutocomplete.cs b/Terminal.Gui/Text/Autocomplete/AppendAutocomplete.cs index 887d09791f..e78646bc85 100644 --- a/Terminal.Gui/Text/Autocomplete/AppendAutocomplete.cs +++ b/Terminal.Gui/Text/Autocomplete/AppendAutocomplete.cs @@ -117,7 +117,7 @@ public override void RenderOverlay (Point renderAt) Suggestion suggestion = Suggestions.ElementAt (SelectedIdx); string fragment = suggestion.Replacement.Substring (suggestion.Remove); - int spaceAvailable = textField.Bounds.Width - textField.Text.GetColumns (); + int spaceAvailable = textField.ContentArea.Width - textField.Text.GetColumns (); int spaceRequired = fragment.EnumerateRunes ().Sum (c => c.GetColumns ()); if (spaceAvailable < spaceRequired) diff --git a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs index bfa9b8b144..3fbeab9e45 100644 --- a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs +++ b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs @@ -57,9 +57,9 @@ public override View HostControl /// public virtual int ScrollOffset { get; set; } - #nullable enable +#nullable enable private Point? LastPopupPos { get; set; } - #nullable restore +#nullable restore /// public override void EnsureSelectedIdxIsValid () @@ -271,13 +271,13 @@ public override void RenderOverlay (Point renderAt) if (PopupInsideContainer) { // don't overspill vertically - height = Math.Min (HostControl.Bounds.Height - renderAt.Y, MaxHeight); + height = Math.Min (HostControl.ContentArea.Height - renderAt.Y, MaxHeight); // There is no space below, lets see if can popup on top - if (height < Suggestions.Count && HostControl.Bounds.Height - renderAt.Y >= height) + if (height < Suggestions.Count && HostControl.ContentArea.Height - renderAt.Y >= height) { // Verifies that the upper limit available is greater than the lower limit - if (renderAt.Y > HostControl.Bounds.Height - renderAt.Y) + if (renderAt.Y > HostControl.ContentArea.Height - renderAt.Y) { renderAt.Y = Math.Max (renderAt.Y - Math.Min (Suggestions.Count + 1, MaxHeight + 1), 0); height = Math.Min (Math.Min (Suggestions.Count, MaxHeight), LastPopupPos.Value.Y - 1); @@ -287,13 +287,13 @@ public override void RenderOverlay (Point renderAt) else { // don't overspill vertically - height = Math.Min (Math.Min (top.Bounds.Height - HostControl.Frame.Bottom, MaxHeight), Suggestions.Count); + height = Math.Min (Math.Min (top.ContentArea.Height - HostControl.Frame.Bottom, MaxHeight), Suggestions.Count); // There is no space below, lets see if can popup on top if (height < Suggestions.Count && HostControl.Frame.Y - top.Frame.Y >= height) { // Verifies that the upper limit available is greater than the lower limit - if (HostControl.Frame.Y > top.Bounds.Height - HostControl.Frame.Y) + if (HostControl.Frame.Y > top.ContentArea.Height - HostControl.Frame.Y) { renderAt.Y = Math.Max (HostControl.Frame.Y - Math.Min (Suggestions.Count, MaxHeight), 0); height = Math.Min (Math.Min (Suggestions.Count, MaxHeight), HostControl.Frame.Y); @@ -323,34 +323,34 @@ public override void RenderOverlay (Point renderAt) if (PopupInsideContainer) { // don't overspill horizontally, let's see if can be displayed on the left - if (width > HostControl.Bounds.Width - renderAt.X) + if (width > HostControl.ContentArea.Width - renderAt.X) { // Verifies that the left limit available is greater than the right limit - if (renderAt.X > HostControl.Bounds.Width - renderAt.X) + if (renderAt.X > HostControl.ContentArea.Width - renderAt.X) { renderAt.X -= Math.Min (width, LastPopupPos.Value.X); width = Math.Min (width, LastPopupPos.Value.X); } else { - width = Math.Min (width, HostControl.Bounds.Width - renderAt.X); + width = Math.Min (width, HostControl.ContentArea.Width - renderAt.X); } } } else { // don't overspill horizontally, let's see if can be displayed on the left - if (width > top.Bounds.Width - (renderAt.X + HostControl.Frame.X)) + if (width > top.ContentArea.Width - (renderAt.X + HostControl.Frame.X)) { // Verifies that the left limit available is greater than the right limit - if (renderAt.X + HostControl.Frame.X > top.Bounds.Width - (renderAt.X + HostControl.Frame.X)) + if (renderAt.X + HostControl.Frame.X > top.ContentArea.Width - (renderAt.X + HostControl.Frame.X)) { renderAt.X -= Math.Min (width, LastPopupPos.Value.X); width = Math.Min (width, LastPopupPos.Value.X); } else { - width = Math.Min (width, top.Bounds.Width - renderAt.X); + width = Math.Min (width, top.ContentArea.Width - renderAt.X); } } } @@ -358,16 +358,16 @@ public override void RenderOverlay (Point renderAt) if (PopupInsideContainer) { popup.Frame = new Rectangle ( - new Point (HostControl.Frame.X + renderAt.X, HostControl.Frame.Y + renderAt.Y), - new Size (width, height) - ); + new Point (HostControl.Frame.X + renderAt.X, HostControl.Frame.Y + renderAt.Y), + new Size (width, height) + ); } else { popup.Frame = new Rectangle ( - new Point (HostControl.Frame.X + renderAt.X, renderAt.Y), - new Size (width, height) - ); + new Point (HostControl.Frame.X + renderAt.X, renderAt.Y), + new Size (width, height) + ); } popup.Move (0, 0); diff --git a/Terminal.Gui/Text/TextFormatter.cs b/Terminal.Gui/Text/TextFormatter.cs index 3045cc2676..aab5bae3de 100644 --- a/Terminal.Gui/Text/TextFormatter.cs +++ b/Terminal.Gui/Text/TextFormatter.cs @@ -128,7 +128,10 @@ public TextAlignment Alignment /// Gets or sets whether the should be automatically changed to fit the . /// - /// Used by to resize the view's to fit . + /// + /// Used by to resize the view's to fit + /// . + /// /// /// AutoSize is ignored if and /// are used. @@ -345,20 +348,20 @@ public void Draw ( maxBounds = containerBounds == default (Rectangle) ? bounds : new Rectangle ( - Math.Max (containerBounds.X, bounds.X), - Math.Max (containerBounds.Y, bounds.Y), - Math.Max ( - Math.Min (containerBounds.Width, containerBounds.Right - bounds.Left), - 0 - ), - Math.Max ( - Math.Min ( - containerBounds.Height, - containerBounds.Bottom - bounds.Top - ), - 0 - ) - ); + Math.Max (containerBounds.X, bounds.X), + Math.Max (containerBounds.Y, bounds.Y), + Math.Max ( + Math.Min (containerBounds.Width, containerBounds.Right - bounds.Left), + 0 + ), + Math.Max ( + Math.Min ( + containerBounds.Height, + containerBounds.Bottom - bounds.Top + ), + 0 + ) + ); } if (maxBounds.Width == 0 || maxBounds.Height == 0) diff --git a/Terminal.Gui/View/Adornment/Adornment.cs b/Terminal.Gui/View/Adornment/Adornment.cs index b2f4ec99fc..703470d290 100644 --- a/Terminal.Gui/View/Adornment/Adornment.cs +++ b/Terminal.Gui/View/Adornment/Adornment.cs @@ -5,7 +5,7 @@ // QUESTION: How does a user navigate out of an Adornment to another Adornment, or back into the Parent's SubViews? /// -/// Adornments are a special form of that appear outside of the : +/// Adornments are a special form of that appear outside of the : /// , , and . They are defined using the /// class, which specifies the thickness of the sides of a rectangle. /// @@ -31,7 +31,7 @@ public Adornment () public Adornment (View parent) { Parent = parent; } /// Gets the rectangle that describes the inner area of the Adornment. The Location is always (0,0). - public override Rectangle Bounds + public override Rectangle ContentArea { get => Thickness?.GetInside (new Rectangle (Point.Empty, Frame.Size)) ?? new Rectangle (Point.Empty, Frame.Size); set => throw new InvalidOperationException ("It makes no sense to set Bounds of a Thickness."); diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index e818a1a570..bf0a6d58a0 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -47,7 +47,7 @@ public partial class View /// /// Gets or sets a flag that determines whether the View will be automatically resized to fit the - /// within . + /// within . /// /// The default is . Set to to turn on AutoSize. If /// then and will be used if can @@ -89,7 +89,8 @@ public virtual bool AutoSize /// /// The adornment (specified as a ) inside of the view that offsets the - /// from the . The Border provides the space for a visual border (drawn using + /// from the . The Border provides the space for a visual border (drawn + /// using /// line-drawing glyphs) and the Title. The Border expands inward; in other words if `Border.Thickness.Top == 2` the /// border and title will take up the first row and the second row will be filled with spaces. /// @@ -141,7 +142,7 @@ public LineStyle BorderStyle } /// - /// The bounds represent the View-relative rectangle used for this view; the area inside of the view where + /// The bounds represent the View-relative rectangle used for this view; the area inside the view where /// subviews and content are presented. /// /// The rectangle describing the location and size of the area where the views' subviews and content are drawn. @@ -160,12 +161,16 @@ public LineStyle BorderStyle /// and methods to be called. /// /// - /// Because coordinates are relative to the upper-left corner of the , the - /// coordinates of the upper-left corner of the rectangle returned by this property are (0,0). Use this property to - /// obtain the size of the area of the view for tasks such as drawing the view's contents. + /// Because coordinates are relative to the upper-left corner of the , + /// the + /// coordinates of the upper-left corner of the rectangle returned by this property are (0,0) if + /// is false. + /// If is true can contains negative location given by the + /// which if it's negative will increment the respective width and height accordingly. + /// Use this property to obtain the size of the area of the view for tasks such as drawing the view's contents. /// /// - public virtual Rectangle Bounds + public virtual Rectangle ContentArea { get { @@ -239,10 +244,10 @@ public virtual Rectangle Bounds /// Gets or sets the absolute location and dimension of the view. /// /// The rectangle describing absolute location and dimension of the view, in coordinates relative to the - /// 's . + /// 's . /// /// - /// Frame is relative to the 's . + /// Frame is relative to the 's . /// /// Setting Frame will set , , , and to the /// values of the corresponding properties of the parameter. @@ -364,7 +369,7 @@ public LayoutStyle LayoutStyle /// /// The frame (specified as a ) that separates a View from other SubViews of the same - /// SuperView. The margin offsets the from the . + /// SuperView. The margin offsets the from the . /// /// /// @@ -380,7 +385,7 @@ public LayoutStyle LayoutStyle public Margin Margin { get; private set; } /// - /// The frame (specified as a ) inside of the view that offsets the + /// The frame (specified as a ) inside of the view that offsets the /// from the . /// /// @@ -511,7 +516,7 @@ public Pos Y /// public event EventHandler Initialized; - /// Converts a -relative region to a screen-relative region. + /// Converts a -relative region to a screen-relative region. public Rectangle BoundsToScreen (Rectangle region) { BoundsToScreen (region.X, region.Y, out int x, out int y, false); @@ -520,11 +525,11 @@ public Rectangle BoundsToScreen (Rectangle region) } /// - /// Converts a -relative coordinate to a screen-relative coordinate. The output is optionally + /// Converts a -relative coordinate to a screen-relative coordinate. The output is optionally /// clamped to the screen dimensions. /// - /// -relative column. - /// -relative row. + /// -relative column. + /// -relative row. /// Absolute column; screen-relative. /// Absolute row; screen-relative. /// @@ -734,7 +739,7 @@ public virtual void LayoutSubviews () LayoutAdornments (); - Rectangle oldBounds = Bounds; + Rectangle oldBounds = ContentArea; OnLayoutStarted (new LayoutEventArgs { OldBounds = oldBounds }); SetTextFormatterSize (); @@ -747,7 +752,7 @@ public virtual void LayoutSubviews () foreach (View v in ordered) { - LayoutSubview (v, new Rectangle (GetBoundsOffset (), Bounds.Size)); + LayoutSubview (v, new Rectangle (GetBoundsOffset (), ContentArea.Size)); } // If the 'to' is rooted to 'from' and the layoutstyle is Computed it's a special-case. @@ -766,7 +771,7 @@ public virtual void LayoutSubviews () } /// Converts a screen-relative coordinate to a bounds-relative coordinate. - /// The coordinate relative to this view's . + /// The coordinate relative to this view's . /// Screen-relative column. /// Screen-relative row. public Point ScreenToBounds (int x, int y) @@ -779,9 +784,9 @@ public Point ScreenToBounds (int x, int y) /// /// Converts a screen-relative coordinate to a Frame-relative coordinate. Frame-relative means relative to the - /// View's 's . + /// View's 's . /// - /// The coordinate relative to the 's . + /// The coordinate relative to the 's . /// Screen-relative column. /// Screen-relative row. public Point ScreenToFrame (int x, int y) @@ -978,8 +983,8 @@ internal void OnResizeNeeded () // TODO: Until then leave it `internal` and non-virtual // First try SuperView.Bounds, then Application.Top, then Driver.Bounds. // Finally, if none of those are valid, use int.MaxValue (for Unit tests). - Rectangle relativeBounds = SuperView is { IsInitialized: true } ? SuperView.Bounds : - Application.Top is { } && Application.Top.IsInitialized ? Application.Top.Bounds : + Rectangle relativeBounds = SuperView is { IsInitialized: true } ? SuperView.ContentArea : + Application.Top is { } && Application.Top.IsInitialized ? Application.Top.ContentArea : Application.Driver?.Bounds ?? new Rectangle (0, 0, int.MaxValue, int.MaxValue); SetRelativeLayout (relativeBounds); @@ -1515,7 +1520,7 @@ private bool ResizeBoundsToFit (Size size) if (boundsChanged) { - Bounds = new Rectangle (Bounds.X, Bounds.Y, canSizeW ? rW : Bounds.Width, canSizeH ? rH : Bounds.Height); + ContentArea = new Rectangle (ContentArea.X, ContentArea.Y, canSizeW ? rW : ContentArea.Width, canSizeH ? rH : ContentArea.Height); } return boundsChanged; diff --git a/Terminal.Gui/View/View.cs b/Terminal.Gui/View/View.cs index 04fea12247..18e098bded 100644 --- a/Terminal.Gui/View/View.cs +++ b/Terminal.Gui/View/View.cs @@ -51,8 +51,9 @@ namespace Terminal.Gui; /// /// To create a View using Absolute layout, call a constructor that takes a Rectangle parameter to specify the /// absolute position and size or simply set ). To create a View using Computed layout use -/// a constructor that does not take a Rectangle parameter and set the X, Y, Width and Height properties on the view to -/// non-absolute values. Both approaches use coordinates that are relative to the of the +/// a constructor that does not take a Rectangle parameter and set the X, Y, Width and Height properties on the +/// view to +/// non-absolute values. Both approaches use coordinates that are relative to the of the /// the View is added to. /// /// @@ -73,7 +74,8 @@ namespace Terminal.Gui; /// a View can be accessed with the property. /// /// -/// To flag a region of the View's to be redrawn call . +/// To flag a region of the View's to be redrawn call +/// . /// To flag the entire view for redraw call . /// /// @@ -309,6 +311,7 @@ public string Title string old = _title; _title = value; TitleTextFormatter.Text = _title; + TitleTextFormatter.Size = new Size ( TextFormatter.GetWidestLineLength (TitleTextFormatter.Text) - (TitleTextFormatter.Text?.Contains ((char)HotKeySpecifier.Value) == true diff --git a/Terminal.Gui/View/ViewDrawing.cs b/Terminal.Gui/View/ViewDrawing.cs index 303150e87d..bc288590b3 100644 --- a/Terminal.Gui/View/ViewDrawing.cs +++ b/Terminal.Gui/View/ViewDrawing.cs @@ -80,7 +80,7 @@ public void AddRune (int col, int row, Rune ch) Driver.AddRune (ch); } - /// Clears the with the normal background color. + /// Clears the with the normal background color. /// /// This clears the Bounds used by this view. /// @@ -88,7 +88,7 @@ public void Clear () { if (IsInitialized) { - Clear (BoundsToScreen (Bounds)); + Clear (BoundsToScreen (ContentArea)); } } @@ -110,14 +110,15 @@ public void Clear (Rectangle regionScreen) Driver.SetAttribute (prev); } - /// Expands the 's clip region to include . + /// Expands the 's clip region to include . /// /// The current screen-relative clip region, which can be then re-applied by setting /// . /// /// /// - /// If and do not intersect, the clip region will be set to + /// If and do not intersect, the clip region will be set + /// to /// . /// /// @@ -140,7 +141,7 @@ public Rectangle ClipToBounds () /// /// /// - /// Always use (view-relative) when calling , NOT + /// Always use (view-relative) when calling , NOT /// (superview-relative). /// /// @@ -170,12 +171,12 @@ public void Draw () } // Invoke DrawContentEvent - var dev = new DrawEventArgs (Bounds); + var dev = new DrawEventArgs (ContentArea); DrawContent?.Invoke (this, dev); if (!dev.Cancel) { - OnDrawContent (Bounds); + OnDrawContent (ContentArea); } if (Driver is { }) @@ -190,12 +191,12 @@ public void Draw () ClearNeedsDisplay (); // Invoke DrawContentCompleteEvent - dev = new DrawEventArgs (Bounds); + dev = new DrawEventArgs (ContentArea); DrawContentComplete?.Invoke (this, dev); if (!dev.Cancel) { - OnDrawContentComplete (Bounds); + OnDrawContentComplete (ContentArea); } } @@ -368,13 +369,13 @@ public virtual bool OnDrawAdornments () return false; } - DrawAdornments?.Invoke (this, new DrawEventArgs (Bounds)); + DrawAdornments?.Invoke (this, new DrawEventArgs (ContentArea)); // Each of these renders lines to either this View's LineCanvas // Those lines will be finally rendered in OnRenderLineCanvas - Margin?.OnDrawContent (Margin.Bounds); - Border?.OnDrawContent (Border.Bounds); - Padding?.OnDrawContent (Padding.Bounds); + Margin?.OnDrawContent (Margin.ContentArea); + Border?.OnDrawContent (Border.ContentArea); + Padding?.OnDrawContent (Padding.ContentArea); return true; } @@ -509,7 +510,7 @@ public virtual bool OnRenderLineCanvas () return true; } - /// Sets the area of this view needing to be redrawn to . + /// Sets the area of this view needing to be redrawn to . /// /// If the view has not been initialized ( is ), this method /// does nothing. @@ -518,7 +519,7 @@ public void SetNeedsDisplay () { if (IsInitialized) { - SetNeedsDisplay (Bounds); + SetNeedsDisplay (ContentArea); } } @@ -552,14 +553,14 @@ public void SetNeedsDisplay (Rectangle region) _superView?.SetSubViewNeedsDisplay (); - if (_needsDisplayRect.X < Bounds.X - || _needsDisplayRect.Y < Bounds.Y - || _needsDisplayRect.Width > Bounds.Width - || _needsDisplayRect.Height > Bounds.Height) + if (_needsDisplayRect.X < ContentArea.X + || _needsDisplayRect.Y < ContentArea.Y + || _needsDisplayRect.Width > ContentArea.Width + || _needsDisplayRect.Height > ContentArea.Height) { - Margin?.SetNeedsDisplay (Margin.Bounds); - Border?.SetNeedsDisplay (Border.Bounds); - Padding?.SetNeedsDisplay (Padding.Bounds); + Margin?.SetNeedsDisplay (Margin.ContentArea); + Border?.SetNeedsDisplay (Border.ContentArea); + Padding?.SetNeedsDisplay (Padding.ContentArea); if (Margin != null) { diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 4f4890fdd4..449a45c989 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -380,14 +380,14 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) { if (scrollBar.IsVertical) { - scrollBar.Position += GetVisibleContentArea().Height; + scrollBar.Position += GetVisibleContentArea ().Height; return true; } if (scrollBar.OtherScrollBarView is { IsVertical: true }) { - scrollBar.OtherScrollBarView.Position += GetVisibleContentArea().Height; + scrollBar.OtherScrollBarView.Position += GetVisibleContentArea ().Height; return true; } @@ -401,14 +401,14 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) { if (scrollBar.IsVertical) { - scrollBar.Position -= GetVisibleContentArea().Height; + scrollBar.Position -= GetVisibleContentArea ().Height; return true; } if (scrollBar.OtherScrollBarView is { IsVertical: true }) { - scrollBar.OtherScrollBarView.Position -= GetVisibleContentArea().Height; + scrollBar.OtherScrollBarView.Position -= GetVisibleContentArea ().Height; return true; } @@ -517,14 +517,14 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) { if (!scrollBar.IsVertical) { - scrollBar.Position += GetVisibleContentArea().Width; + scrollBar.Position += GetVisibleContentArea ().Width; return true; } if (scrollBar.OtherScrollBarView is { IsVertical: false }) { - scrollBar.OtherScrollBarView.Position += GetVisibleContentArea().Width; + scrollBar.OtherScrollBarView.Position += GetVisibleContentArea ().Width; return true; } @@ -538,7 +538,7 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) { if (!scrollBar.IsVertical) { - scrollBar.Position -= GetVisibleContentArea().Width; + scrollBar.Position -= GetVisibleContentArea ().Width; return true; } @@ -591,11 +591,11 @@ private void SetBoundsByPosition (ScrollBarView scrollBar) { if (UseContentOffset) { - ContentOffset = new Point (Bounds.X, -scrollBar.Position); + ContentOffset = new Point (ContentArea.X, -scrollBar.Position); - if (Bounds.Y != -scrollBar.Position) + if (ContentArea.Y != -scrollBar.Position) { - scrollBar.Position = Bounds.Y; + scrollBar.Position = ContentArea.Y; } } else @@ -610,11 +610,11 @@ private void SetBoundsByPosition (ScrollBarView scrollBar) { if (UseContentOffset) { - ContentOffset = new Point (-scrollBar.Position, Bounds.Y); + ContentOffset = new Point (-scrollBar.Position, ContentArea.Y); - if (Bounds.X != -scrollBar.Position) + if (ContentArea.X != -scrollBar.Position) { - scrollBar.Position = Bounds.X; + scrollBar.Position = ContentArea.X; } } else diff --git a/Terminal.Gui/View/ViewText.cs b/Terminal.Gui/View/ViewText.cs index 09c109586d..d6f9e1674a 100644 --- a/Terminal.Gui/View/ViewText.cs +++ b/Terminal.Gui/View/ViewText.cs @@ -30,10 +30,11 @@ public virtual bool PreserveTrailingSpaces /// and . /// /// - /// The text will word-wrap to additional lines if it does not fit horizontally. If 's height + /// The text will word-wrap to additional lines if it does not fit horizontally. If 's + /// height /// is 1, the text will be clipped. /// - /// If is true, the will be adjusted to fit the text. + /// If is true, the will be adjusted to fit the text. /// When the text changes, the is fired. /// public virtual string Text @@ -60,27 +61,12 @@ public virtual string Text } } - /// - /// Called when the has changed. Fires the event. - /// - /// - /// - public void OnTextChanged (string oldValue, string newValue) - { - TextChanged?.Invoke (this, new StateEventArgs (oldValue, newValue)); - } - - /// - /// Text changed event, raised when the text has changed. - /// - public event EventHandler> TextChanged; - /// /// Gets or sets how the View's is aligned horizontally when drawn. Changing this property will /// redisplay the . /// /// - /// If is true, the will be adjusted to fit the text. + /// If is true, the will be adjusted to fit the text. /// /// The text alignment. public virtual TextAlignment TextAlignment @@ -99,7 +85,7 @@ public virtual TextAlignment TextAlignment /// . /// /// - /// If is true, the will be adjusted to fit the text. + /// If is true, the will be adjusted to fit the text. /// /// The text alignment. public virtual TextDirection TextDirection @@ -120,7 +106,7 @@ public virtual TextDirection TextDirection /// redisplay the . /// /// - /// If is true, the will be adjusted to fit the text. + /// If is true, the will be adjusted to fit the text. /// /// The text alignment. public virtual VerticalTextAlignment VerticalTextAlignment @@ -134,7 +120,7 @@ public virtual VerticalTextAlignment VerticalTextAlignment } /// - /// Gets the Frame dimensions required to fit within using the text + /// Gets the Frame dimensions required to fit within using the text /// specified by the property and accounting for any /// characters. /// @@ -146,8 +132,8 @@ public Size GetAutoSize () if (IsInitialized) { - x = Bounds.X; - y = Bounds.Y; + x = ContentArea.X; + y = ContentArea.Y; } Rectangle rect = TextFormatter.CalcRect (x, y, TextFormatter.Text, TextFormatter.Direction); @@ -205,6 +191,18 @@ public int GetHotKeySpecifierLength (bool isWidth = true) : 0; } + /// + /// Called when the has changed. Fires the event. + /// + /// + /// + public void OnTextChanged (string oldValue, string newValue) { TextChanged?.Invoke (this, new StateEventArgs (oldValue, newValue)); } + + /// + /// Text changed event, raised when the text has changed. + /// + public event EventHandler> TextChanged; + /// Can be overridden if the has different format than the default. protected virtual void UpdateTextFormatterText () { @@ -225,7 +223,7 @@ internal Size GetSizeNeededForTextWithoutHotKey () } /// - /// Internal API. Sets .Size to the current size, adjusted for + /// Internal API. Sets .Size to the current size, adjusted for /// . /// /// @@ -244,14 +242,14 @@ internal void SetTextFormatterSize () if (string.IsNullOrEmpty (TextFormatter.Text)) { - TextFormatter.Size = Bounds.Size; + TextFormatter.Size = ContentArea.Size; return; } TextFormatter.Size = new Size ( - Bounds.Size.Width + GetHotKeySpecifierLength (), - Bounds.Size.Height + GetHotKeySpecifierLength (false) + ContentArea.Size.Width + GetHotKeySpecifierLength (), + ContentArea.Size.Height + GetHotKeySpecifierLength (false) ); } @@ -324,7 +322,7 @@ bool GetMinimumSizeOfText (out Size sizeRequired) return false; } - sizeRequired = Bounds.Size; + sizeRequired = ContentArea.Size; if (AutoSize || string.IsNullOrEmpty (TextFormatter.Text)) { @@ -338,9 +336,9 @@ bool GetMinimumSizeOfText (out Size sizeRequired) // TODO: v2 - This uses frame.Width; it should only use Bounds if (_frame.Width < colWidth - && (Width is null || (Bounds.Width >= 0 && Width is Dim.DimAbsolute && Width.Anchor (0) >= 0 && Width.Anchor (0) < colWidth))) + && (Width is null || (ContentArea.Width >= 0 && Width is Dim.DimAbsolute && Width.Anchor (0) >= 0 && Width.Anchor (0) < colWidth))) { - sizeRequired = new Size (colWidth, Bounds.Height); + sizeRequired = new Size (colWidth, ContentArea.Height); return true; } @@ -349,7 +347,7 @@ bool GetMinimumSizeOfText (out Size sizeRequired) default: if (_frame.Height < 1 && (Height is null || (Height is Dim.DimAbsolute && Height.Anchor (0) == 0))) { - sizeRequired = new Size (Bounds.Width, 1); + sizeRequired = new Size (ContentArea.Width, 1); return true; } @@ -392,7 +390,7 @@ private void UpdateTextDirection (TextDirection newDirection) } else if (AutoSize && directionChanged && IsAdded) { - ResizeBoundsToFit (Bounds.Size); + ResizeBoundsToFit (ContentArea.Size); } SetTextFormatterSize (); diff --git a/Terminal.Gui/Views/ColorPicker.cs b/Terminal.Gui/Views/ColorPicker.cs index d25b85bf97..6a76a27953 100644 --- a/Terminal.Gui/Views/ColorPicker.cs +++ b/Terminal.Gui/Views/ColorPicker.cs @@ -98,7 +98,7 @@ public override bool MouseEvent (MouseEvent me) SetFocus (); - if (me.X > Bounds.Width || me.Y > Bounds.Height) + if (me.X > ContentArea.Width || me.Y > ContentArea.Height) { return true; } @@ -164,9 +164,9 @@ public override void OnDrawContent (Rectangle contentArea) Driver.SetAttribute (HasFocus ? ColorScheme.Focus : GetNormalColor ()); var colorIndex = 0; - for (var y = 0; y < Bounds.Height / BoxHeight; y++) + for (var y = 0; y < ContentArea.Height / BoxHeight; y++) { - for (var x = 0; x < Bounds.Width / BoxWidth; x++) + for (var x = 0; x < ContentArea.Width / BoxWidth; x++) { int foregroundColorIndex = y == 0 ? colorIndex + _cols : colorIndex - _cols; Driver.SetAttribute (new Attribute ((ColorName)foregroundColorIndex, (ColorName)colorIndex)); diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 870d8a501a..12098c1b1c 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -194,7 +194,7 @@ public IListDataSource Source { SelectedItem = -1; _search.Text = string.Empty; - Search_Changed (this, new StateEventArgs (string.Empty, _search.Text)); + Search_Changed (this, new StateEventArgs (string.Empty, _search.Text)); SetNeedsDisplay (); } } @@ -252,8 +252,8 @@ public virtual bool Expand () /// public override bool MouseEvent (MouseEvent me) { - if (me.X == Bounds.Right - 1 - && me.Y == Bounds.Top + if (me.X == ContentArea.Right - 1 + && me.Y == ContentArea.Top && me.Flags == MouseFlags.Button1Pressed && _autoHide) { @@ -301,7 +301,7 @@ public override void OnDrawContent (Rectangle contentArea) } Driver.SetAttribute (ColorScheme.Focus); - Move (Bounds.Right - 1, 0); + Move (ContentArea.Right - 1, 0); Driver.AddRune (Glyphs.DownArrow); } @@ -408,15 +408,15 @@ private bool ActivateSelected () /// private int CalculatetHeight () { - if (!IsInitialized || Bounds.Height == 0) + if (!IsInitialized || ContentArea.Height == 0) { return 0; } return Math.Min ( - Math.Max (Bounds.Height - 1, _minimumHeight - 1), + Math.Max (ContentArea.Height - 1, _minimumHeight - 1), _searchset?.Count > 0 ? _searchset.Count : - IsShow ? Math.Max (Bounds.Height - 1, _minimumHeight - 1) : 0 + IsShow ? Math.Max (ContentArea.Height - 1, _minimumHeight - 1) : 0 ); } @@ -497,7 +497,7 @@ private void HideList () OnOpenSelectedItem (); } - Rectangle rect = _listview.BoundsToScreen (_listview.IsInitialized ? _listview.Bounds : Rectangle.Empty); + Rectangle rect = _listview.BoundsToScreen (_listview.IsInitialized ? _listview.ContentArea : Rectangle.Empty); Reset (true); _listview.Clear (rect); _listview.TabStop = false; @@ -614,18 +614,18 @@ private bool PageUp () private void ProcessLayout () { - if (Bounds.Height < _minimumHeight && (Height is null || Height is Dim.DimAbsolute)) + if (ContentArea.Height < _minimumHeight && (Height is null || Height is Dim.DimAbsolute)) { Height = _minimumHeight; } - if ((!_autoHide && Bounds.Width > 0 && _search.Frame.Width != Bounds.Width) - || (_autoHide && Bounds.Width > 0 && _search.Frame.Width != Bounds.Width - 1)) + if ((!_autoHide && ContentArea.Width > 0 && _search.Frame.Width != ContentArea.Width) + || (_autoHide && ContentArea.Width > 0 && _search.Frame.Width != ContentArea.Width - 1)) { - _search.Width = _listview.Width = _autoHide ? Bounds.Width - 1 : Bounds.Width; + _search.Width = _listview.Width = _autoHide ? ContentArea.Width - 1 : ContentArea.Width; _listview.Height = CalculatetHeight (); - _search.SetRelativeLayout (Bounds); - _listview.SetRelativeLayout (Bounds); + _search.SetRelativeLayout (ContentArea); + _listview.SetRelativeLayout (ContentArea); } } @@ -661,7 +661,7 @@ private void ResetSearchSet (bool noCopy = false) } // Tell TextField to handle Accept Command (Enter) - void Search_Accept (object sender, CancelEventArgs e) { e.Cancel = true; } + private void Search_Accept (object sender, CancelEventArgs e) { e.Cancel = true; } private void Search_Changed (object sender, StateEventArgs e) { diff --git a/Terminal.Gui/Views/Dialog.cs b/Terminal.Gui/Views/Dialog.cs index 7b821bf131..209936068b 100644 --- a/Terminal.Gui/Views/Dialog.cs +++ b/Terminal.Gui/Views/Dialog.cs @@ -165,7 +165,7 @@ private void LayoutButtons () { case ButtonAlignments.Center: // Center Buttons - shiftLeft = (Bounds.Width - buttonsWidth - _buttons.Count - 1) / 2 + 1; + shiftLeft = (ContentArea.Width - buttonsWidth - _buttons.Count - 1) / 2 + 1; for (int i = _buttons.Count - 1; i >= 0; i--) { @@ -178,7 +178,7 @@ private void LayoutButtons () } else { - button.X = Bounds.Width - shiftLeft; + button.X = ContentArea.Width - shiftLeft; } button.Y = Pos.AnchorEnd (1); @@ -190,7 +190,7 @@ private void LayoutButtons () // Justify Buttons // leftmost and rightmost buttons are hard against edges. The rest are evenly spaced. - var spacing = (int)Math.Ceiling ((double)(Bounds.Width - buttonsWidth) / (_buttons.Count - 1)); + var spacing = (int)Math.Ceiling ((double)(ContentArea.Width - buttonsWidth) / (_buttons.Count - 1)); for (int i = _buttons.Count - 1; i >= 0; i--) { @@ -206,7 +206,7 @@ private void LayoutButtons () if (i == 0) { // first (leftmost) button - int left = Bounds.Width; + int left = ContentArea.Width; button.X = Pos.AnchorEnd (left); } else diff --git a/Terminal.Gui/Views/FileDialog.cs b/Terminal.Gui/Views/FileDialog.cs index f36099d291..1f43932b1c 100644 --- a/Terminal.Gui/Views/FileDialog.cs +++ b/Terminal.Gui/Views/FileDialog.cs @@ -185,14 +185,14 @@ internal FileDialog (IFileSystem fileSystem) _btnToggleSplitterCollapse = new Button { Y = Pos.AnchorEnd (1), Text = GetToggleSplitterText (false) }; _btnToggleSplitterCollapse.Accept += (s, e) => - { - Tile tile = _splitContainer.Tiles.ElementAt (0); + { + Tile tile = _splitContainer.Tiles.ElementAt (0); - bool newState = !tile.ContentView.Visible; - tile.ContentView.Visible = newState; - _btnToggleSplitterCollapse.Text = GetToggleSplitterText (newState); - LayoutSubviews (); - }; + bool newState = !tile.ContentView.Visible; + tile.ContentView.Visible = newState; + _btnToggleSplitterCollapse.Text = GetToggleSplitterText (newState); + LayoutSubviews (); + }; _tbFind = new TextField { @@ -414,16 +414,16 @@ public override void OnDrawContent (Rectangle contentArea) if (!string.IsNullOrWhiteSpace (_feedback)) { int feedbackWidth = _feedback.EnumerateRunes ().Sum (c => c.GetColumns ()); - int feedbackPadLeft = (Bounds.Width - feedbackWidth) / 2 - 1; + int feedbackPadLeft = (ContentArea.Width - feedbackWidth) / 2 - 1; - feedbackPadLeft = Math.Min (Bounds.Width, feedbackPadLeft); + feedbackPadLeft = Math.Min (ContentArea.Width, feedbackPadLeft); feedbackPadLeft = Math.Max (0, feedbackPadLeft); - int feedbackPadRight = Bounds.Width - (feedbackPadLeft + feedbackWidth + 2); - feedbackPadRight = Math.Min (Bounds.Width, feedbackPadRight); + int feedbackPadRight = ContentArea.Width - (feedbackPadLeft + feedbackWidth + 2); + feedbackPadRight = Math.Min (ContentArea.Width, feedbackPadRight); feedbackPadRight = Math.Max (0, feedbackPadRight); - Move (0, Bounds.Height / 2); + Move (0, ContentArea.Height / 2); Driver.SetAttribute (new Attribute (Color.Red, ColorScheme.Normal.Background)); Driver.AddStr (new string (' ', feedbackPadLeft)); @@ -773,9 +773,9 @@ private int CalculateOkButtonPosX () return 0; } - return Bounds.Width - - _btnOk.Bounds.Width - - _btnCancel.Bounds.Width + return ContentArea.Width + - _btnOk.ContentArea.Width + - _btnCancel.ContentArea.Width - 1 // TODO: Fiddle factor, seems the Bounds are wrong for someone diff --git a/Terminal.Gui/Views/GraphView/Annotations.cs b/Terminal.Gui/Views/GraphView/Annotations.cs index 1a77a49496..2cbdc3e59b 100644 --- a/Terminal.Gui/Views/GraphView/Annotations.cs +++ b/Terminal.Gui/Views/GraphView/Annotations.cs @@ -18,7 +18,7 @@ public interface IAnnotation /// /// Called once after series have been rendered (or before if is true). Use - /// to draw and to avoid drawing outside of graph + /// to draw and to avoid drawing outside of graph /// /// void Render (GraphView graph); @@ -70,7 +70,7 @@ public void Render (GraphView graph) protected void DrawText (GraphView graph, int x, int y) { // the draw point is out of control bounds - if (!graph.Bounds.Contains (new Point (x, y))) + if (!graph.ContentArea.Contains (new Point (x, y))) { return; } @@ -83,7 +83,7 @@ protected void DrawText (GraphView graph, int x, int y) graph.Move (x, y); - int availableWidth = graph.Bounds.Width - x; + int availableWidth = graph.ContentArea.Width - x; if (availableWidth <= 0) { @@ -127,7 +127,7 @@ public LegendAnnotation (Rectangle legendBounds) /// Returns false i.e. Legends render after series public bool BeforeSeries => false; - /// Draws the Legend and all entries into the area within + /// Draws the Legend and all entries into the area within /// public void Render (GraphView graph) { @@ -165,13 +165,13 @@ public void Render (GraphView graph) // add the text Move (1, linesDrawn); - string str = TextFormatter.ClipOrPad (entry.Item2, Bounds.Width - 1); + string str = TextFormatter.ClipOrPad (entry.Item2, ContentArea.Width - 1); Application.Driver.AddStr (str); linesDrawn++; // Legend has run out of space - if (linesDrawn >= Bounds.Height) + if (linesDrawn >= ContentArea.Height) { break; } @@ -182,7 +182,7 @@ public void Render (GraphView graph) /// The symbol appearing on the graph that should appear in the legend /// /// Text to render on this line of the legend. Will be truncated if outside of Legend - /// + /// /// public void AddEntry (GraphCellToRender graphCellToRender, string text) { _entries.Add (Tuple.Create (graphCellToRender, text)); } } diff --git a/Terminal.Gui/Views/GraphView/Axis.cs b/Terminal.Gui/Views/GraphView/Axis.cs index 8d0389b371..3a7ae5cadd 100644 --- a/Terminal.Gui/Views/GraphView/Axis.cs +++ b/Terminal.Gui/Views/GraphView/Axis.cs @@ -113,7 +113,7 @@ public override void DrawAxisLabel (GraphView graph, int screenPosition, string string toRender = text; // this is how much space is left - int xSpaceAvailable = graph.Bounds.Width - drawAtX; + int xSpaceAvailable = graph.ContentArea.Width - drawAtX; // There is no space for the label at all! if (xSpaceAvailable <= 0) @@ -127,7 +127,7 @@ public override void DrawAxisLabel (GraphView graph, int screenPosition, string toRender = toRender.Substring (0, xSpaceAvailable); } - graph.Move (drawAtX, Math.Min (y + 1, graph.Bounds.Height - 1)); + graph.Move (drawAtX, Math.Min (y + 1, graph.ContentArea.Height - 1)); driver.AddStr (toRender); } } @@ -140,7 +140,7 @@ public override void DrawAxisLabels (GraphView graph) return; } - Rectangle bounds = graph.Bounds; + Rectangle bounds = graph.ContentArea; IEnumerable labels = GetLabels (graph, bounds); @@ -155,12 +155,12 @@ public override void DrawAxisLabels (GraphView graph) string toRender = Text; // if label is too long - if (toRender.Length > graph.Bounds.Width) + if (toRender.Length > graph.ContentArea.Width) { - toRender = toRender.Substring (0, graph.Bounds.Width); + toRender = toRender.Substring (0, graph.ContentArea.Width); } - graph.Move (graph.Bounds.Width / 2 - toRender.Length / 2, graph.Bounds.Height - 1); + graph.Move (graph.ContentArea.Width / 2 - toRender.Length / 2, graph.ContentArea.Height - 1); Application.Driver.AddStr (toRender); } } @@ -174,7 +174,7 @@ public override void DrawAxisLine (GraphView graph) return; } - Rectangle bounds = graph.Bounds; + Rectangle bounds = graph.ContentArea; graph.Move (0, 0); @@ -212,7 +212,7 @@ public int GetAxisYPosition (GraphView graph) // float the X axis so that it accurately represents the origin of the graph // but anchor it to top/bottom if the origin is offscreen - return Math.Min (Math.Max (0, origin.Y), graph.Bounds.Height - ((int)graph.MarginBottom + 1)); + return Math.Min (Math.Max (0, origin.Y), graph.ContentArea.Height - ((int)graph.MarginBottom + 1)); } /// Draws a horizontal axis line at the given , screen coordinates @@ -317,7 +317,7 @@ public override void DrawAxisLabels (GraphView graph) return; } - Rectangle bounds = graph.Bounds; + Rectangle bounds = graph.ContentArea; IEnumerable labels = GetLabels (graph, bounds); foreach (AxisIncrementToRender label in labels) @@ -331,13 +331,13 @@ public override void DrawAxisLabels (GraphView graph) string toRender = Text; // if label is too long - if (toRender.Length > graph.Bounds.Height) + if (toRender.Length > graph.ContentArea.Height) { - toRender = toRender.Substring (0, graph.Bounds.Height); + toRender = toRender.Substring (0, graph.ContentArea.Height); } // Draw it 1 letter at a time vertically down row 0 of the control - int startDrawingAtY = graph.Bounds.Height / 2 - toRender.Length / 2; + int startDrawingAtY = graph.ContentArea.Height / 2 - toRender.Length / 2; for (var i = 0; i < toRender.Length; i++) { @@ -356,7 +356,7 @@ public override void DrawAxisLine (GraphView graph) return; } - Rectangle bounds = graph.Bounds; + Rectangle bounds = graph.ContentArea; int x = GetAxisXPosition (graph); @@ -385,7 +385,7 @@ public int GetAxisXPosition (GraphView graph) // float the Y axis so that it accurately represents the origin of the graph // but anchor it to left/right if the origin is offscreen - return Math.Min (Math.Max ((int)graph.MarginLeft, origin.X), graph.Bounds.Width - 1); + return Math.Min (Math.Max ((int)graph.MarginLeft, origin.X), graph.ContentArea.Width - 1); } /// Draws a vertical axis line at the given , screen coordinates @@ -409,7 +409,7 @@ private int GetAxisYEnd (GraphView graph) return graph.GraphSpaceToScreen (new PointF (0, Minimum.Value)).Y; } - return graph.Bounds.Height; + return graph.ContentArea.Height; } private IEnumerable GetLabels (GraphView graph, Rectangle bounds) diff --git a/Terminal.Gui/Views/GraphView/GraphView.cs b/Terminal.Gui/Views/GraphView/GraphView.cs index 12c63a4eec..0abac319de 100644 --- a/Terminal.Gui/Views/GraphView/GraphView.cs +++ b/Terminal.Gui/Views/GraphView/GraphView.cs @@ -192,7 +192,7 @@ public Point GraphSpaceToScreen (PointF location) (int)((location.X - ScrollOffset.X) / CellSize.X) + (int)MarginLeft, // screen coordinates are top down while graph coordinates are bottom up - Bounds.Height - 1 - (int)MarginBottom - (int)((location.Y - ScrollOffset.Y) / CellSize.Y) + ContentArea.Height - 1 - (int)MarginBottom - (int)((location.Y - ScrollOffset.Y) / CellSize.Y) ); } @@ -209,10 +209,10 @@ public override void OnDrawContent (Rectangle contentArea) Move (0, 0); // clear all old content - for (var i = 0; i < Bounds.Height; i++) + for (var i = 0; i < ContentArea.Height; i++) { Move (0, i); - Driver.AddStr (new string (' ', Bounds.Width)); + Driver.AddStr (new string (' ', ContentArea.Width)); } // If there is no data do not display a graph @@ -222,8 +222,8 @@ public override void OnDrawContent (Rectangle contentArea) } // The drawable area of the graph (anything that isn't in the margins) - int graphScreenWidth = Bounds.Width - (int)MarginLeft; - int graphScreenHeight = Bounds.Height - (int)MarginBottom; + int graphScreenWidth = ContentArea.Width - (int)MarginLeft; + int graphScreenHeight = ContentArea.Height - (int)MarginBottom; // if the margins take up the full draw bounds don't render if (graphScreenWidth < 0 || graphScreenHeight < 0) @@ -287,10 +287,10 @@ public override bool OnEnter (View view) } /// Scrolls the graph down 1 page. - public void PageDown () { Scroll (0, -1 * CellSize.Y * Bounds.Height); } + public void PageDown () { Scroll (0, -1 * CellSize.Y * ContentArea.Height); } /// Scrolls the graph up 1 page. - public void PageUp () { Scroll (0, CellSize.Y * Bounds.Height); } + public void PageUp () { Scroll (0, CellSize.Y * ContentArea.Height); } /// /// Clears all settings configured on the graph and resets all properties to default values ( @@ -316,7 +316,7 @@ public RectangleF ScreenToGraphSpace (int col, int row) { return new RectangleF ( ScrollOffset.X + (col - MarginLeft) * CellSize.X, - ScrollOffset.Y + (Bounds.Height - (row + MarginBottom + 1)) * CellSize.Y, + ScrollOffset.Y + (ContentArea.Height - (row + MarginBottom + 1)) * CellSize.Y, CellSize.X, CellSize.Y ); diff --git a/Terminal.Gui/Views/GraphView/Series.cs b/Terminal.Gui/Views/GraphView/Series.cs index 673419b161..262125a4b9 100644 --- a/Terminal.Gui/Views/GraphView/Series.cs +++ b/Terminal.Gui/Views/GraphView/Series.cs @@ -192,7 +192,7 @@ public virtual void DrawSeries (GraphView graph, Rectangle drawBounds, Rectangle screenStart.X = graph.AxisY.GetAxisXPosition (graph); // dont draw bar off the right of the control - screenEnd.X = Math.Min (graph.Bounds.Width - 1, screenEnd.X); + screenEnd.X = Math.Min (graph.ContentArea.Width - 1, screenEnd.X); // if bar is off the screen if (screenStart.Y < 0 || screenStart.Y > drawBounds.Height - graph.MarginBottom) diff --git a/Terminal.Gui/Views/HexView.cs b/Terminal.Gui/Views/HexView.cs index 0ad25d89ef..4cd728daac 100644 --- a/Terminal.Gui/Views/HexView.cs +++ b/Terminal.Gui/Views/HexView.cs @@ -366,7 +366,7 @@ public override void OnDrawContent (Rectangle contentArea) { var lineRect = new Rectangle (0, line, frame.Width, 1); - if (!Bounds.Contains (lineRect)) + if (!ContentArea.Contains (lineRect)) { continue; } @@ -604,9 +604,9 @@ private void HexView_LayoutComplete (object sender, LayoutEventArgs e) // Small buffers will just show the position, with the bsize field value (4 bytes) bytesPerLine = bsize; - if (Bounds.Width - displayWidth > 17) + if (ContentArea.Width - displayWidth > 17) { - bytesPerLine = bsize * ((Bounds.Width - displayWidth) / 18); + bytesPerLine = bsize * ((ContentArea.Width - displayWidth) / 18); } } diff --git a/Terminal.Gui/Views/Line.cs b/Terminal.Gui/Views/Line.cs index 122e5cb19a..90c311e489 100644 --- a/Terminal.Gui/Views/Line.cs +++ b/Terminal.Gui/Views/Line.cs @@ -15,7 +15,7 @@ public Line () { } /// public override bool OnDrawAdornments () { - Rectangle screenBounds = BoundsToScreen (Bounds); + Rectangle screenBounds = BoundsToScreen (ContentArea); LineCanvas lc; lc = SuperView?.LineCanvas; diff --git a/Terminal.Gui/Views/LineView.cs b/Terminal.Gui/Views/LineView.cs index 2f43411139..80e9234a94 100644 --- a/Terminal.Gui/Views/LineView.cs +++ b/Terminal.Gui/Views/LineView.cs @@ -63,7 +63,7 @@ public override void OnDrawContent (Rectangle contentArea) int hLineWidth = Math.Max (1, Glyphs.HLine.GetColumns ()); - int dEnd = Orientation == Orientation.Horizontal ? Bounds.Width : Bounds.Height; + int dEnd = Orientation == Orientation.Horizontal ? ContentArea.Width : ContentArea.Height; for (var d = 0; d < dEnd; d += hLineWidth) { diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs index f60065d070..60ecac5fa5 100644 --- a/Terminal.Gui/Views/ListView.cs +++ b/Terminal.Gui/Views/ListView.cs @@ -369,9 +369,9 @@ public void EnsureSelectedItemVisible () { _top = Math.Max (_selected, 0); } - else if (Bounds.Height > 0 && _selected >= _top + Bounds.Height) + else if (ContentArea.Height > 0 && _selected >= _top + ContentArea.Height) { - _top = Math.Max (_selected - Bounds.Height + 1, 0); + _top = Math.Max (_selected - ContentArea.Height + 1, 0); } LayoutStarted -= ListView_LayoutStarted; @@ -450,7 +450,7 @@ public override bool MouseEvent (MouseEvent me) if (me.Y + _top >= _source.Count || me.Y + _top < 0 - || me.Y + _top > _top + Bounds.Height) + || me.Y + _top > _top + ContentArea.Height) { return true; } @@ -500,7 +500,7 @@ public virtual bool MoveDown () //can move by down by one. _selected++; - if (_selected >= _top + Bounds.Height) + if (_selected >= _top + ContentArea.Height) { _top++; } @@ -517,9 +517,9 @@ public virtual bool MoveDown () OnSelectedChanged (); SetNeedsDisplay (); } - else if (_selected >= _top + Bounds.Height) + else if (_selected >= _top + ContentArea.Height) { - _top = Math.Max (_source.Count - Bounds.Height, 0); + _top = Math.Max (_source.Count - ContentArea.Height, 0); SetNeedsDisplay (); } @@ -534,7 +534,7 @@ public virtual bool MoveEnd () { _selected = _source.Count - 1; - if (_top + _selected > Bounds.Height - 1) + if (_top + _selected > ContentArea.Height - 1) { _top = Math.Max (_selected, 0); } @@ -568,7 +568,7 @@ public virtual bool MoveHome () /// public virtual bool MovePageDown () { - int n = _selected + Bounds.Height; + int n = _selected + ContentArea.Height; if (n >= _source.Count) { @@ -579,7 +579,7 @@ public virtual bool MovePageDown () { _selected = n; - if (_source.Count >= Bounds.Height) + if (_source.Count >= ContentArea.Height) { _top = Math.Max (_selected, 0); } @@ -599,7 +599,7 @@ public virtual bool MovePageDown () /// public virtual bool MovePageUp () { - int n = _selected - Bounds.Height; + int n = _selected - ContentArea.Height; if (n < 0) { @@ -649,9 +649,9 @@ public virtual bool MoveUp () { _top = Math.Max (_selected, 0); } - else if (_selected > _top + Bounds.Height) + else if (_selected > _top + ContentArea.Height) { - _top = Math.Max (_selected - Bounds.Height + 1, 0); + _top = Math.Max (_selected - ContentArea.Height + 1, 0); } OnSelectedChanged (); @@ -674,7 +674,7 @@ public override void OnDrawContent (Rectangle contentArea) Attribute current = ColorScheme.Focus; Driver.SetAttribute (current); Move (0, 0); - Rectangle f = Bounds; + Rectangle f = ContentArea; int item = _top; bool focused = HasFocus; int col = _allowsMarking ? 2 : 0; @@ -761,6 +761,7 @@ public bool OnOpenSelectedItem () } OpenSelectedItem?.Invoke (this, new ListViewItemEventArgs (_selected, value)); + return true; } @@ -818,7 +819,7 @@ public override void PositionCursor () } else { - Move (Bounds.Width - 1, _selected - _top); + Move (ContentArea.Width - 1, _selected - _top); } } diff --git a/Terminal.Gui/Views/Menu/Menu.cs b/Terminal.Gui/Views/Menu/Menu.cs index 1fb1adcb35..1cca293272 100644 --- a/Terminal.Gui/Views/Menu/Menu.cs +++ b/Terminal.Gui/Views/Menu/Menu.cs @@ -610,6 +610,7 @@ private bool SelectOrRun () { _menuBarItemToActivate = -1; _menuItemToSelect = c; + //keyEvent.Scope = KeyBindingScope.HotKey; return base.OnInvokingKeyBindings (keyEvent); @@ -780,14 +781,14 @@ public override void OnDrawContent (Rectangle contentArea) OnDrawAdornments (); OnRenderLineCanvas (); - for (int i = Bounds.Y; i < _barItems.Children.Length; i++) + for (int i = ContentArea.Y; i < _barItems.Children.Length; i++) { if (i < 0) { continue; } - if (BoundsToScreen (Bounds).Y + i >= Driver.Rows) + if (BoundsToScreen (ContentArea).Y + i >= Driver.Rows) { break; } @@ -811,7 +812,7 @@ public override void OnDrawContent (Rectangle contentArea) Driver.SetAttribute (DetermineColorSchemeFor (item, i)); - for (int p = Bounds.X; p < Frame.Width - 2; p++) + for (int p = ContentArea.X; p < Frame.Width - 2; p++) { // This - 2 is for the border if (p < 0) @@ -819,7 +820,7 @@ public override void OnDrawContent (Rectangle contentArea) continue; } - if (BoundsToScreen (Bounds).X + p >= Driver.Cols) + if (BoundsToScreen (ContentArea).X + p >= Driver.Cols) { break; } @@ -906,7 +907,7 @@ public override void OnDrawContent (Rectangle contentArea) BoundsToScreen (new Rectangle (1, i, Frame.Width - 3, 1)), i == _currentChild ? ColorScheme.Focus : GetNormalColor (), i == _currentChild ? ColorScheme.HotFocus : ColorScheme.HotNormal, - SuperView?.BoundsToScreen (SuperView.Bounds) ?? default (Rectangle) + SuperView?.BoundsToScreen (SuperView.ContentArea) ?? default (Rectangle) ); } else @@ -949,7 +950,7 @@ private void Current_DrawContentComplete (object sender, DrawEventArgs e) { if (Visible) { - OnDrawContent (Bounds); + OnDrawContent (ContentArea); } } diff --git a/Terminal.Gui/Views/MessageBox.cs b/Terminal.Gui/Views/MessageBox.cs index 8eb8e82e37..97a0a56664 100644 --- a/Terminal.Gui/Views/MessageBox.cs +++ b/Terminal.Gui/Views/MessageBox.cs @@ -394,7 +394,7 @@ params string [] buttons } // TODO: replace with Dim.Fit when implemented - Rectangle maxBounds = d.SuperView?.Bounds ?? Application.Top.Bounds; + Rectangle maxBounds = d.SuperView?.ContentArea ?? Application.Top.ContentArea; if (wrapMessage) { @@ -452,10 +452,10 @@ params string [] buttons Button b = buttonList [n]; b.Accept += (s, e) => - { - Clicked = buttonId; - Application.RequestStop (); - }; + { + Clicked = buttonId; + Application.RequestStop (); + }; if (b.IsDefault) { diff --git a/Terminal.Gui/Views/ProgressBar.cs b/Terminal.Gui/Views/ProgressBar.cs index 189533ee60..c6606bdea1 100644 --- a/Terminal.Gui/Views/ProgressBar.cs +++ b/Terminal.Gui/Views/ProgressBar.cs @@ -151,7 +151,7 @@ public override void OnDrawContent (Rectangle contentArea) if (_isActivity) { - for (var i = 0; i < Bounds.Width; i++) + for (var i = 0; i < ContentArea.Width; i++) { if (Array.IndexOf (_activityPos, i) != -1) { @@ -165,15 +165,15 @@ public override void OnDrawContent (Rectangle contentArea) } else { - var mid = (int)(_fraction * Bounds.Width); + var mid = (int)(_fraction * ContentArea.Width); int i; - for (i = 0; (i < mid) & (i < Bounds.Width); i++) + for (i = 0; (i < mid) & (i < ContentArea.Width); i++) { Driver.AddRune (SegmentCharacter); } - for (; i < Bounds.Width; i++) + for (; i < ContentArea.Width; i++) { Driver.AddRune ((Rune)' '); } @@ -190,10 +190,10 @@ public override void OnDrawContent (Rectangle contentArea) } tf?.Draw ( - BoundsToScreen (Bounds), + BoundsToScreen (ContentArea), attr, ColorScheme.Normal, - SuperView?.BoundsToScreen (SuperView.Bounds) ?? default (Rectangle) + SuperView?.BoundsToScreen (SuperView.ContentArea) ?? default (Rectangle) ); } } @@ -244,13 +244,13 @@ public void Pulse () _delta = 1; } - else if (_activityPos [0] >= Bounds.Width) + else if (_activityPos [0] >= ContentArea.Width) { if (_bidirectionalMarquee) { for (var i = 0; i < _activityPos.Length; i++) { - _activityPos [i] = Bounds.Width + i - 2; + _activityPos [i] = ContentArea.Width + i - 2; } _delta = -1; diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index 968441cc79..2dcfbbdb16 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -213,7 +213,7 @@ public override bool MouseEvent (MouseEvent mouseEvent) } int location = _vertical ? mouseEvent.Y : mouseEvent.X; - int barsize = _vertical ? Bounds.Height : Bounds.Width; + int barsize = _vertical ? ContentArea.Height : ContentArea.Width; int posTopLeftTee = _vertical ? _posTopTee + 1 : _posLeftTee + 1; int posBottomRightTee = _vertical ? _posBottomTee + 1 : _posRightTee + 1; barsize -= 2; @@ -381,7 +381,7 @@ public override void OnDrawContent (Rectangle contentArea) return; } - if (Size == 0 || (_vertical && Bounds.Height == 0) || (!_vertical && Bounds.Width == 0)) + if (Size == 0 || (_vertical && ContentArea.Height == 0) || (!_vertical && ContentArea.Width == 0)) { return; } @@ -397,13 +397,13 @@ public override void OnDrawContent (Rectangle contentArea) if (_vertical) { - if (Bounds.Right < Bounds.Width - 1) + if (ContentArea.Right < ContentArea.Width - 1) { return; } - int col = Bounds.Width - 1; - int bh = Bounds.Height; + int col = ContentArea.Width - 1; + int bh = ContentArea.Height; Rune special; if (bh < 4) @@ -413,7 +413,7 @@ public override void OnDrawContent (Rectangle contentArea) Move (col, 0); - if (Bounds.Height == 1) + if (ContentArea.Height == 1) { Driver.AddRune (Glyphs.Diamond); } @@ -422,15 +422,15 @@ public override void OnDrawContent (Rectangle contentArea) Driver.AddRune (Glyphs.UpArrow); } - if (Bounds.Height == 3) + if (ContentArea.Height == 3) { Move (col, 1); Driver.AddRune (Glyphs.Diamond); } - if (Bounds.Height > 1) + if (ContentArea.Height > 1) { - Move (col, Bounds.Height - 1); + Move (col, ContentArea.Height - 1); Driver.AddRune (Glyphs.DownArrow); } } @@ -499,23 +499,23 @@ public override void OnDrawContent (Rectangle contentArea) if (!hasTopTee) { - Move (col, Bounds.Height - 2); + Move (col, ContentArea.Height - 2); Driver.AddRune (Glyphs.TopTee); } - Move (col, Bounds.Height - 1); + Move (col, ContentArea.Height - 1); Driver.AddRune (Glyphs.DownArrow); } } else { - if (Bounds.Bottom < Bounds.Height - 1) + if (ContentArea.Bottom < ContentArea.Height - 1) { return; } - int row = Bounds.Height - 1; - int bw = Bounds.Width; + int row = ContentArea.Height - 1; + int bw = ContentArea.Width; Rune special; if (bw < 4) @@ -590,7 +590,7 @@ public override void OnDrawContent (Rectangle contentArea) if (!hasLeftTee) { - Move (Bounds.Width - 2, row); + Move (ContentArea.Width - 2, row); Driver.AddRune (Glyphs.LeftTee); } @@ -687,7 +687,7 @@ private void AdjustContentInViewport (bool refresh = true) private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = false) { - int barsize = scrollBarView._vertical ? scrollBarView.Bounds.Height : scrollBarView.Bounds.Width; + int barsize = scrollBarView._vertical ? scrollBarView.ContentArea.Height : scrollBarView.ContentArea.Width; if (barsize == 0 || barsize >= scrollBarView.Size) { @@ -867,7 +867,9 @@ private Rectangle GetSuperViewBounds () return Rectangle.Empty; } - return new Rectangle (Point.Empty, new Size (SuperView.Bounds.Width + SuperView.ContentOffset.X, SuperView.Bounds.Height + SuperView.ContentOffset.Y)); + return new Rectangle ( + Point.Empty, + new Size (SuperView.ContentArea.Width + SuperView.ContentOffset.X, SuperView.ContentArea.Height + SuperView.ContentOffset.Y)); } private void ManageScrollBarThickness () @@ -1040,12 +1042,12 @@ private void SetWidthHeight () Width = _vertical ? 1 : SuperView is Adornment ? Dim.Fill () : Dim.Fill (1); Height = _vertical ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) : 1; - _otherScrollBarView.Width = _otherScrollBarView._vertical ? 1 : - SuperView is Adornment ? Dim.Fill () : Dim.Fill (1); + _otherScrollBarView.Width = _otherScrollBarView._vertical ? 1 : + SuperView is Adornment ? Dim.Fill () : Dim.Fill (1); - _otherScrollBarView.Height = _otherScrollBarView._vertical - ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) - : 1; + _otherScrollBarView.Height = _otherScrollBarView._vertical + ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) + : 1; } } else if (_showScrollIndicator) @@ -1078,7 +1080,7 @@ private void SetWidthHeight () } else { - _otherScrollBarView.Width = _otherScrollBarView._vertical ? 1 : Dim.Fill(); + _otherScrollBarView.Width = _otherScrollBarView._vertical ? 1 : Dim.Fill (); _otherScrollBarView.Height = _otherScrollBarView._vertical ? Dim.Fill () : 1; } } diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index 4e8c70cc99..bb9bcff2a9 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -79,10 +79,10 @@ public ScrollView () AddCommand (Command.ScrollDown, () => ScrollDown (1)); AddCommand (Command.ScrollLeft, () => ScrollLeft (1)); AddCommand (Command.ScrollRight, () => ScrollRight (1)); - AddCommand (Command.PageUp, () => ScrollUp (Bounds.Height)); - AddCommand (Command.PageDown, () => ScrollDown (Bounds.Height)); - AddCommand (Command.PageLeft, () => ScrollLeft (Bounds.Width)); - AddCommand (Command.PageRight, () => ScrollRight (Bounds.Width)); + AddCommand (Command.PageUp, () => ScrollUp (ContentArea.Height)); + AddCommand (Command.PageDown, () => ScrollDown (ContentArea.Height)); + AddCommand (Command.PageLeft, () => ScrollLeft (ContentArea.Width)); + AddCommand (Command.PageRight, () => ScrollRight (ContentArea.Width)); AddCommand (Command.TopHome, () => ScrollUp (_contentSize.Height)); AddCommand (Command.BottomEnd, () => ScrollDown (_contentSize.Height)); AddCommand (Command.LeftHome, () => ScrollLeft (_contentSize.Width)); @@ -603,7 +603,7 @@ private void ShowHideScrollBars () bool v = false, h = false; var p = false; - if (Bounds.Height == 0 || Bounds.Height > _contentSize.Height) + if (ContentArea.Height == 0 || ContentArea.Height > _contentSize.Height) { if (ShowVerticalScrollIndicator) { @@ -612,7 +612,7 @@ private void ShowHideScrollBars () v = false; } - else if (Bounds.Height > 0 && Bounds.Height == _contentSize.Height) + else if (ContentArea.Height > 0 && ContentArea.Height == _contentSize.Height) { p = true; } @@ -626,7 +626,7 @@ private void ShowHideScrollBars () v = true; } - if (Bounds.Width == 0 || Bounds.Width > _contentSize.Width) + if (ContentArea.Width == 0 || ContentArea.Width > _contentSize.Width) { if (ShowHorizontalScrollIndicator) { @@ -635,7 +635,7 @@ private void ShowHideScrollBars () h = false; } - else if (Bounds.Width > 0 && Bounds.Width == _contentSize.Width && p) + else if (ContentArea.Width > 0 && ContentArea.Width == _contentSize.Width && p) { if (ShowHorizontalScrollIndicator) { @@ -687,13 +687,13 @@ private void ShowHideScrollBars () if (v) { - _vertical.SetRelativeLayout (Bounds); + _vertical.SetRelativeLayout (ContentArea); _vertical.Draw (); } if (h) { - _horizontal.SetRelativeLayout (Bounds); + _horizontal.SetRelativeLayout (ContentArea); _horizontal.Draw (); } @@ -701,7 +701,7 @@ private void ShowHideScrollBars () if (v && h) { - _contentBottomRightCorner.SetRelativeLayout (Bounds); + _contentBottomRightCorner.SetRelativeLayout (ContentArea); _contentBottomRightCorner.Draw (); } } diff --git a/Terminal.Gui/Views/Slider.cs b/Terminal.Gui/Views/Slider.cs index 54d553ed77..b27c5e5d8e 100644 --- a/Terminal.Gui/Views/Slider.cs +++ b/Terminal.Gui/Views/Slider.cs @@ -669,11 +669,11 @@ internal void CalcSpacingConfig () // Calculate the size of the slider based on the size of the SuperView's Bounds. if (_config._sliderOrientation == Orientation.Horizontal) { - size = int.Min (SuperView.Bounds.Width, CalcBestLength ()); + size = int.Min (SuperView.ContentArea.Width, CalcBestLength ()); } else { - size = int.Min (SuperView.Bounds.Height, CalcBestLength ()); + size = int.Min (SuperView.ContentArea.Height, CalcBestLength ()); } } else @@ -689,11 +689,11 @@ internal void CalcSpacingConfig () // Fit Slider to the Bounds if (_config._sliderOrientation == Orientation.Horizontal) { - size = Bounds.Width; + size = ContentArea.Width; } else { - size = Bounds.Height; + size = ContentArea.Height; } } @@ -775,35 +775,35 @@ public void SetBoundsBestFit () if (_config._sliderOrientation == Orientation.Horizontal) { - Bounds = new Rectangle ( - Bounds.Location, - new Size ( - int.Min ( - SuperView.Bounds.Width - GetAdornmentsThickness ().Horizontal, - CalcBestLength () - ), - int.Min ( - SuperView.Bounds.Height - GetAdornmentsThickness ().Vertical, - CalcThickness () - ) - ) - ); + ContentArea = new Rectangle ( + ContentArea.Location, + new Size ( + int.Min ( + SuperView.ContentArea.Width - GetAdornmentsThickness ().Horizontal, + CalcBestLength () + ), + int.Min ( + SuperView.ContentArea.Height - GetAdornmentsThickness ().Vertical, + CalcThickness () + ) + ) + ); } else { - Bounds = new Rectangle ( - Bounds.Location, - new Size ( - int.Min ( - SuperView.Bounds.Width - GetAdornmentsThickness ().Horizontal, - CalcThickness () - ), - int.Min ( - SuperView.Bounds.Height - GetAdornmentsThickness ().Vertical, - CalcBestLength () - ) - ) - ); + ContentArea = new Rectangle ( + ContentArea.Location, + new Size ( + int.Min ( + SuperView.ContentArea.Width - GetAdornmentsThickness ().Horizontal, + CalcThickness () + ), + int.Min ( + SuperView.ContentArea.Height - GetAdornmentsThickness ().Vertical, + CalcBestLength () + ) + ) + ); } } @@ -986,7 +986,7 @@ public override void PositionCursor () if (TryGetPositionByOption (FocusedOption, out (int x, int y) position)) { - if (IsInitialized && Bounds.Contains (position.x, position.y)) + if (IsInitialized && ContentArea.Contains (position.x, position.y)) { Move (position.x, position.y); } @@ -1239,7 +1239,7 @@ private void DrawSlider () } } - int remaining = isVertical ? Bounds.Height - y : Bounds.Width - x; + int remaining = isVertical ? ContentArea.Height - y : ContentArea.Width - x; // Right Spacing if (_config._showEndSpacing) diff --git a/Terminal.Gui/Views/TabView.cs b/Terminal.Gui/Views/TabView.cs index a8874a1cc7..c230b78826 100644 --- a/Terminal.Gui/Views/TabView.cs +++ b/Terminal.Gui/Views/TabView.cs @@ -297,7 +297,7 @@ public void EnsureSelectedTabIsVisible () } // if current viewport does not include the selected tab - if (!CalculateViewport (Bounds).Any (r => Equals (SelectedTab, r.Tab))) + if (!CalculateViewport (ContentArea).Any (r => Equals (SelectedTab, r.Tab))) { // Set scroll offset so the first tab rendered is the TabScrollOffset = Math.Max (0, Tabs.IndexOf (SelectedTab)); @@ -659,7 +659,7 @@ public override bool MouseEvent (MouseEvent me) public override void OnDrawContent (Rectangle contentArea) { - _host._tabLocations = _host.CalculateViewport (Bounds).ToArray (); + _host._tabLocations = _host.CalculateViewport (ContentArea).ToArray (); // clear any old text Clear (); @@ -683,7 +683,7 @@ public override void OnDrawContentComplete (Rectangle contentArea) for (var i = 0; i < tabLocations.Length; i++) { View tab = tabLocations [i].Tab; - Rectangle vts = tab.BoundsToScreen (tab.Bounds); + Rectangle vts = tab.BoundsToScreen (tab.ContentArea); var lc = new LineCanvas (); int selectedOffset = _host.Style.ShowTopLine && tabLocations [i].IsSelected ? 0 : 1; @@ -1115,7 +1115,7 @@ public override void OnDrawContentComplete (Rectangle contentArea) int lastSelectedTab = !_host.Style.ShowTopLine && i == selectedTab ? 1 : _host.Style.TabsOnBottom ? 1 : 0; - Rectangle tabsBarVts = BoundsToScreen (Bounds); + Rectangle tabsBarVts = BoundsToScreen (ContentArea); int lineLength = tabsBarVts.Right - vts.Right; // Right horizontal line @@ -1238,7 +1238,7 @@ private void RenderTabLine () View selected = null; int topLine = _host.Style.ShowTopLine ? 1 : 0; - int width = Bounds.Width; + int width = ContentArea.Width; foreach (TabToRender toRender in tabLocations) { @@ -1314,7 +1314,7 @@ private void RenderTabLine () } tab.TextFormatter.Draw ( - tab.BoundsToScreen (tab.Bounds), + tab.BoundsToScreen (tab.ContentArea), prevAttr, ColorScheme.HotNormal ); @@ -1360,7 +1360,7 @@ private void RenderUnderline () // if there are more tabs to the right not visible if (ShouldDrawRightScrollIndicator ()) { - _rightScrollIndicator.X = Bounds.Width - 1; + _rightScrollIndicator.X = ContentArea.Width - 1; _rightScrollIndicator.Y = y; // indicate that diff --git a/Terminal.Gui/Views/TableView/ListTableSource.cs b/Terminal.Gui/Views/TableView/ListTableSource.cs index 8695155019..4fdbd3b663 100644 --- a/Terminal.Gui/Views/TableView/ListTableSource.cs +++ b/Terminal.Gui/Views/TableView/ListTableSource.cs @@ -109,12 +109,12 @@ private int CalculateColumns () if (Style.Orientation == Orientation.Vertical != Style.ScrollParallel) { - float f = (float)_tableView.Bounds.Height - _tableView.GetHeaderHeight (); + float f = (float)_tableView.ContentArea.Height - _tableView.GetHeaderHeight (); cols = (int)Math.Ceiling (Count / f); } else { - cols = (int)Math.Ceiling (((float)_tableView.Bounds.Width - 1) / colWidth) - 2; + cols = (int)Math.Ceiling (((float)_tableView.ContentArea.Width - 1) / colWidth) - 2; } return cols > 1 ? cols : 1; @@ -179,7 +179,7 @@ private DataTable CreateTable (int cols = 1) private void TableView_DrawContent (object sender, DrawEventArgs e) { - if (!_tableView.Bounds.Equals (_lastBounds) + if (!_tableView.ContentArea.Equals (_lastBounds) || _tableView.MaxCellWidth != _lastMaxCellWidth || _tableView.MinCellWidth != _lastMinCellWidth || Style != _lastStyle @@ -188,7 +188,7 @@ private void TableView_DrawContent (object sender, DrawEventArgs e) DataTable = CreateTable (CalculateColumns ()); } - _lastBounds = _tableView.Bounds; + _lastBounds = _tableView.ContentArea; _lastMinCellWidth = _tableView.MaxCellWidth; _lastMaxCellWidth = _tableView.MaxCellWidth; _lastStyle = Style; diff --git a/Terminal.Gui/Views/TableView/TableView.cs b/Terminal.Gui/Views/TableView/TableView.cs index 066e402ccc..567cf8f748 100644 --- a/Terminal.Gui/Views/TableView/TableView.cs +++ b/Terminal.Gui/Views/TableView/TableView.cs @@ -526,7 +526,7 @@ public ITableSource Table return null; } - IEnumerable viewPort = CalculateViewport (Bounds); + IEnumerable viewPort = CalculateViewport (ContentArea); int headerHeight = GetHeaderHeightIfAny (); @@ -545,7 +545,7 @@ public ITableSource Table } // the cell is way down below the scroll area and off the screen - if (tableRow > RowOffset + (Bounds.Height - headerHeight)) + if (tableRow > RowOffset + (ContentArea.Height - headerHeight)) { return null; } @@ -620,7 +620,7 @@ public void EnsureSelectedCellIsVisible () return; } - ColumnToRender [] columnsToRender = CalculateViewport (Bounds).ToArray (); + ColumnToRender [] columnsToRender = CalculateViewport (ContentArea).ToArray (); int headerHeight = GetHeaderHeightIfAny (); //if we have scrolled too far to the left @@ -638,7 +638,7 @@ public void EnsureSelectedCellIsVisible () while (SelectedColumn > columnsToRender.Max (r => r.Column)) { ColumnOffset++; - columnsToRender = CalculateViewport (Bounds).ToArray (); + columnsToRender = CalculateViewport (ContentArea).ToArray (); // if we are already scrolled to the last column then break // this will prevent any theoretical infinite loop @@ -655,9 +655,9 @@ public void EnsureSelectedCellIsVisible () } //if we have scrolled too far down - if (SelectedRow >= RowOffset + (Bounds.Height - headerHeight)) + if (SelectedRow >= RowOffset + (ContentArea.Height - headerHeight)) { - RowOffset = SelectedRow - (Bounds.Height - headerHeight) + 1; + RowOffset = SelectedRow - (ContentArea.Height - headerHeight) + 1; } //if we have scrolled too far up @@ -736,11 +736,11 @@ public void EnsureValidSelection () // ensure regions do not go over edge of table bounds region.Rectangle = Rectangle.FromLTRB ( - region.Rectangle.Left, - region.Rectangle.Top, - Math.Max (Math.Min (region.Rectangle.Right, Table.Columns), 0), - Math.Max (Math.Min (region.Rectangle.Bottom, Table.Rows), 0) - ); + region.Rectangle.Left, + region.Rectangle.Top, + Math.Max (Math.Min (region.Rectangle.Right, Table.Columns), 0), + Math.Max (Math.Min (region.Rectangle.Bottom, Table.Rows), 0) + ); MultiSelectedRegions.Push (region); } @@ -949,12 +949,12 @@ public override void OnDrawContent (Rectangle contentArea) _scrollLeftPoint = null; // What columns to render at what X offset in viewport - ColumnToRender [] columnsToRender = CalculateViewport (Bounds).ToArray (); + ColumnToRender [] columnsToRender = CalculateViewport (ContentArea).ToArray (); Driver.SetAttribute (GetNormalColor ()); //invalidate current row (prevents scrolling around leaving old characters in the frame - Driver.AddStr (new string (' ', Bounds.Width)); + Driver.AddStr (new string (' ', ContentArea.Width)); var line = 0; @@ -968,7 +968,7 @@ public override void OnDrawContent (Rectangle contentArea) */ if (Style.ShowHorizontalHeaderOverline) { - RenderHeaderOverline (line, Bounds.Width, columnsToRender); + RenderHeaderOverline (line, ContentArea.Width, columnsToRender); line++; } @@ -980,7 +980,7 @@ public override void OnDrawContent (Rectangle contentArea) if (Style.ShowHorizontalHeaderUnderline) { - RenderHeaderUnderline (line, Bounds.Width, columnsToRender); + RenderHeaderUnderline (line, ContentArea.Width, columnsToRender); line++; } } @@ -988,9 +988,9 @@ public override void OnDrawContent (Rectangle contentArea) int headerLinesConsumed = line; //render the cells - for (; line < Bounds.Height; line++) + for (; line < ContentArea.Height; line++) { - ClearLine (line, Bounds.Width); + ClearLine (line, ContentArea.Width); //work out what Row to render int rowToRender = RowOffset + (line - headerLinesConsumed); @@ -1006,7 +1006,7 @@ public override void OnDrawContent (Rectangle contentArea) { if (rowToRender == Table.Rows && Style.ShowHorizontalBottomline) { - RenderBottomLine (line, Bounds.Width, columnsToRender); + RenderBottomLine (line, ContentArea.Width, columnsToRender); } continue; @@ -1044,7 +1044,7 @@ public override bool OnProcessKeyDown (Key keyEvent) /// true to extend the current selection (if any) instead of replacing public void PageDown (bool extend) { - ChangeSelectionByOffset (0, Bounds.Height - GetHeaderHeightIfAny (), extend); + ChangeSelectionByOffset (0, ContentArea.Height - GetHeaderHeightIfAny (), extend); Update (); } @@ -1052,7 +1052,7 @@ public void PageDown (bool extend) /// true to extend the current selection (if any) instead of replacing public void PageUp (bool extend) { - ChangeSelectionByOffset (0, -(Bounds.Height - GetHeaderHeightIfAny ()), extend); + ChangeSelectionByOffset (0, -(ContentArea.Height - GetHeaderHeightIfAny ()), extend); Update (); } @@ -1116,7 +1116,7 @@ public override void PositionCursor () return null; } - IEnumerable viewPort = CalculateViewport (Bounds); + IEnumerable viewPort = CalculateViewport (ContentArea); int headerHeight = GetHeaderHeightIfAny (); @@ -1704,7 +1704,7 @@ private void RenderHeaderMidline (int row, ColumnToRender [] columnsToRender) // Renders something like: // │ArithmeticComparator│chi │Healthboard│Interpretation│Labnumber│ - ClearLine (row, Bounds.Width); + ClearLine (row, ContentArea.Width); //render start of line if (_style.ShowVerticalHeaderLines) @@ -1734,7 +1734,7 @@ private void RenderHeaderMidline (int row, ColumnToRender [] columnsToRender) //render end of line if (_style.ShowVerticalHeaderLines) { - AddRune (Bounds.Width - 1, row, Glyphs.VLine); + AddRune (ContentArea.Width - 1, row, Glyphs.VLine); } } @@ -1892,7 +1892,7 @@ private void RenderRow (int row, int rowToRender, ColumnToRender [] columnsToRen } Driver.SetAttribute (color); - Driver.AddStr (new string (' ', Bounds.Width)); + Driver.AddStr (new string (' ', ContentArea.Width)); // Render cells for each visible header for the current row for (var i = 0; i < columnsToRender.Length; i++) @@ -2001,7 +2001,7 @@ private void RenderRow (int row, int rowToRender, ColumnToRender [] columnsToRen //render start and end of line AddRune (0, row, Glyphs.VLine); - AddRune (Bounds.Width - 1, row, Glyphs.VLine); + AddRune (ContentArea.Width - 1, row, Glyphs.VLine); } } @@ -2020,7 +2020,7 @@ private void RenderSeparator (int col, int row, bool isHeader) private void SetScrollRowsColsSize () { - int scrollColsSize = Table?.Columns + Bounds.Width - 1 ?? 0; + int scrollColsSize = Table?.Columns + ContentArea.Width - 1 ?? 0; if (ScrollColsSize != scrollColsSize) { diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index a99dacd7df..0bd8db26b5 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -1,4 +1,3 @@ -using System.Data; using System.Globalization; using Terminal.Gui.Resources; @@ -343,7 +342,7 @@ public TextField () // OnAccept returns true if the event is canceled. // By Default pressing ENTER should be ignored (Invoke(Command.Accept) should return false). - AddCommand (Command.Accept, () => OnAccept() != true); + AddCommand (Command.Accept, () => OnAccept () != true); // Default keybindings for this view // We follow this as closely as possible: https://en.wikipedia.org/wiki/Table_of_keyboard_shortcuts @@ -1203,8 +1202,8 @@ public override void PositionCursor () int pos = _cursorPosition - ScrollOffset + Math.Min (Frame.X, 0); int offB = OffSetBackground (); - Rectangle containerFrame = SuperView?.BoundsToScreen (SuperView.Bounds) ?? default (Rectangle); - Rectangle thisFrame = BoundsToScreen (Bounds); + Rectangle containerFrame = SuperView?.BoundsToScreen (SuperView.ContentArea) ?? default (Rectangle); + Rectangle thisFrame = BoundsToScreen (ContentArea); if (pos > -1 && col >= pos @@ -1897,9 +1896,9 @@ private void RenderCaption () Move (0, 0); string render = Caption; - if (render.GetColumns () > Bounds.Width) + if (render.GetColumns () > ContentArea.Width) { - render = render [..Bounds.Width]; + render = render [..ContentArea.Width]; } Driver.AddStr (render); @@ -1960,9 +1959,9 @@ private void TextField_Initialized (object sender, EventArgs e) { _cursorPosition = Text.GetRuneCount (); - if (Bounds.Width > 0) + if (ContentArea.Width > 0) { - ScrollOffset = _cursorPosition > Bounds.Width + 1 ? _cursorPosition - Bounds.Width + 1 : 0; + ScrollOffset = _cursorPosition > ContentArea.Width + 1 ? _cursorPosition - ContentArea.Width + 1 : 0; } Autocomplete.HostControl = this; diff --git a/Terminal.Gui/Views/TextValidateField.cs b/Terminal.Gui/Views/TextValidateField.cs index ae99aba046..f6f673e31d 100644 --- a/Terminal.Gui/Views/TextValidateField.cs +++ b/Terminal.Gui/Views/TextValidateField.cs @@ -537,7 +537,7 @@ public override bool MouseEvent (MouseEvent mouseEvent) { if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed)) { - int c = _provider.Cursor (mouseEvent.X - GetMargins (Bounds.Width).left); + int c = _provider.Cursor (mouseEvent.X - GetMargins (ContentArea.Width).left); if (_provider.Fixed == false && TextAlignment == TextAlignment.Right && Text.Length > 0) { @@ -568,7 +568,7 @@ public override void OnDrawContent (Rectangle contentArea) Color bgcolor = !IsValid ? new Color (Color.BrightRed) : ColorScheme.Focus.Background; var textColor = new Attribute (ColorScheme.Focus.Foreground, bgcolor); - (int margin_left, int margin_right) = GetMargins (Bounds.Width); + (int margin_left, int margin_right) = GetMargins (ContentArea.Width); Move (0, 0); @@ -642,7 +642,7 @@ public override bool OnProcessKeyDown (Key a) /// public override void PositionCursor () { - (int left, _) = GetMargins (Bounds.Width); + (int left, _) = GetMargins (ContentArea.Width); // Fixed = true, is for inputs that have fixed width, like masked ones. // Fixed = false, is for normal input. @@ -660,7 +660,7 @@ public override void PositionCursor () Move (curPos, 0); } - if (curPos < 0 || curPos >= Bounds.Width) + if (curPos < 0 || curPos >= ContentArea.Width) { Application.Driver.SetCursorVisibility (CursorVisibility.Invisible); } diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index cf517748af..db23a622fa 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -2675,7 +2675,7 @@ public int LeftColumn public int Lines => _model.Count; /// Gets the maximum visible length line including additional last column to accommodate the cursor. - public int Maxlength => _model.GetMaxVisibleLine (_topRow, _topRow + Bounds.Height, TabWidth) + (ReadOnly ? 0 : 1); + public int Maxlength => _model.GetMaxVisibleLine (_topRow, _topRow + ContentArea.Height, TabWidth) + (ReadOnly ? 0 : 1); /// Gets or sets a value indicating whether this is a multiline text view. public bool Multiline @@ -2871,17 +2871,17 @@ public override string Text } set { - var old = Text; + string old = Text; ResetPosition (); _model.LoadString (value); if (_wordWrap) { _wrapManager = new WordWrapManager (_model); - _model = _wrapManager.WrapModel (Bounds.Width, out _, out _, out _, out _); + _model = _wrapManager.WrapModel (ContentArea.Width, out _, out _, out _, out _); } - OnTextChanged (old,Text); + OnTextChanged (old, Text); SetNeedsDisplay (); _historyText.Clear (Text); @@ -2935,7 +2935,6 @@ public bool WordWrap } } - /// Allows clearing the items updating the original text. public void ClearHistoryChanges () { _historyText?.Clear (Text); } @@ -3408,15 +3407,15 @@ public override bool MouseEvent (MouseEvent ev) if (_model.Count > 0 && _shiftSelecting && Selecting) { - if (CurrentRow - _topRow >= Bounds.Height - 1 && _model.Count > _topRow + CurrentRow) + if (CurrentRow - _topRow >= ContentArea.Height - 1 && _model.Count > _topRow + CurrentRow) { - ScrollTo (_topRow + Bounds.Height); + ScrollTo (_topRow + ContentArea.Height); } else if (_topRow > 0 && CurrentRow <= _topRow) { - ScrollTo (_topRow - Bounds.Height); + ScrollTo (_topRow - ContentArea.Height); } - else if (ev.Y >= Bounds.Height) + else if (ev.Y >= ContentArea.Height) { ScrollTo (_model.Count); } @@ -3425,15 +3424,15 @@ public override bool MouseEvent (MouseEvent ev) ScrollTo (0); } - if (CurrentColumn - _leftColumn >= Bounds.Width - 1 && line.Count > _leftColumn + CurrentColumn) + if (CurrentColumn - _leftColumn >= ContentArea.Width - 1 && line.Count > _leftColumn + CurrentColumn) { - ScrollTo (_leftColumn + Bounds.Width, false); + ScrollTo (_leftColumn + ContentArea.Width, false); } else if (_leftColumn > 0 && CurrentColumn <= _leftColumn) { - ScrollTo (_leftColumn - Bounds.Width, false); + ScrollTo (_leftColumn - ContentArea.Width, false); } - else if (ev.X >= Bounds.Width) + else if (ev.X >= ContentArea.Width) { ScrollTo (line.Count, false); } @@ -3602,8 +3601,8 @@ public override void OnDrawContent (Rectangle contentArea) SetNormalColor (); (int width, int height) offB = OffSetBackground (); - int right = Bounds.Width + offB.width ; - int bottom = Bounds.Height + offB.height; + int right = ContentArea.Width + offB.width; + int bottom = ContentArea.Height + offB.height; var row = 0; for (int idxRow = _topRow; idxRow < _model.Count; idxRow++) @@ -3877,7 +3876,7 @@ public override void PositionCursor () cols += TabWidth + 1; } - if (!TextModel.SetCol (ref col, Bounds.Width, cols)) + if (!TextModel.SetCol (ref col, ContentArea.Width, cols)) { col = CurrentColumn; @@ -3889,7 +3888,7 @@ public override void PositionCursor () int posX = CurrentColumn - _leftColumn; int posY = CurrentRow - _topRow; - if (posX > -1 && col >= posX && posX < Bounds.Width && _topRow <= CurrentRow && posY < Bounds.Height) + if (posX > -1 && col >= posX && posX < ContentArea.Width && _topRow <= CurrentRow && posY < ContentArea.Height) { ResetCursorVisibility (); Move (col, CurrentRow - _topRow); @@ -3962,7 +3961,7 @@ public void ScrollTo (int idx, bool isRow = true) else if (!_wordWrap) { int maxlength = - _model.GetMaxVisibleLine (_topRow, _topRow + Bounds.Height, TabWidth); + _model.GetMaxVisibleLine (_topRow, _topRow + ContentArea.Height, TabWidth); ScrollLeftOffset = _leftColumn = Math.Max (!_wordWrap && idx > maxlength - 1 ? maxlength - 1 : idx, 0); } @@ -4141,19 +4140,19 @@ private void Adjust () need = true; } else if (!_wordWrap - && (CurrentColumn - _leftColumn + 1 > Bounds.Width + offB.width || dSize.size + 1 >= Bounds.Width + offB.width)) + && (CurrentColumn - _leftColumn + 1 > ContentArea.Width + offB.width || dSize.size + 1 >= ContentArea.Width + offB.width)) { _leftColumn = TextModel.CalculateLeftColumn ( line, _leftColumn, CurrentColumn, - Bounds.Width + offB.width, + ContentArea.Width + offB.width, TabWidth ); need = true; } else if ((_wordWrap && _leftColumn > 0) - || (dSize.size < Bounds.Width + offB.width && tSize.size < Bounds.Width + offB.width)) + || (dSize.size < ContentArea.Width + offB.width && tSize.size < ContentArea.Width + offB.width)) { if (_leftColumn > 0) { @@ -4167,9 +4166,9 @@ private void Adjust () _topRow = CurrentRow; need = true; } - else if (CurrentRow - _topRow >= Bounds.Height + offB.height) + else if (CurrentRow - _topRow >= ContentArea.Height + offB.height) { - _topRow = Math.Min (Math.Max (CurrentRow - Bounds.Height + 1, 0), CurrentRow); + _topRow = Math.Min (Math.Max (CurrentRow - ContentArea.Height + 1, 0), CurrentRow); need = true; } else if (_topRow > 0 && CurrentRow < _topRow) @@ -4500,7 +4499,7 @@ private bool DeleteTextForwards () _wrapNeeded = true; } - DoSetNeedsDisplay (new Rectangle (0, CurrentRow - _topRow, Bounds.Width, CurrentRow - _topRow + 1)); + DoSetNeedsDisplay (new Rectangle (0, CurrentRow - _topRow, ContentArea.Width, CurrentRow - _topRow + 1)); } else { @@ -4521,11 +4520,11 @@ private bool DeleteTextForwards () DoSetNeedsDisplay ( new Rectangle ( - CurrentColumn - _leftColumn, - CurrentRow - _topRow, - Bounds.Width, - Math.Max (CurrentRow - _topRow + 1, 0) - ) + CurrentColumn - _leftColumn, + CurrentRow - _topRow, + ContentArea.Width, + Math.Max (CurrentRow - _topRow + 1, 0) + ) ); } @@ -4855,9 +4854,9 @@ private void InsertAllText (string text) HistoryText.LineStatus.Replaced ); - if (!_wordWrap && CurrentColumn - _leftColumn > Bounds.Width) + if (!_wordWrap && CurrentColumn - _leftColumn > ContentArea.Width) { - _leftColumn = Math.Max (CurrentColumn - Bounds.Width + 1, 0); + _leftColumn = Math.Max (CurrentColumn - ContentArea.Width + 1, 0); } if (_wordWrap) @@ -4963,7 +4962,7 @@ private bool InsertText (Key a, ColorScheme? colorScheme = null) Insert (new RuneCell { Rune = a.AsRune, ColorScheme = colorScheme }); CurrentColumn++; - if (CurrentColumn >= _leftColumn + Bounds.Width) + if (CurrentColumn >= _leftColumn + ContentArea.Width) { _leftColumn++; SetNeedsDisplay (); @@ -5081,7 +5080,7 @@ private void KillToEndOfLine () UpdateWrapModel (); - DoSetNeedsDisplay (new Rectangle (0, CurrentRow - _topRow, Bounds.Width, Bounds.Height)); + DoSetNeedsDisplay (new Rectangle (0, CurrentRow - _topRow, ContentArea.Width, ContentArea.Height)); _lastWasKill = setLastWasKill; DoNeededAction (); @@ -5186,7 +5185,7 @@ private void KillToStartOfLine () UpdateWrapModel (); - DoSetNeedsDisplay (new Rectangle (0, CurrentRow - _topRow, Bounds.Width, Bounds.Height)); + DoSetNeedsDisplay (new Rectangle (0, CurrentRow - _topRow, ContentArea.Width, ContentArea.Height)); _lastWasKill = setLastWasKill; DoNeededAction (); @@ -5256,7 +5255,7 @@ private void KillWordBackward () UpdateWrapModel (); - DoSetNeedsDisplay (new Rectangle (0, CurrentRow - _topRow, Bounds.Width, Bounds.Height)); + DoSetNeedsDisplay (new Rectangle (0, CurrentRow - _topRow, ContentArea.Width, ContentArea.Height)); DoNeededAction (); } @@ -5315,7 +5314,7 @@ private void KillWordForward () UpdateWrapModel (); - DoSetNeedsDisplay (new Rectangle (0, CurrentRow - _topRow, Bounds.Width, Bounds.Height)); + DoSetNeedsDisplay (new Rectangle (0, CurrentRow - _topRow, ContentArea.Width, ContentArea.Height)); DoNeededAction (); } @@ -5331,7 +5330,7 @@ private void Model_LinesLoaded (object sender, EventArgs e) if (!_multiline && !IsInitialized) { CurrentColumn = Text.GetRuneCount (); - _leftColumn = CurrentColumn > Bounds.Width + 1 ? CurrentColumn - Bounds.Width + 1 : 0; + _leftColumn = CurrentColumn > ContentArea.Width + 1 ? CurrentColumn - ContentArea.Width + 1 : 0; } } @@ -5365,7 +5364,7 @@ private void MoveDown () CurrentRow++; - if (CurrentRow >= _topRow + Bounds.Height) + if (CurrentRow >= _topRow + ContentArea.Height) { _topRow++; SetNeedsDisplay (); @@ -5374,7 +5373,7 @@ private void MoveDown () TrackColumn (); PositionCursor (); } - else if (CurrentRow > Bounds.Height) + else if (CurrentRow > ContentArea.Height) { Adjust (); } @@ -5429,7 +5428,7 @@ private bool MoveNextView () private void MovePageDown () { - int nPageDnShift = Bounds.Height - 1; + int nPageDnShift = ContentArea.Height - 1; if (CurrentRow >= 0 && CurrentRow < _model.Count) { @@ -5459,7 +5458,7 @@ private void MovePageDown () private void MovePageUp () { - int nPageUpShift = Bounds.Height - 1; + int nPageUpShift = ContentArea.Height - 1; if (CurrentRow > 0) { @@ -5508,7 +5507,7 @@ private void MoveRight () CurrentRow++; CurrentColumn = 0; - if (CurrentRow >= _topRow + Bounds.Height) + if (CurrentRow >= _topRow + ContentArea.Height) { _topRow++; SetNeedsDisplay (); @@ -5609,14 +5608,14 @@ private void MoveWordForward () var w = 0; var h = 0; - if (SuperView?.Bounds.Right - Bounds.Right < 0) + if (SuperView?.ContentArea.Right - ContentArea.Right < 0) { - w = SuperView!.Bounds.Right - Bounds.Right - 1; + w = SuperView!.ContentArea.Right - ContentArea.Right - 1; } - if (SuperView?.Bounds.Bottom - Bounds.Bottom < 0) + if (SuperView?.ContentArea.Bottom - ContentArea.Bottom < 0) { - h = SuperView!.Bounds.Bottom - Bounds.Bottom - 1; + h = SuperView!.ContentArea.Bottom - ContentArea.Bottom - 1; } return (w, h); @@ -6157,7 +6156,7 @@ private bool ProcessReturn () var fullNeedsDisplay = false; - if (CurrentRow >= _topRow + Bounds.Height) + if (CurrentRow >= _topRow + ContentArea.Height) { _topRow++; fullNeedsDisplay = true; @@ -6353,6 +6352,17 @@ private void SetOverwrite (bool overwrite) DoNeededAction (); } + private void SetScrollColsRowsSize () + { + if (ScrollBarType != ScrollBarType.None) + { + ScrollColsSize = Maxlength; + ScrollRowsSize = Lines; + ScrollLeftOffset = LeftColumn; + ScrollTopOffset = TopRow; + } + } + private static void SetValidUsedColor (ColorScheme colorScheme) { // BUGBUG: (v2 truecolor) This code depends on 8-bit color names; disabling for now @@ -6441,17 +6451,6 @@ private string StringFromRunes (List cells) private void TextView_DrawAdornments (object? sender, DrawEventArgs e) { SetScrollColsRowsSize (); } - private void SetScrollColsRowsSize () - { - if (ScrollBarType != ScrollBarType.None) - { - ScrollColsSize = Maxlength; - ScrollRowsSize = Lines; - ScrollLeftOffset = LeftColumn; - ScrollTopOffset = TopRow; - } - } - private void TextView_Initialized (object sender, EventArgs e) { Autocomplete.HostControl = this; @@ -6550,7 +6549,7 @@ private void WrapTextModel () if (_wordWrap && _wrapManager is { }) { _model = _wrapManager.WrapModel ( - Math.Max (Bounds.Width - (ReadOnly ? 0 : 1), 0), // For the cursor on the last column of a line + Math.Max (ContentArea.Width - (ReadOnly ? 0 : 1), 0), // For the cursor on the last column of a line out int nRow, out int nCol, out int nStartRow, diff --git a/Terminal.Gui/Views/TileView.cs b/Terminal.Gui/Views/TileView.cs index 3051bb4767..b2ea5b4b79 100644 --- a/Terminal.Gui/Views/TileView.cs +++ b/Terminal.Gui/Views/TileView.cs @@ -156,16 +156,16 @@ public override void LayoutSubviews () return; } - Rectangle contentArea = Bounds; + Rectangle contentArea = ContentArea; if (HasBorder ()) { contentArea = new Rectangle ( - contentArea.X + 1, - contentArea.Y + 1, - Math.Max (0, contentArea.Width - 2), - Math.Max (0, contentArea.Height - 2) - ); + contentArea.X + 1, + contentArea.Y + 1, + Math.Max (0, contentArea.Width - 2), + Math.Max (0, contentArea.Height - 2) + ); } Setup (contentArea); @@ -193,19 +193,19 @@ public override void OnDrawContent (Rectangle contentArea) { if (HasBorder ()) { - lc.AddLine (new Point (0, 0), Bounds.Width, Orientation.Horizontal, LineStyle); - lc.AddLine (new Point (0, 0), Bounds.Height, Orientation.Vertical, LineStyle); + lc.AddLine (new Point (0, 0), ContentArea.Width, Orientation.Horizontal, LineStyle); + lc.AddLine (new Point (0, 0), ContentArea.Height, Orientation.Vertical, LineStyle); lc.AddLine ( - new Point (Bounds.Width - 1, Bounds.Height - 1), - -Bounds.Width, + new Point (ContentArea.Width - 1, ContentArea.Height - 1), + -ContentArea.Width, Orientation.Horizontal, LineStyle ); lc.AddLine ( - new Point (Bounds.Width - 1, Bounds.Height - 1), - -Bounds.Height, + new Point (ContentArea.Width - 1, ContentArea.Height - 1), + -ContentArea.Height, Orientation.Vertical, LineStyle ); @@ -239,7 +239,7 @@ public override void OnDrawContent (Rectangle contentArea) Driver.SetAttribute (ColorScheme.Normal); - foreach (KeyValuePair p in lc.GetMap (Bounds)) + foreach (KeyValuePair p in lc.GetMap (ContentArea)) { AddRune (p.Key.X, p.Key.Y, p.Value); } @@ -421,7 +421,7 @@ public bool SetSplitterPos (int idx, Pos value) ); } - int fullSpace = _orientation == Orientation.Vertical ? Bounds.Width : Bounds.Height; + int fullSpace = _orientation == Orientation.Vertical ? ContentArea.Width : ContentArea.Height; if (fullSpace != 0 && !IsValidNewSplitterPos (idx, value, fullSpace)) { @@ -804,14 +804,14 @@ private void Setup (Rectangle contentArea) tile.ContentView.X = i == 0 ? contentArea.X : Pos.Right (visibleSplitterLines [i - 1]); tile.ContentView.Y = contentArea.Y; tile.ContentView.Height = contentArea.Height; - tile.ContentView.Width = GetTileWidthOrHeight (i, Bounds.Width, visibleTiles, visibleSplitterLines); + tile.ContentView.Width = GetTileWidthOrHeight (i, ContentArea.Width, visibleTiles, visibleSplitterLines); } else { tile.ContentView.X = contentArea.X; tile.ContentView.Y = i == 0 ? contentArea.Y : Pos.Bottom (visibleSplitterLines [i - 1]); tile.ContentView.Width = contentArea.Width; - tile.ContentView.Height = GetTileWidthOrHeight (i, Bounds.Height, visibleTiles, visibleSplitterLines); + tile.ContentView.Height = GetTileWidthOrHeight (i, ContentArea.Height, visibleTiles, visibleSplitterLines); } } } @@ -845,7 +845,7 @@ internal string GetTrimmedTitle () { Dim spaceDim = Tile.ContentView.Width; - int spaceAbs = spaceDim.Anchor (Parent.Bounds.Width); + int spaceAbs = spaceDim.Anchor (Parent.ContentArea.Width); var title = $" {Tile.Title} "; @@ -893,7 +893,7 @@ public void DrawSplitterSymbol () { if (dragPosition is { } || CanFocus) { - Point location = moveRuneRenderLocation ?? new Point (Bounds.Width / 2, Bounds.Height / 2); + Point location = moveRuneRenderLocation ?? new Point (ContentArea.Width / 2, ContentArea.Height / 2); AddRune (location.X, location.Y, Glyphs.Diamond); } @@ -919,7 +919,7 @@ public override bool MouseEvent (MouseEvent mouseEvent) { moveRuneRenderLocation = new Point ( 0, - Math.Max (1, Math.Min (Bounds.Height - 2, mouseEvent.Y)) + Math.Max (1, Math.Min (ContentArea.Height - 2, mouseEvent.Y)) ); } } @@ -943,7 +943,7 @@ public override bool MouseEvent (MouseEvent mouseEvent) { int dx = mouseEvent.X - dragPosition.Value.X; Parent.SetSplitterPos (Idx, Offset (X, dx)); - moveRuneRenderLocation = new Point (0, Math.Max (1, Math.Min (Bounds.Height - 2, mouseEvent.Y))); + moveRuneRenderLocation = new Point (0, Math.Max (1, Math.Min (ContentArea.Height - 2, mouseEvent.Y))); } Parent.SetNeedsDisplay (); @@ -988,7 +988,7 @@ public override void PositionCursor () { base.PositionCursor (); - Point location = moveRuneRenderLocation ?? new Point (Bounds.Width / 2, Bounds.Height / 2); + Point location = moveRuneRenderLocation ?? new Point (ContentArea.Width / 2, ContentArea.Height / 2); Move (location.X, location.Y); } @@ -1032,10 +1032,10 @@ private bool FinalisePosition (Pos oldValue, Pos newValue) { if (Orientation == Orientation.Horizontal) { - return Parent.SetSplitterPos (Idx, ConvertToPosFactor (newValue, Parent.Bounds.Height)); + return Parent.SetSplitterPos (Idx, ConvertToPosFactor (newValue, Parent.ContentArea.Height)); } - return Parent.SetSplitterPos (Idx, ConvertToPosFactor (newValue, Parent.Bounds.Width)); + return Parent.SetSplitterPos (Idx, ConvertToPosFactor (newValue, Parent.ContentArea.Width)); } return Parent.SetSplitterPos (Idx, newValue); @@ -1071,8 +1071,8 @@ private Pos Offset (Pos pos, int delta) { int posAbsolute = pos.Anchor ( Orientation == Orientation.Horizontal - ? Parent.Bounds.Height - : Parent.Bounds.Width + ? Parent.ContentArea.Height + : Parent.ContentArea.Width ); return posAbsolute + delta; diff --git a/Terminal.Gui/Views/Toplevel.cs b/Terminal.Gui/Views/Toplevel.cs index 6014289843..f07f306960 100644 --- a/Terminal.Gui/Views/Toplevel.cs +++ b/Terminal.Gui/Views/Toplevel.cs @@ -366,12 +366,12 @@ public override void OnDrawContent (Rectangle contentArea) { foreach (Toplevel top in Application.OverlappedChildren.AsEnumerable ().Reverse ()) { - if (top.Frame.IntersectsWith (Bounds)) + if (top.Frame.IntersectsWith (ContentArea)) { if (top != this && !top.IsCurrentTop && !OutsideTopFrame (top) && top.Visible) { top.SetNeedsLayout (); - top.SetNeedsDisplay (top.Bounds); + top.SetNeedsDisplay (top.ContentArea); top.Draw (); top.OnRenderLineCanvas (); } @@ -382,10 +382,10 @@ public override void OnDrawContent (Rectangle contentArea) // This should not be here, but in base foreach (View view in Subviews) { - if (view.Frame.IntersectsWith (Bounds) && !OutsideTopFrame (this)) + if (view.Frame.IntersectsWith (ContentArea) && !OutsideTopFrame (this)) { //view.SetNeedsLayout (); - view.SetNeedsDisplay (view.Bounds); + view.SetNeedsDisplay (view.ContentArea); view.SetSubViewNeedsDisplay (); } } @@ -711,7 +711,7 @@ out StatusBar statusBar else { // Use the SuperView's Bounds, not Frame - maxWidth = top.SuperView.Bounds.Width; + maxWidth = top.SuperView.ContentArea.Width; superView = top.SuperView; } diff --git a/Terminal.Gui/Views/TreeView/TreeView.cs b/Terminal.Gui/Views/TreeView/TreeView.cs index ab156bde5d..c87078dc36 100644 --- a/Terminal.Gui/Views/TreeView/TreeView.cs +++ b/Terminal.Gui/Views/TreeView/TreeView.cs @@ -506,8 +506,10 @@ public void ClearObjects () ObjectActivatedEventArgs e = new (this, o); OnObjectActivated (e); PositionCursor (); + return true; } + return false; } @@ -779,10 +781,10 @@ public void EnsureVisible (T model) //if user has scrolled up too far to see their selection ScrollOffsetVertical = idx; } - else if (idx >= ScrollOffsetVertical + Bounds.Height - leaveSpace) + else if (idx >= ScrollOffsetVertical + ContentArea.Height - leaveSpace) { //if user has scrolled off bottom of visible tree - ScrollOffsetVertical = Math.Max (0, idx + 1 - (Bounds.Height - leaveSpace)); + ScrollOffsetVertical = Math.Max (0, idx + 1 - (ContentArea.Height - leaveSpace)); } } @@ -905,12 +907,12 @@ public int GetContentWidth (bool visible) } // If control has no height to it then there is no visible area for content - if (Bounds.Height == 0) + if (ContentArea.Height == 0) { return 0; } - return map.Skip (ScrollOffsetVertical).Take (Bounds.Height).Max (b => b.GetWidth (Driver)); + return map.Skip (ScrollOffsetVertical).Take (ContentArea.Height).Max (b => b.GetWidth (Driver)); } return map.Max (b => b.GetWidth (Driver)); @@ -923,13 +925,14 @@ public int GetContentWidth (bool visible) /// If you have screen coordinates then use to translate these into the client area of /// the . /// - /// The row of the of the . + /// The row of the of the . /// The object currently displayed on this row or null. public T GetObjectOnRow (int row) { return HitTest (row)?.Model; } /// /// - /// Returns the Y coordinate within the of the tree at which + /// Returns the Y coordinate within the of the tree at which + /// /// would be displayed or null if it is not currently exposed (e.g. its parent is collapsed). /// /// @@ -1004,7 +1007,7 @@ public void GoTo (T toSelect) public void GoToEnd () { IReadOnlyCollection> map = BuildLineMap (); - ScrollOffsetVertical = Math.Max (0, map.Count - Bounds.Height + 1); + ScrollOffsetVertical = Math.Max (0, map.Count - ContentArea.Height + 1); SelectedObject = map.LastOrDefault ()?.Model; SetNeedsDisplay (); @@ -1166,12 +1169,12 @@ public override bool MouseEvent (MouseEvent me) /// Moves the selection down by the height of the control (1 page). /// True if the navigation should add the covered nodes to the selected current selection. /// - public void MovePageDown (bool expandSelection = false) { AdjustSelection (Bounds.Height, expandSelection); } + public void MovePageDown (bool expandSelection = false) { AdjustSelection (ContentArea.Height, expandSelection); } /// Moves the selection up by the height of the control (1 page). /// True if the navigation should add the covered nodes to the selected current selection. /// - public void MovePageUp (bool expandSelection = false) { AdjustSelection (-Bounds.Height, expandSelection); } + public void MovePageUp (bool expandSelection = false) { AdjustSelection (-ContentArea.Height, expandSelection); } /// /// This event is raised when an object is activated e.g. by double clicking or pressing @@ -1197,7 +1200,7 @@ public override void OnDrawContent (Rectangle contentArea) IReadOnlyCollection> map = BuildLineMap (); - for (var line = 0; line < Bounds.Height; line++) + for (var line = 0; line < ContentArea.Height; line++) { int idxToRender = ScrollOffsetVertical + line; @@ -1205,14 +1208,14 @@ public override void OnDrawContent (Rectangle contentArea) if (idxToRender < map.Count) { // Render the line - map.ElementAt (idxToRender).Draw (Driver, ColorScheme, line, Bounds.Width); + map.ElementAt (idxToRender).Draw (Driver, ColorScheme, line, ContentArea.Width); } else { // Else clear the line to prevent stale symbols due to scrolling etc Move (0, line); Driver.SetAttribute (GetNormalColor ()); - Driver.AddStr (new string (' ', Bounds.Width)); + Driver.AddStr (new string (' ', ContentArea.Width)); } } } @@ -1284,7 +1287,7 @@ public override void PositionCursor () int idx = map.IndexOf (b => b.Model.Equals (SelectedObject)); // if currently selected line is visible - if (idx - ScrollOffsetVertical >= 0 && idx - ScrollOffsetVertical < Bounds.Height) + if (idx - ScrollOffsetVertical >= 0 && idx - ScrollOffsetVertical < ContentArea.Height) { Move (0, idx - ScrollOffsetVertical); } diff --git a/UICatalog/Scenarios/ASCIICustomButton.cs b/UICatalog/Scenarios/ASCIICustomButton.cs index 5555585577..6f929a24d1 100644 --- a/UICatalog/Scenarios/ASCIICustomButton.cs +++ b/UICatalog/Scenarios/ASCIICustomButton.cs @@ -79,14 +79,14 @@ public void CustomInitialize () var fillText = new StringBuilder (); - for (var i = 0; i < Bounds.Height; i++) + for (var i = 0; i < ContentArea.Height; i++) { if (i > 0) { fillText.AppendLine (""); } - for (var j = 0; j < Bounds.Width; j++) + for (var j = 0; j < ContentArea.Width; j++) { fillText.Append ("█"); } diff --git a/UICatalog/Scenarios/Animation.cs b/UICatalog/Scenarios/Animation.cs index 0b85e9a0b7..3bffff6a60 100644 --- a/UICatalog/Scenarios/Animation.cs +++ b/UICatalog/Scenarios/Animation.cs @@ -168,12 +168,12 @@ public override void OnDrawContent (Rectangle contentArea) { base.OnDrawContent (contentArea); - if (oldSize != Bounds) + if (oldSize != ContentArea) { // Invalidate cached images now size has changed matchSizes = new Image [frameCount]; brailleCache = new string [frameCount]; - oldSize = Bounds; + oldSize = ContentArea; } Image imgScaled = matchSizes [currentFrame]; @@ -184,7 +184,7 @@ public override void OnDrawContent (Rectangle contentArea) Image imgFull = fullResImages [currentFrame]; // keep aspect ratio - int newSize = Math.Min (Bounds.Width, Bounds.Height); + int newSize = Math.Min (ContentArea.Width, ContentArea.Height); // generate one matchSizes [currentFrame] = imgScaled = imgFull.Clone ( diff --git a/UICatalog/Scenarios/BackgroundWorkerCollection.cs b/UICatalog/Scenarios/BackgroundWorkerCollection.cs index 9445c226fb..a8512af29f 100644 --- a/UICatalog/Scenarios/BackgroundWorkerCollection.cs +++ b/UICatalog/Scenarios/BackgroundWorkerCollection.cs @@ -264,10 +264,10 @@ public StagingUIController () _start = new Button { Text = "Start", IsDefault = true, ClearOnVisibleFalse = false }; _start.Accept += (s, e) => - { - Staging = new Staging (DateTime.Now); - RequestStop (); - }; + { + Staging = new Staging (DateTime.Now); + RequestStop (); + }; Add (_start); _close = new Button { Text = "Close" }; @@ -285,7 +285,7 @@ public StagingUIController () LayoutStarted += (s, e) => { int btnsWidth = _start.Frame.Width + _close.Frame.Width + 2 - 1; - int shiftLeft = Math.Max ((Bounds.Width - btnsWidth) / 2 - 2, 0); + int shiftLeft = Math.Max ((ContentArea.Width - btnsWidth) / 2 - 2, 0); shiftLeft += _close.Frame.Width + 1; _close.X = Pos.AnchorEnd (shiftLeft); diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index e22df4f239..c6a6cc0619 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -73,6 +73,7 @@ public override void Setup () void JumpEditOnAccept (object sender, CancelEventArgs e) { JumpEdit_TextChanged (sender, new StateEventArgs (jumpEdit.Text, jumpEdit.Text)); + // Cancel the event to prevent ENTER from being handled elsewhere e.Cancel = true; } @@ -372,7 +373,7 @@ public CharMap () Command.PageUp, () => { - int page = (Bounds.Height / _rowHeight - 1) * 16; + int page = (ContentArea.Height / _rowHeight - 1) * 16; SelectedCodePoint -= Math.Min (page, SelectedCodePoint); return true; @@ -383,7 +384,7 @@ public CharMap () Command.PageDown, () => { - int page = (Bounds.Height / _rowHeight - 1) * 16; + int page = (ContentArea.Height / _rowHeight - 1) * 16; SelectedCodePoint += Math.Min (page, MaxCodePoint - SelectedCodePoint); return true; @@ -456,7 +457,7 @@ public int SelectedCodePoint int row = SelectedCodePoint / 16 * _rowHeight; int col = SelectedCodePoint % 16 * COLUMN_WIDTH; - int height = Bounds.Height - (ShowHorizontalScrollIndicator ? 2 : 1); + int height = ContentArea.Height - (ShowHorizontalScrollIndicator ? 2 : 1); if (row + ContentOffset.Y < 0) { @@ -472,7 +473,7 @@ public int SelectedCodePoint ); } - int width = Bounds.Width / COLUMN_WIDTH * COLUMN_WIDTH - (ShowVerticalScrollIndicator ? RowLabelWidth + 1 : RowLabelWidth); + int width = ContentArea.Width / COLUMN_WIDTH * COLUMN_WIDTH - (ShowVerticalScrollIndicator ? RowLabelWidth + 1 : RowLabelWidth); if (col + ContentOffset.X < 0) { @@ -556,12 +557,12 @@ public override void OnDrawContentComplete (Rectangle contentArea) } var viewport = new Rectangle ( - ContentOffset, - new Size ( - Math.Max (Bounds.Width - (ShowVerticalScrollIndicator ? 1 : 0), 0), - Math.Max (Bounds.Height - (ShowHorizontalScrollIndicator ? 1 : 0), 0) - ) - ); + ContentOffset, + new Size ( + Math.Max (ContentArea.Width - (ShowVerticalScrollIndicator ? 1 : 0), 0), + Math.Max (ContentArea.Height - (ShowHorizontalScrollIndicator ? 1 : 0), 0) + ) + ); Rectangle oldClip = ClipToBounds (); @@ -569,18 +570,18 @@ public override void OnDrawContentComplete (Rectangle contentArea) { // ClipToBounds doesn't know about the scroll indicators, so if off, subtract one from height Driver.Clip = new Rectangle ( - Driver.Clip.Location, - new Size (Driver.Clip.Width, Driver.Clip.Height - 1) - ); + Driver.Clip.Location, + new Size (Driver.Clip.Width, Driver.Clip.Height - 1) + ); } if (ShowVerticalScrollIndicator) { // ClipToBounds doesn't know about the scroll indicators, so if off, subtract one from width Driver.Clip = new Rectangle ( - Driver.Clip.Location, - new Size (Driver.Clip.Width - 1, Driver.Clip.Height) - ); + Driver.Clip.Location, + new Size (Driver.Clip.Width - 1, Driver.Clip.Height) + ); } int cursorCol = Cursor.X - ContentOffset.X - RowLabelWidth - 1; @@ -613,7 +614,7 @@ public override void OnDrawContentComplete (Rectangle contentArea) int firstColumnX = viewport.X + RowLabelWidth; - for (var y = 1; y < Bounds.Height; y++) + for (var y = 1; y < ContentArea.Height; y++) { // What row is this? int row = (y - ContentOffset.Y - 1) / _rowHeight; @@ -738,9 +739,9 @@ public override void PositionCursor () { if (HasFocus && Cursor.X >= RowLabelWidth - && Cursor.X < Bounds.Width - (ShowVerticalScrollIndicator ? 1 : 0) + && Cursor.X < ContentArea.Width - (ShowVerticalScrollIndicator ? 1 : 0) && Cursor.Y > 0 - && Cursor.Y < Bounds.Height - (ShowHorizontalScrollIndicator ? 1 : 0)) + && Cursor.Y < ContentArea.Height - (ShowHorizontalScrollIndicator ? 1 : 0)) { Driver.SetCursorVisibility (_cursor); Move (Cursor.X, Cursor.Y); @@ -952,16 +953,16 @@ private void ShowDetails () var dlg = new Dialog { Title = title, Buttons = [copyGlyph, copyCP, cancel] }; copyGlyph.Accept += (s, a) => - { - CopyGlyph (); - dlg.RequestStop (); - }; + { + CopyGlyph (); + dlg.RequestStop (); + }; copyCP.Accept += (s, a) => - { - CopyCodePoint (); - dlg.RequestStop (); - }; + { + CopyCodePoint (); + dlg.RequestStop (); + }; cancel.Accept += (s, a) => dlg.RequestStop (); var rune = (Rune)SelectedCodePoint; diff --git a/UICatalog/Scenarios/ComputedLayout.cs b/UICatalog/Scenarios/ComputedLayout.cs index f15fc77267..7281ef7230 100644 --- a/UICatalog/Scenarios/ComputedLayout.cs +++ b/UICatalog/Scenarios/ComputedLayout.cs @@ -56,12 +56,12 @@ public override void Setup () Application.Top.LayoutComplete += (s, a) => { horizontalRuler.Text = - rule.Repeat ((int)Math.Ceiling (horizontalRuler.Bounds.Width / (double)rule.Length)) [ - ..horizontalRuler.Bounds.Width]; + rule.Repeat ((int)Math.Ceiling (horizontalRuler.ContentArea.Width / (double)rule.Length)) [ + ..horizontalRuler.ContentArea.Width]; verticalRuler.Text = - vrule.Repeat ((int)Math.Ceiling (verticalRuler.Bounds.Height * 2 / (double)rule.Length)) - [..(verticalRuler.Bounds.Height * 2)]; + vrule.Repeat ((int)Math.Ceiling (verticalRuler.ContentArea.Height * 2 / (double)rule.Length)) + [..(verticalRuler.ContentArea.Height * 2)]; }; Application.Top.Add (verticalRuler); @@ -319,14 +319,14 @@ public override void Setup () anchorButton.X = Pos.AnchorEnd () - (Pos.Right (anchorButton) - Pos.Left (anchorButton)); anchorButton.Accept += (s, e) => - { - // This demonstrates how to have a dynamically sized button - // Each time the button is clicked the button's text gets longer - // The call to Application.Top.LayoutSubviews causes the Computed layout to - // get updated. - anchorButton.Text += "!"; - Application.Top.LayoutSubviews (); - }; + { + // This demonstrates how to have a dynamically sized button + // Each time the button is clicked the button's text gets longer + // The call to Application.Top.LayoutSubviews causes the Computed layout to + // get updated. + anchorButton.Text += "!"; + Application.Top.LayoutSubviews (); + }; Application.Top.Add (anchorButton); // Demonstrate AnchorEnd(n) @@ -365,14 +365,14 @@ public override void Setup () }; leftButton.Accept += (s, e) => - { - // This demonstrates how to have a dynamically sized button - // Each time the button is clicked the button's text gets longer - // The call to Application.Top.LayoutSubviews causes the Computed layout to - // get updated. - leftButton.Text += "!"; - Application.Top.LayoutSubviews (); - }; + { + // This demonstrates how to have a dynamically sized button + // Each time the button is clicked the button's text gets longer + // The call to Application.Top.LayoutSubviews causes the Computed layout to + // get updated. + leftButton.Text += "!"; + Application.Top.LayoutSubviews (); + }; // show positioning vertically using Pos.AnchorEnd var centerButton = new Button @@ -381,28 +381,28 @@ public override void Setup () }; centerButton.Accept += (s, e) => - { - // This demonstrates how to have a dynamically sized button - // Each time the button is clicked the button's text gets longer - // The call to Application.Top.LayoutSubviews causes the Computed layout to - // get updated. - centerButton.Text += "!"; - Application.Top.LayoutSubviews (); - }; - - // show positioning vertically using another window and Pos.Bottom - var rightButton = new Button { Text = "Right", Y = Pos.Y (centerButton) }; - - rightButton.Accept += (s, e) => { // This demonstrates how to have a dynamically sized button // Each time the button is clicked the button's text gets longer // The call to Application.Top.LayoutSubviews causes the Computed layout to // get updated. - rightButton.Text += "!"; + centerButton.Text += "!"; Application.Top.LayoutSubviews (); }; + // show positioning vertically using another window and Pos.Bottom + var rightButton = new Button { Text = "Right", Y = Pos.Y (centerButton) }; + + rightButton.Accept += (s, e) => + { + // This demonstrates how to have a dynamically sized button + // Each time the button is clicked the button's text gets longer + // The call to Application.Top.LayoutSubviews causes the Computed layout to + // get updated. + rightButton.Text += "!"; + Application.Top.LayoutSubviews (); + }; + // Center three buttons with 5 spaces between them leftButton.X = Pos.Left (centerButton) - (Pos.Right (leftButton) - Pos.Left (leftButton)) - 5; rightButton.X = Pos.Right (centerButton) + 5; diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index 1dbb724c9c..b763dd7411 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -691,8 +691,8 @@ private void CreateFindReplace (bool isFind = true) _winDialog = new Window { Title = isFind ? "Find" : "Replace", - X = Win.Bounds.Width / 2 - 30, - Y = Win.Bounds.Height / 2 - 10, + X = Win.ContentArea.Width / 2 - 30, + Y = Win.ContentArea.Height / 2 - 10, ColorScheme = Colors.ColorSchemes ["TopLevel"] }; diff --git a/UICatalog/Scenarios/GraphViewExample.cs b/UICatalog/Scenarios/GraphViewExample.cs index b65bf42be9..1857e578de 100644 --- a/UICatalog/Scenarios/GraphViewExample.cs +++ b/UICatalog/Scenarios/GraphViewExample.cs @@ -254,7 +254,7 @@ private void MultiBarGraph () _graphView.AxisY.Minimum = 0; - var legend = new LegendAnnotation (new Rectangle (_graphView.Bounds.Width - 20, 0, 20, 5)); + var legend = new LegendAnnotation (new Rectangle (_graphView.ContentArea.Width - 20, 0, 20, 5)); legend.AddEntry ( new GraphCellToRender (stiple, series.SubSeries.ElementAt (0).OverrideBarColor), @@ -872,7 +872,7 @@ private void SetupPopulationPyramid () _graphView.Annotations.Add (new TextAnnotation { Text = "M", ScreenPosition = new Point (0, 10) }); _graphView.Annotations.Add ( - new TextAnnotation { Text = "F", ScreenPosition = new Point (_graphView.Bounds.Width - 1, 10) } + new TextAnnotation { Text = "F", ScreenPosition = new Point (_graphView.ContentArea.Width - 1, 10) } ); _graphView.SetNeedsDisplay (); diff --git a/UICatalog/Scenarios/ProgressBarStyles.cs b/UICatalog/Scenarios/ProgressBarStyles.cs index 44b2875b1b..d77d63da82 100644 --- a/UICatalog/Scenarios/ProgressBarStyles.cs +++ b/UICatalog/Scenarios/ProgressBarStyles.cs @@ -70,7 +70,7 @@ ColorName ChooseColor (string text, ColorName colorName) dialog.X = pbList.Frame.X; dialog.Y = pbList.Frame.Height; - dialog.Bounds = new Rectangle (0, 0, colorPicker.Frame.Width, colorPicker.Frame.Height); + dialog.ContentArea = new Rectangle (0, 0, colorPicker.Frame.Width, colorPicker.Frame.Height); Application.Top.LayoutSubviews (); }; @@ -92,23 +92,23 @@ ColorName ChooseColor (string text, ColorName colorName) editor.Add (fgColorPickerBtn); fgColorPickerBtn.Accept += (s, e) => - { - ColorName newColor = ChooseColor ( - fgColorPickerBtn.Text, - editor.ViewToEdit.ColorScheme.HotNormal.Foreground - .GetClosestNamedColor () - ); - - var cs = new ColorScheme (editor.ViewToEdit.ColorScheme) - { - HotNormal = new Attribute ( - newColor, - editor.ViewToEdit.ColorScheme.HotNormal - .Background - ) - }; - editor.ViewToEdit.ColorScheme = cs; - }; + { + ColorName newColor = ChooseColor ( + fgColorPickerBtn.Text, + editor.ViewToEdit.ColorScheme.HotNormal.Foreground + .GetClosestNamedColor () + ); + + var cs = new ColorScheme (editor.ViewToEdit.ColorScheme) + { + HotNormal = new Attribute ( + newColor, + editor.ViewToEdit.ColorScheme.HotNormal + .Background + ) + }; + editor.ViewToEdit.ColorScheme = cs; + }; var bgColorPickerBtn = new Button { @@ -117,23 +117,23 @@ ColorName ChooseColor (string text, ColorName colorName) editor.Add (bgColorPickerBtn); bgColorPickerBtn.Accept += (s, e) => - { - ColorName newColor = ChooseColor ( - fgColorPickerBtn.Text, - editor.ViewToEdit.ColorScheme.HotNormal.Background - .GetClosestNamedColor () - ); - - var cs = new ColorScheme (editor.ViewToEdit.ColorScheme) - { - HotNormal = new Attribute ( - editor.ViewToEdit.ColorScheme.HotNormal - .Foreground, - newColor - ) - }; - editor.ViewToEdit.ColorScheme = cs; - }; + { + ColorName newColor = ChooseColor ( + fgColorPickerBtn.Text, + editor.ViewToEdit.ColorScheme.HotNormal.Background + .GetClosestNamedColor () + ); + + var cs = new ColorScheme (editor.ViewToEdit.ColorScheme) + { + HotNormal = new Attribute ( + editor.ViewToEdit.ColorScheme.HotNormal + .Foreground, + newColor + ) + }; + editor.ViewToEdit.ColorScheme = cs; + }; #endregion @@ -178,36 +178,36 @@ ColorName ChooseColor (string text, ColorName colorName) editor.Add (continuousPB); button.Accept += (s, e) => - { - if (_fractionTimer == null) - { - //blocksPB.Enabled = false; - blocksPB.Fraction = 0; - continuousPB.Fraction = 0; - float fractionSum = 0; - - _fractionTimer = new Timer ( - _ => - { - fractionSum += fractionStep; - blocksPB.Fraction = fractionSum; - continuousPB.Fraction = fractionSum; - - if (fractionSum > 1) - { - _fractionTimer.Dispose (); - _fractionTimer = null; - button.Enabled = true; - } - - Application.Wakeup (); - }, - null, - 0, - _timerTick - ); - } - }; + { + if (_fractionTimer == null) + { + //blocksPB.Enabled = false; + blocksPB.Fraction = 0; + continuousPB.Fraction = 0; + float fractionSum = 0; + + _fractionTimer = new Timer ( + _ => + { + fractionSum += fractionStep; + blocksPB.Fraction = fractionSum; + continuousPB.Fraction = fractionSum; + + if (fractionSum > 1) + { + _fractionTimer.Dispose (); + _fractionTimer = null; + button.Enabled = true; + } + + Application.Wakeup (); + }, + null, + 0, + _timerTick + ); + } + }; var ckbBidirectional = new CheckBox { diff --git a/UICatalog/Scenarios/Scrolling.cs b/UICatalog/Scenarios/Scrolling.cs index 0d93ff9e58..cab84f6244 100644 --- a/UICatalog/Scenarios/Scrolling.cs +++ b/UICatalog/Scenarios/Scrolling.cs @@ -67,17 +67,17 @@ public override void Setup () void Top_Loaded (object sender, EventArgs args) { horizontalRuler.Text = - rule.Repeat ((int)Math.Ceiling (horizontalRuler.Bounds.Width / (double)rule.Length)) [ - ..horizontalRuler.Bounds.Width] + rule.Repeat ((int)Math.Ceiling (horizontalRuler.ContentArea.Width / (double)rule.Length)) [ + ..horizontalRuler.ContentArea.Width] + "\n" + "| ".Repeat ( - (int)Math.Ceiling (horizontalRuler.Bounds.Width / (double)rule.Length) + (int)Math.Ceiling (horizontalRuler.ContentArea.Width / (double)rule.Length) ) [ - ..horizontalRuler.Bounds.Width]; + ..horizontalRuler.ContentArea.Width]; verticalRuler.Text = - vrule.Repeat ((int)Math.Ceiling (verticalRuler.Bounds.Height * 2 / (double)rule.Length)) - [..(verticalRuler.Bounds.Height * 2)]; + vrule.Repeat ((int)Math.Ceiling (verticalRuler.ContentArea.Height * 2 / (double)rule.Length)) + [..(verticalRuler.ContentArea.Height * 2)]; Application.Top.Loaded -= Top_Loaded; } @@ -138,14 +138,14 @@ void Top_Loaded (object sender, EventArgs args) anchorButton.X = Pos.AnchorEnd () - (Pos.Right (anchorButton) - Pos.Left (anchorButton)); anchorButton.Accept += (s, e) => - { - // This demonstrates how to have a dynamically sized button - // Each time the button is clicked the button's text gets longer - // The call to Win.LayoutSubviews causes the Computed layout to - // get updated. - anchorButton.Text += "!"; - Win.LayoutSubviews (); - }; + { + // This demonstrates how to have a dynamically sized button + // Each time the button is clicked the button's text gets longer + // The call to Win.LayoutSubviews causes the Computed layout to + // get updated. + anchorButton.Text += "!"; + Win.LayoutSubviews (); + }; scrollView.Add (anchorButton); Win.Add (scrollView); diff --git a/UICatalog/Scenarios/Snake.cs b/UICatalog/Scenarios/Snake.cs index fcb010d68e..90ba2020b8 100644 --- a/UICatalog/Scenarios/Snake.cs +++ b/UICatalog/Scenarios/Snake.cs @@ -341,7 +341,7 @@ public override void OnDrawContent (Rectangle contentArea) ); } - foreach (KeyValuePair p in canvas.GetMap (Bounds)) + foreach (KeyValuePair p in canvas.GetMap (ContentArea)) { AddRune (p.Key.X, p.Key.Y, p.Value); } diff --git a/UICatalog/Scenarios/ViewExperiments.cs b/UICatalog/Scenarios/ViewExperiments.cs index f1303e0bfe..e29e42df42 100644 --- a/UICatalog/Scenarios/ViewExperiments.cs +++ b/UICatalog/Scenarios/ViewExperiments.cs @@ -218,17 +218,17 @@ public override void Setup () $"Container.Frame: { Application.Top.Frame } .Bounds: { - Application.Top.Bounds + Application.Top.ContentArea }\nView.Frame: { view.Frame } .Bounds: { - view.Bounds + view.ContentArea } .BoundsOffset: { view.GetBoundsOffset () }\n .Padding.Frame: { view.Padding.Frame } .Padding.Bounds: { - view.Padding.Bounds + view.Padding.ContentArea }"; }; diff --git a/UICatalog/Scenarios/VkeyPacketSimulator.cs b/UICatalog/Scenarios/VkeyPacketSimulator.cs index 37ffced397..a5334fb18f 100644 --- a/UICatalog/Scenarios/VkeyPacketSimulator.cs +++ b/UICatalog/Scenarios/VkeyPacketSimulator.cs @@ -243,21 +243,21 @@ public override void Setup () }; btnInput.Accept += (s, e) => + { + if (!tvInput.HasFocus && _keyboardStrokes.Count == 0) + { + tvInput.SetFocus (); + } + }; + + btnOutput.Accept += (s, e) => { - if (!tvInput.HasFocus && _keyboardStrokes.Count == 0) + if (!tvOutput.HasFocus && _keyboardStrokes.Count == 0) { - tvInput.SetFocus (); + tvOutput.SetFocus (); } }; - btnOutput.Accept += (s, e) => - { - if (!tvOutput.HasFocus && _keyboardStrokes.Count == 0) - { - tvOutput.SetFocus (); - } - }; - tvInput.SetFocus (); void Win_LayoutComplete (object sender, LayoutEventArgs obj) @@ -265,20 +265,20 @@ void Win_LayoutComplete (object sender, LayoutEventArgs obj) inputHorizontalRuler.Text = outputHorizontalRuler.Text = ruler.Repeat ( (int)Math.Ceiling ( - inputHorizontalRuler.Bounds.Width + inputHorizontalRuler.ContentArea.Width / (double)ruler.Length ) ) [ - ..inputHorizontalRuler.Bounds.Width]; + ..inputHorizontalRuler.ContentArea.Width]; inputVerticalRuler.Height = tvInput.Frame.Height + 1; inputVerticalRuler.Text = - ruler.Repeat ((int)Math.Ceiling (inputVerticalRuler.Bounds.Height / (double)ruler.Length)) [ - ..inputVerticalRuler.Bounds.Height]; + ruler.Repeat ((int)Math.Ceiling (inputVerticalRuler.ContentArea.Height / (double)ruler.Length)) [ + ..inputVerticalRuler.ContentArea.Height]; outputVerticalRuler.Text = - ruler.Repeat ((int)Math.Ceiling (outputVerticalRuler.Bounds.Height / (double)ruler.Length)) [ - ..outputVerticalRuler.Bounds.Height]; + ruler.Repeat ((int)Math.Ceiling (outputVerticalRuler.ContentArea.Height / (double)ruler.Length)) [ + ..outputVerticalRuler.ContentArea.Height]; } Win.LayoutComplete += Win_LayoutComplete; diff --git a/UnitTests/Drawing/LineCanvasTests.cs b/UnitTests/Drawing/LineCanvasTests.cs index 928b7b4a42..28d22baccf 100644 --- a/UnitTests/Drawing/LineCanvasTests.cs +++ b/UnitTests/Drawing/LineCanvasTests.cs @@ -293,7 +293,7 @@ string expected View v = GetCanvas (out LineCanvas lc); v.Width = 10; v.Height = 10; - v.Bounds = new Rectangle (0, 0, 10, 10); + v.ContentArea = new Rectangle (0, 0, 10, 10); lc.AddLine (new Point (x1, y1), len1, o1, s1); lc.AddLine (new Point (x2, y2), len2, o2, s2); @@ -990,7 +990,7 @@ string expected View v = GetCanvas (out LineCanvas lc); v.Width = 10; v.Height = 10; - v.Bounds = new Rectangle (0, 0, 10, 10); + v.ContentArea = new Rectangle (0, 0, 10, 10); lc.AddLine (new Point (x1, y1), length, o1, s1); @@ -1304,7 +1304,7 @@ public void Zero_Length_Intersections () /// private View GetCanvas (out LineCanvas canvas, int offsetX = 0, int offsetY = 0) { - var v = new View { Width = 10, Height = 5, Bounds = new Rectangle (0, 0, 10, 5) }; + var v = new View { Width = 10, Height = 5, ContentArea = new Rectangle (0, 0, 10, 5) }; Application.Top.Add (v); Application.Begin (Application.Top); diff --git a/UnitTests/View/Adornment/AdornmentTests.cs b/UnitTests/View/Adornment/AdornmentTests.cs index c60b4a7a62..1ee46a915a 100644 --- a/UnitTests/View/Adornment/AdornmentTests.cs +++ b/UnitTests/View/Adornment/AdornmentTests.cs @@ -19,22 +19,22 @@ public void BoundsToScreen_All_Adornments_With_Thickness () parent.EndInit (); Assert.Equal (new Rectangle (1, 2, 10, 10), parent.Frame); - Assert.Equal (new Rectangle (0, 0, 4, 4), parent.Bounds); + Assert.Equal (new Rectangle (0, 0, 4, 4), parent.ContentArea); Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Margin.Frame); - Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Margin.Bounds); + Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Margin.ContentArea); Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Border.Frame); - Assert.Equal (new Rectangle (1, 1, 6, 6), parent.Border.Bounds); + Assert.Equal (new Rectangle (1, 1, 6, 6), parent.Border.ContentArea); Assert.Equal (new Rectangle (2, 2, 6, 6), parent.Padding.Frame); - Assert.Equal (new Rectangle (1, 1, 4, 4), parent.Padding.Bounds); + Assert.Equal (new Rectangle (1, 1, 4, 4), parent.Padding.ContentArea); Assert.Null (parent.Margin.SuperView); - Rectangle boundsAsScreen = parent.BoundsToScreen (parent.Bounds); + Rectangle boundsAsScreen = parent.BoundsToScreen (parent.ContentArea); Assert.Equal (new Rectangle (4, 5, 4, 4), boundsAsScreen); - boundsAsScreen = parent.Margin.BoundsToScreen (parent.Margin.Bounds); + boundsAsScreen = parent.Margin.BoundsToScreen (parent.Margin.ContentArea); Assert.Equal (new Rectangle (2, 3, 8, 8), boundsAsScreen); - boundsAsScreen = parent.Border.BoundsToScreen (parent.Border.Bounds); + boundsAsScreen = parent.Border.BoundsToScreen (parent.Border.ContentArea); Assert.Equal (new Rectangle (2, 3, 6, 6), boundsAsScreen); - boundsAsScreen = parent.Padding.BoundsToScreen (parent.Padding.Bounds); + boundsAsScreen = parent.Padding.BoundsToScreen (parent.Padding.ContentArea); Assert.Equal (new Rectangle (2, 3, 4, 4), boundsAsScreen); } @@ -47,13 +47,13 @@ public void BoundsToScreen_Uses_Parent_Not_SuperView () parent.EndInit (); Assert.Equal (new Rectangle (1, 2, 10, 10), parent.Frame); - Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 10), parent.ContentArea); Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Margin.Frame); - Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Margin.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Margin.ContentArea); Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Border.Frame); - Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Border.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Border.ContentArea); Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Padding.Frame); - Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Padding.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Padding.ContentArea); Assert.Null (parent.Margin.SuperView); Rectangle boundsAsScreen = parent.BoundsToScreen (new Rectangle (1, 2, 5, 5)); @@ -110,10 +110,10 @@ public void Draw_Centered_View_With_Thickness_One_On_All_Adornments () Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Border.Frame.ToString ()); Assert.Equal ("{X=2,Y=2,Width=6,Height=5}", parent.Padding.Frame.ToString ()); Assert.Equal ("{X=5,Y=1,Width=10,Height=9}", parent.Frame.ToString ()); - Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Margin.Bounds.ToString ()); - Assert.Equal ("{X=1,Y=1,Width=6,Height=5}", parent.Border.Bounds.ToString ()); - Assert.Equal ("{X=1,Y=1,Width=4,Height=3}", parent.Padding.Bounds.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=4,Height=3}", parent.Bounds.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Margin.ContentArea.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=6,Height=5}", parent.Border.ContentArea.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=4,Height=3}", parent.Padding.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=4,Height=3}", parent.ContentArea.ToString ()); Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Margin.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=1,Y=1,Width=6,Height=5}", parent.Border.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=1,Y=1,Width=4,Height=3}", parent.Padding.GetVisibleContentArea ().ToString ()); @@ -197,10 +197,10 @@ public void Draw_Centered_View_With_Thickness_One_On_All_Adornments_Inside_Anoth Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Border.Frame.ToString ()); Assert.Equal ("{X=2,Y=2,Width=6,Height=5}", parent.Padding.Frame.ToString ()); Assert.Equal ("{X=4,Y=0,Width=10,Height=9}", parent.Frame.ToString ()); - Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Margin.Bounds.ToString ()); - Assert.Equal ("{X=1,Y=1,Width=6,Height=5}", parent.Border.Bounds.ToString ()); - Assert.Equal ("{X=1,Y=1,Width=4,Height=3}", parent.Padding.Bounds.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=4,Height=3}", parent.Bounds.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Margin.ContentArea.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=6,Height=5}", parent.Border.ContentArea.ToString ()); + Assert.Equal ("{X=1,Y=1,Width=4,Height=3}", parent.Padding.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=4,Height=3}", parent.ContentArea.ToString ()); Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Margin.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=1,Y=1,Width=6,Height=5}", parent.Border.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=1,Y=1,Width=4,Height=3}", parent.Padding.GetVisibleContentArea ().ToString ()); @@ -250,13 +250,13 @@ public void FrameToScreen_All_Adornments_With_Thickness () parent.EndInit (); Assert.Equal (new Rectangle (1, 2, 10, 10), parent.Frame); - Assert.Equal (new Rectangle (0, 0, 4, 4), parent.Bounds); + Assert.Equal (new Rectangle (0, 0, 4, 4), parent.ContentArea); Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Margin.Frame); - Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Margin.Bounds); + Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Margin.ContentArea); Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Border.Frame); - Assert.Equal (new Rectangle (1, 1, 6, 6), parent.Border.Bounds); + Assert.Equal (new Rectangle (1, 1, 6, 6), parent.Border.ContentArea); Assert.Equal (new Rectangle (2, 2, 6, 6), parent.Padding.Frame); - Assert.Equal (new Rectangle (1, 1, 4, 4), parent.Padding.Bounds); + Assert.Equal (new Rectangle (1, 1, 4, 4), parent.Padding.ContentArea); Assert.Null (parent.Margin.SuperView); Assert.Equal (new Rectangle (1, 2, 10, 10), parent.FrameToScreen ()); @@ -279,15 +279,15 @@ public void FrameToScreen_All_Adornments_With_Thickness_With_SuperView () parent.EndInit (); Assert.Equal (new Rectangle (0, 0, 12, 12), top.Frame); - Assert.Equal (new Rectangle (0, 0, 12, 12), top.Bounds); + Assert.Equal (new Rectangle (0, 0, 12, 12), top.ContentArea); Assert.Equal (new Rectangle (1, 2, 10, 10), parent.Frame); - Assert.Equal (new Rectangle (0, 0, 4, 4), parent.Bounds); + Assert.Equal (new Rectangle (0, 0, 4, 4), parent.ContentArea); Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Margin.Frame); - Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Margin.Bounds); + Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Margin.ContentArea); Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Border.Frame); - Assert.Equal (new Rectangle (1, 1, 6, 6), parent.Border.Bounds); + Assert.Equal (new Rectangle (1, 1, 6, 6), parent.Border.ContentArea); Assert.Equal (new Rectangle (2, 2, 6, 6), parent.Padding.Frame); - Assert.Equal (new Rectangle (1, 1, 4, 4), parent.Padding.Bounds); + Assert.Equal (new Rectangle (1, 1, 4, 4), parent.Padding.ContentArea); Assert.Null (parent.Margin.SuperView); Assert.Equal (new Rectangle (0, 0, 12, 12), top.FrameToScreen ()); @@ -346,13 +346,13 @@ public void FrameToScreen_Uses_Parent_Not_SuperView () parent.EndInit (); Assert.Equal (new Rectangle (1, 2, 10, 10), parent.Frame); - Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 10), parent.ContentArea); Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Margin.Frame); - Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Margin.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Margin.ContentArea); Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Border.Frame); - Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Border.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Border.ContentArea); Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Padding.Frame); - Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Padding.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Padding.ContentArea); Assert.Null (parent.Margin.SuperView); Assert.Equal (new Rectangle (1, 2, 10, 10), parent.FrameToScreen ()); @@ -406,7 +406,7 @@ public void GetAdornmentsThickness_On_Adornments () public void Setting_Bounds_Throws () { var adornment = new Adornment (null); - Assert.Throws (() => adornment.Bounds = new Rectangle (1, 2, 3, 4)); + Assert.Throws (() => adornment.ContentArea = new Rectangle (1, 2, 3, 4)); } [Fact] @@ -431,11 +431,11 @@ public void Setting_Thickness_Changes_Parent_Bounds () parent.EndInit (); Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Frame); - Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 10), parent.ContentArea); parent.Margin.Thickness = new Thickness (1); Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Frame); - Assert.Equal (new Rectangle (0, 0, 8, 8), parent.Bounds); + Assert.Equal (new Rectangle (0, 0, 8, 8), parent.ContentArea); } [Fact] diff --git a/UnitTests/View/DrawTests.cs b/UnitTests/View/DrawTests.cs index 725fe47aed..cfff1e812e 100644 --- a/UnitTests/View/DrawTests.cs +++ b/UnitTests/View/DrawTests.cs @@ -4,7 +4,7 @@ namespace Terminal.Gui.ViewsTests; -[Trait("Category","Output")] +[Trait ("Category", "Output")] public class DrawTests { private readonly ITestOutputHelper _output; @@ -12,7 +12,7 @@ public class DrawTests [Fact] [AutoInitShutdown] - [Trait("Category","Unicode")] + [Trait ("Category", "Unicode")] public void CJK_Compatibility_Ideographs_ConsoleWidth_ColumnWidth_Equal_Two () { const string us = "\U0000f900"; @@ -74,7 +74,7 @@ Colors.ColorSchemes ["Base"].HotNormal // TODO: Refactor this test to not depend on TextView etc... Make it as primitive as possible [Fact] [AutoInitShutdown] - [Trait("Category","Unicode")] + [Trait ("Category", "Unicode")] public void Clipping_AddRune_Left_Or_Right_Replace_Previous_Or_Next_Wide_Rune_With_Space () { var tv = new TextView @@ -126,7 +126,7 @@ public void Clipping_AddRune_Left_Or_Right_Replace_Previous_Or_Next_Wide_Rune_Wi [Fact] [AutoInitShutdown] - [Trait("Category","Output")] + [Trait ("Category", "Output")] public void Colors_On_TextAlignment_Right_And_Bottom () { var viewRight = new View @@ -156,14 +156,14 @@ public void Colors_On_TextAlignment_Right_And_Bottom () TestHelpers.AssertDriverContentsWithFrameAre ( """ - + Test - T - e - s - t + T + e + s + t """, _output ); @@ -193,8 +193,8 @@ public void Draw_Minimum_Full_Border_With_Empty_Bounds () view.EndInit (); view.SetRelativeLayout (Application.Driver.Bounds); - Assert.Equal (new (0,0,2,2), view.Frame); - Assert.Equal (Rectangle.Empty, view.Bounds); + Assert.Equal (new Rectangle (0, 0, 2, 2), view.Frame); + Assert.Equal (Rectangle.Empty, view.ContentArea); view.Draw (); @@ -218,8 +218,8 @@ public void Draw_Minimum_Full_Border_With_Empty_Bounds_Without_Bottom () view.EndInit (); view.SetRelativeLayout (Application.Driver.Bounds); - Assert.Equal (new (0,0,2,1), view.Frame); - Assert.Equal (Rectangle.Empty, view.Bounds); + Assert.Equal (new Rectangle (0, 0, 2, 1), view.Frame); + Assert.Equal (Rectangle.Empty, view.ContentArea); view.Draw (); @@ -236,8 +236,8 @@ public void Draw_Minimum_Full_Border_With_Empty_Bounds_Without_Left () view.EndInit (); view.SetRelativeLayout (Application.Driver.Bounds); - Assert.Equal (new (0,0,1,2), view.Frame); - Assert.Equal (Rectangle.Empty, view.Bounds); + Assert.Equal (new Rectangle (0, 0, 1, 2), view.Frame); + Assert.Equal (Rectangle.Empty, view.ContentArea); view.Draw (); @@ -261,8 +261,8 @@ public void Draw_Minimum_Full_Border_With_Empty_Bounds_Without_Right () view.EndInit (); view.SetRelativeLayout (Application.Driver.Bounds); - Assert.Equal (new (0,0,1,2), view.Frame); - Assert.Equal (Rectangle.Empty, view.Bounds); + Assert.Equal (new Rectangle (0, 0, 1, 2), view.Frame); + Assert.Equal (Rectangle.Empty, view.ContentArea); view.Draw (); @@ -287,8 +287,8 @@ public void Draw_Minimum_Full_Border_With_Empty_Bounds_Without_Top () view.EndInit (); view.SetRelativeLayout (Application.Driver.Bounds); - Assert.Equal (new (0,0,2,1), view.Frame); - Assert.Equal (Rectangle.Empty, view.Bounds); + Assert.Equal (new Rectangle (0, 0, 2, 1), view.Frame); + Assert.Equal (Rectangle.Empty, view.ContentArea); view.Draw (); @@ -313,40 +313,40 @@ public void Draw_Negative_Bounds_Horizontal_With_New_Lines () Width = 1, Height = 7, Text = """ - s - u - b - V - i - e - w - """ + s + u + b + V + i + e + w + """ }; var view = new View { Id = "view", Width = 2, Height = 20, Text = """ - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - """ + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + """ }; view.Add (subView); var content = new View { Id = "content", Width = 20, Height = 20 }; @@ -368,7 +368,7 @@ public void Draw_Negative_Bounds_Horizontal_With_New_Lines () TestHelpers.AssertDriverContentsWithFrameAre ( """ - + 0s 1u 2b @@ -383,7 +383,7 @@ public void Draw_Negative_Bounds_Horizontal_With_New_Lines () TestHelpers.AssertDriverContentsWithFrameAre ( """ - + s u b @@ -403,7 +403,7 @@ public void Draw_Negative_Bounds_Horizontal_With_New_Lines () TestHelpers.AssertDriverContentsWithFrameAre ( """ - + 1u 2b 3V @@ -418,12 +418,12 @@ public void Draw_Negative_Bounds_Horizontal_With_New_Lines () TestHelpers.AssertDriverContentsWithFrameAre ( """ - + 6w - 7 - 8 - 9 - 0 + 7 + 8 + 9 + 0 """, _output ); @@ -433,7 +433,7 @@ public void Draw_Negative_Bounds_Horizontal_With_New_Lines () TestHelpers.AssertDriverContentsWithFrameAre ( """ - + 9 """, _output @@ -488,7 +488,7 @@ public void Draw_Negative_Bounds_Horizontal_Without_New_Lines () TestHelpers.AssertDriverContentsWithFrameAre ( """ - + 01234 subVi """, @@ -500,7 +500,7 @@ public void Draw_Negative_Bounds_Horizontal_Without_New_Lines () TestHelpers.AssertDriverContentsWithFrameAre ( """ - + 12345 ubVie """, @@ -512,7 +512,7 @@ public void Draw_Negative_Bounds_Horizontal_Without_New_Lines () TestHelpers.AssertDriverContentsWithFrameAre ( """ - + ubVie """, _output @@ -570,7 +570,7 @@ public void Draw_Negative_Bounds_Vertical () TestHelpers.AssertDriverContentsWithFrameAre ( """ - + 0s 1u 2b @@ -585,7 +585,7 @@ public void Draw_Negative_Bounds_Vertical () TestHelpers.AssertDriverContentsWithFrameAre ( """ - + s u b @@ -605,7 +605,7 @@ public void Draw_Negative_Bounds_Vertical () TestHelpers.AssertDriverContentsWithFrameAre ( """ - + 1u 2b 3V @@ -620,12 +620,12 @@ public void Draw_Negative_Bounds_Vertical () TestHelpers.AssertDriverContentsWithFrameAre ( """ - + 6w - 7 - 8 - 9 - 0 + 7 + 8 + 9 + 0 """, _output ); @@ -635,7 +635,7 @@ public void Draw_Negative_Bounds_Vertical () TestHelpers.AssertDriverContentsWithFrameAre ( """ - + 9 """, _output @@ -690,11 +690,11 @@ public void Non_Bmp_ConsoleWidth_ColumnWidth_Equal_Two () var expected = """ - ┌┤𝔹├─────┐ - │𝔹 │ - │𝔹 │ - └────────┘ - """; + ┌┤𝔹├─────┐ + │𝔹 │ + │𝔹 │ + └────────┘ + """; TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); TestHelpers.AssertDriverContentsAre (expected, _output); diff --git a/UnitTests/View/Layout/AbsoluteLayoutTests.cs b/UnitTests/View/Layout/AbsoluteLayoutTests.cs index 2f4b27fea5..89dbf9d9ad 100644 --- a/UnitTests/View/Layout/AbsoluteLayoutTests.cs +++ b/UnitTests/View/Layout/AbsoluteLayoutTests.cs @@ -31,7 +31,7 @@ public void AbsoluteLayout_Change_Frame () Assert.Equal ( new Rectangle (0, 0, newFrame.Width, newFrame.Height), - v.Bounds + v.ContentArea ); // With Absolute Bounds *is* deterministic before Layout Assert.Equal (Pos.At (1), v.X); Assert.Equal (Pos.At (2), v.Y); @@ -46,7 +46,7 @@ public void AbsoluteLayout_Change_Frame () Assert.Equal ( new Rectangle (0, 0, newFrame.Width, newFrame.Height), - v.Bounds + v.ContentArea ); // With Absolute Bounds *is* deterministic before Layout Assert.Equal (Pos.At (1), v.X); Assert.Equal (Pos.At (2), v.Y); @@ -62,7 +62,7 @@ public void AbsoluteLayout_Change_Frame () Assert.Equal ( new Rectangle (0, 0, newFrame.Width, newFrame.Height), - v.Bounds + v.ContentArea ); // With Absolute Bounds *is* deterministic before Layout Assert.Equal (Pos.At (10), v.X); Assert.Equal (Pos.At (20), v.Y); @@ -77,7 +77,7 @@ public void AbsoluteLayout_Change_Frame () Assert.Equal ( new Rectangle (0, 0, newFrame.Width, newFrame.Height), - v.Bounds + v.ContentArea ); // With Absolute Bounds *is* deterministic before Layout Assert.Equal (Pos.At (10), v.X); Assert.Equal (Pos.At (20), v.Y); @@ -101,7 +101,7 @@ public void AbsoluteLayout_Change_Height_or_Width_Absolute () Assert.Equal ( new Rectangle (0, 0, newFrame.Width, newFrame.Height), - v.Bounds + v.ContentArea ); // With Absolute Bounds *is* deterministic before Layout Assert.Equal (Pos.At (1), v.X); Assert.Equal (Pos.At (2), v.Y); @@ -136,7 +136,7 @@ public void AbsoluteLayout_Change_X_or_Y_Absolute () Assert.Equal ( new Rectangle (0, 0, newFrame.Width, newFrame.Height), - v.Bounds + v.ContentArea ); // With Absolute Bounds *is* deterministic before Layout Assert.Equal ($"Absolute({newFrame.X})", v.X.ToString ()); Assert.Equal ($"Absolute({newFrame.Y})", v.Y.ToString ()); @@ -250,7 +250,7 @@ public void AbsoluteLayout_Constructor () Assert.Equal ( new Rectangle (0, 0, frame.Width, frame.Height), - v.Bounds + v.ContentArea ); // With Absolute Bounds *is* deterministic before Layout Assert.Equal (Pos.At (0), v.X); Assert.Equal (Pos.At (0), v.Y); @@ -265,7 +265,7 @@ public void AbsoluteLayout_Constructor () Assert.Equal ( new Rectangle (0, 0, frame.Width, frame.Height), - v.Bounds + v.ContentArea ); // With Absolute Bounds *is* deterministic before Layout Assert.Equal (Pos.At (1), v.X); Assert.Equal (Pos.At (2), v.Y); @@ -279,7 +279,7 @@ public void AbsoluteLayout_Constructor () Assert.Equal ( new Rectangle (0, 0, frame.Width, frame.Height), - v.Bounds + v.ContentArea ); // With Absolute Bounds *is* deterministic before Layout Assert.Equal (Pos.At (1), v.X); Assert.Equal (Pos.At (2), v.Y); @@ -294,7 +294,7 @@ public void AbsoluteLayout_Constructor () // That is correct it should be 0,0 because AutoSize is false // and the size wasn't set on the initializer Assert.Equal (new Rectangle (frame.X, frame.Y, 0, 0), v.Frame); - Assert.Equal (new Rectangle (0, 0, 0, 0), v.Bounds); // With Absolute Bounds *is* deterministic before Layout + Assert.Equal (new Rectangle (0, 0, 0, 0), v.ContentArea); // With Absolute Bounds *is* deterministic before Layout Assert.Equal (Pos.At (1), v.X); Assert.Equal (Pos.At (2), v.Y); Assert.Equal (Dim.Sized (0), v.Width); @@ -304,7 +304,7 @@ public void AbsoluteLayout_Constructor () v = new View (); Assert.True (v.LayoutStyle == LayoutStyle.Absolute); Assert.Equal (new Rectangle (0, 0, 0, 0), v.Frame); - Assert.Equal (new Rectangle (0, 0, 0, 0), v.Bounds); // With Absolute Bounds *is* deterministic before Layout + Assert.Equal (new Rectangle (0, 0, 0, 0), v.ContentArea); // With Absolute Bounds *is* deterministic before Layout Assert.Equal (Pos.At (0), v.X); Assert.Equal (Pos.At (0), v.Y); Assert.Equal (Dim.Sized (0), v.Width); @@ -314,7 +314,7 @@ public void AbsoluteLayout_Constructor () v = new View { X = frame.X, Y = frame.Y, Width = frame.Width, Height = frame.Height }; Assert.True (v.LayoutStyle == LayoutStyle.Absolute); Assert.Equal (new Rectangle (frame.X, frame.Y, 3, 4), v.Frame); - Assert.Equal (new Rectangle (0, 0, 3, 4), v.Bounds); // With Absolute Bounds *is* deterministic before Layout + Assert.Equal (new Rectangle (0, 0, 3, 4), v.ContentArea); // With Absolute Bounds *is* deterministic before Layout Assert.Equal (Pos.At (1), v.X); Assert.Equal (Pos.At (2), v.Y); Assert.Equal (Dim.Sized (3), v.Width); @@ -353,8 +353,8 @@ public void AbsoluteLayout_Setting_Bounds_Location_NotEmpty () var frame = new Rectangle (1, 2, 3, 4); var newBounds = new Rectangle (10, 20, 30, 40); var view = new View { Frame = frame }; - view.Bounds = newBounds; - Assert.Equal (new Rectangle (0, 0, 30, 40), view.Bounds); + view.ContentArea = newBounds; + Assert.Equal (new Rectangle (0, 0, 30, 40), view.ContentArea); Assert.Equal (new Rectangle (1, 2, 30, 40), view.Frame); } @@ -367,21 +367,21 @@ public void AbsoluteLayout_Setting_Bounds_Sets_Frame () var v = new View { Frame = frame }; Assert.True (v.LayoutStyle == LayoutStyle.Absolute); - v.Bounds = newBounds; + v.ContentArea = newBounds; Assert.True (v.LayoutStyle == LayoutStyle.Absolute); - Assert.Equal (newBounds, v.Bounds); + Assert.Equal (newBounds, v.ContentArea); Assert.Equal (new Rectangle (1, 2, newBounds.Width, newBounds.Height), v.Frame); - Assert.Equal (new Rectangle (0, 0, newBounds.Width, newBounds.Height), v.Bounds); + Assert.Equal (new Rectangle (0, 0, newBounds.Width, newBounds.Height), v.ContentArea); Assert.Equal (Pos.At (1), v.X); Assert.Equal (Pos.At (2), v.Y); Assert.Equal (Dim.Sized (30), v.Width); Assert.Equal (Dim.Sized (40), v.Height); newBounds = new Rectangle (0, 0, 3, 4); - v.Bounds = newBounds; - Assert.Equal (newBounds, v.Bounds); + v.ContentArea = newBounds; + Assert.Equal (newBounds, v.ContentArea); Assert.Equal (new Rectangle (1, 2, newBounds.Width, newBounds.Height), v.Frame); - Assert.Equal (new Rectangle (0, 0, newBounds.Width, newBounds.Height), v.Bounds); + Assert.Equal (new Rectangle (0, 0, newBounds.Width, newBounds.Height), v.ContentArea); Assert.Equal (Pos.At (1), v.X); Assert.Equal (Pos.At (2), v.Y); Assert.Equal (Dim.Sized (3), v.Width); @@ -390,7 +390,7 @@ public void AbsoluteLayout_Setting_Bounds_Sets_Frame () v.BorderStyle = LineStyle.Single; // Bounds should shrink - Assert.Equal (new Rectangle (0, 0, 1, 2), v.Bounds); + Assert.Equal (new Rectangle (0, 0, 1, 2), v.ContentArea); // Frame should not change Assert.Equal (new Rectangle (1, 2, 3, 4), v.Frame); @@ -401,12 +401,12 @@ public void AbsoluteLayout_Setting_Bounds_Sets_Frame () // Now set bounds bigger as before newBounds = new Rectangle (0, 0, 3, 4); - v.Bounds = newBounds; - Assert.Equal (newBounds, v.Bounds); + v.ContentArea = newBounds; + Assert.Equal (newBounds, v.ContentArea); // Frame grows because there's now a border Assert.Equal (new Rectangle (1, 2, 5, 6), v.Frame); - Assert.Equal (new Rectangle (0, 0, newBounds.Width, newBounds.Height), v.Bounds); + Assert.Equal (new Rectangle (0, 0, newBounds.Width, newBounds.Height), v.ContentArea); Assert.Equal (Pos.At (1), v.X); Assert.Equal (Pos.At (2), v.Y); Assert.Equal (Dim.Sized (5), v.Width); diff --git a/UnitTests/View/Layout/DimTests.cs b/UnitTests/View/Layout/DimTests.cs index 43fa36603d..55d74cecb7 100644 --- a/UnitTests/View/Layout/DimTests.cs +++ b/UnitTests/View/Layout/DimTests.cs @@ -39,7 +39,7 @@ public void Dim_Add_Operator () if (k.KeyCode == KeyCode.Enter) { field.Text = $"Label {count}"; - var label = new Label { X = 0, Y = view.Bounds.Height, /*Width = 20,*/ Text = field.Text }; + var label = new Label { X = 0, Y = view.ContentArea.Height, /*Width = 20,*/ Text = field.Text }; view.Add (label); Assert.Equal ($"Label {count}", label.Text); Assert.Equal ($"Absolute({count})", label.Y.ToString ()); @@ -112,7 +112,7 @@ public void Dim_Subtract_Operator () for (var i = 0; i < count; i++) { field.Text = $"Label {i}"; - var label = new Label { X = 0, Y = view.Bounds.Height, /*Width = 20,*/ Text = field.Text }; + var label = new Label { X = 0, Y = view.ContentArea.Height, /*Width = 20,*/ Text = field.Text }; view.Add (label); Assert.Equal ($"Label {i}", label.Text); Assert.Equal ($"Absolute({i})", label.Y.ToString ()); @@ -615,45 +615,45 @@ public void Only_DimAbsolute_And_DimFactor_As_A_Different_Procedure_For_Assignin t.Ready += (s, e) => { - Assert.Equal ("Absolute(100)", w.Width.ToString ()); - Assert.Equal ("Absolute(100)", w.Height.ToString ()); - Assert.Equal (100, w.Frame.Width); - Assert.Equal (100, w.Frame.Height); - - Assert.Equal ("Factor(0.5,False)", f1.Width.ToString ()); - Assert.Equal ("Absolute(5)", f1.Height.ToString ()); - Assert.Equal (49, f1.Frame.Width); // 50-1=49 - Assert.Equal (5, f1.Frame.Height); - - Assert.Equal ("Fill(0)", f2.Width.ToString ()); - Assert.Equal ("Absolute(5)", f2.Height.ToString ()); - Assert.Equal (49, f2.Frame.Width); // 50-1=49 - Assert.Equal (5, f2.Frame.Height); - - #if DEBUG + Assert.Equal ("Absolute(100)", w.Width.ToString ()); + Assert.Equal ("Absolute(100)", w.Height.ToString ()); + Assert.Equal (100, w.Frame.Width); + Assert.Equal (100, w.Frame.Height); + + Assert.Equal ("Factor(0.5,False)", f1.Width.ToString ()); + Assert.Equal ("Absolute(5)", f1.Height.ToString ()); + Assert.Equal (49, f1.Frame.Width); // 50-1=49 + Assert.Equal (5, f1.Frame.Height); + + Assert.Equal ("Fill(0)", f2.Width.ToString ()); + Assert.Equal ("Absolute(5)", f2.Height.ToString ()); + Assert.Equal (49, f2.Frame.Width); // 50-1=49 + Assert.Equal (5, f2.Frame.Height); + +#if DEBUG Assert.Equal ($"Combine(View(Width,FrameView(f1){f1.Border.Frame})-Absolute(2))", v1.Width.ToString ()); - #else +#else Assert.Equal ($"Combine(View(Width,FrameView(){f1.Border.Frame})-Absolute(2))", v1.Width.ToString ()); - #endif +#endif Assert.Equal ("Combine(Fill(0)-Absolute(2))", v1.Height.ToString ()); Assert.Equal (47, v1.Frame.Width); // 49-2=47 Assert.Equal (89, v1.Frame.Height); // 98-5-2-2=89 - #if DEBUG +#if DEBUG Assert.Equal ( $"Combine(View(Width,FrameView(f2){f2.Frame})-Absolute(2))", v2.Width.ToString () - #else +#else Assert.Equal ( $"Combine(View(Width,FrameView(){f2.Frame})-Absolute(2))", v2.Width.ToString () - #endif +#endif ); - #if DEBUG +#if DEBUG Assert.Equal ("Combine(Fill(0)-Absolute(2))", v2.Height.ToString ()); - #else +#else Assert.Equal ("Combine(Fill(0)-Absolute(2))", v2.Height.ToString ()); - #endif +#endif Assert.Equal (47, v2.Frame.Width); // 49-2=47 Assert.Equal (89, v2.Frame.Height); // 98-5-2-2=89 @@ -666,17 +666,17 @@ public void Only_DimAbsolute_And_DimFactor_As_A_Different_Procedure_For_Assignin Assert.Equal ("Absolute(50)", v4.Height.ToString ()); Assert.Equal (50, v4.Frame.Width); Assert.Equal (50, v4.Frame.Height); - #if DEBUG - Assert.Equal ($"Combine(View(Width,Button(v1){v1.Frame})-View(Width,Button(v3){v3.Bounds}))", v5.Width.ToString ()); - #else +#if DEBUG + Assert.Equal ($"Combine(View(Width,Button(v1){v1.Frame})-View(Width,Button(v3){v3.ContentArea}))", v5.Width.ToString ()); +#else Assert.Equal ("Combine(View(Height,Button()(2,7,47,89))-View(Height,Button()(0,0,9,9)))", v5.Height.ToString ( )); - #endif - Assert.Equal (38, v5.Frame.Width); // 47-9=38 +#endif + Assert.Equal (38, v5.Frame.Width); // 47-9=38 Assert.Equal (80, v5.Frame.Height); // 89-9=80 Assert.Equal ("Factor(0.2,True)", v6.Width.ToString ()); Assert.Equal ("Factor(0.2,True)", v6.Height.ToString ()); - Assert.Equal (9, v6.Frame.Width); // 47*20%=9 + Assert.Equal (9, v6.Frame.Width); // 47*20%=9 Assert.Equal (18, v6.Frame.Height); // 89*20%=18 w.Width = 200; @@ -702,24 +702,24 @@ public void Only_DimAbsolute_And_DimFactor_As_A_Different_Procedure_For_Assignin Assert.Equal (5, f2.Frame.Height); v1.Text = "Button1"; - #if DEBUG +#if DEBUG Assert.Equal ($"Combine(View(Width,FrameView(f1){f1.Frame})-Absolute(2))", v1.Width.ToString ()); - #else +#else Assert.Equal ("Combine(View(Width,FrameView()(0,0,99,5))-Absolute(2))", v1.Width.ToString ()); - #endif +#endif Assert.Equal ("Combine(Fill(0)-Absolute(2))", v1.Height.ToString ()); - Assert.Equal (97, v1.Frame.Width); // 99-2=97 + Assert.Equal (97, v1.Frame.Width); // 99-2=97 Assert.Equal (189, v1.Frame.Height); // 198-2-7=189 v2.Text = "Button2"; - #if DEBUG - Assert.Equal ( $"Combine(View(Width,FrameView(f2){f2.Frame})-Absolute(2))", v2.Width.ToString ()); - #else +#if DEBUG + Assert.Equal ($"Combine(View(Width,FrameView(f2){f2.Frame})-Absolute(2))", v2.Width.ToString ()); +#else Assert.Equal ( "Combine(View(Width,FrameView()(99,0,99,5))-Absolute(2))", v2.Width.ToString ()); - #endif +#endif Assert.Equal ("Combine(Fill(0)-Absolute(2))", v2.Height.ToString ()); - Assert.Equal (97, v2.Frame.Width); // 99-2=97 + Assert.Equal (97, v2.Frame.Width); // 99-2=97 Assert.Equal (189, v2.Frame.Height); // 198-2-7=189 v3.Text = "Button3"; @@ -727,7 +727,8 @@ public void Only_DimAbsolute_And_DimFactor_As_A_Different_Procedure_For_Assignin Assert.Equal ("Factor(0.1,False)", v3.Height.ToString ()); // 198*10%=19 * Percent is related to the super-view if it isn't null otherwise the view width - Assert.Equal (19, v3.Frame.Width ); + Assert.Equal (19, v3.Frame.Width); + // 199*10%=19 Assert.Equal (19, v3.Frame.Height); @@ -745,21 +746,21 @@ public void Only_DimAbsolute_And_DimFactor_As_A_Different_Procedure_For_Assignin v5.Text = "Button5"; - #if DEBUG +#if DEBUG Assert.Equal ($"Combine(View(Width,Button(v1){v1.Frame})-View(Width,Button(v3){v3.Frame}))", v5.Width.ToString ()); Assert.Equal ($"Combine(View(Height,Button(v1){v1.Frame})-View(Height,Button(v3){v3.Frame}))", v5.Height.ToString ()); - #else +#else Assert.Equal ("Combine(View(Width,Button()(2,7,97,189))-View(Width,Button()(0,0,19,19)))", v5.Width.ToString ()); Assert.Equal ("Combine(View(Height,Button()(2,7,97,189))-View(Height,Button()(0,0,19,19)))", v5.Height.ToString ()); - #endif +#endif - Assert.Equal (78, v5.Frame.Width); // 97-9=78 + Assert.Equal (78, v5.Frame.Width); // 97-9=78 Assert.Equal (170, v5.Frame.Height); // 189-19=170 v6.Text = "Button6"; Assert.Equal ("Factor(0.2,True)", v6.Width.ToString ()); Assert.Equal ("Factor(0.2,True)", v6.Height.ToString ()); - Assert.Equal (19, v6.Frame.Width); // 99*20%=19 + Assert.Equal (19, v6.Frame.Width); // 99*20%=19 Assert.Equal (38, v6.Frame.Height); // 198-7*20=18 }; diff --git a/UnitTests/View/Layout/PosTests.cs b/UnitTests/View/Layout/PosTests.cs index 644e4580e3..d63e11473a 100644 --- a/UnitTests/View/Layout/PosTests.cs +++ b/UnitTests/View/Layout/PosTests.cs @@ -116,11 +116,11 @@ public void AnchorEnd_View_And_Button () var b = $"{CM.Glyphs.LeftBracket} Ok {CM.Glyphs.RightBracket}"; var frame = new FrameView { Width = 18, Height = 3 }; - Assert.Equal (16, frame.Bounds.Width); + Assert.Equal (16, frame.ContentArea.Width); Button btn = null; - int Btn_Width () { return btn?.Bounds.Width ?? 0; } + int Btn_Width () { return btn?.ContentArea.Width ?? 0; } btn = new Button { Text = "Ok", X = Pos.AnchorEnd () - Pos.Function (Btn_Width) }; @@ -140,13 +140,13 @@ public void AnchorEnd_View_And_Button () frame.EndInit (); frame.Draw (); - Assert.Equal (6, btn.Bounds.Width); + Assert.Equal (6, btn.ContentArea.Width); Assert.Equal (10, btn.Frame.X); // frame.Bounds.Width (16) - btn.Frame.Width (6) = 10 Assert.Equal (0, btn.Frame.Y); Assert.Equal (6, btn.Frame.Width); Assert.Equal (1, btn.Frame.Height); - Assert.Equal (9, view.Bounds.Width); // frame.Bounds.Width (16) - Dim.Fill (1) - Dim.Function (6) = 9 + Assert.Equal (9, view.ContentArea.Width); // frame.Bounds.Width (16) - Dim.Fill (1) - Dim.Function (6) = 9 Assert.Equal (0, view.Frame.X); Assert.Equal (0, view.Frame.Y); Assert.Equal (9, view.Frame.Width); diff --git a/UnitTests/View/Layout/SetRelativeLayoutTests.cs b/UnitTests/View/Layout/SetRelativeLayoutTests.cs index cfd0288208..26d3a31695 100644 --- a/UnitTests/View/Layout/SetRelativeLayoutTests.cs +++ b/UnitTests/View/Layout/SetRelativeLayoutTests.cs @@ -54,10 +54,10 @@ public void DimFill_Is_Honored () Assert.Equal (1, view.Frame.Y); Assert.Equal (79, view.Frame.Width); Assert.Equal (24, view.Frame.Height); - Assert.Equal (0, view.Bounds.X); - Assert.Equal (0, view.Bounds.Y); - Assert.Equal (79, view.Bounds.Width); - Assert.Equal (24, view.Bounds.Height); + Assert.Equal (0, view.ContentArea.X); + Assert.Equal (0, view.ContentArea.Y); + Assert.Equal (79, view.ContentArea.Width); + Assert.Equal (24, view.ContentArea.Height); view.X = 0; view.Y = 0; @@ -68,10 +68,10 @@ public void DimFill_Is_Honored () Assert.Equal (0, view.Frame.Y); Assert.Equal (80, view.Frame.Width); Assert.Equal (25, view.Frame.Height); - Assert.Equal (0, view.Bounds.X); - Assert.Equal (0, view.Bounds.Y); - Assert.Equal (80, view.Bounds.Width); - Assert.Equal (25, view.Bounds.Height); + Assert.Equal (0, view.ContentArea.X); + Assert.Equal (0, view.ContentArea.Y); + Assert.Equal (80, view.ContentArea.Width); + Assert.Equal (25, view.ContentArea.Height); } [Fact] diff --git a/UnitTests/View/SubviewTests.cs b/UnitTests/View/SubviewTests.cs index d4f730c958..429891b171 100644 --- a/UnitTests/View/SubviewTests.cs +++ b/UnitTests/View/SubviewTests.cs @@ -1,5 +1,4 @@ -using System.Text; -using Xunit.Abstractions; +using Xunit.Abstractions; namespace Terminal.Gui.ViewTests; @@ -75,7 +74,7 @@ public void GetTopSuperView_Test () w2.Dispose (); top2.Dispose (); } - + [Fact] [TestRespondersDisposed] public void Initialized_Event_Comparing_With_Added_Event () @@ -151,8 +150,8 @@ public void Initialized_Event_Comparing_With_Added_Event () winAddedToTop.Initialized += (s, e) => { wc++; - Assert.Equal (top.Bounds.Width, winAddedToTop.Frame.Width); - Assert.Equal (top.Bounds.Height, winAddedToTop.Frame.Height); + Assert.Equal (top.ContentArea.Width, winAddedToTop.Frame.Width); + Assert.Equal (top.ContentArea.Height, winAddedToTop.Frame.Height); }; v1AddedToWin.Initialized += (s, e) => @@ -258,8 +257,8 @@ public void Initialized_Event_Will_Be_Invoked_When_Added_Dynamically () w.Initialized += (s, e) => { wc++; - Assert.Equal (t.Bounds.Width, w.Frame.Width); - Assert.Equal (t.Bounds.Height, w.Frame.Height); + Assert.Equal (t.ContentArea.Width, w.Frame.Width); + Assert.Equal (t.ContentArea.Height, w.Frame.Height); }; v1.Initialized += (s, e) => diff --git a/UnitTests/View/Text/AutoSizeFalseTests.cs b/UnitTests/View/Text/AutoSizeFalseTests.cs index 2065907002..219c37c6d8 100644 --- a/UnitTests/View/Text/AutoSizeFalseTests.cs +++ b/UnitTests/View/Text/AutoSizeFalseTests.cs @@ -145,7 +145,7 @@ public void AutoSize_False_ResizeView_Is_Always_False () Rectangle expectedViewBounds = new (0, 0, 0, 0); Assert.False (view.AutoSize); - Assert.Equal (expectedViewBounds, view.Bounds); + Assert.Equal (expectedViewBounds, view.ContentArea); super.Dispose (); } @@ -162,7 +162,7 @@ public void AutoSize_False_ResizeView_With_Dim_Fill_After_IsInitialized () Rectangle expectedViewBounds = new (0, 0, 30, 80); Assert.False (view.AutoSize); - Assert.Equal (expectedViewBounds, view.Bounds); + Assert.Equal (expectedViewBounds, view.ContentArea); Assert.False (view.IsInitialized); super.BeginInit (); @@ -170,7 +170,7 @@ public void AutoSize_False_ResizeView_With_Dim_Fill_After_IsInitialized () Assert.True (view.IsInitialized); Assert.False (view.AutoSize); - Assert.Equal (expectedViewBounds, view.Bounds); + Assert.Equal (expectedViewBounds, view.ContentArea); } [Fact] diff --git a/UnitTests/View/Text/AutoSizeTrueTests.cs b/UnitTests/View/Text/AutoSizeTrueTests.cs index 5b438de6f5..c57d6b55d0 100644 --- a/UnitTests/View/Text/AutoSizeTrueTests.cs +++ b/UnitTests/View/Text/AutoSizeTrueTests.cs @@ -585,7 +585,7 @@ public void AutoSize_Dim_Add_Operator_With_Text () field.Text = $"Label {count}"; // Label is AutoSize = true - var label = new Label { Text = field.Text, X = 0, Y = view.Bounds.Height /*, Width = 10*/ }; + var label = new Label { Text = field.Text, X = 0, Y = view.ContentArea.Height /*, Width = 10*/ }; view.Add (label); Assert.Equal ($"Label {count}", label.Text); Assert.Equal ($"Absolute({count + 1})", label.Y.ToString ()); @@ -868,16 +868,16 @@ public void AutoSize_False_SetWidthHeight_With_Dim_Fill_And_Dim_Absolute_With_In win.EndInit (); Assert.True (label.AutoSize); - Rectangle expectedLabelBounds = Rectangle.Empty; - Assert.Equal (expectedLabelBounds, label.Bounds); + var expectedLabelBounds = Rectangle.Empty; + Assert.Equal (expectedLabelBounds, label.ContentArea); Assert.True (label.AutoSize); label.Text = "First line\nSecond line"; win.LayoutSubviews (); - expectedLabelBounds = new (0, 0, 11, 2); + expectedLabelBounds = new Rectangle (0, 0, 11, 2); Assert.True (label.AutoSize); - Assert.Equal (expectedLabelBounds, label.Bounds); + Assert.Equal (expectedLabelBounds, label.ContentArea); label.AutoSize = false; label.Width = Dim.Fill (); @@ -887,9 +887,9 @@ public void AutoSize_False_SetWidthHeight_With_Dim_Fill_And_Dim_Absolute_With_In // Here the SetMinWidthHeight ensuring the minimum height // #3127: After: (0,0,28,2) because turning off AutoSize leaves // Height set to 2. - expectedLabelBounds = new (0, 0, 28, 2); + expectedLabelBounds = new Rectangle (0, 0, 28, 2); Assert.False (label.AutoSize); - Assert.Equal (expectedLabelBounds, label.Bounds); + Assert.Equal (expectedLabelBounds, label.ContentArea); label.Text = "First changed line\nSecond changed line\nNew line"; win.LayoutSubviews (); @@ -897,9 +897,9 @@ public void AutoSize_False_SetWidthHeight_With_Dim_Fill_And_Dim_Absolute_With_In // Here the AutoSize is false and the width 28 (Dim.Fill) and // #3127: Before: height 1 because it wasn't set and SetMinWidthHeight ensuring the minimum height // #3127: After: (0,0,28,2) because setting Text leaves Height set to 2. - expectedLabelBounds = new (0, 0, 28, 2); + expectedLabelBounds = new Rectangle (0, 0, 28, 2); Assert.False (label.AutoSize); - Assert.Equal (expectedLabelBounds, label.Bounds); + Assert.Equal (expectedLabelBounds, label.ContentArea); label.AutoSize = true; @@ -907,9 +907,9 @@ public void AutoSize_False_SetWidthHeight_With_Dim_Fill_And_Dim_Absolute_With_In // Here the AutoSize ensuring the right size with width 19 (width of longest line) // and height 3 because the text has 3 lines - expectedLabelBounds = new (0, 0, 19, 3); + expectedLabelBounds = new Rectangle (0, 0, 19, 3); Assert.True (label.AutoSize); - Assert.Equal (expectedLabelBounds, label.Bounds); + Assert.Equal (expectedLabelBounds, label.ContentArea); } [Fact] @@ -1492,7 +1492,7 @@ public void AutoSize_True_ResizeView_With_Dim_Absolute () Assert.True (label.AutoSize); Rectangle expectedLabelBounds = new (0, 0, 8, 1); - Assert.Equal (expectedLabelBounds, label.Bounds); + Assert.Equal (expectedLabelBounds, label.ContentArea); super.Dispose (); } @@ -2350,320 +2350,320 @@ public void GetCurrentWidth_TrySetWidth () top.Dispose (); } - // [Fact] - // [AutoInitShutdown] - // public void AutoSize_False_TextDirection_Toggle () - // { - // var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () }; - // // View is AutoSize == true - // var view = new View (); - // win.Add (view); - // Application.Top.Add (win); - - // var rs = Application.Begin (Application.Top); - // ((FakeDriver)Application.Driver).SetBufferSize (22, 22); - - // Assert.Equal (new Rectangle (0, 0, 22, 22), win.Frame); - // Assert.Equal (new Rectangle (0, 0, 22, 22), win.Margin.Frame); - // Assert.Equal (new Rectangle (0, 0, 22, 22), win.Border.Frame); - // Assert.Equal (new Rectangle (1, 1, 20, 20), win.Padding.Frame); - // Assert.False (view.AutoSize); - // Assert.Equal (TextDirection.LeftRight_TopBottom, view.TextDirection); - // Assert.Equal (Rect.Empty, view.Frame); - // Assert.Equal ("Absolute(0)", view.X.ToString ()); - // Assert.Equal ("Absolute(0)", view.Y.ToString ()); - // Assert.Equal ("Absolute(0)", view.Width.ToString ()); - // Assert.Equal ("Absolute(0)", view.Height.ToString ()); - // var expected = @" - //┌────────────────────┐ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //└────────────────────┘ - //"; - - // var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rectangle (0, 0, 22, 22), pos); - - // view.Text = "Hello World"; - // view.Width = 11; - // view.Height = 1; - // win.LayoutSubviews (); - // Application.Refresh (); - - // Assert.Equal (new Rectangle (0, 0, 11, 1), view.Frame); - // Assert.Equal ("Absolute(0)", view.X.ToString ()); - // Assert.Equal ("Absolute(0)", view.Y.ToString ()); - // Assert.Equal ("Absolute(11)", view.Width.ToString ()); - // Assert.Equal ("Absolute(1)", view.Height.ToString ()); - // expected = @" - //┌────────────────────┐ - //│Hello World │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //└────────────────────┘ - //"; - - // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rectangle (0, 0, 22, 22), pos); - - // view.AutoSize = true; - // view.Text = "Hello Worlds"; - // Application.Refresh (); - - // Assert.Equal (new Rectangle (0, 0, 12, 1), view.Frame); - // Assert.Equal ("Absolute(0)", view.X.ToString ()); - // Assert.Equal ("Absolute(0)", view.Y.ToString ()); - // Assert.Equal ("Absolute(11)", view.Width.ToString ()); - // Assert.Equal ("Absolute(1)", view.Height.ToString ()); - // expected = @" - //┌────────────────────┐ - //│Hello Worlds │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //└────────────────────┘ - //"; - - // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rectangle (0, 0, 22, 22), pos); - - // view.TextDirection = TextDirection.TopBottom_LeftRight; - // Application.Refresh (); - - // Assert.Equal (new Rectangle (0, 0, 11, 12), view.Frame); - // Assert.Equal ("Absolute(0)", view.X.ToString ()); - // Assert.Equal ("Absolute(0)", view.Y.ToString ()); - // Assert.Equal ("Absolute(11)", view.Width.ToString ()); - // Assert.Equal ("Absolute(1)", view.Height.ToString ()); - // expected = @" - //┌────────────────────┐ - //│H │ - //│e │ - //│l │ - //│l │ - //│o │ - //│ │ - //│W │ - //│o │ - //│r │ - //│l │ - //│d │ - //│s │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //└────────────────────┘ - //"; - - // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rectangle (0, 0, 22, 22), pos); - - // view.AutoSize = false; - // view.Height = 1; - // Application.Refresh (); - - // Assert.Equal (new Rectangle (0, 0, 11, 1), view.Frame); - // Assert.Equal ("Absolute(0)", view.X.ToString ()); - // Assert.Equal ("Absolute(0)", view.Y.ToString ()); - // Assert.Equal ("Absolute(11)", view.Width.ToString ()); - // Assert.Equal ("Absolute(1)", view.Height.ToString ()); - // expected = @" - //┌────────────────────┐ - //│HelloWorlds │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //└────────────────────┘ - //"; - - // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rectangle (0, 0, 22, 22), pos); - - // view.PreserveTrailingSpaces = true; - // Application.Refresh (); - - // Assert.Equal (new Rectangle (0, 0, 11, 1), view.Frame); - // Assert.Equal ("Absolute(0)", view.X.ToString ()); - // Assert.Equal ("Absolute(0)", view.Y.ToString ()); - // Assert.Equal ("Absolute(11)", view.Width.ToString ()); - // Assert.Equal ("Absolute(1)", view.Height.ToString ()); - // expected = @" - //┌────────────────────┐ - //│Hello World │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //└────────────────────┘ - //"; - - // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rectangle (0, 0, 22, 22), pos); - - // view.PreserveTrailingSpaces = false; - // var f = view.Frame; - // view.Width = f.Height; - // view.Height = f.Width; - // view.TextDirection = TextDirection.TopBottom_LeftRight; - // Application.Refresh (); - - // Assert.Equal (new Rectangle (0, 0, 1, 11), view.Frame); - // Assert.Equal ("Absolute(0)", view.X.ToString ()); - // Assert.Equal ("Absolute(0)", view.Y.ToString ()); - // Assert.Equal ("Absolute(1)", view.Width.ToString ()); - // Assert.Equal ("Absolute(11)", view.Height.ToString ()); - // expected = @" - //┌────────────────────┐ - //│H │ - //│e │ - //│l │ - //│l │ - //│o │ - //│ │ - //│W │ - //│o │ - //│r │ - //│l │ - //│d │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //└────────────────────┘ - //"; - - // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rectangle (0, 0, 22, 22), pos); - - // view.AutoSize = true; - // Application.Refresh (); - - // Assert.Equal (new Rectangle (0, 0, 1, 12), view.Frame); - // Assert.Equal ("Absolute(0)", view.X.ToString ()); - // Assert.Equal ("Absolute(0)", view.Y.ToString ()); - // Assert.Equal ("Absolute(1)", view.Width.ToString ()); - // Assert.Equal ("Absolute(12)", view.Height.ToString ()); - // expected = @" - //┌────────────────────┐ - //│H │ - //│e │ - //│l │ - //│l │ - //│o │ - //│ │ - //│W │ - //│o │ - //│r │ - //│l │ - //│d │ - //│s │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //│ │ - //└────────────────────┘ - //"; - - // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rectangle (0, 0, 22, 22), pos); - // Application.End (rs); - // } +// [Fact] +// [AutoInitShutdown] +// public void AutoSize_False_TextDirection_Toggle () +// { +// var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () }; +// // View is AutoSize == true +// var view = new View (); +// win.Add (view); +// Application.Top.Add (win); + +// var rs = Application.Begin (Application.Top); +// ((FakeDriver)Application.Driver).SetBufferSize (22, 22); + +// Assert.Equal (new Rectangle (0, 0, 22, 22), win.Frame); +// Assert.Equal (new Rectangle (0, 0, 22, 22), win.Margin.Frame); +// Assert.Equal (new Rectangle (0, 0, 22, 22), win.Border.Frame); +// Assert.Equal (new Rectangle (1, 1, 20, 20), win.Padding.Frame); +// Assert.False (view.AutoSize); +// Assert.Equal (TextDirection.LeftRight_TopBottom, view.TextDirection); +// Assert.Equal (Rectangle.Empty, view.Frame); +// Assert.Equal ("Absolute(0)", view.X.ToString ()); +// Assert.Equal ("Absolute(0)", view.Y.ToString ()); +// Assert.Equal ("Absolute(0)", view.Width.ToString ()); +// Assert.Equal ("Absolute(0)", view.Height.ToString ()); +// var expected = @" +//┌────────────────────┐ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//└────────────────────┘ +//"; + +// var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); +// Assert.Equal (new Rectangle (0, 0, 22, 22), pos); + +// view.Text = "Hello World"; +// view.Width = 11; +// view.Height = 1; +// win.LayoutSubviews (); +// Application.Refresh (); + +// Assert.Equal (new Rectangle (0, 0, 11, 1), view.Frame); +// Assert.Equal ("Absolute(0)", view.X.ToString ()); +// Assert.Equal ("Absolute(0)", view.Y.ToString ()); +// Assert.Equal ("Absolute(11)", view.Width.ToString ()); +// Assert.Equal ("Absolute(1)", view.Height.ToString ()); +// expected = @" +//┌────────────────────┐ +//│Hello World │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//└────────────────────┘ +//"; + +// pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); +// Assert.Equal (new Rectangle (0, 0, 22, 22), pos); + +// view.AutoSize = true; +// view.Text = "Hello Worlds"; +// Application.Refresh (); + +// Assert.Equal (new Rectangle (0, 0, 12, 1), view.Frame); +// Assert.Equal ("Absolute(0)", view.X.ToString ()); +// Assert.Equal ("Absolute(0)", view.Y.ToString ()); +// Assert.Equal ("Absolute(11)", view.Width.ToString ()); +// Assert.Equal ("Absolute(1)", view.Height.ToString ()); +// expected = @" +//┌────────────────────┐ +//│Hello Worlds │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//└────────────────────┘ +//"; + +// pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); +// Assert.Equal (new Rectangle (0, 0, 22, 22), pos); + +// view.TextDirection = TextDirection.TopBottom_LeftRight; +// Application.Refresh (); + +// Assert.Equal (new Rectangle (0, 0, 11, 12), view.Frame); +// Assert.Equal ("Absolute(0)", view.X.ToString ()); +// Assert.Equal ("Absolute(0)", view.Y.ToString ()); +// Assert.Equal ("Absolute(11)", view.Width.ToString ()); +// Assert.Equal ("Absolute(1)", view.Height.ToString ()); +// expected = @" +//┌────────────────────┐ +//│H │ +//│e │ +//│l │ +//│l │ +//│o │ +//│ │ +//│W │ +//│o │ +//│r │ +//│l │ +//│d │ +//│s │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//└────────────────────┘ +//"; + +// pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); +// Assert.Equal (new Rectangle (0, 0, 22, 22), pos); + +// view.AutoSize = false; +// view.Height = 1; +// Application.Refresh (); + +// Assert.Equal (new Rectangle (0, 0, 11, 1), view.Frame); +// Assert.Equal ("Absolute(0)", view.X.ToString ()); +// Assert.Equal ("Absolute(0)", view.Y.ToString ()); +// Assert.Equal ("Absolute(11)", view.Width.ToString ()); +// Assert.Equal ("Absolute(1)", view.Height.ToString ()); +// expected = @" +//┌────────────────────┐ +//│HelloWorlds │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//└────────────────────┘ +//"; + +// pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); +// Assert.Equal (new Rectangle (0, 0, 22, 22), pos); + +// view.PreserveTrailingSpaces = true; +// Application.Refresh (); + +// Assert.Equal (new Rectangle (0, 0, 11, 1), view.Frame); +// Assert.Equal ("Absolute(0)", view.X.ToString ()); +// Assert.Equal ("Absolute(0)", view.Y.ToString ()); +// Assert.Equal ("Absolute(11)", view.Width.ToString ()); +// Assert.Equal ("Absolute(1)", view.Height.ToString ()); +// expected = @" +//┌────────────────────┐ +//│Hello World │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//└────────────────────┘ +//"; + +// pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); +// Assert.Equal (new Rectangle (0, 0, 22, 22), pos); + +// view.PreserveTrailingSpaces = false; +// var f = view.Frame; +// view.Width = f.Height; +// view.Height = f.Width; +// view.TextDirection = TextDirection.TopBottom_LeftRight; +// Application.Refresh (); + +// Assert.Equal (new Rectangle (0, 0, 1, 11), view.Frame); +// Assert.Equal ("Absolute(0)", view.X.ToString ()); +// Assert.Equal ("Absolute(0)", view.Y.ToString ()); +// Assert.Equal ("Absolute(1)", view.Width.ToString ()); +// Assert.Equal ("Absolute(11)", view.Height.ToString ()); +// expected = @" +//┌────────────────────┐ +//│H │ +//│e │ +//│l │ +//│l │ +//│o │ +//│ │ +//│W │ +//│o │ +//│r │ +//│l │ +//│d │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//└────────────────────┘ +//"; + +// pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); +// Assert.Equal (new Rectangle (0, 0, 22, 22), pos); + +// view.AutoSize = true; +// Application.Refresh (); + +// Assert.Equal (new Rectangle (0, 0, 1, 12), view.Frame); +// Assert.Equal ("Absolute(0)", view.X.ToString ()); +// Assert.Equal ("Absolute(0)", view.Y.ToString ()); +// Assert.Equal ("Absolute(1)", view.Width.ToString ()); +// Assert.Equal ("Absolute(12)", view.Height.ToString ()); +// expected = @" +//┌────────────────────┐ +//│H │ +//│e │ +//│l │ +//│l │ +//│o │ +//│ │ +//│W │ +//│o │ +//│r │ +//│l │ +//│d │ +//│s │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//│ │ +//└────────────────────┘ +//"; + +// pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); +// Assert.Equal (new Rectangle (0, 0, 22, 22), pos); +// Application.End (rs); +// } [Fact] [AutoInitShutdown] @@ -2684,7 +2684,6 @@ public void GetTextFormatterBoundsSize_GetSizeNeededForText_HotKeySpecifier () verticalView.Text = text; verticalView.TextFormatter.HotKeySpecifier = (Rune)'_'; - Application.Top.Add (horizontalView, verticalView); Application.Begin (Application.Top); ((FakeDriver)Application.Driver).SetBufferSize (50, 50); diff --git a/UnitTests/View/ViewTests.cs b/UnitTests/View/ViewTests.cs index fa8702bc34..2431c92c8b 100644 --- a/UnitTests/View/ViewTests.cs +++ b/UnitTests/View/ViewTests.cs @@ -9,6 +9,43 @@ public class ViewTests private readonly ITestOutputHelper _output; public ViewTests (ITestOutputHelper output) { _output = output; } + [Fact] + public void Accept_Cancel_Event_OnAccept_Returns_True () + { + var view = new View (); + var acceptInvoked = false; + + view.Accept += ViewOnAccept; + + bool? ret = view.OnAccept (); + Assert.True (ret); + Assert.True (acceptInvoked); + + return; + + void ViewOnAccept (object sender, CancelEventArgs e) + { + acceptInvoked = true; + e.Cancel = true; + } + } + + [Fact] + public void Accept_Command_Invokes_Accept_Event () + { + var view = new View (); + var accepted = false; + + view.Accept += ViewOnAccept; + + view.InvokeCommand (Command.Accept); + Assert.True (accepted); + + return; + + void ViewOnAccept (object sender, CancelEventArgs e) { accepted = true; } + } + [Fact] [AutoInitShutdown] public void Clear_Bounds_Can_Use_Driver_AddRune_Or_AddStr_Methods () @@ -18,13 +55,13 @@ public void Clear_Bounds_Can_Use_Driver_AddRune_Or_AddStr_Methods () view.DrawContent += (s, e) => { Rectangle savedClip = Application.Driver.Clip; - Application.Driver.Clip = new Rectangle (1, 1, view.Bounds.Width, view.Bounds.Height); + Application.Driver.Clip = new Rectangle (1, 1, view.ContentArea.Width, view.ContentArea.Height); - for (var row = 0; row < view.Bounds.Height; row++) + for (var row = 0; row < view.ContentArea.Height; row++) { Application.Driver.Move (1, row + 1); - for (var col = 0; col < view.Bounds.Width; col++) + for (var col = 0; col < view.ContentArea.Width; col++) { Application.Driver.AddStr ($"{col}"); } @@ -71,13 +108,13 @@ public void Clear_Can_Use_Driver_AddRune_Or_AddStr_Methods () view.DrawContent += (s, e) => { Rectangle savedClip = Application.Driver.Clip; - Application.Driver.Clip = new Rectangle (1, 1, view.Bounds.Width, view.Bounds.Height); + Application.Driver.Clip = new Rectangle (1, 1, view.ContentArea.Width, view.ContentArea.Height); - for (var row = 0; row < view.Bounds.Height; row++) + for (var row = 0; row < view.ContentArea.Height; row++) { Application.Driver.Move (1, row + 1); - for (var col = 0; col < view.Bounds.Width; col++) + for (var col = 0; col < view.ContentArea.Width; col++) { Application.Driver.AddStr ($"{col}"); } @@ -230,7 +267,7 @@ A text with some long width view.Frame = new Rectangle (3, 3, 10, 1); Assert.Equal (new Rectangle (3, 3, 10, 1), view.Frame); Assert.Equal (LayoutStyle.Absolute, view.LayoutStyle); - Assert.Equal (new Rectangle (0, 0, 10, 1), view.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 1), view.ContentArea); Assert.Equal (new Rectangle (0, 0, 10, 1), view._needsDisplayRect); top.Draw (); @@ -279,7 +316,7 @@ A text with some long width view.Width = 10; view.Height = 1; Assert.Equal (new Rectangle (3, 3, 10, 1), view.Frame); - Assert.Equal (new Rectangle (0, 0, 10, 1), view.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 1), view.ContentArea); Assert.Equal (new Rectangle (0, 0, 30, 2), view._needsDisplayRect); top.Draw (); @@ -326,7 +363,7 @@ A text with some long width view.Frame = new Rectangle (1, 1, 10, 1); Assert.Equal (new Rectangle (1, 1, 10, 1), view.Frame); Assert.Equal (LayoutStyle.Absolute, view.LayoutStyle); - Assert.Equal (new Rectangle (0, 0, 10, 1), view.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 1), view.ContentArea); Assert.Equal (new Rectangle (0, 0, 10, 1), view._needsDisplayRect); top.Draw (); @@ -373,7 +410,7 @@ A text with some long width view.Width = 10; view.Height = 1; Assert.Equal (new Rectangle (1, 1, 10, 1), view.Frame); - Assert.Equal (new Rectangle (0, 0, 10, 1), view.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 1), view.ContentArea); Assert.Equal (new Rectangle (0, 0, 30, 2), view._needsDisplayRect); top.Draw (); @@ -470,11 +507,11 @@ public void Frame_Set_After_Initialize_Update_NeededDisplay () Assert.Equal ( new Rectangle (20, 8, 60, 16), new Rectangle ( - frame.Frame.Left, - frame.Frame.Top, - frame.Frame.Right, - frame.Frame.Bottom - ) + frame.Frame.Left, + frame.Frame.Top, + frame.Frame.Right, + frame.Frame.Bottom + ) ); Assert.Equal (new Rectangle (0, 0, 30, 1), label.Frame); Assert.Equal (new Rectangle (0, 1, 13, 1), button.Frame); // this proves frame was set @@ -507,6 +544,17 @@ public void GetNormalColor_ColorScheme () view.Dispose (); } + [Fact] + public void HotKey_Command_SetsFocus () + { + var view = new View (); + + view.CanFocus = true; + Assert.False (view.HasFocus); + view.InvokeCommand (Command.HotKey); + Assert.True (view.HasFocus); + } + [Fact] [AutoInitShutdown] public void Incorrect_Redraw_Bounds_NeedDisplay_On_Shrink_And_Move_Down_Right_Using_Frame () @@ -537,7 +585,7 @@ A text with some long width ); view.Frame = new Rectangle (3, 3, 10, 1); - Assert.Equal (new Rectangle (0, 0, 10, 1), view.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 1), view.ContentArea); Assert.Equal (new Rectangle (0, 0, 10, 1), view._needsDisplayRect); view.Draw (); @@ -586,7 +634,7 @@ A text with some long width view.Width = 10; view.Height = 1; Assert.Equal (new Rectangle (3, 3, 10, 1), view.Frame); - Assert.Equal (new Rectangle (0, 0, 10, 1), view.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 1), view.ContentArea); Assert.Equal (new Rectangle (0, 0, 30, 2), view._needsDisplayRect); view.Draw (); @@ -633,7 +681,7 @@ A text with some long width view.Frame = new Rectangle (1, 1, 10, 1); Assert.Equal (new Rectangle (1, 1, 10, 1), view.Frame); Assert.Equal (LayoutStyle.Absolute, view.LayoutStyle); - Assert.Equal (new Rectangle (0, 0, 10, 1), view.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 1), view.ContentArea); Assert.Equal (new Rectangle (0, 0, 10, 1), view._needsDisplayRect); view.Draw (); @@ -682,7 +730,7 @@ A text with some long width view.Width = 10; view.Height = 1; Assert.Equal (new Rectangle (1, 1, 10, 1), view.Frame); - Assert.Equal (new Rectangle (0, 0, 10, 1), view.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 1), view.ContentArea); Assert.Equal (new Rectangle (0, 0, 30, 2), view._needsDisplayRect); view.Draw (); @@ -704,21 +752,6 @@ public void Internal_Tests () var view = new View { Frame = rect }; } - [Fact] - [SetupFakeDriver] - public void SetText_RendersCorrectly () - { - View view; - var text = "test"; - - view = new Label { Text = text }; - view.BeginInit (); - view.EndInit (); - view.Draw (); - - TestHelpers.AssertDriverContentsWithFrameAre ( text, _output); - } - [Fact] [TestRespondersDisposed] public void New_Initializes () @@ -727,10 +760,10 @@ public void New_Initializes () var r = new View (); Assert.NotNull (r); Assert.Equal (LayoutStyle.Absolute, r.LayoutStyle); - Assert.Equal ($"View(){r.Bounds}", r.ToString ()); + Assert.Equal ($"View(){r.ContentArea}", r.ToString ()); Assert.False (r.CanFocus); Assert.False (r.HasFocus); - Assert.Equal (new Rectangle (0, 0, 0, 0), r.Bounds); + Assert.Equal (new Rectangle (0, 0, 0, 0), r.ContentArea); Assert.Equal (new Rectangle (0, 0, 0, 0), r.Frame); Assert.Null (r.Focused); Assert.Null (r.ColorScheme); @@ -752,10 +785,10 @@ public void New_Initializes () r = new View { Frame = Rectangle.Empty }; Assert.NotNull (r); Assert.Equal (LayoutStyle.Absolute, r.LayoutStyle); - Assert.Equal ($"View(){r.Bounds}", r.ToString ()); + Assert.Equal ($"View(){r.ContentArea}", r.ToString ()); Assert.False (r.CanFocus); Assert.False (r.HasFocus); - Assert.Equal (new Rectangle (0, 0, 0, 0), r.Bounds); + Assert.Equal (new Rectangle (0, 0, 0, 0), r.ContentArea); Assert.Equal (new Rectangle (0, 0, 0, 0), r.Frame); Assert.Null (r.Focused); Assert.Null (r.ColorScheme); @@ -780,7 +813,7 @@ public void New_Initializes () Assert.Equal ($"View(){r.Frame}", r.ToString ()); Assert.False (r.CanFocus); Assert.False (r.HasFocus); - Assert.Equal (new Rectangle (0, 0, 3, 4), r.Bounds); + Assert.Equal (new Rectangle (0, 0, 3, 4), r.ContentArea); Assert.Equal (new Rectangle (1, 2, 3, 4), r.Frame); Assert.Null (r.Focused); Assert.Null (r.ColorScheme); @@ -811,7 +844,7 @@ public void New_Initializes () r.EndInit (); Assert.False (r.CanFocus); Assert.False (r.HasFocus); - Assert.Equal (new Rectangle (0, 0, 1, 13), r.Bounds); + Assert.Equal (new Rectangle (0, 0, 1, 13), r.ContentArea); Assert.Equal (new Rectangle (0, 0, 1, 13), r.Frame); Assert.Null (r.Focused); Assert.Null (r.ColorScheme); @@ -857,6 +890,38 @@ public void New_Methods_Return_False () // TODO: Add more } + // OnAccept/Accept tests + [Fact] + public void OnAccept_Fires_Accept () + { + var view = new View (); + var accepted = false; + + view.Accept += ViewOnAccept; + + view.OnAccept (); + Assert.True (accepted); + + return; + + void ViewOnAccept (object sender, CancelEventArgs e) { accepted = true; } + } + + [Fact] + [SetupFakeDriver] + public void SetText_RendersCorrectly () + { + View view; + var text = "test"; + + view = new Label { Text = text }; + view.BeginInit (); + view.EndInit (); + view.Draw (); + + TestHelpers.AssertDriverContentsWithFrameAre (text, _output); + } + [Fact] [AutoInitShutdown] public void Test_Nested_Views_With_Height_Equal_To_One () @@ -908,8 +973,8 @@ public void View_With_No_Difference_Between_An_Object_Initializer_Compute_And_A_ Assert.Equal (4, view.Height); Assert.False (view.Frame.IsEmpty); Assert.Equal (new Rectangle (1, 2, 3, 4), view.Frame); - Assert.False (view.Bounds.IsEmpty); - Assert.Equal (new Rectangle (0, 0, 3, 4), view.Bounds); + Assert.False (view.ContentArea.IsEmpty); + Assert.Equal (new Rectangle (0, 0, 3, 4), view.ContentArea); view.LayoutSubviews (); @@ -918,7 +983,7 @@ public void View_With_No_Difference_Between_An_Object_Initializer_Compute_And_A_ Assert.Equal (3, view.Width); Assert.Equal (4, view.Height); Assert.False (view.Frame.IsEmpty); - Assert.False (view.Bounds.IsEmpty); + Assert.False (view.ContentArea.IsEmpty); super.Dispose (); #if DEBUG_IDISPOSABLE @@ -932,7 +997,7 @@ public void View_With_No_Difference_Between_An_Object_Initializer_Compute_And_A_ Assert.Equal (0, view.Width); Assert.Equal (0, view.Height); Assert.True (view.Frame.IsEmpty); - Assert.True (view.Bounds.IsEmpty); + Assert.True (view.ContentArea.IsEmpty); view.Dispose (); // Object Initializer @@ -942,7 +1007,7 @@ public void View_With_No_Difference_Between_An_Object_Initializer_Compute_And_A_ Assert.Equal (0, view.Width); Assert.Equal (0, view.Height); Assert.False (view.Frame.IsEmpty); - Assert.True (view.Bounds.IsEmpty); + Assert.True (view.ContentArea.IsEmpty); view.Dispose (); // Default Constructor and post assignment equivalent to Object Initializer @@ -962,8 +1027,8 @@ public void View_With_No_Difference_Between_An_Object_Initializer_Compute_And_A_ Assert.Equal (4, view.Height); Assert.False (view.Frame.IsEmpty); Assert.Equal (new Rectangle (1, 2, 3, 4), view.Frame); - Assert.False (view.Bounds.IsEmpty); - Assert.Equal (new Rectangle (0, 0, 3, 4), view.Bounds); + Assert.False (view.ContentArea.IsEmpty); + Assert.Equal (new Rectangle (0, 0, 3, 4), view.ContentArea); super.Dispose (); } @@ -1151,65 +1216,4 @@ public override bool OnProcessKeyDown (Key keyEvent) return true; } } - - // OnAccept/Accept tests - [Fact] - public void OnAccept_Fires_Accept () - { - var view = new View (); - var accepted = false; - - view.Accept += ViewOnAccept; - - view.OnAccept (); - Assert.True (accepted); - - return; - void ViewOnAccept (object sender, CancelEventArgs e) { accepted = true; } - } - - [Fact] - public void Accept_Cancel_Event_OnAccept_Returns_True () - { - var view = new View (); - var acceptInvoked = false; - - view.Accept += ViewOnAccept; - - var ret = view.OnAccept (); - Assert.True (ret); - Assert.True (acceptInvoked); - - return; - void ViewOnAccept (object sender, CancelEventArgs e) { - acceptInvoked = true; - e.Cancel = true; - } - } - - [Fact] - public void Accept_Command_Invokes_Accept_Event () - { - var view = new View (); - var accepted = false; - - view.Accept += ViewOnAccept; - - view.InvokeCommand (Command.Accept); - Assert.True (accepted); - - return; - void ViewOnAccept (object sender, CancelEventArgs e) { accepted = true; } - } - - [Fact] - public void HotKey_Command_SetsFocus () - { - var view = new View (); - - view.CanFocus = true; - Assert.False (view.HasFocus); - view.InvokeCommand (Command.HotKey); - Assert.True (view.HasFocus); - } } diff --git a/UnitTests/Views/ButtonTests.cs b/UnitTests/Views/ButtonTests.cs index 4c5b5f9e8c..3a4c84c06a 100644 --- a/UnitTests/Views/ButtonTests.cs +++ b/UnitTests/Views/ButtonTests.cs @@ -8,29 +8,25 @@ public class ButtonTests private readonly ITestOutputHelper _output; public ButtonTests (ITestOutputHelper output) { _output = output; } - // Test that Title and Text are the same [Fact] - public void Text_Mirrors_Title () + public void Accept_Cancel_Event_OnAccept_Returns_True () { - var view = new Button (); - view.Title = "Hello"; - Assert.Equal ("Hello", view.Title); - Assert.Equal ($"Hello", view.TitleTextFormatter.Text); + var button = new Button (); + var acceptInvoked = false; - Assert.Equal ("Hello", view.Text); - Assert.Equal ($"{CM.Glyphs.LeftBracket} Hello {CM.Glyphs.RightBracket}", view.TextFormatter.Text); - } + button.Accept += ButtonAccept; - [Fact] - public void Title_Mirrors_Text () - { - var view = new Button (); - view.Text = "Hello"; - Assert.Equal ("Hello", view.Text); - Assert.Equal ($"{CM.Glyphs.LeftBracket} Hello {CM.Glyphs.RightBracket}", view.TextFormatter.Text); + bool? ret = button.OnAccept (); + Assert.True (ret); + Assert.True (acceptInvoked); - Assert.Equal ("Hello", view.Title); - Assert.Equal ($"Hello", view.TitleTextFormatter.Text); + return; + + void ButtonAccept (object sender, CancelEventArgs e) + { + acceptInvoked = true; + e.Cancel = true; + } } // BUGBUG: This test is NOT a unit test and needs to be broken apart into @@ -127,9 +123,10 @@ public void AutoSize_False_With_Fixed_Width () Assert.Equal (0, txtToFind.ScrollOffset); Assert.Equal (16, txtToFind.CursorPosition); - Assert.Equal (new (30, 1, 20, 1), btnFindNext.Frame); - Assert.Equal (new (30, 2, 20, 1), btnFindPrevious.Frame); - Assert.Equal (new (30, 4, 20, 1), btnCancel.Frame); + Assert.Equal (new Rectangle (30, 1, 20, 1), btnFindNext.Frame); + Assert.Equal (new Rectangle (30, 2, 20, 1), btnFindPrevious.Frame); + Assert.Equal (new Rectangle (30, 4, 20, 1), btnCancel.Frame); + // Assert.Equal (new (0, 3, 12, 1), ckbMatchCase.Frame); // Assert.Equal (new (0, 4, 18, 1), ckbMatchWholeWord.Frame); @@ -432,14 +429,14 @@ public void Constructors_Defaults () Assert.Equal (TextAlignment.Centered, btn.TextAlignment); Assert.Equal ('_', btn.HotKeySpecifier.Value); Assert.True (btn.CanFocus); - Assert.Equal (new Rectangle (0, 0, 4, 1), btn.Bounds); + Assert.Equal (new Rectangle (0, 0, 4, 1), btn.ContentArea); Assert.Equal (new Rectangle (0, 0, 4, 1), btn.Frame); Assert.Equal ($"{CM.Glyphs.LeftBracket} {CM.Glyphs.RightBracket}", btn.TextFormatter.Text); Assert.False (btn.IsDefault); Assert.Equal (TextAlignment.Centered, btn.TextAlignment); Assert.Equal ('_', btn.HotKeySpecifier.Value); Assert.True (btn.CanFocus); - Assert.Equal (new Rectangle (0, 0, 4, 1), btn.Bounds); + Assert.Equal (new Rectangle (0, 0, 4, 1), btn.ContentArea); Assert.Equal (new Rectangle (0, 0, 4, 1), btn.Frame); Assert.Equal (string.Empty, btn.Title); @@ -478,7 +475,7 @@ public void Constructors_Defaults () Assert.True (btn.IsDefault); Assert.Equal (TextAlignment.Centered, btn.TextAlignment); Assert.True (btn.CanFocus); - Assert.Equal (new Rectangle (0, 0, 10, 1), btn.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 1), btn.ContentArea); Assert.Equal (new Rectangle (0, 0, 10, 1), btn.Frame); Assert.Equal (KeyCode.T, btn.HotKey); @@ -521,10 +518,26 @@ public void Constructors_Defaults () "; TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 9, 1), btn.Bounds); + Assert.Equal (new Rectangle (0, 0, 9, 1), btn.ContentArea); Assert.Equal (new Rectangle (1, 2, 9, 1), btn.Frame); } + [Fact] + public void HotKey_Command_Accepts () + { + var button = new Button (); + var accepted = false; + + button.Accept += ButtonOnAccept; + button.InvokeCommand (Command.HotKey); + + Assert.True (accepted); + + return; + + void ButtonOnAccept (object sender, CancelEventArgs e) { accepted = true; } + } + [Fact] [AutoInitShutdown] public void HotKeyChange_Works () @@ -670,40 +683,6 @@ public void KeyBindings_Command () clicked = false; } - [Fact] - public void HotKey_Command_Accepts () - { - var button = new Button (); - var accepted = false; - - button.Accept += ButtonOnAccept; - button.InvokeCommand (Command.HotKey); - - Assert.True (accepted); - - return; - void ButtonOnAccept (object sender, CancelEventArgs e) { accepted = true; } - } - - [Fact] - public void Accept_Cancel_Event_OnAccept_Returns_True () - { - var button = new Button (); - var acceptInvoked = false; - - button.Accept += ButtonAccept; - - var ret = button.OnAccept (); - Assert.True (ret); - Assert.True (acceptInvoked); - - return; - void ButtonAccept (object sender, CancelEventArgs e) - { - acceptInvoked = true; - e.Cancel = true; - } - } [Fact] public void Setting_Empty_Text_Sets_HoKey_To_KeyNull () { @@ -742,6 +721,31 @@ public void TestAssignTextToButton () Assert.Equal ("heyb", ((Button)b).Text); } + // Test that Title and Text are the same + [Fact] + public void Text_Mirrors_Title () + { + var view = new Button (); + view.Title = "Hello"; + Assert.Equal ("Hello", view.Title); + Assert.Equal ("Hello", view.TitleTextFormatter.Text); + + Assert.Equal ("Hello", view.Text); + Assert.Equal ($"{CM.Glyphs.LeftBracket} Hello {CM.Glyphs.RightBracket}", view.TextFormatter.Text); + } + + [Fact] + public void Title_Mirrors_Text () + { + var view = new Button (); + view.Text = "Hello"; + Assert.Equal ("Hello", view.Text); + Assert.Equal ($"{CM.Glyphs.LeftBracket} Hello {CM.Glyphs.RightBracket}", view.TextFormatter.Text); + + Assert.Equal ("Hello", view.Title); + Assert.Equal ("Hello", view.TitleTextFormatter.Text); + } + [Fact] [AutoInitShutdown] public void Update_Only_On_Or_After_Initialize () @@ -762,7 +766,7 @@ public void Update_Only_On_Or_After_Initialize () Assert.True (btn.IsInitialized); Assert.Equal ("Say Hello 你", btn.Text); Assert.Equal ($"{CM.Glyphs.LeftBracket} {btn.Text} {CM.Glyphs.RightBracket}", btn.TextFormatter.Text); - Assert.Equal (new Rectangle (0, 0, 16, 1), btn.Bounds); + Assert.Equal (new Rectangle (0, 0, 16, 1), btn.ContentArea); var btnTxt = $"{CM.Glyphs.LeftBracket} {btn.Text} {CM.Glyphs.RightBracket}"; var expected = @$" @@ -799,7 +803,7 @@ public void Update_Parameterless_Only_On_Or_After_Initialize () Assert.True (btn.IsInitialized); Assert.Equal ("Say Hello 你", btn.Text); Assert.Equal ($"{CM.Glyphs.LeftBracket} {btn.Text} {CM.Glyphs.RightBracket}", btn.TextFormatter.Text); - Assert.Equal (new Rectangle (0, 0, 16, 1), btn.Bounds); + Assert.Equal (new Rectangle (0, 0, 16, 1), btn.ContentArea); var btnTxt = $"{CM.Glyphs.LeftBracket} {btn.Text} {CM.Glyphs.RightBracket}"; var expected = @$" diff --git a/UnitTests/Views/ComboBoxTests.cs b/UnitTests/Views/ComboBoxTests.cs index cc582af01a..d052d6e50d 100644 --- a/UnitTests/Views/ComboBoxTests.cs +++ b/UnitTests/Views/ComboBoxTests.cs @@ -144,7 +144,7 @@ public void HideDropdownListOnClick_False_OpenSelectedItem_With_Mouse_And_Key_Cu Assert.True ( cb.MouseEvent ( - new MouseEvent { X = cb.Bounds.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } + new MouseEvent { X = cb.ContentArea.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); @@ -200,7 +200,7 @@ public void HideDropdownListOnClick_False_OpenSelectedItem_With_Mouse_And_Key_F4 Assert.True ( cb.MouseEvent ( - new MouseEvent { X = cb.Bounds.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } + new MouseEvent { X = cb.ContentArea.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); @@ -236,7 +236,7 @@ public void Assert.True ( cb.MouseEvent ( - new MouseEvent { X = cb.Bounds.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } + new MouseEvent { X = cb.ContentArea.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); @@ -292,7 +292,7 @@ public void HideDropdownListOnClick_Gets_Sets () Assert.True ( cb.MouseEvent ( - new MouseEvent { X = cb.Bounds.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } + new MouseEvent { X = cb.ContentArea.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); @@ -337,7 +337,7 @@ cb.Subviews [1] Assert.True ( cb.MouseEvent ( - new MouseEvent { X = cb.Bounds.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } + new MouseEvent { X = cb.ContentArea.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } ) ); @@ -354,7 +354,7 @@ cb.Subviews [1] Assert.True ( cb.MouseEvent ( - new MouseEvent { X = cb.Bounds.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } + new MouseEvent { X = cb.ContentArea.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("Three", selected); @@ -392,14 +392,14 @@ public void HideDropdownListOnClick_True_Colapse_On_Click_Outside_Frame () Assert.True ( cb.MouseEvent ( - new MouseEvent { X = cb.Bounds.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } + new MouseEvent { X = cb.ContentArea.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } ) ); Assert.True ( cb.Subviews [1] .MouseEvent ( - new MouseEvent { X = cb.Bounds.Right - 1, Y = 0, Flags = MouseFlags.Button1Clicked } + new MouseEvent { X = cb.ContentArea.Right - 1, Y = 0, Flags = MouseFlags.Button1Clicked } ) ); Assert.Equal ("", selected); @@ -423,7 +423,7 @@ cb.Subviews [1] Assert.True ( cb.Subviews [1] .MouseEvent ( - new MouseEvent { X = cb.Bounds.Right - 1, Y = 0, Flags = MouseFlags.Button1Clicked } + new MouseEvent { X = cb.ContentArea.Right - 1, Y = 0, Flags = MouseFlags.Button1Clicked } ) ); Assert.Equal ("", selected); @@ -447,7 +447,7 @@ cb.Subviews [1] Assert.True ( cb.Subviews [1] .MouseEvent ( - new MouseEvent { X = cb.Bounds.Right - 1, Y = 0, Flags = MouseFlags.Button1Clicked } + new MouseEvent { X = cb.ContentArea.Right - 1, Y = 0, Flags = MouseFlags.Button1Clicked } ) ); Assert.Equal ("", selected); @@ -471,7 +471,7 @@ cb.Subviews [1] Assert.True ( cb.Subviews [1] .MouseEvent ( - new MouseEvent { X = cb.Bounds.Right - 1, Y = 0, Flags = MouseFlags.Button1Clicked } + new MouseEvent { X = cb.ContentArea.Right - 1, Y = 0, Flags = MouseFlags.Button1Clicked } ) ); Assert.Equal ("", selected); @@ -509,7 +509,7 @@ public void HideDropdownListOnClick_True_Highlight_Current_Item () Assert.True ( cb.MouseEvent ( - new MouseEvent { X = cb.Bounds.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } + new MouseEvent { X = cb.ContentArea.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); @@ -665,7 +665,7 @@ public void HideDropdownListOnClick_True_OpenSelectedItem_With_Mouse_And_Key_And Assert.True ( cb.MouseEvent ( - new MouseEvent { X = cb.Bounds.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } + new MouseEvent { X = cb.ContentArea.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); @@ -677,7 +677,7 @@ public void HideDropdownListOnClick_True_OpenSelectedItem_With_Mouse_And_Key_And Assert.True ( cb.MouseEvent ( - new MouseEvent { X = cb.Bounds.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } + new MouseEvent { X = cb.ContentArea.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); @@ -687,7 +687,7 @@ public void HideDropdownListOnClick_True_OpenSelectedItem_With_Mouse_And_Key_And Assert.True ( cb.MouseEvent ( - new MouseEvent { X = cb.Bounds.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } + new MouseEvent { X = cb.ContentArea.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); @@ -699,7 +699,7 @@ public void HideDropdownListOnClick_True_OpenSelectedItem_With_Mouse_And_Key_And Assert.True ( cb.MouseEvent ( - new MouseEvent { X = cb.Bounds.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } + new MouseEvent { X = cb.ContentArea.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); @@ -726,7 +726,7 @@ public void HideDropdownListOnClick_True_OpenSelectedItem_With_Mouse_And_Key_Cur Assert.True ( cb.MouseEvent ( - new MouseEvent { X = cb.Bounds.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } + new MouseEvent { X = cb.ContentArea.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); @@ -782,7 +782,7 @@ public void HideDropdownListOnClick_True_OpenSelectedItem_With_Mouse_And_Key_F4 Assert.True ( cb.MouseEvent ( - new MouseEvent { X = cb.Bounds.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } + new MouseEvent { X = cb.ContentArea.Right - 1, Y = 0, Flags = MouseFlags.Button1Pressed } ) ); Assert.Equal ("", selected); diff --git a/UnitTests/Views/GraphViewTests.cs b/UnitTests/Views/GraphViewTests.cs index 7362e7cf18..5e3ba2eed5 100644 --- a/UnitTests/Views/GraphViewTests.cs +++ b/UnitTests/Views/GraphViewTests.cs @@ -61,7 +61,7 @@ public void CellSizeZero () gv.EndInit (); gv.ColorScheme = new ColorScheme (); - gv.Bounds = new Rectangle (0, 0, 50, 30); + gv.ContentArea = new Rectangle (0, 0, 50, 30); gv.Series.Add (new ScatterSeries { Points = new List { new (1, 1) } }); gv.CellSize = new PointF (0, 5); var ex = Assert.Throws (() => gv.Draw ()); @@ -85,7 +85,7 @@ public static GraphView GetGraph () gv.ColorScheme = new ColorScheme (); gv.MarginBottom = 1; gv.MarginLeft = 1; - gv.Bounds = new Rectangle (0, 0, 10, 5); + gv.ContentArea = new Rectangle (0, 0, 10, 5); return gv; } @@ -128,7 +128,7 @@ public void TestReversing_ScreenToGraphSpace () var gv = new GraphView (); gv.BeginInit (); gv.EndInit (); - gv.Bounds = new Rectangle (0, 0, 50, 30); + gv.ContentArea = new Rectangle (0, 0, 50, 30); // How much graph space each cell of the console depicts gv.CellSize = new PointF (0.1f, 0.25f); @@ -141,9 +141,9 @@ public void TestReversing_ScreenToGraphSpace () // Start the graph at 80 gv.ScrollOffset = new PointF (0, 80); - for (var x = 0; x < gv.Bounds.Width; x++) + for (var x = 0; x < gv.ContentArea.Width; x++) { - for (var y = 0; y < gv.Bounds.Height; y++) + for (var y = 0; y < gv.ContentArea.Height; y++) { RectangleF graphSpace = gv.ScreenToGraphSpace (x, y); @@ -199,7 +199,7 @@ public void ScreenToGraphSpace_DefaultCellSize () gv.BeginInit (); gv.EndInit (); - gv.Bounds = new Rectangle (0, 0, 20, 10); + gv.ContentArea = new Rectangle (0, 0, 20, 10); // origin should be bottom left RectangleF botLeft = gv.ScreenToGraphSpace (0, 9); @@ -221,7 +221,7 @@ public void ScreenToGraphSpace_DefaultCellSize_WithMargin () gv.BeginInit (); gv.EndInit (); - gv.Bounds = new Rectangle (0, 0, 20, 10); + gv.ContentArea = new Rectangle (0, 0, 20, 10); // origin should be bottom left RectangleF botLeft = gv.ScreenToGraphSpace (0, 9); @@ -261,7 +261,7 @@ public void ScreenToGraphSpace_CustomCellSize () gv.BeginInit (); gv.EndInit (); - gv.Bounds = new Rectangle (0, 0, 20, 10); + gv.ContentArea = new Rectangle (0, 0, 20, 10); // Each cell of screen measures 5 units in graph data model vertically and 1/4 horizontally gv.CellSize = new PointF (0.25f, 5); @@ -293,7 +293,7 @@ public void GraphSpaceToScreen_DefaultCellSize () gv.BeginInit (); gv.EndInit (); - gv.Bounds = new Rectangle (0, 0, 20, 10); + gv.ContentArea = new Rectangle (0, 0, 20, 10); // origin should be bottom left Point botLeft = gv.GraphSpaceToScreen (new PointF (0, 0)); @@ -313,7 +313,7 @@ public void GraphSpaceToScreen_DefaultCellSize_WithMargin () gv.BeginInit (); gv.EndInit (); - gv.Bounds = new Rectangle (0, 0, 20, 10); + gv.ContentArea = new Rectangle (0, 0, 20, 10); // origin should be bottom left Point botLeft = gv.GraphSpaceToScreen (new PointF (0, 0)); @@ -343,7 +343,7 @@ public void GraphSpaceToScreen_ScrollOffset () gv.BeginInit (); gv.EndInit (); - gv.Bounds = new Rectangle (0, 0, 20, 10); + gv.ContentArea = new Rectangle (0, 0, 20, 10); //graph is scrolled to present chart space -5 to 5 in both axes gv.ScrollOffset = new PointF (-5, -5); @@ -366,7 +366,7 @@ public void GraphSpaceToScreen_CustomCellSize () gv.BeginInit (); gv.EndInit (); - gv.Bounds = new Rectangle (0, 0, 20, 10); + gv.ContentArea = new Rectangle (0, 0, 20, 10); // Each cell of screen is responsible for rendering 5 units in graph data model // vertically and 1/4 horizontally @@ -407,7 +407,7 @@ public void GraphSpaceToScreen_CustomCellSize_WithScrollOffset () gv.BeginInit (); gv.EndInit (); - gv.Bounds = new Rectangle (0, 0, 20, 10); + gv.ContentArea = new Rectangle (0, 0, 20, 10); // Each cell of screen is responsible for rendering 5 units in graph data model // vertically and 1/4 horizontally @@ -449,7 +449,7 @@ public void Series_GetsPassedCorrectBounds_AllAtOnce () gv.BeginInit (); gv.EndInit (); gv.ColorScheme = new ColorScheme (); - gv.Bounds = new Rectangle (0, 0, 50, 30); + gv.ContentArea = new Rectangle (0, 0, 50, 30); var fullGraphBounds = RectangleF.Empty; var graphScreenBounds = Rectangle.Empty; @@ -501,7 +501,7 @@ public void Series_GetsPassedCorrectBounds_AllAtOnce_LargeCellSize () gv.BeginInit (); gv.EndInit (); gv.ColorScheme = new ColorScheme (); - gv.Bounds = new Rectangle (0, 0, 50, 30); + gv.ContentArea = new Rectangle (0, 0, 50, 30); // the larger the cell size the more condensed (smaller) the graph space is gv.CellSize = new PointF (2, 5); @@ -641,7 +641,7 @@ public void TestRendering_MultibarSeries () // y axis goes from 0.1 to 1 across 10 console rows // x axis goes from 0 to 20 across 20 console columns - gv.Bounds = new Rectangle (0, 0, 20, 10); + gv.ContentArea = new Rectangle (0, 0, 20, 10); gv.CellSize = new PointF (1f, 0.1f); gv.MarginBottom = 1; gv.MarginLeft = 1; @@ -873,7 +873,7 @@ private GraphView GetGraph (out FakeBarSeries series, out FakeHAxis axisX, out F // y axis goes from 0.1 to 1 across 10 console rows // x axis goes from 0 to 10 across 20 console columns - gv.Bounds = new Rectangle (0, 0, 20, 10); + gv.ContentArea = new Rectangle (0, 0, 20, 10); gv.CellSize = new PointF (0.5f, 0.1f); gv.Series.Add (series = new FakeBarSeries ()); @@ -914,7 +914,7 @@ private GraphView GetGraph (out FakeHAxis axisX, out FakeVAxis axisY) var gv = new GraphView (); gv.ColorScheme = new ColorScheme (); - gv.Bounds = new Rectangle (0, 0, 50, 30); + gv.ContentArea = new Rectangle (0, 0, 50, 30); // graph can't be completely empty or it won't draw gv.Series.Add (new ScatterSeries ()); @@ -1298,19 +1298,19 @@ public class LegendTests public void Constructors_Defaults () { var legend = new LegendAnnotation (); - Assert.Equal (Rectangle.Empty, legend.Bounds); + Assert.Equal (Rectangle.Empty, legend.ContentArea); Assert.Equal (Rectangle.Empty, legend.Frame); Assert.Equal (LineStyle.Single, legend.BorderStyle); Assert.False (legend.BeforeSeries); var bounds = new Rectangle (1, 2, 10, 3); legend = new LegendAnnotation (bounds); - Assert.Equal (new Rectangle (0, 0, 8, 1), legend.Bounds); + Assert.Equal (new Rectangle (0, 0, 8, 1), legend.ContentArea); Assert.Equal (bounds, legend.Frame); Assert.Equal (LineStyle.Single, legend.BorderStyle); Assert.False (legend.BeforeSeries); legend.BorderStyle = LineStyle.None; - Assert.Equal (new Rectangle (0, 0, 10, 3), legend.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 3), legend.ContentArea); Assert.Equal (bounds, legend.Frame); } @@ -1549,7 +1549,7 @@ public void ViewChangeText_RendersCorrectly (bool useFill) public void XAxisLabels_With_MarginLeft () { GraphViewTests.InitFakeDriver (); - var gv = new GraphView { ColorScheme = new ColorScheme (), Bounds = new Rectangle (0, 0, 10, 7) }; + var gv = new GraphView { ColorScheme = new ColorScheme (), ContentArea = new Rectangle (0, 0, 10, 7) }; gv.CellSize = new PointF (1, 0.5f); gv.AxisY.Increment = 1; @@ -1591,7 +1591,7 @@ 0 5 public void YAxisLabels_With_MarginBottom () { GraphViewTests.InitFakeDriver (); - var gv = new GraphView { ColorScheme = new ColorScheme (), Bounds = new Rectangle (0, 0, 10, 7) }; + var gv = new GraphView { ColorScheme = new ColorScheme (), ContentArea = new Rectangle (0, 0, 10, 7) }; gv.CellSize = new PointF (1, 0.5f); gv.AxisY.Increment = 1; diff --git a/UnitTests/Views/LabelTests.cs b/UnitTests/Views/LabelTests.cs index 4b098d1ba3..1b31d2b147 100644 --- a/UnitTests/Views/LabelTests.cs +++ b/UnitTests/Views/LabelTests.cs @@ -8,64 +8,6 @@ public class LabelTests private readonly ITestOutputHelper _output; public LabelTests (ITestOutputHelper output) { _output = output; } - // Test that Title and Text are the same - [Fact] - public void Text_Mirrors_Title () - { - var label = new Label (); - label.Title = "Hello"; - Assert.Equal ("Hello", label.Title); - Assert.Equal ("Hello", label.TitleTextFormatter.Text); - - Assert.Equal ("Hello", label.Text); - Assert.Equal ("Hello", label.TextFormatter.Text); - } - - [Fact] - public void Title_Mirrors_Text () - { - var label = new Label (); - label.Text = "Hello"; - Assert.Equal ("Hello", label.Text); - Assert.Equal ("Hello", label.TextFormatter.Text); - - Assert.Equal ("Hello", label.Title); - Assert.Equal ("Hello", label.TitleTextFormatter.Text); - } - - [Fact] - public void HotKey_Command_SetsFocus_OnNextSubview () - { - var superView = new View () { CanFocus = true }; - var label = new Label (); - var nextSubview = new View () { CanFocus = true }; - superView.Add (label, nextSubview); - superView.BeginInit (); - superView.EndInit (); - - Assert.False (label.HasFocus); - Assert.False (nextSubview.HasFocus); - - label.InvokeCommand (Command.HotKey); - Assert.False (label.HasFocus); - Assert.True (nextSubview.HasFocus); - } - - [Fact] - public void HotKey_Command_Does_Not_Accept () - { - var label = new Label (); - var accepted = false; - - label.Accept += LabelOnAccept; - label.InvokeCommand (Command.HotKey); - - Assert.False (accepted); - - return; - void LabelOnAccept (object sender, CancelEventArgs e) { accepted = true; } - } - [Fact] [AutoInitShutdown] public void AutoSize_Stays_True_AnchorEnd () @@ -228,6 +170,60 @@ public void Constructors_Defaults () Application.End (rs); } + [Fact] + [AutoInitShutdown] + public void Full_Border () + { + var label = new Label { Text = "Test", /*Width = 6, Height = 3, */BorderStyle = LineStyle.Single }; + Application.Top.Add (label); + Application.Begin (Application.Top); + + Assert.Equal (new Rectangle (0, 0, 6, 3), label.Frame); + Assert.Equal (new Rectangle (0, 0, 4, 1), label.ContentArea); + + TestHelpers.AssertDriverContentsWithFrameAre ( + @" +┌┤Te├┐ +│Test│ +└────┘", + _output + ); + } + + [Fact] + public void HotKey_Command_Does_Not_Accept () + { + var label = new Label (); + var accepted = false; + + label.Accept += LabelOnAccept; + label.InvokeCommand (Command.HotKey); + + Assert.False (accepted); + + return; + + void LabelOnAccept (object sender, CancelEventArgs e) { accepted = true; } + } + + [Fact] + public void HotKey_Command_SetsFocus_OnNextSubview () + { + var superView = new View { CanFocus = true }; + var label = new Label (); + var nextSubview = new View { CanFocus = true }; + superView.Add (label, nextSubview); + superView.BeginInit (); + superView.EndInit (); + + Assert.False (label.HasFocus); + Assert.False (nextSubview.HasFocus); + + label.InvokeCommand (Command.HotKey); + Assert.False (label.HasFocus); + Assert.True (nextSubview.HasFocus); + } + [Fact] [AutoInitShutdown] public void Label_Draw_Fill_Remaining_AutoSize_True () @@ -420,6 +416,31 @@ public void TestAssignTextToLabel () Assert.Equal ("heyb", ((Label)b).Text); } + // Test that Title and Text are the same + [Fact] + public void Text_Mirrors_Title () + { + var label = new Label (); + label.Title = "Hello"; + Assert.Equal ("Hello", label.Title); + Assert.Equal ("Hello", label.TitleTextFormatter.Text); + + Assert.Equal ("Hello", label.Text); + Assert.Equal ("Hello", label.TextFormatter.Text); + } + + [Fact] + public void Title_Mirrors_Text () + { + var label = new Label (); + label.Text = "Hello"; + Assert.Equal ("Hello", label.Text); + Assert.Equal ("Hello", label.TextFormatter.Text); + + Assert.Equal ("Hello", label.Title); + Assert.Equal ("Hello", label.TitleTextFormatter.Text); + } + [Fact] [AutoInitShutdown] public void Update_Only_On_Or_After_Initialize () @@ -437,7 +458,7 @@ public void Update_Only_On_Or_After_Initialize () Assert.True (label.IsInitialized); Assert.Equal ("Say Hello 你", label.Text); Assert.Equal ("Say Hello 你", label.TextFormatter.Text); - Assert.Equal (new Rectangle (0, 0, 12, 1), label.Bounds); + Assert.Equal (new Rectangle (0, 0, 12, 1), label.ContentArea); var expected = @" ┌────────────────────────────┐ @@ -467,7 +488,7 @@ public void Update_Parameterless_Only_On_Or_After_Initialize () Assert.True (label.IsInitialized); Assert.Equal ("Say Hello 你", label.Text); Assert.Equal ("Say Hello 你", label.TextFormatter.Text); - Assert.Equal (new Rectangle (0, 0, 12, 1), label.Bounds); + Assert.Equal (new Rectangle (0, 0, 12, 1), label.ContentArea); var expected = @" ┌────────────────────────────┐ @@ -481,27 +502,6 @@ public void Update_Parameterless_Only_On_Or_After_Initialize () Assert.Equal (new Rectangle (0, 0, 30, 5), pos); } - - [Fact] - [AutoInitShutdown] - public void Full_Border () - { - var label = new Label { Text = "Test", /*Width = 6, Height = 3, */BorderStyle = LineStyle.Single }; - Application.Top.Add (label); - Application.Begin (Application.Top); - - Assert.Equal (new (0, 0, 6, 3), label.Frame); - Assert.Equal (new (0, 0, 4, 1), label.Bounds); - - TestHelpers.AssertDriverContentsWithFrameAre ( - @" -┌┤Te├┐ -│Test│ -└────┘", - _output - ); - } - [Fact] [AutoInitShutdown] public void With_Top_Margin_Without_Top_Border () @@ -512,8 +512,8 @@ public void With_Top_Margin_Without_Top_Border () Application.Top.Add (label); Application.Begin (Application.Top); - Assert.Equal (new (0, 0, 6, 3), label.Frame); - Assert.Equal (new (0, 0, 4, 1), label.Bounds); + Assert.Equal (new Rectangle (0, 0, 6, 3), label.Frame); + Assert.Equal (new Rectangle (0, 0, 4, 1), label.ContentArea); Application.Begin (Application.Top); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -533,8 +533,8 @@ public void Without_Top_Border () Application.Top.Add (label); Application.Begin (Application.Top); - Assert.Equal (new (0, 0, 6, 2), label.Frame); - Assert.Equal (new (0, 0, 4, 1), label.Bounds); + Assert.Equal (new Rectangle (0, 0, 6, 2), label.Frame); + Assert.Equal (new Rectangle (0, 0, 4, 1), label.ContentArea); Application.Begin (Application.Top); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -544,5 +544,4 @@ public void Without_Top_Border () _output ); } - } diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index 8e4bf878fc..d927a48384 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -23,13 +23,13 @@ public void AutoHideScrollBars_Check () Assert.True (_scrollBar.ShowScrollIndicator); Assert.True (_scrollBar.Visible); Assert.Equal ("Absolute(1)", _scrollBar.Width.ToString ()); - Assert.Equal (1, _scrollBar.Bounds.Width); + Assert.Equal (1, _scrollBar.ContentArea.Width); Assert.Equal ( "Fill(1)", _scrollBar.Height.ToString () ); - Assert.Equal (24, _scrollBar.Bounds.Height); + Assert.Equal (24, _scrollBar.ContentArea.Height); Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); Assert.True (_scrollBar.OtherScrollBarView.Visible); @@ -37,22 +37,22 @@ public void AutoHideScrollBars_Check () "Fill(1)", _scrollBar.OtherScrollBarView.Width.ToString () ); - Assert.Equal (79, _scrollBar.OtherScrollBarView.Bounds.Width); + Assert.Equal (79, _scrollBar.OtherScrollBarView.ContentArea.Width); Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ()); - Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height); + Assert.Equal (1, _scrollBar.OtherScrollBarView.ContentArea.Height); _hostView.Lines = 10; _hostView.Draw (); Assert.False (_scrollBar.ShowScrollIndicator); Assert.False (_scrollBar.Visible); Assert.Equal ("Absolute(1)", _scrollBar.Width.ToString ()); - Assert.Equal (1, _scrollBar.Bounds.Width); + Assert.Equal (1, _scrollBar.ContentArea.Width); Assert.Equal ( "Fill(1)", _scrollBar.Height.ToString () ); - Assert.Equal (24, _scrollBar.Bounds.Height); + Assert.Equal (24, _scrollBar.ContentArea.Height); Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); Assert.True (_scrollBar.OtherScrollBarView.Visible); @@ -60,22 +60,22 @@ public void AutoHideScrollBars_Check () "Fill(0)", _scrollBar.OtherScrollBarView.Width.ToString () ); - Assert.Equal (80, _scrollBar.OtherScrollBarView.Bounds.Width); + Assert.Equal (80, _scrollBar.OtherScrollBarView.ContentArea.Width); Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ()); - Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height); + Assert.Equal (1, _scrollBar.OtherScrollBarView.ContentArea.Height); _hostView.Cols = 60; _hostView.Draw (); Assert.False (_scrollBar.ShowScrollIndicator); Assert.False (_scrollBar.Visible); Assert.Equal ("Absolute(1)", _scrollBar.Width.ToString ()); - Assert.Equal (1, _scrollBar.Bounds.Width); + Assert.Equal (1, _scrollBar.ContentArea.Width); Assert.Equal ( "Fill(1)", _scrollBar.Height.ToString () ); - Assert.Equal (24, _scrollBar.Bounds.Height); + Assert.Equal (24, _scrollBar.ContentArea.Height); Assert.False (_scrollBar.OtherScrollBarView.ShowScrollIndicator); Assert.False (_scrollBar.OtherScrollBarView.Visible); @@ -83,22 +83,22 @@ public void AutoHideScrollBars_Check () "Fill(0)", _scrollBar.OtherScrollBarView.Width.ToString () ); - Assert.Equal (80, _scrollBar.OtherScrollBarView.Bounds.Width); + Assert.Equal (80, _scrollBar.OtherScrollBarView.ContentArea.Width); Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ()); - Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height); + Assert.Equal (1, _scrollBar.OtherScrollBarView.ContentArea.Height); _hostView.Lines = 40; _hostView.Draw (); Assert.True (_scrollBar.ShowScrollIndicator); Assert.True (_scrollBar.Visible); Assert.Equal ("Absolute(1)", _scrollBar.Width.ToString ()); - Assert.Equal (1, _scrollBar.Bounds.Width); + Assert.Equal (1, _scrollBar.ContentArea.Width); Assert.Equal ( "Fill(0)", _scrollBar.Height.ToString () ); - Assert.Equal (25, _scrollBar.Bounds.Height); + Assert.Equal (25, _scrollBar.ContentArea.Height); Assert.False (_scrollBar.OtherScrollBarView.ShowScrollIndicator); Assert.False (_scrollBar.OtherScrollBarView.Visible); @@ -106,22 +106,22 @@ public void AutoHideScrollBars_Check () "Fill(0)", _scrollBar.OtherScrollBarView.Width.ToString () ); - Assert.Equal (80, _scrollBar.OtherScrollBarView.Bounds.Width); + Assert.Equal (80, _scrollBar.OtherScrollBarView.ContentArea.Width); Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ()); - Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height); + Assert.Equal (1, _scrollBar.OtherScrollBarView.ContentArea.Height); _hostView.Cols = 120; _hostView.Draw (); Assert.True (_scrollBar.ShowScrollIndicator); Assert.True (_scrollBar.Visible); Assert.Equal ("Absolute(1)", _scrollBar.Width.ToString ()); - Assert.Equal (1, _scrollBar.Bounds.Width); + Assert.Equal (1, _scrollBar.ContentArea.Width); Assert.Equal ( "Fill(1)", _scrollBar.Height.ToString () ); - Assert.Equal (24, _scrollBar.Bounds.Height); + Assert.Equal (24, _scrollBar.ContentArea.Height); Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); Assert.True (_scrollBar.OtherScrollBarView.Visible); @@ -129,9 +129,9 @@ public void AutoHideScrollBars_Check () "Fill(1)", _scrollBar.OtherScrollBarView.Width.ToString () ); - Assert.Equal (79, _scrollBar.OtherScrollBarView.Bounds.Width); + Assert.Equal (79, _scrollBar.OtherScrollBarView.ContentArea.Width); Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ()); - Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height); + Assert.Equal (1, _scrollBar.OtherScrollBarView.ContentArea.Height); } [Fact] @@ -443,7 +443,7 @@ public void newScrollBarView.Position, newScrollBarView.Size - listView.LeftItem - + (listView.LeftItem - listView.Bounds.Width)); + + (listView.LeftItem - listView.ContentArea.Width)); Assert.Equal (newScrollBarView.Position, listView.LeftItem); Assert.Equal (92, newScrollBarView.Position); @@ -520,7 +520,7 @@ public void newScrollBarView.Position, newScrollBarView.Size - listView.TopItem - + (listView.TopItem - listView.Bounds.Height) + + (listView.TopItem - listView.ContentArea.Height) ); Assert.Equal (newScrollBarView.Position, listView.TopItem); Assert.Equal (27, newScrollBarView.Position); @@ -929,7 +929,7 @@ public void Hosting_Two_Vertical_ScrollBarView_Throws_ArgumentException () public void Internal_Tests () { Toplevel top = Application.Top; - Assert.Equal (new Rectangle (0, 0, 80, 25), top.Bounds); + Assert.Equal (new Rectangle (0, 0, 80, 25), top.ContentArea); var view = new View { Width = Dim.Fill (), Height = Dim.Fill () }; var sbv = new ScrollBarView { IsVertical = true, OtherScrollBarView = new ScrollBarView { IsVertical = false } }; view.Add (sbv); @@ -1006,10 +1006,10 @@ public void KeepContentAlwaysInViewport_True () AddHandlers (); - Assert.Equal (80, _hostView.Bounds.Width); - Assert.Equal (25, _hostView.Bounds.Height); - Assert.Equal (79, _scrollBar.OtherScrollBarView.Bounds.Width); - Assert.Equal (24, _scrollBar.Bounds.Height); + Assert.Equal (80, _hostView.ContentArea.Width); + Assert.Equal (25, _hostView.ContentArea.Height); + Assert.Equal (79, _scrollBar.OtherScrollBarView.ContentArea.Width); + Assert.Equal (24, _scrollBar.ContentArea.Height); Assert.Equal (30, _scrollBar.Size); Assert.Equal (100, _scrollBar.OtherScrollBarView.Size); Assert.True (_scrollBar.ShowScrollIndicator); @@ -1018,7 +1018,7 @@ public void KeepContentAlwaysInViewport_True () Assert.True (_scrollBar.OtherScrollBarView.Visible); _scrollBar.Position = 50; - Assert.Equal (_scrollBar.Position, _scrollBar.Size - _scrollBar.Bounds.Height); + Assert.Equal (_scrollBar.Position, _scrollBar.Size - _scrollBar.ContentArea.Height); Assert.Equal (_scrollBar.Position, _hostView.Top); Assert.Equal (6, _scrollBar.Position); Assert.Equal (6, _hostView.Top); @@ -1031,7 +1031,7 @@ public void KeepContentAlwaysInViewport_True () Assert.Equal ( _scrollBar.OtherScrollBarView.Position, - _scrollBar.OtherScrollBarView.Size - _scrollBar.OtherScrollBarView.Bounds.Width + _scrollBar.OtherScrollBarView.Size - _scrollBar.OtherScrollBarView.ContentArea.Width ); Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); Assert.Equal (21, _scrollBar.OtherScrollBarView.Position); @@ -1165,16 +1165,16 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Padding_Thickne Assert.False (view2.HasFocus); Assert.Equal (12, view.ScrollColsSize); Assert.Equal (7, view.ScrollRowsSize); - Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=3,Y=2,Width=9,Height=6}", view.Frame.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.Frame.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Frame.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Padding.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Padding.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Padding.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.Frame.ToString ()); Assert.Equal ("(Left=0,Top=0,Right=1,Bottom=1)", view.Padding.Thickness.ToString ()); @@ -1282,16 +1282,16 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Padding_Thickne Assert.False (view2.HasFocus); Assert.Equal (12, view.ScrollColsSize); Assert.Equal (7, view.ScrollRowsSize); - Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=2,Y=1,Width=9,Height=6}", view.Frame.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.Frame.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Frame.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Padding.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Padding.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Padding.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.Frame.ToString ()); Assert.Equal ("(Left=0,Top=0,Right=1,Bottom=1)", view.Padding.Thickness.ToString ()); @@ -1400,16 +1400,16 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Parent_Inside_A Assert.False (view2.HasFocus); Assert.Equal (12, view.ScrollColsSize); Assert.Equal (7, view.ScrollRowsSize); - Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=2,Y=1,Width=9,Height=6}", view.Frame.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.Frame.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Frame.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.Bounds.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.Frame.ToString ()); Assert.Equal ("(Left=0,Top=0,Right=0,Bottom=0)", view.Padding.Thickness.ToString ()); diff --git a/UnitTests/Views/ScrollViewTests.cs b/UnitTests/Views/ScrollViewTests.cs index 43326be59c..3cc7d87046 100644 --- a/UnitTests/Views/ScrollViewTests.cs +++ b/UnitTests/Views/ScrollViewTests.cs @@ -34,7 +34,7 @@ public void AutoHideScrollBars_False_ShowHorizontalScrollIndicator_ShowVerticalS Application.Top.Add (sv); Application.Begin (Application.Top); - Assert.Equal (new Rectangle (0, 0, 10, 10), sv.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 10), sv.ContentArea); Assert.False (sv.AutoHideScrollBars); Assert.True (sv.ShowHorizontalScrollIndicator); @@ -58,9 +58,9 @@ public void AutoHideScrollBars_False_ShowHorizontalScrollIndicator_ShowVerticalS ); sv.ShowHorizontalScrollIndicator = false; - Assert.Equal (new Rectangle (0, 0, 10, 10), sv.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 10), sv.ContentArea); sv.ShowVerticalScrollIndicator = true; - Assert.Equal (new Rectangle (0, 0, 10, 10), sv.Bounds); + Assert.Equal (new Rectangle (0, 0, 10, 10), sv.ContentArea); Assert.False (sv.AutoHideScrollBars); Assert.False (sv.ShowHorizontalScrollIndicator); @@ -1093,14 +1093,14 @@ public CustomButton (string fill, string text, int width, int height) { var fillText = new StringBuilder (); - for (var i = 0; i < _labelFill.Bounds.Height; i++) + for (var i = 0; i < _labelFill.ContentArea.Height; i++) { if (i > 0) { fillText.AppendLine (""); } - for (var j = 0; j < _labelFill.Bounds.Width; j++) + for (var j = 0; j < _labelFill.ContentArea.Width; j++) { fillText.Append (fill); } diff --git a/UnitTests/Views/StatusBarTests.cs b/UnitTests/Views/StatusBarTests.cs index d72c781488..3ecee073af 100644 --- a/UnitTests/Views/StatusBarTests.cs +++ b/UnitTests/Views/StatusBarTests.cs @@ -99,7 +99,7 @@ public void Redraw_Output () ); Application.Top.Add (sb); - sb.OnDrawContent (sb.Bounds); + sb.OnDrawContent (sb.ContentArea); var expected = @$" ^O Open { @@ -121,7 +121,7 @@ public void Redraw_Output_CTRLQ () } ); Application.Top.Add (sb); - sb.OnDrawContent (sb.Bounds); + sb.OnDrawContent (sb.ContentArea); var expected = @$" CTRL-O Open { diff --git a/UnitTests/Views/TableViewTests.cs b/UnitTests/Views/TableViewTests.cs index b2a289d30c..5871282eff 100644 --- a/UnitTests/Views/TableViewTests.cs +++ b/UnitTests/Views/TableViewTests.cs @@ -125,7 +125,7 @@ public void DeleteRow_SelectAll_AdjustsSelectionToPreventOverrun () // create a 4 by 4 table var tableView = new TableView { - Table = BuildTable (4, 4, out DataTable dt), MultiSelect = true, Bounds = new Rectangle (0, 0, 10, 5) + Table = BuildTable (4, 4, out DataTable dt), MultiSelect = true, ContentArea = new Rectangle (0, 0, 10, 5) }; tableView.BeginInit (); tableView.EndInit (); @@ -152,7 +152,7 @@ public void DeleteRow_SelectLastRow_AdjustsSelectionToPreventOverrun () // create a 4 by 4 table var tableView = new TableView { - Table = BuildTable (4, 4, out DataTable dt), MultiSelect = true, Bounds = new Rectangle (0, 0, 10, 5) + Table = BuildTable (4, 4, out DataTable dt), MultiSelect = true, ContentArea = new Rectangle (0, 0, 10, 5) }; tableView.BeginInit (); tableView.EndInit (); @@ -180,7 +180,7 @@ public void EnsureValidScrollOffsets_LoadSmallerTable () var tableView = new TableView (); tableView.BeginInit (); tableView.EndInit (); - tableView.Bounds = new Rectangle (0, 0, 25, 10); + tableView.ContentArea = new Rectangle (0, 0, 25, 10); Assert.Equal (0, tableView.RowOffset); Assert.Equal (0, tableView.ColumnOffset); @@ -237,7 +237,7 @@ public void GetAllSelectedCells_SingleCellSelected_ReturnsOne (bool multiSelect) { var tableView = new TableView { - Table = BuildTable (3, 3), MultiSelect = multiSelect, Bounds = new Rectangle (0, 0, 10, 5) + Table = BuildTable (3, 3), MultiSelect = multiSelect, ContentArea = new Rectangle (0, 0, 10, 5) }; tableView.BeginInit (); tableView.EndInit (); @@ -253,7 +253,7 @@ public void GetAllSelectedCells_SquareSelection_FullRowSelect () { var tableView = new TableView { - Table = BuildTable (3, 3), MultiSelect = true, FullRowSelect = true, Bounds = new Rectangle (0, 0, 10, 5) + Table = BuildTable (3, 3), MultiSelect = true, FullRowSelect = true, ContentArea = new Rectangle (0, 0, 10, 5) }; tableView.BeginInit (); tableView.EndInit (); @@ -280,7 +280,7 @@ public void GetAllSelectedCells_SquareSelection_ReturnsFour () { var tableView = new TableView { - Table = BuildTable (3, 3), MultiSelect = true, Bounds = new Rectangle (0, 0, 10, 5) + Table = BuildTable (3, 3), MultiSelect = true, ContentArea = new Rectangle (0, 0, 10, 5) }; tableView.BeginInit (); tableView.EndInit (); @@ -305,7 +305,7 @@ public void GetAllSelectedCells_TwoIsolatedSelections_ReturnsSix () { var tableView = new TableView { - Table = BuildTable (20, 20), MultiSelect = true, Bounds = new Rectangle (0, 0, 10, 5) + Table = BuildTable (20, 20), MultiSelect = true, ContentArea = new Rectangle (0, 0, 10, 5) }; tableView.BeginInit (); tableView.EndInit (); @@ -423,7 +423,7 @@ public void LongColumnTest () tableView.ColorScheme = Colors.ColorSchemes ["TopLevel"]; // 25 characters can be printed into table - tableView.Bounds = new Rectangle (0, 0, 25, 5); + tableView.ContentArea = new Rectangle (0, 0, 25, 5); tableView.Style.ShowHorizontalHeaderUnderline = true; tableView.Style.ShowHorizontalHeaderOverline = false; tableView.Style.AlwaysShowHeaders = true; @@ -524,7 +524,7 @@ public void LongColumnTest () var driver = (FakeDriver)Application.Driver; driver.ClearContents (); - tableView.Bounds = new Rectangle (0, 0, 9, 5); + tableView.ContentArea = new Rectangle (0, 0, 9, 5); tableView.LayoutSubviews (); tableView.Draw (); @@ -541,7 +541,7 @@ public void LongColumnTest () // setting width to 10 leaves just enough space for the column to // meet MinAcceptableWidth of 5. Column width includes terminator line // symbol (e.g. ┤ or │) - tableView.Bounds = new Rectangle (0, 0, 10, 5); + tableView.ContentArea = new Rectangle (0, 0, 10, 5); tableView.LayoutSubviews (); tableView.Draw (); @@ -554,7 +554,7 @@ public void LongColumnTest () "; TestHelpers.AssertDriverContentsAre (expected, output); - tableView.Bounds = new Rectangle (0, 0, 25, 5); + tableView.ContentArea = new Rectangle (0, 0, 25, 5); // revert style change style.MinAcceptableWidth = TableView.DefaultMinAcceptableWidth; @@ -601,7 +601,7 @@ public void PageDown_ExcludesHeaders () { var tableView = new TableView { - Table = BuildTable (25, 50), MultiSelect = true, Bounds = new Rectangle (0, 0, 10, 5) + Table = BuildTable (25, 50), MultiSelect = true, ContentArea = new Rectangle (0, 0, 10, 5) }; // Header should take up 2 lines @@ -637,7 +637,7 @@ public void Redraw_EmptyTable () { var tableView = new TableView (); tableView.ColorScheme = new ColorScheme (); - tableView.Bounds = new Rectangle (0, 0, 25, 10); + tableView.ContentArea = new Rectangle (0, 0, 25, 10); // Set a table with 1 column tableView.Table = BuildTable (1, 50, out DataTable dt); @@ -659,7 +659,7 @@ public void ScrollDown_OneLineAtATime () tableView.Table = BuildTable (25, 50); // 1 header + 4 rows visible - tableView.Bounds = new Rectangle (0, 0, 25, 5); + tableView.ContentArea = new Rectangle (0, 0, 25, 5); tableView.Style.ShowHorizontalHeaderUnderline = false; tableView.Style.ShowHorizontalHeaderOverline = false; tableView.Style.AlwaysShowHeaders = true; @@ -686,7 +686,7 @@ public void ScrollIndicators () tableView.ColorScheme = Colors.ColorSchemes ["TopLevel"]; // 3 columns are visibile - tableView.Bounds = new Rectangle (0, 0, 7, 5); + tableView.ContentArea = new Rectangle (0, 0, 7, 5); tableView.Style.ShowHorizontalHeaderUnderline = true; tableView.Style.ShowHorizontalHeaderOverline = false; tableView.Style.AlwaysShowHeaders = true; @@ -764,7 +764,7 @@ public void ScrollRight_SmoothScrolling () tableView.LayoutSubviews (); // 3 columns are visibile - tableView.Bounds = new Rectangle (0, 0, 7, 5); + tableView.ContentArea = new Rectangle (0, 0, 7, 5); tableView.Style.ShowHorizontalHeaderUnderline = false; tableView.Style.ShowHorizontalHeaderOverline = false; tableView.Style.AlwaysShowHeaders = true; @@ -827,7 +827,7 @@ public void ScrollRight_WithoutSmoothScrolling () tableView.ColorScheme = Colors.ColorSchemes ["TopLevel"]; // 3 columns are visibile - tableView.Bounds = new Rectangle (0, 0, 7, 5); + tableView.ContentArea = new Rectangle (0, 0, 7, 5); tableView.Style.ShowHorizontalHeaderUnderline = false; tableView.Style.ShowHorizontalHeaderOverline = false; tableView.Style.AlwaysShowHeaders = true; @@ -944,7 +944,7 @@ public void ShowHorizontalBottomLine_NoCellLines () tableView.ColorScheme = Colors.ColorSchemes ["TopLevel"]; // 3 columns are visibile - tableView.Bounds = new Rectangle (0, 0, 7, 5); + tableView.ContentArea = new Rectangle (0, 0, 7, 5); tableView.Style.ShowHorizontalHeaderUnderline = true; tableView.Style.ShowHorizontalHeaderOverline = false; tableView.Style.AlwaysShowHeaders = true; @@ -975,7 +975,7 @@ public void ShowHorizontalBottomLine_WithVerticalCellLines () tableView.ColorScheme = Colors.ColorSchemes ["TopLevel"]; // 3 columns are visibile - tableView.Bounds = new Rectangle (0, 0, 7, 5); + tableView.ContentArea = new Rectangle (0, 0, 7, 5); tableView.Style.ShowHorizontalHeaderUnderline = true; tableView.Style.ShowHorizontalHeaderOverline = false; tableView.Style.AlwaysShowHeaders = true; @@ -1044,7 +1044,7 @@ public void TableView_ColorsTest_ColorGetter (bool focused) tv.LayoutSubviews (); // width exactly matches the max col widths - tv.Bounds = new Rectangle (0, 0, 5, 4); + tv.ContentArea = new Rectangle (0, 0, 5, 4); // Create a style for column B ColumnStyle bStyle = tv.Style.GetOrCreateColumnStyle (1); @@ -1141,7 +1141,7 @@ public void TableView_ColorsTest_RowColorGetter (bool focused) tv.LayoutSubviews (); // width exactly matches the max col widths - tv.Bounds = new Rectangle (0, 0, 5, 4); + tv.ContentArea = new Rectangle (0, 0, 5, 4); var rowHighlight = new ColorScheme { @@ -1235,7 +1235,7 @@ public void TableView_ColorTests_FocusedOrNot (bool focused) tv.LayoutSubviews (); // width exactly matches the max col widths - tv.Bounds = new Rectangle (0, 0, 5, 4); + tv.ContentArea = new Rectangle (0, 0, 5, 4); // private method for forcing the view to be focused/not focused MethodInfo setFocusMethod = @@ -1282,7 +1282,7 @@ public void TableView_ColorTests_InvertSelectedCellFirstCharacter (bool focused) tv.LayoutSubviews (); // width exactly matches the max col widths - tv.Bounds = new Rectangle (0, 0, 5, 4); + tv.ContentArea = new Rectangle (0, 0, 5, 4); // private method for forcing the view to be focused/not focused MethodInfo setFocusMethod = @@ -1354,7 +1354,7 @@ public void TableView_ExpandLastColumn_False_ExactBounds () tv.Style.ExpandLastColumn = false; // width exactly matches the max col widths - tv.Bounds = new Rectangle (0, 0, 5, 4); + tv.ContentArea = new Rectangle (0, 0, 5, 4); tv.Draw (); @@ -1398,7 +1398,7 @@ public void TableView_ExpandLastColumn_True () public void TableView_ShowHeadersFalse_AllLines () { TableView tv = GetABCDEFTableView (out _); - tv.Bounds = new Rectangle (0, 0, 5, 5); + tv.ContentArea = new Rectangle (0, 0, 5, 5); tv.Style.ShowHeaders = false; tv.Style.ShowHorizontalHeaderOverline = true; @@ -1422,7 +1422,7 @@ public void TableView_ShowHeadersFalse_AllLines () public void TableView_ShowHeadersFalse_AndNoHeaderLines () { TableView tv = GetABCDEFTableView (out _); - tv.Bounds = new Rectangle (0, 0, 5, 5); + tv.ContentArea = new Rectangle (0, 0, 5, 5); tv.Style.ShowHeaders = false; tv.Style.ShowHorizontalHeaderOverline = false; @@ -1441,7 +1441,7 @@ public void TableView_ShowHeadersFalse_AndNoHeaderLines () public void TableView_ShowHeadersFalse_OverlineTrue () { TableView tv = GetABCDEFTableView (out _); - tv.Bounds = new Rectangle (0, 0, 5, 5); + tv.ContentArea = new Rectangle (0, 0, 5, 5); tv.Style.ShowHeaders = false; tv.Style.ShowHorizontalHeaderOverline = true; @@ -1461,7 +1461,7 @@ public void TableView_ShowHeadersFalse_OverlineTrue () public void TableView_ShowHeadersFalse_UnderlineTrue () { TableView tv = GetABCDEFTableView (out _); - tv.Bounds = new Rectangle (0, 0, 5, 5); + tv.ContentArea = new Rectangle (0, 0, 5, 5); tv.Style.ShowHeaders = false; tv.Style.ShowHorizontalHeaderOverline = false; @@ -1588,7 +1588,7 @@ public void Test_CollectionNavigator () { var tv = new TableView (); tv.ColorScheme = Colors.ColorSchemes ["TopLevel"]; - tv.Bounds = new Rectangle (0, 0, 50, 7); + tv.ContentArea = new Rectangle (0, 0, 50, 7); tv.Table = new EnumerableTableSource ( new [] { "fish", "troll", "trap", "zoo" }, @@ -2219,7 +2219,7 @@ public void TestEnumerableDataSource_BasicTypes () { var tv = new TableView (); tv.ColorScheme = Colors.ColorSchemes ["TopLevel"]; - tv.Bounds = new Rectangle (0, 0, 50, 6); + tv.ContentArea = new Rectangle (0, 0, 50, 6); tv.Table = new EnumerableTableSource ( new [] { typeof (string), typeof (int), typeof (float) }, @@ -2253,7 +2253,7 @@ public void TestFullRowSelect_AlwaysUseNormalColorForVerticalCellLines () TableView tv = GetTwoRowSixColumnTable (out DataTable dt); dt.Rows.Add (1, 2, 3, 4, 5, 6); - tv.Bounds = new Rectangle (0, 0, 7, 6); + tv.ContentArea = new Rectangle (0, 0, 7, 6); tv.Frame = new Rectangle (0, 0, 7, 6); tv.LayoutSubviews (); @@ -2269,7 +2269,7 @@ public void TestFullRowSelect_AlwaysUseNormalColorForVerticalCellLines () // should select that row Assert.Equal (2, tv.SelectedRow); - tv.OnDrawContent (tv.Bounds); + tv.OnDrawContent (tv.ContentArea); var expected = @" @@ -2310,7 +2310,7 @@ public void TestFullRowSelect_SelectionColorDoesNotStop_WhenShowVerticalCellLine dt.Rows.Add (1, 2, 3, 4, 5, 6); tv.LayoutSubviews (); - tv.Bounds = new Rectangle (0, 0, 7, 6); + tv.ContentArea = new Rectangle (0, 0, 7, 6); tv.FullRowSelect = true; tv.Style.ShowVerticalCellLines = false; @@ -2362,7 +2362,7 @@ public void TestFullRowSelect_SelectionColorStopsAtTableEdge_WithCellLines () TableView tv = GetTwoRowSixColumnTable (out DataTable dt); dt.Rows.Add (1, 2, 3, 4, 5, 6); - tv.Bounds = new Rectangle (0, 0, 7, 6); + tv.ContentArea = new Rectangle (0, 0, 7, 6); tv.Frame = new Rectangle (0, 0, 7, 6); tv.LayoutSubviews (); @@ -2377,7 +2377,7 @@ public void TestFullRowSelect_SelectionColorStopsAtTableEdge_WithCellLines () // should select that row Assert.Equal (2, tv.SelectedRow); - tv.OnDrawContent (tv.Bounds); + tv.OnDrawContent (tv.ContentArea); var expected = @" @@ -2425,7 +2425,7 @@ public void TestListTableSource (Orientation orient, bool parallel) //tv.BeginInit (); tv.EndInit (); tv.ColorScheme = Colors.ColorSchemes ["TopLevel"]; - tv.Bounds = new Rectangle (0, 0, 25, 4); + tv.ContentArea = new Rectangle (0, 0, 25, 4); tv.Style = new TableStyle { @@ -3021,7 +3021,7 @@ public void TestToggleCells_MultiSelectOn () Assert.Equal (0, selectedCell.Y); // Go Right - tableView.NewKeyDownEvent (Key.CursorRight ); + tableView.NewKeyDownEvent (Key.CursorRight); selectedCell = tableView.GetAllSelectedCells ().Single (); Assert.Equal (1, selectedCell.X); @@ -3050,7 +3050,7 @@ public void TestToggleCells_MultiSelectOn () Assert.Equal (0, s2.Y); // Go Down - tableView.NewKeyDownEvent (Key.CursorDown ); + tableView.NewKeyDownEvent (Key.CursorDown); // Both Toggled and Moved to should be selected but not 0,0 // which we moved down from @@ -3194,7 +3194,7 @@ private TableView GetABCDEFTableView (out DataTable dt) tableView.ColorScheme = Colors.ColorSchemes ["TopLevel"]; // 3 columns are visible - tableView.Bounds = new Rectangle (0, 0, 7, 5); + tableView.ContentArea = new Rectangle (0, 0, 7, 5); tableView.Style.ShowHorizontalHeaderUnderline = false; tableView.Style.ShowHorizontalHeaderOverline = false; tableView.Style.AlwaysShowHeaders = true; @@ -3218,7 +3218,7 @@ private TableView GetPetTable (out EnumerableTableSource source) { var tv = new TableView (); tv.ColorScheme = Colors.ColorSchemes ["TopLevel"]; - tv.Bounds = new Rectangle (0, 0, 25, 6); + tv.ContentArea = new Rectangle (0, 0, 25, 6); List pets = new () { @@ -3248,7 +3248,7 @@ private TableView GetTwoRowSixColumnTable (out DataTable dt) tableView.ColorScheme = Colors.ColorSchemes ["TopLevel"]; // 3 columns are visible - tableView.Bounds = new Rectangle (0, 0, 7, 5); + tableView.ContentArea = new Rectangle (0, 0, 7, 5); tableView.Style.ShowHorizontalHeaderUnderline = true; tableView.Style.ShowHorizontalHeaderOverline = false; tableView.Style.AlwaysShowHeaders = true; @@ -3277,7 +3277,7 @@ private TableView SetUpMiniTable (out DataTable dt) var tv = new TableView (); tv.BeginInit (); tv.EndInit (); - tv.Bounds = new Rectangle (0, 0, 10, 4); + tv.ContentArea = new Rectangle (0, 0, 10, 4); dt = new DataTable (); dt.Columns.Add ("A"); diff --git a/UnitTests/Views/TextValidateFieldTests.cs b/UnitTests/Views/TextValidateFieldTests.cs index 162172ce57..cf1a88c049 100644 --- a/UnitTests/Views/TextValidateFieldTests.cs +++ b/UnitTests/Views/TextValidateFieldTests.cs @@ -71,7 +71,7 @@ public void Default_Width_Is_Always_Equal_To_The_Provider_DisplayText_Length () // A-Alphanumeric, required. a-Alphanumeric, optional. var field = new TextValidateField { Provider = new NetMaskedTextProvider ("999 000 LLL >LLL |AAA aaa") }; - Assert.Equal (field.Bounds.Width, field.Provider.DisplayText.Length); + Assert.Equal (field.ContentArea.Width, field.Provider.DisplayText.Length); Assert.NotEqual (field.Provider.DisplayText.Length, field.Provider.Text.Length); Assert.Equal (new string (' ', field.Text.Length), field.Provider.Text); } diff --git a/UnitTests/Views/TextViewTests.cs b/UnitTests/Views/TextViewTests.cs index 6f47b350e4..f99f625098 100644 --- a/UnitTests/Views/TextViewTests.cs +++ b/UnitTests/Views/TextViewTests.cs @@ -63,7 +63,7 @@ public void BackTab_Test_Follow_By_Tab () Application.Iteration += (s, a) => { - int width = _textView.Bounds.Width - 1; + int width = _textView.ContentArea.Width - 1; Assert.Equal (30, width + 1); Assert.Equal (10, _textView.Height); _textView.Text = ""; @@ -6912,28 +6912,28 @@ public void ScrollBarType_IsBuiltIn_Always_Adjust_LeftColumn () Assert.Equal (4, tv.LeftColumn); Assert.Equal (14, tv.Maxlength); - Assert.Equal (tv.LeftColumn, tv.Maxlength - tv.Bounds.Width); + Assert.Equal (tv.LeftColumn, tv.Maxlength - tv.ContentArea.Width); tv.NewKeyDownEvent (new Key (KeyCode.Backspace)); tv.NewKeyDownEvent (new Key (KeyCode.End)); Assert.Equal (3, tv.LeftColumn); Assert.Equal (13, tv.Maxlength); - Assert.Equal (tv.LeftColumn, tv.Maxlength - tv.Bounds.Width); + Assert.Equal (tv.LeftColumn, tv.Maxlength - tv.ContentArea.Width); tv.NewKeyDownEvent (new Key (KeyCode.Space)); tv.NewKeyDownEvent (new Key (KeyCode.Space)); Assert.Equal (5, tv.LeftColumn); Assert.Equal (15, tv.Maxlength); - Assert.Equal (tv.LeftColumn, tv.Maxlength - tv.Bounds.Width); + Assert.Equal (tv.LeftColumn, tv.Maxlength - tv.ContentArea.Width); tv.NewKeyDownEvent (new Key (KeyCode.Backspace)); tv.NewKeyDownEvent (new Key (KeyCode.Backspace)); Assert.Equal (3, tv.LeftColumn); Assert.Equal (13, tv.Maxlength); - Assert.Equal (tv.LeftColumn, tv.Maxlength - tv.Bounds.Width); + Assert.Equal (tv.LeftColumn, tv.Maxlength - tv.ContentArea.Width); } [Fact] @@ -6958,27 +6958,27 @@ public void ScrollBarType_IsBuiltIn_Always_Adjust_TopRow () Assert.Equal (4, tv.TopRow); Assert.Equal (13, tv.Lines); - Assert.Equal (tv.TopRow, tv.Lines - tv.Bounds.Height); + Assert.Equal (tv.TopRow, tv.Lines - tv.ContentArea.Height); tv.NewKeyDownEvent (new Key (KeyCode.Backspace)); Assert.Equal (3, tv.TopRow); Assert.Equal (12, tv.Lines); - Assert.Equal (tv.TopRow, tv.Lines - tv.Bounds.Height); + Assert.Equal (tv.TopRow, tv.Lines - tv.ContentArea.Height); tv.NewKeyDownEvent (new Key (KeyCode.Enter)); tv.NewKeyDownEvent (new Key (KeyCode.Enter)); Assert.Equal (5, tv.TopRow); Assert.Equal (14, tv.Lines); - Assert.Equal (tv.TopRow, tv.Lines - tv.Bounds.Height); + Assert.Equal (tv.TopRow, tv.Lines - tv.ContentArea.Height); tv.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.AltMask)); tv.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.AltMask)); Assert.Equal (3, tv.TopRow); Assert.Equal (12, tv.Lines); - Assert.Equal (tv.TopRow, tv.Lines - tv.Bounds.Height); + Assert.Equal (tv.TopRow, tv.Lines - tv.ContentArea.Height); } [Fact] @@ -7139,7 +7139,7 @@ public void Tab_Test_Follow_By_BackTab () Application.Iteration += (s, a) => { - int width = _textView.Bounds.Width - 1; + int width = _textView.ContentArea.Width - 1; Assert.Equal (30, width + 1); Assert.Equal (10, _textView.Height); _textView.Text = ""; @@ -7180,7 +7180,7 @@ public void Tab_Test_Follow_By_BackTab_With_Text () Application.Iteration += (s, a) => { - int width = _textView.Bounds.Width - 1; + int width = _textView.ContentArea.Width - 1; Assert.Equal (30, width + 1); Assert.Equal (10, _textView.Height); var col = 0; @@ -7221,7 +7221,7 @@ public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight () Application.Iteration += (s, a) => { - int width = _textView.Bounds.Width - 1; + int width = _textView.ContentArea.Width - 1; Assert.Equal (30, width + 1); Assert.Equal (10, _textView.Height); _textView.Text = ""; @@ -7271,7 +7271,7 @@ public void Tab_Test_Follow_By_CursorLeft_And_Then_Follow_By_CursorRight_With_Te Application.Iteration += (s, a) => { - int width = _textView.Bounds.Width - 1; + int width = _textView.ContentArea.Width - 1; Assert.Equal (30, width + 1); Assert.Equal (10, _textView.Height); Assert.Equal ("TAB to jump between text fields.", _textView.Text); @@ -7323,7 +7323,7 @@ public void Tab_Test_Follow_By_Home_And_Then_Follow_By_End_And_Then_Follow_By_Ba Application.Iteration += (s, a) => { - int width = _textView.Bounds.Width - 1; + int width = _textView.ContentArea.Width - 1; Assert.Equal (30, width + 1); Assert.Equal (10, _textView.Height); var col = 0; @@ -7489,7 +7489,7 @@ public void TextView_InsertText_Newline_CRLF () //this passes Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre ( - @" + @" ┌─────────────┐ │ │ │aaa │ @@ -7505,8 +7505,8 @@ public void TextView_InsertText_Newline_CRLF () │ │ │ │ └─────────────┘", - _output - ); + _output + ); Assert.Equal (new Rectangle (0, 0, 15, 15), pos); @@ -7565,7 +7565,7 @@ public void TextView_InsertText_Newline_LF () //this passes Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre ( - @" + @" ┌─────────────┐ │ │ │aaa │ @@ -7581,8 +7581,8 @@ public void TextView_InsertText_Newline_LF () │ │ │ │ └─────────────┘", - _output - ); + _output + ); Assert.Equal (new Rectangle (0, 0, 15, 15), pos); diff --git a/UnitTests/Views/ToplevelTests.cs b/UnitTests/Views/ToplevelTests.cs index 5707a485cc..6119f2152c 100644 --- a/UnitTests/Views/ToplevelTests.cs +++ b/UnitTests/Views/ToplevelTests.cs @@ -1364,7 +1364,7 @@ void view_LayoutStarted (object sender, LayoutEventArgs e) Assert.Equal (new Rectangle (1, 3, 10, 5), view.Frame); Assert.Equal (new Rectangle (0, 0, 10, 5), view._needsDisplayRect); - view.OnDrawContent (view.Bounds); + view.OnDrawContent (view.ContentArea); view.Frame = new Rectangle (1, 3, 10, 5); Assert.Equal (new Rectangle (1, 3, 10, 5), view.Frame); Assert.Equal (new Rectangle (0, 0, 10, 5), view._needsDisplayRect); diff --git a/UnitTests/Views/TreeTableSourceTests.cs b/UnitTests/Views/TreeTableSourceTests.cs index 68d006f35a..14fc17f622 100644 --- a/UnitTests/Views/TreeTableSourceTests.cs +++ b/UnitTests/Views/TreeTableSourceTests.cs @@ -227,7 +227,7 @@ private TableView GetTreeTable (out TreeView tree) var tableView = new TableView (); tableView.ColorScheme = Colors.ColorSchemes ["TopLevel"]; tableView.ColorScheme = Colors.ColorSchemes ["TopLevel"]; - tableView.Bounds = new Rectangle (0, 0, 40, 6); + tableView.ContentArea = new Rectangle (0, 0, 40, 6); tableView.Style.ShowHorizontalHeaderUnderline = true; tableView.Style.ShowHorizontalHeaderOverline = false; diff --git a/UnitTests/Views/TreeViewTests.cs b/UnitTests/Views/TreeViewTests.cs index d170a7ec32..b2701ada7d 100644 --- a/UnitTests/Views/TreeViewTests.cs +++ b/UnitTests/Views/TreeViewTests.cs @@ -9,6 +9,70 @@ public class TreeViewTests private readonly ITestOutputHelper _output; public TreeViewTests (ITestOutputHelper output) { _output = output; } + [Fact] + public void Accept_Cancel_Event_Prevents_ObjectActivated () + { + TreeView treeView = CreateTree (out Factory f, out Car car1, out _); + treeView.SelectedObject = car1; + var accepted = false; + var activated = false; + object selectedObject = null; + + treeView.Accept += Accept; + treeView.ObjectActivated += ObjectActivated; + + treeView.InvokeCommand (Command.Accept); + + Assert.True (accepted); + Assert.False (activated); + Assert.Equal (null, selectedObject); + + return; + + void ObjectActivated (object sender, ObjectActivatedEventArgs e) + { + activated = true; + selectedObject = e.ActivatedObject; + } + + void Accept (object sender, CancelEventArgs e) + { + accepted = true; + e.Cancel = true; + } + } + + [Fact] + public void Accept_Command_Accepts_and_ActivatesObject () + { + TreeView treeView = CreateTree (out Factory f, out Car car1, out _); + Assert.NotNull (car1); + treeView.SelectedObject = car1; + + var accepted = false; + var activated = false; + object selectedObject = null; + + treeView.Accept += Accept; + treeView.ObjectActivated += ObjectActivated; + + treeView.InvokeCommand (Command.Accept); + + Assert.True (accepted); + Assert.True (activated); + Assert.Equal (car1, selectedObject); + + return; + + void ObjectActivated (object sender, ObjectActivatedEventArgs e) + { + activated = true; + selectedObject = e.ActivatedObject; + } + + void Accept (object sender, CancelEventArgs e) { accepted = true; } + } + /// Tests that results in a correct content height [Fact] public void ContentHeight_BiggerAfterExpand () @@ -30,7 +94,7 @@ public void ContentWidth_BiggerAfterExpand () tree.BeginInit (); tree.EndInit (); - tree.Bounds = new Rectangle (0, 0, 10, 10); + tree.ContentArea = new Rectangle (0, 0, 10, 10); InitFakeDriver (); @@ -60,7 +124,7 @@ public void ContentWidth_VisibleVsAll () tree.EndInit (); // control only allows 1 row to be viewed at once - tree.Bounds = new Rectangle (0, 0, 20, 1); + tree.ContentArea = new Rectangle (0, 0, 20, 1); InitFakeDriver (); @@ -234,7 +298,7 @@ public void GoTo_OnlyAppliesToExposedObjects () tree.EndInit (); // Make tree bounds 1 in height so that EnsureVisible always requires updating scroll offset - tree.Bounds = new Rectangle (0, 0, 50, 1); + tree.ContentArea = new Rectangle (0, 0, 50, 1); Assert.Null (tree.SelectedObject); Assert.Equal (0, tree.ScrollOffsetVertical); @@ -264,6 +328,33 @@ public void GoToEnd_ShouldNotFailOnEmptyTreeView () Assert.Null (exception); } + [Fact] + public void HotKey_Command_Does_Not_Accept () + { + var treeView = new TreeView (); + var accepted = false; + + treeView.Accept += OnAccept; + treeView.InvokeCommand (Command.HotKey); + + Assert.False (accepted); + + return; + + void OnAccept (object sender, CancelEventArgs e) { accepted = true; } + } + + [Fact] + public void HotKey_Command_SetsFocus () + { + var view = new TreeView (); + + view.CanFocus = true; + Assert.False (view.HasFocus); + view.InvokeCommand (Command.HotKey); + Assert.True (view.HasFocus); + } + /// /// Tests that and behaves /// correctly when an object cannot be expanded (because it has no children) @@ -1348,95 +1439,4 @@ private TreeView CreateTree (out Factory factory1, out Car car1, out Car } #endregion - - - [Fact] - public void HotKey_Command_SetsFocus () - { - var view = new TreeView (); - - view.CanFocus = true; - Assert.False (view.HasFocus); - view.InvokeCommand (Command.HotKey); - Assert.True (view.HasFocus); - } - - [Fact] - public void HotKey_Command_Does_Not_Accept () - { - var treeView = new TreeView (); - var accepted = false; - - treeView.Accept += OnAccept; - treeView.InvokeCommand (Command.HotKey); - - Assert.False (accepted); - - return; - void OnAccept (object sender, CancelEventArgs e) { accepted = true; } - } - - - [Fact] - public void Accept_Command_Accepts_and_ActivatesObject () - { - var treeView = CreateTree (out Factory f, out Car car1, out _); - Assert.NotNull (car1); - treeView.SelectedObject = car1; - - var accepted = false; - var activated = false; - object selectedObject = null; - - treeView.Accept += Accept; - treeView.ObjectActivated += ObjectActivated; - - treeView.InvokeCommand (Command.Accept); - - Assert.True (accepted); - Assert.True (activated); - Assert.Equal (car1, selectedObject); - - return; - - void ObjectActivated (object sender, ObjectActivatedEventArgs e) - { - activated = true; - selectedObject = e.ActivatedObject; - } - void Accept (object sender, CancelEventArgs e) { accepted = true; } - } - - [Fact] - public void Accept_Cancel_Event_Prevents_ObjectActivated () - { - var treeView = CreateTree (out Factory f, out Car car1, out _); - treeView.SelectedObject = car1; - var accepted = false; - var activated = false; - object selectedObject = null; - - treeView.Accept += Accept; - treeView.ObjectActivated += ObjectActivated; - - treeView.InvokeCommand (Command.Accept); - - Assert.True (accepted); - Assert.False (activated); - Assert.Equal (null, selectedObject); - - return; - - void ObjectActivated (object sender, ObjectActivatedEventArgs e) - { - activated = true; - selectedObject = e.ActivatedObject; - } - - void Accept (object sender, CancelEventArgs e) - { - accepted = true; - e.Cancel = true; - } - } } diff --git a/UnitTests/Views/WindowTests.cs b/UnitTests/Views/WindowTests.cs index 57fc532186..633d7ebf65 100644 --- a/UnitTests/Views/WindowTests.cs +++ b/UnitTests/Views/WindowTests.cs @@ -135,7 +135,7 @@ public void New_Initializes () Assert.Equal ($"Window(){defaultWindow.Frame}", defaultWindow.ToString ()); Assert.True (defaultWindow.CanFocus); Assert.False (defaultWindow.HasFocus); - Assert.Equal (new Rectangle (0, 0, 2147483645, 2147483645), defaultWindow.Bounds); + Assert.Equal (new Rectangle (0, 0, 2147483645, 2147483645), defaultWindow.ContentArea); Assert.Equal (new Rectangle (0, 0, 2147483647, 2147483647), defaultWindow.Frame); Assert.Null (defaultWindow.Focused); Assert.NotNull (defaultWindow.ColorScheme); @@ -158,16 +158,17 @@ public void New_Initializes () Assert.Equal (LayoutStyle.Absolute, windowWithFrameRectEmpty.LayoutStyle); Assert.Equal ("title", windowWithFrameRectEmpty.Title); Assert.Equal (LayoutStyle.Absolute, windowWithFrameRectEmpty.LayoutStyle); + // TODO: Fix things so that this works in release and debug // BUG: This also looks like it might be unintended behavior. - #if DEBUG +#if DEBUG Assert.Equal ($"Window(title){windowWithFrameRectEmpty.Frame}", windowWithFrameRectEmpty.ToString ()); - #else +#else Assert.Equal ("Window()(0,0,0,0)", windowWithFrameRectEmpty.ToString ()); - #endif +#endif Assert.True (windowWithFrameRectEmpty.CanFocus); Assert.False (windowWithFrameRectEmpty.HasFocus); - Assert.Equal (new Rectangle (0, 0, 0, 0), windowWithFrameRectEmpty.Bounds); + Assert.Equal (new Rectangle (0, 0, 0, 0), windowWithFrameRectEmpty.ContentArea); Assert.Equal (new Rectangle (0, 0, 0, 0), windowWithFrameRectEmpty.Frame); Assert.Null (windowWithFrameRectEmpty.Focused); Assert.NotNull (windowWithFrameRectEmpty.ColorScheme); @@ -176,9 +177,9 @@ public void New_Initializes () Assert.Equal (0, windowWithFrameRectEmpty.Width); Assert.Equal (0, windowWithFrameRectEmpty.Height); Assert.False (windowWithFrameRectEmpty.IsCurrentTop); - #if DEBUG +#if DEBUG Assert.Equal (windowWithFrameRectEmpty.Title, windowWithFrameRectEmpty.Id); - #endif +#endif Assert.False (windowWithFrameRectEmpty.WantContinuousButtonPressed); Assert.False (windowWithFrameRectEmpty.WantMousePositionReports); Assert.Null (windowWithFrameRectEmpty.SuperView); @@ -186,21 +187,21 @@ public void New_Initializes () Assert.Equal (TextDirection.LeftRight_TopBottom, windowWithFrameRectEmpty.TextDirection); // Rectangle with values - using var windowWithFrame1234 = new Window ( ); - windowWithFrame1234.Frame = new (1, 2, 3, 4); + using var windowWithFrame1234 = new Window (); + windowWithFrame1234.Frame = new Rectangle (1, 2, 3, 4); windowWithFrame1234.Title = "title"; Assert.Equal ("title", windowWithFrame1234.Title); Assert.NotNull (windowWithFrame1234); Assert.Equal (LayoutStyle.Absolute, windowWithFrame1234.LayoutStyle); Assert.Equal (LayoutStyle.Absolute, windowWithFrame1234.LayoutStyle); - #if DEBUG +#if DEBUG Assert.Equal ($"Window(title){windowWithFrame1234.Frame}", windowWithFrame1234.ToString ()); - #else +#else Assert.Equal ("Window()(1,2,3,4)", windowWithFrame1234.ToString ()); - #endif +#endif Assert.True (windowWithFrame1234.CanFocus); Assert.False (windowWithFrame1234.HasFocus); - Assert.Equal (new Rectangle (0, 0, 1, 2), windowWithFrame1234.Bounds); + Assert.Equal (new Rectangle (0, 0, 1, 2), windowWithFrame1234.ContentArea); Assert.Equal (new Rectangle (1, 2, 3, 4), windowWithFrame1234.Frame); Assert.Null (windowWithFrame1234.Focused); Assert.NotNull (windowWithFrame1234.ColorScheme); @@ -209,9 +210,9 @@ public void New_Initializes () Assert.Equal (3, windowWithFrame1234.Width); Assert.Equal (4, windowWithFrame1234.Height); Assert.False (windowWithFrame1234.IsCurrentTop); - #if DEBUG +#if DEBUG Assert.Equal (windowWithFrame1234.Title, windowWithFrame1234.Id); - #endif +#endif Assert.False (windowWithFrame1234.WantContinuousButtonPressed); Assert.False (windowWithFrame1234.WantMousePositionReports); Assert.Null (windowWithFrame1234.SuperView); From 498fdabd172f05783174fcdbf934afc256d20ed7 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 25 Feb 2024 01:35:11 +0000 Subject: [PATCH 054/130] Fix unit tests when rename Bounds to ContentArea. --- UnitTests/View/DrawTests.cs | 49 ++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/UnitTests/View/DrawTests.cs b/UnitTests/View/DrawTests.cs index cfff1e812e..03dc21cf26 100644 --- a/UnitTests/View/DrawTests.cs +++ b/UnitTests/View/DrawTests.cs @@ -155,18 +155,15 @@ public void Colors_On_TextAlignment_Right_And_Bottom () ((FakeDriver)Application.Driver).SetBufferSize (7, 7); TestHelpers.AssertDriverContentsWithFrameAre ( - """ - - Test - - - T - e - s - t - """, - _output - ); + @" + Test + + +T +e +s +t ", + _output); TestHelpers.AssertDriverAttributesAre ( """ @@ -417,14 +414,12 @@ public void Draw_Negative_Bounds_Horizontal_With_New_Lines () Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre ( - """ - - 6w - 7 - 8 - 9 - 0 - """, + @" + 6w + 7 + 8 + 9 + 0 ", _output ); @@ -619,14 +614,12 @@ public void Draw_Negative_Bounds_Vertical () Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre ( - """ - - 6w - 7 - 8 - 9 - 0 - """, + @" + 6w + 7 + 8 + 9 + 0 ", _output ); From 824c3cf2a3a72f95f8f833b672bdaa8baccc4801 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 25 Feb 2024 12:48:41 +0000 Subject: [PATCH 055/130] Replace ScrollLeftOffset and ScrollTopOffset with ContentOffset. --- Terminal.Gui/View/Layout/ViewLayout.cs | 46 +++++++++-- Terminal.Gui/View/ViewScrollBar.cs | 99 +---------------------- Terminal.Gui/Views/ListView.cs | 67 +++++++-------- Terminal.Gui/Views/ScrollBarView.cs | 34 +++----- Terminal.Gui/Views/TableView/TableView.cs | 65 ++++++--------- Terminal.Gui/Views/TextView.cs | 70 +++++++--------- Terminal.Gui/Views/TreeView/TreeView.cs | 63 ++++++--------- UnitTests/Views/TableViewTests.cs | 2 +- 8 files changed, 161 insertions(+), 285 deletions(-) diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index bf0a6d58a0..97a8e02ccc 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -37,8 +37,7 @@ public enum LayoutStyle public partial class View { private bool _autoSize; - - private Rectangle _bounds; + private Point _contentOffset; private Rectangle _frame; private Dim _height = Dim.Sized (0); private Dim _width = Dim.Sized (0); @@ -195,7 +194,7 @@ public virtual Rectangle ContentArea - Margin.Thickness.Horizontal - Border.Thickness.Horizontal - Padding.Thickness.Horizontal - - ContentOffset.X); + - (UseContentOffset ? ContentOffset.X : 0)); int height = Math.Max ( 0, @@ -203,9 +202,9 @@ public virtual Rectangle ContentArea - Margin.Thickness.Vertical - Border.Thickness.Vertical - Padding.Thickness.Vertical - - ContentOffset.Y); + - (UseContentOffset ? ContentOffset.Y : 0)); - return new Rectangle (ContentOffset, new Size (width, height)); + return new Rectangle (UseContentOffset ? ContentOffset : Point.Empty, new Size (width, height)); } set { @@ -239,7 +238,37 @@ public virtual Rectangle ContentArea /// /// Represent the content offset if is true. /// - public Point ContentOffset { get; set; } + public virtual Point ContentOffset + { + get => _contentOffset; + set + { + _contentOffset = value; + + if (_scrollBar is null) + { + return; + } + + if (!_scrollBar.IsVertical && _scrollBar.Position != -_contentOffset.X) + { + _scrollBar.Position = -_contentOffset.X; + } + else if (_scrollBar is { OtherScrollBarView.IsVertical: false } && _scrollBar?.OtherScrollBarView.Position != -_contentOffset.X) + { + _scrollBar!.OtherScrollBarView.Position = -_contentOffset.X; + } + + if (_scrollBar.IsVertical && _scrollBar.Position != -_contentOffset.Y) + { + _scrollBar.Position = -_contentOffset.Y; + } + else if (_scrollBar is { OtherScrollBarView.IsVertical: true } && _scrollBar?.OtherScrollBarView.Position != -_contentOffset.Y) + { + _scrollBar!.OtherScrollBarView.Position = -_contentOffset.Y; + } + } + } /// Gets or sets the absolute location and dimension of the view. /// @@ -401,6 +430,11 @@ public LayoutStyle LayoutStyle /// public Padding Padding { get; private set; } + /// + /// Determines if negative bounds location is allowed for scrolling the . + /// + public bool UseContentOffset { get; set; } + /// Gets or sets whether validation of and occurs. /// /// Setting this to will enable validation of , , diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 449a45c989..6510999a79 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -31,9 +31,7 @@ public partial class View private ScrollBarView _scrollBar; private ScrollBarType _scrollBarType; private int _scrollColsSize; - private int _scrollLeftOffset; private int _scrollRowsSize; - private int _scrollTopOffset; /// If true the vertical/horizontal scroll bars won't be showed if it's not needed. public bool ScrollAutoHideScrollBars @@ -143,35 +141,6 @@ public bool ScrollKeepContentAlwaysInViewPort set => _scrollBar.KeepContentAlwaysInViewPort = value; } - /// - /// Determines the left offset on scrolling. - /// - public virtual int ScrollLeftOffset - { - get => _scrollLeftOffset; - set - { - if (!UseContentOffset) - { - _scrollLeftOffset = value; - - if (_scrollBar is null) - { - return; - } - - if (!_scrollBar.IsVertical && _scrollBar.Position != _scrollLeftOffset) - { - _scrollBar.Position = _scrollLeftOffset; - } - else if (_scrollBar is { OtherScrollBarView.IsVertical: false } && _scrollBar?.OtherScrollBarView.Position != _scrollLeftOffset) - { - _scrollBar!.OtherScrollBarView.Position = _scrollLeftOffset; - } - } - } - } - /// Represent a vertical or horizontal ScrollBarView other than this. public ScrollBarView ScrollOtherScrollBarView { @@ -236,40 +205,6 @@ public bool ScrollShowScrollIndicator set => _scrollBar.ShowScrollIndicator = value; } - /// - /// Determines the top offset on scrolling. - /// - public virtual int ScrollTopOffset - { - get => _scrollTopOffset; - set - { - if (!UseContentOffset) - { - _scrollTopOffset = value; - - if (_scrollBar is null) - { - return; - } - - if (_scrollBar.IsVertical && _scrollBar.Position != _scrollTopOffset) - { - _scrollBar.Position = _scrollTopOffset; - } - else if (_scrollBar is { OtherScrollBarView.IsVertical: true } && _scrollBar?.OtherScrollBarView.Position != _scrollTopOffset) - { - _scrollBar!.OtherScrollBarView.Position = _scrollTopOffset; - } - } - } - } - - /// - /// Determines if negative bounds location is allowed for scrolling the . - /// - public bool UseContentOffset { get; set; } - private void AddEventHandlersForScrollBars (ScrollBarView scrollBar) { if (scrollBar is null) @@ -589,41 +524,11 @@ private void SetBoundsByPosition (ScrollBarView scrollBar) { if (scrollBar.IsVertical) { - if (UseContentOffset) - { - ContentOffset = new Point (ContentArea.X, -scrollBar.Position); - - if (ContentArea.Y != -scrollBar.Position) - { - scrollBar.Position = ContentArea.Y; - } - } - else - { - if (ScrollTopOffset != scrollBar.Position) - { - ScrollTopOffset = scrollBar.Position; - } - } + ContentOffset = new Point (ContentArea.X, -scrollBar.Position); } else { - if (UseContentOffset) - { - ContentOffset = new Point (-scrollBar.Position, ContentArea.Y); - - if (ContentArea.X != -scrollBar.Position) - { - scrollBar.Position = ContentArea.X; - } - } - else - { - if (ScrollLeftOffset != scrollBar.Position) - { - ScrollLeftOffset = scrollBar.Position; - } - } + ContentOffset = new Point (-scrollBar.Position, ContentArea.Y); } SetTextFormatterSize (); diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs index 60ecac5fa5..d20b4002dc 100644 --- a/Terminal.Gui/Views/ListView.cs +++ b/Terminal.Gui/Views/ListView.cs @@ -191,6 +191,29 @@ public bool AllowsMultipleSelection } } + /// + public override Point ContentOffset + { + get => base.ContentOffset; + set + { + if (base.ContentOffset != value) + { + base.ContentOffset = value; + } + + if (LeftItem != -ContentOffset.X) + { + _left = -ContentOffset.X; + } + + if (TopItem != -ContentOffset.Y) + { + _top = -ContentOffset.Y; + } + } + } + /// /// Gets the that searches the collection as the /// user types. @@ -214,7 +237,7 @@ public int LeftItem throw new ArgumentException ("value"); } - ScrollLeftOffset = _leftItem = value; + ContentOffset = ContentOffset with { X = -(_leftItem = value) }; SetNeedsDisplay (); } } @@ -222,42 +245,6 @@ public int LeftItem /// Gets the widest item in the list. public int MaxLength => _source?.Length ?? 0; - /// - public override int ScrollLeftOffset - { - get => base.ScrollLeftOffset; - set - { - if (base.ScrollLeftOffset != value) - { - base.ScrollLeftOffset = value; - } - - if (LeftItem != ScrollLeftOffset) - { - _left = ScrollLeftOffset; - } - } - } - - /// - public override int ScrollTopOffset - { - get => base.ScrollTopOffset; - set - { - if (base.ScrollTopOffset != value) - { - base.ScrollTopOffset = value; - } - - if (TopItem != ScrollTopOffset) - { - _top = ScrollTopOffset; - } - } - } - /// Gets or sets the index of the currently selected item. /// The selected item. public int SelectedItem @@ -315,7 +302,7 @@ public int TopItem throw new ArgumentException ("value"); } - ScrollTopOffset = _topItem = Math.Max (value, 0); + ContentOffset = ContentOffset with { Y = -(_topItem = Math.Max (value, 0)) }; SetNeedsDisplay (); } } @@ -323,13 +310,13 @@ public int TopItem private int _left { get => _leftItem; - set => ScrollLeftOffset = _leftItem = value; + set => ContentOffset = ContentOffset with { X = -(_leftItem = value) }; } private int _top { get => _topItem; - set => ScrollTopOffset = _topItem = value; + set => ContentOffset = ContentOffset with { Y = -(_topItem = value) }; } /// diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index 2dcfbbdb16..c26daf133f 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -632,7 +632,9 @@ public override bool OnMouseLeave (MouseEvent mouseEvent) // param n is the new position and the max is the positive/negative value that can be scrolled for the new position internal bool CanScroll (int n, out int maxToScroll, bool isVertical = false) { - if (GetSuperViewBounds ().IsEmpty) + Rectangle bounds = SuperView?.GetVisibleContentArea () ?? Rectangle.Empty; + + if (bounds.IsEmpty) { maxToScroll = 0; @@ -657,7 +659,7 @@ private void AdjustContentInViewport (bool refresh = true) } var pos = 0; - Rectangle bounds = GetSuperViewBounds (); + Rectangle bounds = SuperView?.GetVisibleContentArea () ?? Rectangle.Empty; if (KeepContentAlwaysInViewPort && !_vertical && _position + bounds.Width > Size + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0)) { @@ -839,7 +841,7 @@ private void CreateBottomRightCorner (View host) private int GetBarSize (bool isVertical) { - Rectangle bounds = GetSuperViewBounds (); + Rectangle bounds = SuperView?.GetVisibleContentArea () ?? Rectangle.Empty; if (bounds.IsEmpty) { @@ -860,18 +862,6 @@ private int GetBarSize (bool isVertical) KeepContentAlwaysInViewPort ? bounds.Width - (_showBothScrollIndicator ? 1 : 0) : 0; } - private Rectangle GetSuperViewBounds () - { - if (SuperView is null) - { - return Rectangle.Empty; - } - - return new Rectangle ( - Point.Empty, - new Size (SuperView.ContentArea.Width + SuperView.ContentOffset.X, SuperView.ContentArea.Height + SuperView.ContentOffset.Y)); - } - private void ManageScrollBarThickness () { if (!IsBuiltIn) @@ -1020,7 +1010,7 @@ private void SetWidthHeight () { if (SuperView is { UseContentOffset: true }) { - Rectangle bounds = GetSuperViewBounds (); + Rectangle bounds = SuperView?.GetVisibleContentArea () ?? Rectangle.Empty; X = _vertical ? bounds.Right - 1 : bounds.Left; Y = _vertical ? bounds.Top : bounds.Bottom - 1; @@ -1054,7 +1044,7 @@ private void SetWidthHeight () { if (SuperView is { UseContentOffset: true }) { - Rectangle bounds = GetSuperViewBounds (); + Rectangle bounds = SuperView?.GetVisibleContentArea () ?? Rectangle.Empty; X = _vertical ? bounds.Right - 1 : bounds.Left; Y = _vertical ? bounds.Top : bounds.Bottom - 1; @@ -1071,7 +1061,7 @@ private void SetWidthHeight () { if (SuperView is { UseContentOffset: true }) { - Rectangle bounds = GetSuperViewBounds (); + Rectangle bounds = SuperView?.GetVisibleContentArea () ?? Rectangle.Empty; _otherScrollBarView.X = _otherScrollBarView._vertical ? bounds.Right - 1 : bounds.Left; _otherScrollBarView.Y = _otherScrollBarView._vertical ? bounds.Top : bounds.Bottom - 1; @@ -1099,7 +1089,7 @@ private void ShowHideScrollBars (bool redraw = true) return; } - SetRelativeLayout (GetSuperViewBounds ()); + SetRelativeLayout (SuperView?.GetVisibleContentArea () ?? Rectangle.Empty); if (AutoHideScrollBars) { @@ -1107,18 +1097,18 @@ private void ShowHideScrollBars (bool redraw = true) if (_otherScrollBarView is { }) { - _otherScrollBarView.SetRelativeLayout (GetSuperViewBounds ()); + _otherScrollBarView.SetRelativeLayout (SuperView?.GetVisibleContentArea () ?? Rectangle.Empty); CheckBothScrollBars (_otherScrollBarView, pending); } } SetWidthHeight (); - SetRelativeLayout (GetSuperViewBounds ()); + SetRelativeLayout (SuperView?.GetVisibleContentArea () ?? Rectangle.Empty); if (_otherScrollBarView is { }) { OtherScrollBarView.SetWidthHeight (); - OtherScrollBarView.SetRelativeLayout (GetSuperViewBounds ()); + OtherScrollBarView.SetRelativeLayout (SuperView?.GetVisibleContentArea () ?? Rectangle.Empty); } if (_showBothScrollIndicator) diff --git a/Terminal.Gui/Views/TableView/TableView.cs b/Terminal.Gui/Views/TableView/TableView.cs index 567cf8f748..ddf94dda2a 100644 --- a/Terminal.Gui/Views/TableView/TableView.cs +++ b/Terminal.Gui/Views/TableView/TableView.cs @@ -345,7 +345,31 @@ public int ColumnOffset get => _columnOffset; //try to prevent this being set to an out of bounds column - set => ScrollLeftOffset = _columnOffset = TableIsNullOrInvisible () ? 0 : Math.Max (0, Math.Min (Table.Columns - 1, value)); + set => ContentOffset = ContentOffset with { X = -(_columnOffset = TableIsNullOrInvisible () ? 0 : Math.Max (0, Math.Min (Table.Columns - 1, value))) }; + } + + /// + public override Point ContentOffset + { + get => base.ContentOffset; + set + { + if (base.ContentOffset != value) + { + base.ContentOffset = value; + } + + if (ColumnOffset != -ContentOffset.X) + { + _ignoreEnsureSelectedCellIsVisible = true; + ColumnOffset = -ContentOffset.X; + } + + if (RowOffset != -ContentOffset.Y) + { + RowOffset = -ContentOffset.Y; + } + } } /// True to select the entire row at once. False to select individual cells. Defaults to false @@ -381,44 +405,7 @@ public int ColumnOffset public int RowOffset { get => _rowOffset; - set => ScrollTopOffset = _rowOffset = TableIsNullOrInvisible () ? 0 : Math.Max (0, Math.Min (Table.Rows - 1, value)); - } - - /// - public override int ScrollLeftOffset - { - get => base.ScrollLeftOffset; - set - { - if (base.ScrollLeftOffset != value) - { - base.ScrollLeftOffset = value; - } - - if (ColumnOffset != ScrollLeftOffset) - { - _ignoreEnsureSelectedCellIsVisible = true; - ColumnOffset = ScrollLeftOffset; - } - } - } - - /// - public override int ScrollTopOffset - { - get => base.ScrollTopOffset; - set - { - if (base.ScrollTopOffset != value) - { - base.ScrollTopOffset = value; - } - - if (RowOffset != ScrollTopOffset) - { - RowOffset = ScrollTopOffset; - } - } + set => ContentOffset = ContentOffset with { Y = -(_rowOffset = TableIsNullOrInvisible () ? 0 : Math.Max (0, Math.Min (Table.Rows - 1, value))) }; } /// The index of in that the user has currently selected diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index db23a622fa..95132ed30e 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -2589,6 +2589,29 @@ public override bool CanFocus set => base.CanFocus = value; } + /// + public override Point ContentOffset + { + get => base.ContentOffset; + set + { + if (base.ContentOffset != value) + { + base.ContentOffset = value; + } + + if (LeftColumn != -ContentOffset.X) + { + LeftColumn = -ContentOffset.X; + } + + if (TopRow != -ContentOffset.Y) + { + TopRow = -ContentOffset.Y; + } + } + } + /// Get the for this view. public ContextMenu? ContextMenu { get; } @@ -2667,7 +2690,7 @@ public int LeftColumn return; } - ScrollLeftOffset = _leftColumn = Math.Max (Math.Min (value, Maxlength - 1), 0); + ContentOffset = ContentOffset with { X = -(_leftColumn = Math.Max (Math.Min (value, Maxlength - 1), 0)) }; } } @@ -2750,42 +2773,6 @@ public bool ReadOnly } } - /// - public override int ScrollLeftOffset - { - get => base.ScrollLeftOffset; - set - { - if (base.ScrollLeftOffset != value) - { - base.ScrollLeftOffset = value; - } - - if (LeftColumn != ScrollLeftOffset) - { - LeftColumn = ScrollLeftOffset; - } - } - } - - /// - public override int ScrollTopOffset - { - get => base.ScrollTopOffset; - set - { - if (base.ScrollTopOffset != value) - { - base.ScrollTopOffset = value; - } - - if (TopRow != ScrollTopOffset) - { - TopRow = ScrollTopOffset; - } - } - } - /// Length of the selected text. public int SelectedLength => GetSelectedLength (); @@ -2892,7 +2879,7 @@ public override string Text public int TopRow { get => _topRow; - set => ScrollTopOffset = _topRow = Math.Max (Math.Min (value, Lines - 1), 0); + set => ContentOffset = ContentOffset with { Y = -(_topRow = Math.Max (Math.Min (value, Lines - 1), 0)) }; } /// @@ -3956,13 +3943,13 @@ public void ScrollTo (int idx, bool isRow = true) if (isRow) { - ScrollTopOffset = _topRow = Math.Max (idx > _model.Count - 1 ? _model.Count - 1 : idx, 0); + ContentOffset = ContentOffset with { Y = -(_topRow = Math.Max (idx > _model.Count - 1 ? _model.Count - 1 : idx, 0)) }; } else if (!_wordWrap) { int maxlength = _model.GetMaxVisibleLine (_topRow, _topRow + ContentArea.Height, TabWidth); - ScrollLeftOffset = _leftColumn = Math.Max (!_wordWrap && idx > maxlength - 1 ? maxlength - 1 : idx, 0); + ContentOffset = ContentOffset with { X = -(_leftColumn = Math.Max (!_wordWrap && idx > maxlength - 1 ? maxlength - 1 : idx, 0)) }; } SetNeedsDisplay (); @@ -6358,8 +6345,7 @@ private void SetScrollColsRowsSize () { ScrollColsSize = Maxlength; ScrollRowsSize = Lines; - ScrollLeftOffset = LeftColumn; - ScrollTopOffset = TopRow; + ContentOffset = new Point (-LeftColumn, -TopRow); } } diff --git a/Terminal.Gui/Views/TreeView/TreeView.cs b/Terminal.Gui/Views/TreeView/TreeView.cs index c87078dc36..17a5f36c6d 100644 --- a/Terminal.Gui/Views/TreeView/TreeView.cs +++ b/Terminal.Gui/Views/TreeView/TreeView.cs @@ -327,6 +327,29 @@ public TreeView () /// The current number of rows in the tree (ignoring the controls bounds). public int ContentHeight => BuildLineMap ().Count (); + /// + public override Point ContentOffset + { + get => base.ContentOffset; + set + { + if (base.ContentOffset != value) + { + base.ContentOffset = value; + } + + if (ScrollOffsetHorizontal != -ContentOffset.X) + { + ScrollOffsetHorizontal = -ContentOffset.X; + } + + if (ScrollOffsetVertical != -ContentOffset.Y) + { + ScrollOffsetVertical = -ContentOffset.Y; + } + } + } + /// /// Get / Set the wished cursor when the tree is focused. Only applies when is true. /// Defaults to . @@ -386,24 +409,6 @@ public KeyCode ObjectActivationKey /// The root objects in the tree, note that this collection is of root objects only. public IEnumerable Objects => roots.Keys; - /// - public override int ScrollLeftOffset - { - get => base.ScrollLeftOffset; - set - { - if (base.ScrollLeftOffset != value) - { - base.ScrollLeftOffset = value; - } - - if (ScrollOffsetHorizontal != ScrollLeftOffset) - { - ScrollOffsetHorizontal = ScrollLeftOffset; - } - } - } - /// The amount of tree view that has been scrolled to the right (horizontally). /// /// Setting a value of less than 0 will result in a offset of 0. To see changes in the UI call @@ -412,7 +417,7 @@ public override int ScrollLeftOffset public int ScrollOffsetHorizontal { get => _scrollOffsetHorizontal; - set => ScrollLeftOffset = _scrollOffsetHorizontal = Math.Max (0, value); + set => ContentOffset = ContentOffset with { X = -(_scrollOffsetHorizontal = Math.Max (0, value)) }; } /// The amount of tree view that has been scrolled off the top of the screen (by the user scrolling down). @@ -423,25 +428,7 @@ public int ScrollOffsetHorizontal public int ScrollOffsetVertical { get => _scrollOffsetVertical; - set => ScrollTopOffset = _scrollOffsetVertical = Math.Max (0, value); - } - - /// - public override int ScrollTopOffset - { - get => base.ScrollTopOffset; - set - { - if (base.ScrollTopOffset != value) - { - base.ScrollTopOffset = value; - } - - if (ScrollOffsetVertical != ScrollTopOffset) - { - ScrollOffsetVertical = ScrollTopOffset; - } - } + set => ContentOffset = ContentOffset with { Y = -(_scrollOffsetVertical = Math.Max (0, value)) }; } /// diff --git a/UnitTests/Views/TableViewTests.cs b/UnitTests/Views/TableViewTests.cs index 5871282eff..4ef3ebd5f9 100644 --- a/UnitTests/Views/TableViewTests.cs +++ b/UnitTests/Views/TableViewTests.cs @@ -763,7 +763,7 @@ public void ScrollRight_SmoothScrolling () tableView.ColorScheme = Colors.ColorSchemes ["TopLevel"]; tableView.LayoutSubviews (); - // 3 columns are visibile + // 3 columns are visible tableView.ContentArea = new Rectangle (0, 0, 7, 5); tableView.Style.ShowHorizontalHeaderUnderline = false; tableView.Style.ShowHorizontalHeaderOverline = false; From f933f846fb96fd851981b1bb05da7d2ff4e65f43 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 25 Feb 2024 19:28:29 +0000 Subject: [PATCH 056/130] Replace ScrollColsSize and ScrollRowsSize with ContentSize. --- Terminal.Gui/View/Layout/ViewLayout.cs | 53 +++++++++++++ Terminal.Gui/View/ViewScrollBar.cs | 92 +---------------------- Terminal.Gui/Views/ListView.cs | 3 +- Terminal.Gui/Views/TableView/TableView.cs | 11 +-- Terminal.Gui/Views/TextView.cs | 3 +- Terminal.Gui/Views/TreeView/TreeView.cs | 6 +- UICatalog/Scenarios/ScrollBars.cs | 3 +- UnitTests/Views/ScrollBarViewTests.cs | 28 +++---- 8 files changed, 78 insertions(+), 121 deletions(-) diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 97a8e02ccc..d646900df6 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -38,6 +38,7 @@ public partial class View { private bool _autoSize; private Point _contentOffset; + private Size _contentSize; private Rectangle _frame; private Dim _height = Dim.Sized (0); private Dim _width = Dim.Sized (0); @@ -270,6 +271,58 @@ public virtual Point ContentOffset } } + /// + /// Represents the contents size of the data shown inside the . + /// + public Size ContentSize + { + get => _contentSize; + set + { + if (_contentSize != value) + { + _contentSize = value; + SetNeedsDisplay (); + } + + if (_scrollBar is null) + { + return; + } + + if (_scrollBar.IsVertical) + { + if (_scrollBar.Size != ContentSize.Height) + { + _scrollBar.Size = ContentSize.Height; + } + + if (_scrollBar.OtherScrollBarView is { }) + { + if (_scrollBar.OtherScrollBarView.Size != ContentSize.Width) + { + _scrollBar.OtherScrollBarView.Size = ContentSize.Width; + } + } + } + else + { + if (_scrollBar.Size != ContentSize.Width) + { + _scrollBar.Size = ContentSize.Width; + } + + if (_scrollBar.OtherScrollBarView is { }) + { + if (_scrollBar.OtherScrollBarView.Size != ContentSize.Height) + { + _scrollBar.OtherScrollBarView.Size = ContentSize.Height; + } + } + } + } + } + /// Gets or sets the absolute location and dimension of the view. /// /// The rectangle describing absolute location and dimension of the view, in coordinates relative to the diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 6510999a79..3d44c9da00 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -30,8 +30,6 @@ public partial class View { private ScrollBarView _scrollBar; private ScrollBarType _scrollBarType; - private int _scrollColsSize; - private int _scrollRowsSize; /// If true the vertical/horizontal scroll bars won't be showed if it's not needed. public bool ScrollAutoHideScrollBars @@ -93,47 +91,6 @@ public virtual ScrollBarType ScrollBarType } } - /// - /// Determines the number of columns to scrolling. - /// - public int ScrollColsSize - { - get => _scrollColsSize; - set - { - _scrollColsSize = value; - - if (ScrollBarType == ScrollBarType.None) - { - return; - } - - switch (_scrollBar.IsVertical) - { - case true when _scrollBar.OtherScrollBarView is { }: - if (_scrollBar.OtherScrollBarView.Size == _scrollColsSize) - { - return; - } - - _scrollBar.OtherScrollBarView.Size = _scrollColsSize; - - break; - case false: - if (_scrollBar.Size == _scrollColsSize) - { - return; - } - - _scrollBar.Size = _scrollColsSize; - - break; - } - - SetNeedsDisplay (); - } - } - /// Get or sets if the view-port is kept always visible in the area of this public bool ScrollKeepContentAlwaysInViewPort { @@ -156,47 +113,6 @@ public int ScrollPosition set => _scrollBar.Position = value; } - /// - /// Determines the number of rows to scrolling. - /// - public int ScrollRowsSize - { - get => _scrollRowsSize; - set - { - _scrollRowsSize = value; - - if (ScrollBarType == ScrollBarType.None) - { - return; - } - - switch (_scrollBar.IsVertical) - { - case true: - if (_scrollBar.Size == _scrollRowsSize) - { - return; - } - - _scrollBar.Size = _scrollRowsSize; - - break; - case false when _scrollBar.OtherScrollBarView is { }: - if (_scrollBar.OtherScrollBarView.Size == _scrollRowsSize) - { - return; - } - - _scrollBar.OtherScrollBarView.Size = _scrollRowsSize; - - break; - } - - SetNeedsDisplay (); - } - } - /// Gets or sets the visibility for the vertical or horizontal scroll indicator. /// true if show vertical or horizontal scroll indicator; otherwise, false. public bool ScrollShowScrollIndicator @@ -294,14 +210,14 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) { if (scrollBar.IsVertical) { - scrollBar.Position = ScrollRowsSize; + scrollBar.Position = ContentSize.Height; return true; } if (scrollBar.OtherScrollBarView is { IsVertical: true }) { - scrollBar.OtherScrollBarView.Position = ScrollRowsSize; + scrollBar.OtherScrollBarView.Position = ContentSize.Height; return true; } @@ -431,14 +347,14 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) { if (!scrollBar.IsVertical) { - scrollBar.Position = ScrollColsSize; + scrollBar.Position = ContentSize.Width; return true; } if (scrollBar.OtherScrollBarView is { IsVertical: false }) { - scrollBar.OtherScrollBarView.Position = ScrollColsSize; + scrollBar.OtherScrollBarView.Position = ContentSize.Width; return true; } diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs index d20b4002dc..dc50b29443 100644 --- a/Terminal.Gui/Views/ListView.cs +++ b/Terminal.Gui/Views/ListView.cs @@ -914,8 +914,7 @@ private void SetScrollRowsColsSize () { try { - ScrollRowsSize = Source?.Count ?? 0; - ScrollColsSize = MaxLength; + ContentSize = new Size (MaxLength, Source?.Count ?? 0); } catch (NotImplementedException) { } diff --git a/Terminal.Gui/Views/TableView/TableView.cs b/Terminal.Gui/Views/TableView/TableView.cs index ddf94dda2a..ea38443e25 100644 --- a/Terminal.Gui/Views/TableView/TableView.cs +++ b/Terminal.Gui/Views/TableView/TableView.cs @@ -2007,16 +2007,11 @@ private void RenderSeparator (int col, int row, bool isHeader) private void SetScrollRowsColsSize () { - int scrollColsSize = Table?.Columns + ContentArea.Width - 1 ?? 0; + int scrollColsSize = Math.Max (Table?.Columns + ContentArea.Width - 1 ?? 0, 0); - if (ScrollColsSize != scrollColsSize) + if (ContentSize.Width != scrollColsSize || ContentSize.Height != Table?.Rows) { - ScrollColsSize = scrollColsSize; - } - - if (ScrollRowsSize != Table?.Rows) - { - ScrollRowsSize = Table?.Rows ?? 0; + ContentSize = new Size (scrollColsSize, Table?.Rows ?? 0); } } diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 95132ed30e..6dce8a35a2 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -6343,8 +6343,7 @@ private void SetScrollColsRowsSize () { if (ScrollBarType != ScrollBarType.None) { - ScrollColsSize = Maxlength; - ScrollRowsSize = Lines; + ContentSize = new Size (Maxlength, Lines); ContentOffset = new Point (-LeftColumn, -TopRow); } } diff --git a/Terminal.Gui/Views/TreeView/TreeView.cs b/Terminal.Gui/Views/TreeView/TreeView.cs index 17a5f36c6d..9ee5b200fe 100644 --- a/Terminal.Gui/Views/TreeView/TreeView.cs +++ b/Terminal.Gui/Views/TreeView/TreeView.cs @@ -1626,11 +1626,7 @@ private Branch HitTest (int y) /// The branch for or null if it is not currently exposed in the tree. private Branch ObjectToBranch (T toFind) { return BuildLineMap ().FirstOrDefault (o => o.Model.Equals (toFind)); } - private void TreeView_DrawAdornments (object sender, DrawEventArgs e) - { - ScrollRowsSize = ContentHeight; - ScrollColsSize = GetContentWidth (true); - } + private void TreeView_DrawAdornments (object sender, DrawEventArgs e) { ContentSize = new Size (GetContentWidth (true), ContentHeight); } } internal class TreeSelection where T : class diff --git a/UICatalog/Scenarios/ScrollBars.cs b/UICatalog/Scenarios/ScrollBars.cs index 15722f2f60..a284fdcda5 100644 --- a/UICatalog/Scenarios/ScrollBars.cs +++ b/UICatalog/Scenarios/ScrollBars.cs @@ -94,7 +94,6 @@ private void SetViewProperties (View view) view.TextFormatter.FillRemaining = true; view.CanFocus = true; string [] strings = view.Text.Split ("\n").ToArray (); - view.ScrollColsSize = strings.OrderByDescending (s => s.Length).First ().GetColumns (); - view.ScrollRowsSize = strings.Length; + view.ContentSize = new Size (strings.OrderByDescending (s => s.Length).First ().GetColumns (), strings.Length); } } diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index d927a48384..14059dd968 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -1060,10 +1060,13 @@ public void OtherScrollBarView_Not_Null () public void ScrollBar_Ungrab_Mouse_If_The_Mouse_Is_On_Another_View () { var top = new Toplevel { Id = "top", Width = 10, Height = 10 }; - var viewLeft = new View { Id = "left", Width = 5, Height = 5, ScrollBarType = ScrollBarType.Vertical, ScrollRowsSize = 20, CanFocus = true }; + var viewLeft = new View { Id = "left", Width = 5, Height = 5, ScrollBarType = ScrollBarType.Vertical, ContentSize = new Size (0, 20), CanFocus = true }; var viewRight = new View - { Id = "right", X = Pos.Right (viewLeft), Width = 5, Height = 6, ScrollBarType = ScrollBarType.Vertical, ScrollRowsSize = 20, CanFocus = true }; + { + Id = "right", X = Pos.Right (viewLeft), Width = 5, Height = 6, ScrollBarType = ScrollBarType.Vertical, ContentSize = new Size (0, 20), + CanFocus = true + }; top.Add (viewLeft, viewRight); Application.Begin (top); @@ -1139,8 +1142,7 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Padding_Thickne view.TextFormatter.WordWrap = false; view.TextFormatter.MultiLine = true; string [] strings = view.Text.Split ("\n").ToArray (); - view.ScrollColsSize = strings.OrderByDescending (s => s.Length).First ().GetColumns (); - view.ScrollRowsSize = strings.Length; + view.ContentSize = new Size (strings.OrderByDescending (s => s.Length).First ().GetColumns (), strings.Length); view.ColorScheme = new ColorScheme { @@ -1163,8 +1165,8 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Padding_Thickne top.Draw (); Assert.True (view.HasFocus); Assert.False (view2.HasFocus); - Assert.Equal (12, view.ScrollColsSize); - Assert.Equal (7, view.ScrollRowsSize); + Assert.Equal (12, view.ContentSize.Width); + Assert.Equal (7, view.ContentSize.Height); Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=3,Y=2,Width=9,Height=6}", view.Frame.ToString ()); @@ -1252,8 +1254,7 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Padding_Thickne view.TextFormatter.WordWrap = false; view.TextFormatter.MultiLine = true; string [] strings = view.Text.Split ("\n").ToArray (); - view.ScrollColsSize = strings.OrderByDescending (s => s.Length).First ().GetColumns (); - view.ScrollRowsSize = strings.Length; + view.ContentSize = new Size (strings.OrderByDescending (s => s.Length).First ().GetColumns (), strings.Length); view.ColorScheme = new ColorScheme { @@ -1280,8 +1281,8 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Padding_Thickne superTop.Draw (); Assert.True (view.HasFocus); Assert.False (view2.HasFocus); - Assert.Equal (12, view.ScrollColsSize); - Assert.Equal (7, view.ScrollRowsSize); + Assert.Equal (12, view.ContentSize.Width); + Assert.Equal (7, view.ContentSize.Height); Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=2,Y=1,Width=9,Height=6}", view.Frame.ToString ()); @@ -1375,8 +1376,7 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Parent_Inside_A view.TextFormatter.WordWrap = false; view.TextFormatter.MultiLine = true; string [] strings = view.Text.Split ("\n").ToArray (); - view.ScrollColsSize = strings.OrderByDescending (s => s.Length).First ().GetColumns (); - view.ScrollRowsSize = strings.Length; + view.ContentSize = new Size (strings.OrderByDescending (s => s.Length).First ().GetColumns (), strings.Length); view.ColorScheme = new ColorScheme { @@ -1398,8 +1398,8 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Parent_Inside_A superTop.Draw (); Assert.True (view.HasFocus); Assert.False (view2.HasFocus); - Assert.Equal (12, view.ScrollColsSize); - Assert.Equal (7, view.ScrollRowsSize); + Assert.Equal (12, view.ContentSize.Width); + Assert.Equal (7, view.ContentSize.Height); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=2,Y=1,Width=9,Height=6}", view.Frame.ToString ()); From a847cf742cb2f41997581fb5eac25f7f0ea29e85 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 25 Feb 2024 19:38:43 +0000 Subject: [PATCH 057/130] Remove ScrollPosition supersede by ContentOffset. --- Terminal.Gui/View/ViewScrollBar.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 3d44c9da00..8f72c92d4d 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -105,14 +105,6 @@ public ScrollBarView ScrollOtherScrollBarView set => _scrollBar.OtherScrollBarView = value; } - /// The position, relative to , to set the scrollbar at. - /// The position. - public int ScrollPosition - { - get => _scrollBar.Position; - set => _scrollBar.Position = value; - } - /// Gets or sets the visibility for the vertical or horizontal scroll indicator. /// true if show vertical or horizontal scroll indicator; otherwise, false. public bool ScrollShowScrollIndicator From ed7ce89e17012898a08b954606c2ed92cd573580 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 25 Feb 2024 20:51:50 +0000 Subject: [PATCH 058/130] Replace ScrollBarView IsVertical bool type with Orientation type. --- Terminal.Gui/View/Layout/ViewLayout.cs | 10 +- Terminal.Gui/View/ViewScrollBar.cs | 60 ++++----- Terminal.Gui/Views/ScrollBarView.cs | 164 +++++++++++++------------ Terminal.Gui/Views/ScrollView.cs | 6 +- UnitTests/Views/ScrollBarViewTests.cs | 52 ++++---- 5 files changed, 151 insertions(+), 141 deletions(-) diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index d646900df6..de477dbcfa 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -251,20 +251,20 @@ public virtual Point ContentOffset return; } - if (!_scrollBar.IsVertical && _scrollBar.Position != -_contentOffset.X) + if (_scrollBar.Orientation == Orientation.Horizontal && _scrollBar.Position != -_contentOffset.X) { _scrollBar.Position = -_contentOffset.X; } - else if (_scrollBar is { OtherScrollBarView.IsVertical: false } && _scrollBar?.OtherScrollBarView.Position != -_contentOffset.X) + else if (_scrollBar is { OtherScrollBarView.Orientation: Orientation.Horizontal } && _scrollBar?.OtherScrollBarView.Position != -_contentOffset.X) { _scrollBar!.OtherScrollBarView.Position = -_contentOffset.X; } - if (_scrollBar.IsVertical && _scrollBar.Position != -_contentOffset.Y) + if (_scrollBar.Orientation == Orientation.Vertical && _scrollBar.Position != -_contentOffset.Y) { _scrollBar.Position = -_contentOffset.Y; } - else if (_scrollBar is { OtherScrollBarView.IsVertical: true } && _scrollBar?.OtherScrollBarView.Position != -_contentOffset.Y) + else if (_scrollBar is { OtherScrollBarView.Orientation: Orientation.Vertical } && _scrollBar?.OtherScrollBarView.Position != -_contentOffset.Y) { _scrollBar!.OtherScrollBarView.Position = -_contentOffset.Y; } @@ -290,7 +290,7 @@ public Size ContentSize return; } - if (_scrollBar.IsVertical) + if (_scrollBar.Orientation == Orientation.Vertical) { if (_scrollBar.Size != ContentSize.Height) { diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 8f72c92d4d..39539eec58 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -60,16 +60,16 @@ public virtual ScrollBarType ScrollBarType switch (view._scrollBarType) { case ScrollBarType.Vertical: - view._scrollBar = new ScrollBarView { IsVertical = true }; + view._scrollBar = new ScrollBarView { Orientation = Orientation.Vertical }; break; case ScrollBarType.Horizontal: - view._scrollBar = new ScrollBarView { IsVertical = false }; + view._scrollBar = new ScrollBarView { Orientation = Orientation.Horizontal }; break; case ScrollBarType.Both: - view._scrollBar = new ScrollBarView { IsVertical = true }; - view._scrollBar.OtherScrollBarView = new ScrollBarView { IsVertical = false, OtherScrollBarView = view._scrollBar }; + view._scrollBar = new ScrollBarView { Orientation = Orientation.Vertical }; + view._scrollBar.OtherScrollBarView = new ScrollBarView { Orientation = Orientation.Horizontal, OtherScrollBarView = view._scrollBar }; break; case ScrollBarType.None: @@ -130,21 +130,21 @@ private void AddEventHandlersForScrollBars (ScrollBarView scrollBar) private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) { - if (scrollBar.IsVertical) + if (scrollBar.Orientation == Orientation.Vertical) { // Things this view knows how to do scrollBar.AddCommand ( Command.ScrollDown, () => { - if (scrollBar.IsVertical) + if (scrollBar.Orientation == Orientation.Vertical) { scrollBar.Position++; return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: true }) + if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Vertical }) { scrollBar.OtherScrollBarView.Position++; @@ -158,14 +158,14 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) Command.ScrollUp, () => { - if (scrollBar.IsVertical) + if (scrollBar.Orientation == Orientation.Vertical) { scrollBar.Position--; return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: true }) + if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Vertical }) { scrollBar.OtherScrollBarView.Position--; @@ -179,14 +179,14 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) Command.TopHome, () => { - if (scrollBar.IsVertical) + if (scrollBar.Orientation == Orientation.Vertical) { scrollBar.Position = 0; return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: true }) + if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Vertical }) { scrollBar.OtherScrollBarView.Position = 0; @@ -200,14 +200,14 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) Command.BottomEnd, () => { - if (scrollBar.IsVertical) + if (scrollBar.Orientation == Orientation.Vertical) { scrollBar.Position = ContentSize.Height; return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: true }) + if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Vertical }) { scrollBar.OtherScrollBarView.Position = ContentSize.Height; @@ -221,14 +221,14 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) Command.PageDown, () => { - if (scrollBar.IsVertical) + if (scrollBar.Orientation == Orientation.Vertical) { scrollBar.Position += GetVisibleContentArea ().Height; return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: true }) + if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Vertical }) { scrollBar.OtherScrollBarView.Position += GetVisibleContentArea ().Height; @@ -242,14 +242,14 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) Command.PageUp, () => { - if (scrollBar.IsVertical) + if (scrollBar.Orientation == Orientation.Vertical) { scrollBar.Position -= GetVisibleContentArea ().Height; return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: true }) + if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Vertical }) { scrollBar.OtherScrollBarView.Position -= GetVisibleContentArea ().Height; @@ -274,14 +274,14 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) Command.Left, () => { - if (!scrollBar.IsVertical) + if (scrollBar.Orientation == Orientation.Horizontal) { scrollBar.Position--; return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: false }) + if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Horizontal }) { scrollBar.OtherScrollBarView.Position--; @@ -295,14 +295,14 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) Command.Right, () => { - if (!scrollBar.IsVertical) + if (scrollBar.Orientation == Orientation.Horizontal) { scrollBar.Position++; return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: false }) + if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Horizontal }) { scrollBar.OtherScrollBarView.Position++; @@ -316,14 +316,14 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) Command.LeftHome, () => { - if (!scrollBar.IsVertical) + if (scrollBar.Orientation == Orientation.Horizontal) { scrollBar.Position = 0; return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: false }) + if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Horizontal }) { scrollBar.OtherScrollBarView.Position = 0; @@ -337,14 +337,14 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) Command.RightEnd, () => { - if (!scrollBar.IsVertical) + if (scrollBar.Orientation == Orientation.Horizontal) { scrollBar.Position = ContentSize.Width; return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: false }) + if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Horizontal }) { scrollBar.OtherScrollBarView.Position = ContentSize.Width; @@ -358,14 +358,14 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) Command.PageRight, () => { - if (!scrollBar.IsVertical) + if (scrollBar.Orientation == Orientation.Horizontal) { scrollBar.Position += GetVisibleContentArea ().Width; return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: false }) + if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Horizontal }) { scrollBar.OtherScrollBarView.Position += GetVisibleContentArea ().Width; @@ -379,14 +379,14 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) Command.PageLeft, () => { - if (!scrollBar.IsVertical) + if (scrollBar.Orientation == Orientation.Horizontal) { scrollBar.Position -= GetVisibleContentArea ().Width; return true; } - if (scrollBar.OtherScrollBarView is { IsVertical: false }) + if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Horizontal }) { scrollBar.OtherScrollBarView.Position -= GetVisibleContentArea ().Width; @@ -430,7 +430,7 @@ private void DisposeScrollBar () private void SetBoundsByPosition (ScrollBarView scrollBar) { - if (scrollBar.IsVertical) + if (scrollBar.Orientation == Orientation.Vertical) { ContentOffset = new Point (ContentArea.X, -scrollBar.Position); } diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index c26daf133f..3da4ca0c03 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -22,6 +22,7 @@ public class ScrollBarView : View private View _contentBottomRightCorner; private bool _keepContentAlwaysInViewport = true; private int _lastLocation = -1; + private Orientation _orientation; private ScrollBarView _otherScrollBarView; private int _posBarOffset; private int _posBottomTee; @@ -30,7 +31,6 @@ public class ScrollBarView : View private int _posTopTee; private bool _showScrollIndicator; private int _size, _position; - private bool _vertical; /// /// Initializes a new instance of the class using @@ -61,32 +61,32 @@ public bool AutoHideScrollBars } } - /// If set to true this is a vertical scrollbar, otherwise, the scrollbar is horizontal. - public bool IsVertical + /// Get or sets if the view-port is kept always visible in the area of this + public bool KeepContentAlwaysInViewPort { - get => _vertical; + get => _keepContentAlwaysInViewport; set { - _vertical = value; - - if (IsInitialized) + if (_keepContentAlwaysInViewport != value) { - SetWidthHeight (); + _keepContentAlwaysInViewport = value; + + AdjustContentInViewport (); } } } - /// Get or sets if the view-port is kept always visible in the area of this - public bool KeepContentAlwaysInViewPort + /// Defines if a scrollbar is vertical or horizontal. + public Orientation Orientation { - get => _keepContentAlwaysInViewport; + get => _orientation; set { - if (_keepContentAlwaysInViewport != value) - { - _keepContentAlwaysInViewport = value; + _orientation = value; - AdjustContentInViewport (); + if (IsInitialized) + { + SetWidthHeight (); } } } @@ -97,10 +97,12 @@ public ScrollBarView OtherScrollBarView get => _otherScrollBarView; set { - if (value is { } && ((value.IsVertical && _vertical) || (!value.IsVertical && !_vertical))) + if (value is { } + && ((value.Orientation == Orientation.Vertical && _orientation == Orientation.Vertical) + || (value.Orientation == Orientation.Horizontal && _orientation == Orientation.Horizontal))) { throw new ArgumentException ( - $"There is already a {(_vertical ? "vertical" : "horizontal")} ScrollBarView." + $"There is already a {(_orientation == Orientation.Vertical ? "vertical" : "horizontal")} ScrollBarView." ); } @@ -165,7 +167,7 @@ public bool ShowScrollIndicator /// public int Size { - get => _size - (IsVertical ? _superViewContentOffset.Y : _superViewContentOffset.X); + get => _size - (Orientation == Orientation.Vertical ? _superViewContentOffset.Y : _superViewContentOffset.X); set { _size = value; @@ -212,10 +214,10 @@ public override bool MouseEvent (MouseEvent mouseEvent) host.SetFocus (); } - int location = _vertical ? mouseEvent.Y : mouseEvent.X; - int barsize = _vertical ? ContentArea.Height : ContentArea.Width; - int posTopLeftTee = _vertical ? _posTopTee + 1 : _posLeftTee + 1; - int posBottomRightTee = _vertical ? _posBottomTee + 1 : _posRightTee + 1; + int location = _orientation == Orientation.Vertical ? mouseEvent.Y : mouseEvent.X; + int barsize = _orientation == Orientation.Vertical ? ContentArea.Height : ContentArea.Width; + int posTopLeftTee = _orientation == Orientation.Vertical ? _posTopTee + 1 : _posLeftTee + 1; + int posBottomRightTee = _orientation == Orientation.Vertical ? _posBottomTee + 1 : _posRightTee + 1; barsize -= 2; int pos = Position; @@ -249,7 +251,7 @@ public override bool MouseEvent (MouseEvent mouseEvent) } else if (_lastLocation == -1 && mouseEvent.Flags == MouseFlags.Button1Pressed && location == barsize + 1) { - if (CanScroll (pos + 1, out _, _vertical)) + if (CanScroll (pos + 1, out _, _orientation)) { Position = pos + 1; } @@ -292,12 +294,12 @@ public override bool MouseEvent (MouseEvent mouseEvent) { int np = (location - _posBarOffset) * Size / barsize + Size / barsize; - if (CanScroll (np, out int nv, _vertical)) + if (CanScroll (np, out int nv, _orientation)) { Position = pos + nv; } } - else if (CanScroll (Size, out int nv, _vertical)) + else if (CanScroll (Size, out int nv, _orientation)) { Position = Math.Min (pos + nv, Size); } @@ -308,7 +310,7 @@ public override bool MouseEvent (MouseEvent mouseEvent) { int np = (location - _posBarOffset) * Size / barsize - Size / barsize; - if (CanScroll (np, out int nv, _vertical)) + if (CanScroll (np, out int nv, _orientation)) { Position = pos + nv; } @@ -322,11 +324,11 @@ public override bool MouseEvent (MouseEvent mouseEvent) { Position = Size; } - else if (location - _posBarOffset >= barsize && posBottomRightTee - posTopLeftTee >= 3 && CanScroll (Size - pos, out int nv, _vertical)) + else if (location - _posBarOffset >= barsize && posBottomRightTee - posTopLeftTee >= 3 && CanScroll (Size - pos, out int nv, _orientation)) { Position = Math.Min (pos + nv, Size); } - else if (location - _posBarOffset >= barsize - 1 && posBottomRightTee - posTopLeftTee <= 3 && CanScroll (Size - pos, out nv, _vertical)) + else if (location - _posBarOffset >= barsize - 1 && posBottomRightTee - posTopLeftTee <= 3 && CanScroll (Size - pos, out nv, _orientation)) { Position = Math.Min (pos + nv, Size); } @@ -337,14 +339,14 @@ public override bool MouseEvent (MouseEvent mouseEvent) } else if (location > posBottomRightTee) { - if (CanScroll (pos + barsize, out int nv, _vertical)) + if (CanScroll (pos + barsize, out int nv, _orientation)) { Position = pos + nv; } } else if (location < posTopLeftTee) { - if (CanScroll (pos - barsize, out int nv, _vertical)) + if (CanScroll (pos - barsize, out int nv, _orientation)) { Position = pos + nv; } @@ -355,7 +357,7 @@ public override bool MouseEvent (MouseEvent mouseEvent) } else if (location == barsize) { - if (CanScroll (Size, out int nv, _vertical)) + if (CanScroll (Size, out int nv, _orientation)) { Position = Math.Min (pos + nv, Size); } @@ -381,7 +383,9 @@ public override void OnDrawContent (Rectangle contentArea) return; } - if (Size == 0 || (_vertical && ContentArea.Height == 0) || (!_vertical && ContentArea.Width == 0)) + if (Size == 0 + || (_orientation == Orientation.Vertical && ContentArea.Height == 0) + || (_orientation == Orientation.Horizontal && ContentArea.Width == 0)) { return; } @@ -395,7 +399,7 @@ public override void OnDrawContent (Rectangle contentArea) Driver.SetAttribute (SuperView.HasFocus ? ColorScheme.Focus : GetNormalColor ()); } - if (_vertical) + if (_orientation == Orientation.Vertical) { if (ContentArea.Right < ContentArea.Width - 1) { @@ -630,7 +634,7 @@ public override bool OnMouseLeave (MouseEvent mouseEvent) public virtual void Refresh () { ShowHideScrollBars (); } // param n is the new position and the max is the positive/negative value that can be scrolled for the new position - internal bool CanScroll (int n, out int maxToScroll, bool isVertical = false) + internal bool CanScroll (int n, out int maxToScroll, Orientation orientation = Orientation.Horizontal) { Rectangle bounds = SuperView?.GetVisibleContentArea () ?? Rectangle.Empty; @@ -641,7 +645,7 @@ internal bool CanScroll (int n, out int maxToScroll, bool isVertical = false) return false; } - int barSize = GetBarSize (isVertical); + int barSize = GetBarSize (orientation); int newPosition = Math.Max (Math.Min (Size - barSize, n), 0); maxToScroll = Size > barSize + newPosition @@ -661,12 +665,16 @@ private void AdjustContentInViewport (bool refresh = true) var pos = 0; Rectangle bounds = SuperView?.GetVisibleContentArea () ?? Rectangle.Empty; - if (KeepContentAlwaysInViewPort && !_vertical && _position + bounds.Width > Size + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0)) + if (KeepContentAlwaysInViewPort + && _orientation == Orientation.Horizontal + && _position + bounds.Width > Size + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0)) { pos = Math.Max (Size - bounds.Width + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0), 0); } - if (KeepContentAlwaysInViewPort && _vertical && _position + bounds.Height > Size + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0)) + if (KeepContentAlwaysInViewPort + && _orientation == Orientation.Vertical + && _position + bounds.Height > Size + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0)) { pos = Math.Max (Size - bounds.Height + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0), 0); } @@ -689,7 +697,7 @@ private void AdjustContentInViewport (bool refresh = true) private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = false) { - int barsize = scrollBarView._vertical ? scrollBarView.ContentArea.Height : scrollBarView.ContentArea.Width; + int barsize = scrollBarView._orientation == Orientation.Vertical ? scrollBarView.ContentArea.Height : scrollBarView.ContentArea.Width; if (barsize == 0 || barsize >= scrollBarView.Size) { @@ -839,7 +847,7 @@ private void CreateBottomRightCorner (View host) } } - private int GetBarSize (bool isVertical) + private int GetBarSize (Orientation orientation) { Rectangle bounds = SuperView?.GetVisibleContentArea () ?? Rectangle.Empty; @@ -850,15 +858,15 @@ private int GetBarSize (bool isVertical) if (IsBuiltIn) { - return isVertical ? KeepContentAlwaysInViewPort - ? bounds.Height - : 0 : + return orientation == Orientation.Vertical ? KeepContentAlwaysInViewPort + ? bounds.Height + : 0 : KeepContentAlwaysInViewPort ? bounds.Width : 0; } - return isVertical ? KeepContentAlwaysInViewPort - ? bounds.Height - (_showBothScrollIndicator ? 1 : 0) - : 0 : + return orientation == Orientation.Vertical ? KeepContentAlwaysInViewPort + ? bounds.Height - (_showBothScrollIndicator ? 1 : 0) + : 0 : KeepContentAlwaysInViewPort ? bounds.Width - (_showBothScrollIndicator ? 1 : 0) : 0; } @@ -877,14 +885,14 @@ private void ManageScrollBarThickness () ScrollBarType.Both => new Thickness ( 0, 0, - IsVertical + Orientation == Orientation.Vertical ? ShowScrollIndicator ? 1 : 0 - : OtherScrollBarView?.IsVertical == true + : OtherScrollBarView?.Orientation == Orientation.Vertical ? OtherScrollBarView?.ShowScrollIndicator == true ? 1 : 0 : 0, - !IsVertical + Orientation == Orientation.Horizontal ? ShowScrollIndicator ? 1 : 0 - : OtherScrollBarView?.IsVertical == false + : OtherScrollBarView?.Orientation == Orientation.Horizontal ? OtherScrollBarView?.ShowScrollIndicator == true ? 1 : 0 : 0), _ => throw new ArgumentOutOfRangeException () @@ -928,13 +936,13 @@ private void ScrollBarView_Added (object sender, SuperViewChangedEventArgs e) { if (IsBuiltIn) { - X = IsVertical ? Pos.AnchorEnd () : 0; - Y = IsVertical ? 0 : Pos.AnchorEnd (); + X = Orientation == Orientation.Vertical ? Pos.AnchorEnd () : 0; + Y = Orientation == Orientation.Vertical ? 0 : Pos.AnchorEnd (); } else { - X = IsVertical ? Pos.AnchorEnd (1) : 0; - Y = IsVertical ? 0 : Pos.AnchorEnd (1); + X = Orientation == Orientation.Vertical ? Pos.AnchorEnd (1) : 0; + Y = Orientation == Orientation.Vertical ? 0 : Pos.AnchorEnd (1); } if (OtherScrollBarView is { SuperView: null } && !e.Parent.Subviews.Contains (OtherScrollBarView)) @@ -967,7 +975,7 @@ private void ScrollBarView_Initialized (object sender, EventArgs e) // Helper to assist Initialized event handler private void SetPosition (int newPosition) { - if (CanScroll (newPosition, out int max, _vertical)) + if (CanScroll (newPosition, out int max, _orientation)) { if (max == newPosition) { @@ -1012,30 +1020,30 @@ private void SetWidthHeight () { Rectangle bounds = SuperView?.GetVisibleContentArea () ?? Rectangle.Empty; - X = _vertical ? bounds.Right - 1 : bounds.Left; - Y = _vertical ? bounds.Top : bounds.Bottom - 1; - Width = _vertical ? 1 : SuperView is Adornment ? Dim.Fill () : bounds.Width - 1; - Height = _vertical ? SuperView is Adornment ? Dim.Fill () : bounds.Height - 1 : 1; + X = _orientation == Orientation.Vertical ? bounds.Right - 1 : bounds.Left; + Y = _orientation == Orientation.Vertical ? bounds.Top : bounds.Bottom - 1; + Width = _orientation == Orientation.Vertical ? 1 : SuperView is Adornment ? Dim.Fill () : bounds.Width - 1; + Height = _orientation == Orientation.Vertical ? SuperView is Adornment ? Dim.Fill () : bounds.Height - 1 : 1; - _otherScrollBarView.X = _otherScrollBarView._vertical ? bounds.Right - 1 : bounds.Left; - _otherScrollBarView.Y = _otherScrollBarView._vertical ? bounds.Top : bounds.Bottom - 1; + _otherScrollBarView.X = _otherScrollBarView._orientation == Orientation.Vertical ? bounds.Right - 1 : bounds.Left; + _otherScrollBarView.Y = _otherScrollBarView._orientation == Orientation.Vertical ? bounds.Top : bounds.Bottom - 1; - _otherScrollBarView.Width = _otherScrollBarView._vertical ? 1 : + _otherScrollBarView.Width = _otherScrollBarView._orientation == Orientation.Vertical ? 1 : SuperView is Adornment ? Dim.Fill () : bounds.Width - 1; - _otherScrollBarView.Height = _otherScrollBarView._vertical + _otherScrollBarView.Height = _otherScrollBarView._orientation == Orientation.Vertical ? SuperView is Adornment ? Dim.Fill () : bounds.Height - 1 : 1; } else { - Width = _vertical ? 1 : SuperView is Adornment ? Dim.Fill () : Dim.Fill (1); - Height = _vertical ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) : 1; + Width = _orientation == Orientation.Vertical ? 1 : SuperView is Adornment ? Dim.Fill () : Dim.Fill (1); + Height = _orientation == Orientation.Vertical ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) : 1; - _otherScrollBarView.Width = _otherScrollBarView._vertical ? 1 : + _otherScrollBarView.Width = _otherScrollBarView._orientation == Orientation.Vertical ? 1 : SuperView is Adornment ? Dim.Fill () : Dim.Fill (1); - _otherScrollBarView.Height = _otherScrollBarView._vertical + _otherScrollBarView.Height = _otherScrollBarView._orientation == Orientation.Vertical ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) : 1; } @@ -1046,15 +1054,15 @@ private void SetWidthHeight () { Rectangle bounds = SuperView?.GetVisibleContentArea () ?? Rectangle.Empty; - X = _vertical ? bounds.Right - 1 : bounds.Left; - Y = _vertical ? bounds.Top : bounds.Bottom - 1; - Width = _vertical ? 1 : bounds.Width; - Height = _vertical ? bounds.Height : 1; + X = _orientation == Orientation.Vertical ? bounds.Right - 1 : bounds.Left; + Y = _orientation == Orientation.Vertical ? bounds.Top : bounds.Bottom - 1; + Width = _orientation == Orientation.Vertical ? 1 : bounds.Width; + Height = _orientation == Orientation.Vertical ? bounds.Height : 1; } else { - Width = _vertical ? 1 : Dim.Fill (); - Height = _vertical ? Dim.Fill () : 1; + Width = _orientation == Orientation.Vertical ? 1 : Dim.Fill (); + Height = _orientation == Orientation.Vertical ? Dim.Fill () : 1; } } else if (_otherScrollBarView?._showScrollIndicator == true) @@ -1063,15 +1071,15 @@ private void SetWidthHeight () { Rectangle bounds = SuperView?.GetVisibleContentArea () ?? Rectangle.Empty; - _otherScrollBarView.X = _otherScrollBarView._vertical ? bounds.Right - 1 : bounds.Left; - _otherScrollBarView.Y = _otherScrollBarView._vertical ? bounds.Top : bounds.Bottom - 1; - _otherScrollBarView.Width = _otherScrollBarView._vertical ? 1 : bounds.Width; - _otherScrollBarView.Height = _otherScrollBarView._vertical ? bounds.Height : 1; + _otherScrollBarView.X = _otherScrollBarView._orientation == Orientation.Vertical ? bounds.Right - 1 : bounds.Left; + _otherScrollBarView.Y = _otherScrollBarView._orientation == Orientation.Vertical ? bounds.Top : bounds.Bottom - 1; + _otherScrollBarView.Width = _otherScrollBarView._orientation == Orientation.Vertical ? 1 : bounds.Width; + _otherScrollBarView.Height = _otherScrollBarView._orientation == Orientation.Vertical ? bounds.Height : 1; } else { - _otherScrollBarView.Width = _otherScrollBarView._vertical ? 1 : Dim.Fill (); - _otherScrollBarView.Height = _otherScrollBarView._vertical ? Dim.Fill () : 1; + _otherScrollBarView.Width = _otherScrollBarView._orientation == Orientation.Vertical ? 1 : Dim.Fill (); + _otherScrollBarView.Height = _otherScrollBarView._orientation == Orientation.Vertical ? Dim.Fill () : 1; } } diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index bb9bcff2a9..4350461450 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -49,7 +49,7 @@ public ScrollView () Y = 0, Width = 1, Size = 1, - IsVertical = true + Orientation = Orientation.Vertical }; _horizontal = new ScrollBarView @@ -58,7 +58,7 @@ public ScrollView () Y = Pos.AnchorEnd (1), Height = 1, Size = 1, - IsVertical = false + Orientation = Orientation.Horizontal }; _vertical.OtherScrollBarView = _horizontal; _horizontal.OtherScrollBarView = _vertical; @@ -453,7 +453,7 @@ public override void Remove (View view) /// Number of lines to scroll. public bool ScrollDown (int lines) { - if (_vertical.CanScroll (_vertical.Position + lines, out _, true)) + if (_vertical.CanScroll (_vertical.Position + lines, out _, Orientation.Vertical)) { ContentOffset = new Point (_contentOffset.X, _contentOffset.Y - lines); diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index 14059dd968..e2a6fa1644 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -150,7 +150,7 @@ public void Both_Default_Draws_Correctly () Size = width * 2, ShowScrollIndicator = true, - IsVertical = false + Orientation = Orientation.Horizontal }; super.Add (horiz); @@ -160,7 +160,7 @@ public void Both_Default_Draws_Correctly () Size = height * 2, ShowScrollIndicator = true, - IsVertical = true, + Orientation = Orientation.Vertical, OtherScrollBarView = horiz }; super.Add (vert); @@ -286,7 +286,7 @@ public void ClearOnVisibleFalse_Gets_Sets () var label = new Label { Text = text }; Application.Top.Add (label); - var sbv = new ScrollBarView { IsVertical = true, Size = 100, ClearOnVisibleFalse = false }; + var sbv = new ScrollBarView { Orientation = Orientation.Vertical, Size = 100, ClearOnVisibleFalse = false }; label.Add (sbv); Application.Begin (Application.Top); @@ -487,7 +487,9 @@ public void Source = new ListWrapper (source) }; win.Add (listView); - var newScrollBarView = new ScrollBarView { IsVertical = true, KeepContentAlwaysInViewPort = true }; + + var newScrollBarView = new ScrollBarView + { Orientation = Orientation.Vertical, KeepContentAlwaysInViewPort = true }; listView.Add (newScrollBarView); newScrollBarView.ChangedPosition += (s, e) => @@ -543,8 +545,8 @@ public void ContentBottomRightCorner_Not_Redraw_If_Both_Size_Equal_To_Zero () var text = "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test"; var label = new Label { Text = text }; - var sbv = new ScrollBarView { X = Pos.AnchorEnd (1), IsVertical = true, Size = 100 }; - sbv.OtherScrollBarView = new ScrollBarView { Y = Pos.AnchorEnd (1), IsVertical = false, Size = 100, OtherScrollBarView = sbv }; + var sbv = new ScrollBarView { X = Pos.AnchorEnd (1), Orientation = Orientation.Vertical, Size = 100 }; + sbv.OtherScrollBarView = new ScrollBarView { Y = Pos.AnchorEnd (1), Orientation = Orientation.Horizontal, Size = 100, OtherScrollBarView = sbv }; label.Add (sbv, sbv.OtherScrollBarView); Application.Top.Add (label); Application.Begin (Application.Top); @@ -626,7 +628,7 @@ public void ContentBottomRightCorner_Not_Redraw_If_One_Size_Equal_To_Zero () "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test"; var label = new Label { Text = text }; - var sbv = new ScrollBarView { X = Pos.AnchorEnd (1), IsVertical = true, Size = 100 }; + var sbv = new ScrollBarView { X = Pos.AnchorEnd (1), Orientation = Orientation.Vertical, Size = 100 }; label.Add (sbv); Application.Top.Add (label); Application.Begin (Application.Top); @@ -712,13 +714,13 @@ public void Hosting_A_View_To_A_ScrollBarView () { RemoveHandlers (); - _scrollBar = new ScrollBarView { IsVertical = true, OtherScrollBarView = new ScrollBarView { IsVertical = false } }; + _scrollBar = new ScrollBarView { Orientation = Orientation.Vertical, OtherScrollBarView = new ScrollBarView { Orientation = Orientation.Horizontal } }; _hostView.Add (_scrollBar); Application.Begin (Application.Top); - Assert.True (_scrollBar.IsVertical); - Assert.False (_scrollBar.OtherScrollBarView.IsVertical); + Assert.True (_scrollBar.Orientation == Orientation.Vertical); + Assert.True (_scrollBar.OtherScrollBarView.Orientation == Orientation.Horizontal); Assert.Equal (_scrollBar.Position, _hostView.Top); Assert.NotEqual (_scrollBar.Size, _hostView.Lines); @@ -903,8 +905,8 @@ public void Hosting_Two_Horizontal_ScrollBarView_Throws_ArgumentException () var top = new Toplevel (); var host = new View (); top.Add (host); - var v = new ScrollBarView { IsVertical = false }; - var h = new ScrollBarView { IsVertical = false }; + var v = new ScrollBarView { Orientation = Orientation.Horizontal }; + var h = new ScrollBarView { Orientation = Orientation.Horizontal }; Assert.Throws (() => v.OtherScrollBarView = h); Assert.Throws (() => h.OtherScrollBarView = v); @@ -917,8 +919,8 @@ public void Hosting_Two_Vertical_ScrollBarView_Throws_ArgumentException () var top = new Toplevel (); var host = new View (); top.Add (host); - var v = new ScrollBarView { IsVertical = true }; - var h = new ScrollBarView { IsVertical = true }; + var v = new ScrollBarView { Orientation = Orientation.Vertical }; + var h = new ScrollBarView { Orientation = Orientation.Vertical }; Assert.Throws (() => v.OtherScrollBarView = h); Assert.Throws (() => h.OtherScrollBarView = v); @@ -931,7 +933,7 @@ public void Internal_Tests () Toplevel top = Application.Top; Assert.Equal (new Rectangle (0, 0, 80, 25), top.ContentArea); var view = new View { Width = Dim.Fill (), Height = Dim.Fill () }; - var sbv = new ScrollBarView { IsVertical = true, OtherScrollBarView = new ScrollBarView { IsVertical = false } }; + var sbv = new ScrollBarView { Orientation = Orientation.Vertical, OtherScrollBarView = new ScrollBarView { Orientation = Orientation.Horizontal } }; view.Add (sbv); top.Add (view); Assert.Equal (view, sbv.SuperView); @@ -941,9 +943,9 @@ public void Internal_Tests () sbv.OtherScrollBarView.Position = 0; // Host bounds is not empty. - Assert.True (sbv.CanScroll (10, out int max, sbv.IsVertical)); + Assert.True (sbv.CanScroll (10, out int max, sbv.Orientation)); Assert.Equal (10, max); - Assert.True (sbv.OtherScrollBarView.CanScroll (10, out max, sbv.OtherScrollBarView.IsVertical)); + Assert.True (sbv.OtherScrollBarView.CanScroll (10, out max, sbv.OtherScrollBarView.Orientation)); Assert.Equal (10, max); Application.Begin (top); @@ -954,23 +956,23 @@ public void Internal_Tests () top.LayoutSubviews (); // Now the host bounds is not empty. - Assert.True (sbv.CanScroll (10, out max, sbv.IsVertical)); + Assert.True (sbv.CanScroll (10, out max, sbv.Orientation)); Assert.Equal (10, max); - Assert.True (sbv.OtherScrollBarView.CanScroll (10, out max, sbv.OtherScrollBarView.IsVertical)); + Assert.True (sbv.OtherScrollBarView.CanScroll (10, out max, sbv.OtherScrollBarView.Orientation)); Assert.Equal (10, max); - Assert.True (sbv.CanScroll (50, out max, sbv.IsVertical)); + Assert.True (sbv.CanScroll (50, out max, sbv.Orientation)); Assert.Equal (40, sbv.Size); Assert.Equal (16, max); // 16+25=41 - Assert.True (sbv.OtherScrollBarView.CanScroll (150, out max, sbv.OtherScrollBarView.IsVertical)); + Assert.True (sbv.OtherScrollBarView.CanScroll (150, out max, sbv.OtherScrollBarView.Orientation)); Assert.Equal (100, sbv.OtherScrollBarView.Size); Assert.Equal (21, max); // 21+80=101 Assert.True (sbv.Visible); Assert.True (sbv.OtherScrollBarView.Visible); sbv.KeepContentAlwaysInViewPort = false; sbv.OtherScrollBarView.KeepContentAlwaysInViewPort = false; - Assert.True (sbv.CanScroll (50, out max, sbv.IsVertical)); + Assert.True (sbv.CanScroll (50, out max, sbv.Orientation)); Assert.Equal (39, max); // Keep 1 row visible - Assert.True (sbv.OtherScrollBarView.CanScroll (150, out max, sbv.OtherScrollBarView.IsVertical)); + Assert.True (sbv.OtherScrollBarView.CanScroll (150, out max, sbv.OtherScrollBarView.Orientation)); Assert.Equal (99, max); // Keep 1 column visible Assert.True (sbv.Visible); Assert.True (sbv.OtherScrollBarView.Visible); @@ -1504,7 +1506,7 @@ public void ShowScrollIndicator_False_Must_Also_Set_Visible_To_False_To_Not_Resp var btn = new Button { X = 14, Text = "Click Me!" }; btn.Accept += (s, e) => clicked = true; - var sbv = new ScrollBarView { IsVertical = true, Size = 5 }; + var sbv = new ScrollBarView { Orientation = Orientation.Vertical, Size = 5 }; label.Add (sbv); Application.Top.Add (label, btn); Application.Begin (Application.Top); @@ -1624,7 +1626,7 @@ public void Vertical_Default_Draws_Correctly () Size = height * 2, ShowScrollIndicator = true, - IsVertical = true + Orientation = Orientation.Vertical }; super.Add (sbv); From 903248fabc2cbc7a5a41caeac8d48185a321614f Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 25 Feb 2024 21:18:56 +0000 Subject: [PATCH 059/130] Remove unnecessary _superViewContentOffset private field. --- Terminal.Gui/Views/ScrollBarView.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index 3da4ca0c03..4b6459919b 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -17,7 +17,6 @@ namespace Terminal.Gui; /// public class ScrollBarView : View { - private static Point _superViewContentOffset; private bool _autoHideScrollBars = true; private View _contentBottomRightCorner; private bool _keepContentAlwaysInViewport = true; @@ -167,7 +166,7 @@ public bool ShowScrollIndicator /// public int Size { - get => _size - (Orientation == Orientation.Vertical ? _superViewContentOffset.Y : _superViewContentOffset.X); + get => _size; set { _size = value; From 6ffdf19d088b0a8ef1378cec1db3c721b46b5682 Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 26 Feb 2024 18:45:35 +0000 Subject: [PATCH 060/130] Replace KeyCode with Key. --- UnitTests/Views/TabViewTests.cs | 20 ++++----- UnitTests/Views/TableViewTests.cs | 6 +-- UnitTests/Views/TextFieldTests.cs | 12 +----- UnitTests/Views/TextViewTests.cs | 68 +++++++++++-------------------- 4 files changed, 37 insertions(+), 69 deletions(-) diff --git a/UnitTests/Views/TabViewTests.cs b/UnitTests/Views/TabViewTests.cs index f23ff10b8b..2895f88586 100644 --- a/UnitTests/Views/TabViewTests.cs +++ b/UnitTests/Views/TabViewTests.cs @@ -413,7 +413,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp () Assert.Equal (tv.SelectedTab.View, top.Focused.MostFocused); // Press the cursor up key to focus the selected tab - var args = new Key (Key.CursorUp); + var args = Key.CursorUp; Application.OnKeyDown (args); Application.Refresh (); @@ -432,7 +432,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp () }; // Press the cursor right key to select the next tab - args = new Key (Key.CursorRight); + args = Key.CursorRight; Application.OnKeyDown (args); Application.Refresh (); Assert.Equal (tab1, oldChanged); @@ -442,7 +442,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp () Assert.Equal (tv.MostFocused, top.Focused.MostFocused); // Press the cursor down key to focus the selected tab view hosting - args = new Key (Key.CursorDown); + args = Key.CursorDown; Application.OnKeyDown (args); Application.Refresh (); Assert.Equal (tab2, tv.SelectedTab); @@ -462,7 +462,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp () Assert.Null (top.Focused.MostFocused); // Press the cursor up key to focus the selected tab view hosting again - args = new Key (Key.CursorUp); + args = Key.CursorUp; Application.OnKeyDown (args); Application.Refresh (); Assert.Equal (tab2, tv.SelectedTab); @@ -470,7 +470,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp () Assert.Equal (tv.MostFocused, top.Focused.MostFocused); // Press the cursor up key to focus the selected tab - args = new Key (Key.CursorUp); + args = Key.CursorUp; Application.OnKeyDown (args); Application.Refresh (); @@ -480,7 +480,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp () Assert.Equal (tv.MostFocused, top.Focused.MostFocused); // Press the cursor left key to select the previous tab - args = new Key (Key.CursorLeft); + args = Key.CursorLeft; Application.OnKeyDown (args); Application.Refresh (); Assert.Equal (tab2, oldChanged); @@ -490,7 +490,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp () Assert.Equal (tv.MostFocused, top.Focused.MostFocused); // Press the end key to select the last tab - args = new Key (Key.End); + args = Key.End; Application.OnKeyDown (args); Application.Refresh (); Assert.Equal (tab1, oldChanged); @@ -500,7 +500,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp () Assert.Equal (tv.MostFocused, top.Focused.MostFocused); // Press the home key to select the first tab - args = new Key (Key.Home); + args = Key.Home; Application.OnKeyDown (args); Application.Refresh (); Assert.Equal (tab2, oldChanged); @@ -510,7 +510,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp () Assert.Equal (tv.MostFocused, top.Focused.MostFocused); // Press the page down key to select the next set of tabs - args = new Key (Key.PageDown); + args = Key.PageDown; Application.OnKeyDown (args); Application.Refresh (); Assert.Equal (tab1, oldChanged); @@ -520,7 +520,7 @@ public void ProcessKey_Down_Up_Right_Left_Home_End_PageDown_PageUp () Assert.Equal (tv.MostFocused, top.Focused.MostFocused); // Press the page up key to select the previous set of tabs - args = new Key (Key.PageUp); + args = Key.PageUp; Application.OnKeyDown (args); Application.Refresh (); Assert.Equal (tab2, oldChanged); diff --git a/UnitTests/Views/TableViewTests.cs b/UnitTests/Views/TableViewTests.cs index b479c7d28c..b3b300a1d9 100644 --- a/UnitTests/Views/TableViewTests.cs +++ b/UnitTests/Views/TableViewTests.cs @@ -2523,11 +2523,7 @@ public void TestMoveStartEnd_WithFullRowSelect (bool withFullRowSelect) Assert.Equal (0, tableView.SelectedRow); } - tableView.NewKeyDownEvent ( - new Key ( - KeyCode.End | KeyCode.CtrlMask - ) - ); + tableView.NewKeyDownEvent (Key.End.WithCtrl); if (withFullRowSelect) { diff --git a/UnitTests/Views/TextFieldTests.cs b/UnitTests/Views/TextFieldTests.cs index cd6cc88c61..6f001228e6 100644 --- a/UnitTests/Views/TextFieldTests.cs +++ b/UnitTests/Views/TextFieldTests.cs @@ -1366,11 +1366,7 @@ public void WordBackward_With_Selection () while (_textField.CursorPosition > 0) { - _textField.NewKeyDownEvent ( - new Key ( - KeyCode.CursorLeft | KeyCode.CtrlMask | KeyCode.ShiftMask - ) - ); + _textField.NewKeyDownEvent (Key.CursorLeft.WithCtrl.WithShift); switch (iteration) { @@ -1440,11 +1436,7 @@ public void while (_textField.CursorPosition > 0) { - _textField.NewKeyDownEvent ( - new Key ( - KeyCode.CursorLeft | KeyCode.CtrlMask | KeyCode.ShiftMask - ) - ); + _textField.NewKeyDownEvent (Key.CursorLeft.WithCtrl.WithShift); switch (iteration) { diff --git a/UnitTests/Views/TextViewTests.cs b/UnitTests/Views/TextViewTests.cs index ed98b90461..fc6f4e23f3 100644 --- a/UnitTests/Views/TextViewTests.cs +++ b/UnitTests/Views/TextViewTests.cs @@ -5521,7 +5521,7 @@ public void KeyBindings_Command () Assert.True (tv.NewKeyDownEvent (Key.PageUp)); Assert.Equal (24, tv.GetCurrentLine ().Count); Assert.Equal (new Point (24, 1), tv.CursorPosition); - Assert.True (tv.NewKeyDownEvent (new Key (Key.V.WithAlt))); + Assert.True (tv.NewKeyDownEvent (Key.V.WithAlt)); Assert.Equal (23, tv.GetCurrentLine ().Count); Assert.Equal (new Point (23, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.PageDown)); @@ -5816,7 +5816,7 @@ public void KeyBindings_Command () Assert.Equal (19, tv.SelectionStartColumn); Assert.Equal (0, tv.SelectionStartRow); tv.SelectionStartColumn = 0; - Assert.True (tv.NewKeyDownEvent (new Key (Key.C.WithAlt))); + Assert.True (tv.NewKeyDownEvent (Key.C.WithAlt)); Assert.Equal ( $"is is the first lin{ @@ -5848,7 +5848,7 @@ public void KeyBindings_Command () Assert.True (tv.Selecting); Assert.Equal (0, tv.SelectionStartColumn); Assert.Equal (0, tv.SelectionStartRow); - Assert.True (tv.NewKeyDownEvent (new Key (Key.W.WithAlt))); + Assert.True (tv.NewKeyDownEvent (Key.W.WithAlt)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -5917,7 +5917,7 @@ public void KeyBindings_Command () Assert.Equal (6, tv.SelectedLength); Assert.Equal ("third ", tv.SelectedText); Assert.True (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (Key.B.WithAlt))); + Assert.True (tv.NewKeyDownEvent (Key.B.WithAlt)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -5947,7 +5947,7 @@ public void KeyBindings_Command () Assert.Equal (6, tv.SelectedLength); Assert.Equal ("third ", tv.SelectedText); Assert.True (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (Key.F.WithAlt))); + Assert.True (tv.NewKeyDownEvent (Key.F.WithAlt)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -5957,7 +5957,7 @@ public void KeyBindings_Command () Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (Key.F.WithAlt))); + Assert.True (tv.NewKeyDownEvent (Key.F.WithAlt)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -5967,7 +5967,7 @@ public void KeyBindings_Command () Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); - Assert.True (tv.NewKeyDownEvent (new Key (Key.F.WithAlt))); + Assert.True (tv.NewKeyDownEvent (Key.F.WithAlt)); Assert.Equal ( $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", @@ -6504,11 +6504,7 @@ public void Kill_To_End_Delete_Forwards_Copy_To_The_Clipboard_And_Paste () break; case 1: - _textView.NewKeyDownEvent ( - new Key ( - KeyCode.Delete | KeyCode.CtrlMask | KeyCode.ShiftMask - ) - ); + _textView.NewKeyDownEvent (Key.Delete.WithCtrl.WithShift); Assert.Equal (0, _textView.CursorPosition.X); Assert.Equal (0, _textView.CursorPosition.Y); Assert.Equal ("This is the second line.", _textView.Text); @@ -6567,11 +6563,7 @@ public void Kill_To_Start_Delete_Backwards_Copy_To_The_Clipboard_And_Paste () break; case 1: - _textView.NewKeyDownEvent ( - new Key ( - KeyCode.Backspace | KeyCode.CtrlMask | KeyCode.ShiftMask - ) - ); + _textView.NewKeyDownEvent (Key.Backspace.WithCtrl.WithShift); Assert.Equal (23, _textView.CursorPosition.X); Assert.Equal (0, _textView.CursorPosition.Y); Assert.Equal ("This is the first line.", _textView.Text); @@ -6914,22 +6906,22 @@ public void ScrollBarType_IsBuiltIn_Always_Adjust_LeftColumn () Assert.Equal (14, tv.Maxlength); Assert.Equal (tv.LeftColumn, tv.Maxlength - tv.ContentArea.Width); - tv.NewKeyDownEvent (new Key (KeyCode.Backspace)); - tv.NewKeyDownEvent (new Key (KeyCode.End)); + tv.NewKeyDownEvent (Key.Backspace); + tv.NewKeyDownEvent (Key.End); Assert.Equal (3, tv.LeftColumn); Assert.Equal (13, tv.Maxlength); Assert.Equal (tv.LeftColumn, tv.Maxlength - tv.ContentArea.Width); - tv.NewKeyDownEvent (new Key (KeyCode.Space)); - tv.NewKeyDownEvent (new Key (KeyCode.Space)); + tv.NewKeyDownEvent (Key.Space); + tv.NewKeyDownEvent (Key.Space); Assert.Equal (5, tv.LeftColumn); Assert.Equal (15, tv.Maxlength); Assert.Equal (tv.LeftColumn, tv.Maxlength - tv.ContentArea.Width); - tv.NewKeyDownEvent (new Key (KeyCode.Backspace)); - tv.NewKeyDownEvent (new Key (KeyCode.Backspace)); + tv.NewKeyDownEvent (Key.Backspace); + tv.NewKeyDownEvent (Key.Backspace); Assert.Equal (3, tv.LeftColumn); Assert.Equal (13, tv.Maxlength); @@ -6954,27 +6946,27 @@ public void ScrollBarType_IsBuiltIn_Always_Adjust_TopRow () tv.BeginInit (); tv.EndInit (); - tv.NewKeyDownEvent (new Key (KeyCode.CtrlMask | KeyCode.End)); + tv.NewKeyDownEvent (Key.End.WithCtrl); Assert.Equal (4, tv.TopRow); Assert.Equal (13, tv.Lines); Assert.Equal (tv.TopRow, tv.Lines - tv.ContentArea.Height); - tv.NewKeyDownEvent (new Key (KeyCode.Backspace)); + tv.NewKeyDownEvent (Key.Backspace); Assert.Equal (3, tv.TopRow); Assert.Equal (12, tv.Lines); Assert.Equal (tv.TopRow, tv.Lines - tv.ContentArea.Height); - tv.NewKeyDownEvent (new Key (KeyCode.Enter)); - tv.NewKeyDownEvent (new Key (KeyCode.Enter)); + tv.NewKeyDownEvent (Key.Enter); + tv.NewKeyDownEvent (Key.Enter); Assert.Equal (5, tv.TopRow); Assert.Equal (14, tv.Lines); Assert.Equal (tv.TopRow, tv.Lines - tv.ContentArea.Height); - tv.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.AltMask)); - tv.NewKeyDownEvent (new Key (KeyCode.K | KeyCode.AltMask)); + tv.NewKeyDownEvent (Key.K.WithAlt); + tv.NewKeyDownEvent (Key.K.WithAlt); Assert.Equal (3, tv.TopRow); Assert.Equal (12, tv.Lines); @@ -8348,11 +8340,7 @@ public void WordForward_Multiline_With_Selection () while (!iterationsFinished) { - _textView.NewKeyDownEvent ( - new Key ( - KeyCode.CursorRight | KeyCode.CtrlMask | KeyCode.ShiftMask - ) - ); + _textView.NewKeyDownEvent (Key.CursorRight.WithCtrl.WithShift); switch (iteration) { @@ -8690,11 +8678,7 @@ public void WordForward_With_Selection () while (_textView.CursorPosition.X < _textView.Text.Length) { - _textView.NewKeyDownEvent ( - new Key ( - KeyCode.CursorRight | KeyCode.CtrlMask | KeyCode.ShiftMask - ) - ); + _textView.NewKeyDownEvent (Key.CursorRight.WithCtrl.WithShift); switch (iteration) { @@ -8770,11 +8754,7 @@ public void while (_textView.CursorPosition.X < _textView.Text.Length) { - _textView.NewKeyDownEvent ( - new Key ( - KeyCode.CursorRight | KeyCode.CtrlMask | KeyCode.ShiftMask - ) - ); + _textView.NewKeyDownEvent (Key.CursorRight.WithCtrl.WithShift); switch (iteration) { From 1443faec2adf757597f24849d4d4ef5c4c95737e Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 26 Feb 2024 21:08:40 +0000 Subject: [PATCH 061/130] Remove unnecessary code. --- Terminal.Gui/View/Layout/ViewLayout.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index c0a9da7158..a06e2386c5 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -888,13 +888,6 @@ public Point ScreenToFrame (int x, int y) protected void ClearLayoutNeeded () { LayoutNeeded = false; - - if (Margin is { }) - { - Margin.LayoutNeeded = false; - Border.LayoutNeeded = false; - Margin.LayoutNeeded = false; - } } internal void CollectAll (View from, ref HashSet nNodes, ref HashSet<(View, View)> nEdges) From 9400c83ccb0e7391d1fb3ea77846d35ceb58cccc Mon Sep 17 00:00:00 2001 From: BDisp Date: Tue, 27 Feb 2024 18:50:10 +0000 Subject: [PATCH 062/130] Auto-hide only set the Visible property and not the ShowScrollIndicator. --- Terminal.Gui/Views/ScrollBarView.cs | 76 +++++++---------------- Terminal.Gui/Views/ScrollView.cs | 89 ++++++++++++--------------- UnitTests/Views/ScrollBarViewTests.cs | 64 +++++++++++++++---- UnitTests/Views/ScrollViewTests.cs | 6 +- 4 files changed, 118 insertions(+), 117 deletions(-) diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index 4b6459919b..1d668cdb20 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -55,6 +55,7 @@ public bool AutoHideScrollBars if (_autoHideScrollBars != value) { _autoHideScrollBars = value; + Visible = _showScrollIndicator; SetNeedsDisplay (); } } @@ -173,13 +174,15 @@ public int Size if (IsInitialized) { - ShowHideScrollBars (false); + AdjustContentInViewport (); } } } private bool _showBothScrollIndicator => OtherScrollBarView?._showScrollIndicator == true && _showScrollIndicator; + private int GetOtherScrollBarViewOffset => OtherScrollBarView?.Visible == true ? 1 : 0; + private bool IsBuiltIn => SuperView is Adornment; /// This event is raised when the position on the scrollbar has changed. @@ -232,7 +235,7 @@ public override bool MouseEvent (MouseEvent mouseEvent) return true; } - if (_showScrollIndicator + if (Visible && (mouseEvent.Flags == MouseFlags.WheeledDown || mouseEvent.Flags == MouseFlags.WheeledUp || mouseEvent.Flags == MouseFlags.WheeledRight @@ -372,9 +375,9 @@ public override bool MouseEvent (MouseEvent mouseEvent) /// public override void OnDrawContent (Rectangle contentArea) { - if (ColorScheme is null || ((!_showScrollIndicator || Size == 0) && AutoHideScrollBars && Visible)) + if (ColorScheme is null || ((!Visible || Size == 0) && AutoHideScrollBars && Visible)) { - if ((!_showScrollIndicator || Size == 0) && AutoHideScrollBars && Visible) + if ((!Visible || Size == 0) && AutoHideScrollBars && Visible) { ShowHideScrollBars (false); } @@ -666,16 +669,16 @@ private void AdjustContentInViewport (bool refresh = true) if (KeepContentAlwaysInViewPort && _orientation == Orientation.Horizontal - && _position + bounds.Width > Size + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0)) + && _position > Math.Max (Size - bounds.Width + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0), GetOtherScrollBarViewOffset)) { - pos = Math.Max (Size - bounds.Width + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0), 0); + pos = Math.Max (Size - bounds.Width + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0), GetOtherScrollBarViewOffset); } if (KeepContentAlwaysInViewPort && _orientation == Orientation.Vertical - && _position + bounds.Height > Size + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0)) + && _position > Math.Max (Size - bounds.Height + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0), GetOtherScrollBarViewOffset)) { - pos = Math.Max (Size - bounds.Height + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0), 0); + pos = Math.Max (Size - bounds.Height + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0), GetOtherScrollBarViewOffset); } if (pos != 0) @@ -701,11 +704,6 @@ private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = fa if (barsize == 0 || barsize >= scrollBarView.Size) { if (scrollBarView._showScrollIndicator) - { - scrollBarView.ShowScrollIndicator = false; - } - - if (scrollBarView.Visible) { scrollBarView.Visible = false; } @@ -713,21 +711,11 @@ private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = fa else if (barsize > 0 && barsize == scrollBarView.Size && scrollBarView.OtherScrollBarView is { } && pending) { if (scrollBarView._showScrollIndicator) - { - scrollBarView.ShowScrollIndicator = false; - } - - if (scrollBarView.Visible) { scrollBarView.Visible = false; } if (scrollBarView.OtherScrollBarView is { } && scrollBarView._showBothScrollIndicator) - { - scrollBarView.OtherScrollBarView.ShowScrollIndicator = false; - } - - if (scrollBarView.OtherScrollBarView.Visible) { scrollBarView.OtherScrollBarView.Visible = false; } @@ -740,23 +728,13 @@ private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = fa { if (scrollBarView.OtherScrollBarView is { } && pending) { - if (!scrollBarView._showBothScrollIndicator) - { - scrollBarView.OtherScrollBarView.ShowScrollIndicator = true; - } - - if (!scrollBarView.OtherScrollBarView.Visible) + if (!scrollBarView._showBothScrollIndicator && scrollBarView.OtherScrollBarView._showScrollIndicator) { scrollBarView.OtherScrollBarView.Visible = true; } } - if (!scrollBarView._showScrollIndicator) - { - scrollBarView.ShowScrollIndicator = true; - } - - if (!scrollBarView.Visible) + if (scrollBarView._showScrollIndicator) { scrollBarView.Visible = true; } @@ -879,20 +857,20 @@ private void ManageScrollBarThickness () ((Adornment)SuperView).Thickness = ((Adornment)SuperView).Parent.ScrollBarType switch { ScrollBarType.None => new Thickness (0), - ScrollBarType.Vertical => new Thickness (0, 0, ShowScrollIndicator ? 1 : 0, 0), - ScrollBarType.Horizontal => new Thickness (0, 0, 0, ShowScrollIndicator ? 1 : 0), + ScrollBarType.Vertical => new Thickness (0, 0, Visible ? 1 : 0, 0), + ScrollBarType.Horizontal => new Thickness (0, 0, 0, Visible ? 1 : 0), ScrollBarType.Both => new Thickness ( 0, 0, Orientation == Orientation.Vertical - ? ShowScrollIndicator ? 1 : 0 + ? Visible ? 1 : 0 : OtherScrollBarView?.Orientation == Orientation.Vertical - ? OtherScrollBarView?.ShowScrollIndicator == true ? 1 : 0 + ? OtherScrollBarView?.Visible == true ? 1 : 0 : 0, Orientation == Orientation.Horizontal - ? ShowScrollIndicator ? 1 : 0 + ? Visible ? 1 : 0 : OtherScrollBarView?.Orientation == Orientation.Horizontal - ? OtherScrollBarView?.ShowScrollIndicator == true ? 1 : 0 + ? OtherScrollBarView?.Visible == true ? 1 : 0 : 0), _ => throw new ArgumentOutOfRangeException () }; @@ -1047,7 +1025,7 @@ private void SetWidthHeight () : 1; } } - else if (_showScrollIndicator) + else if (Visible) { if (SuperView is { UseContentOffset: true }) { @@ -1064,7 +1042,7 @@ private void SetWidthHeight () Height = _orientation == Orientation.Vertical ? Dim.Fill () : 1; } } - else if (_otherScrollBarView?._showScrollIndicator == true) + else if (_otherScrollBarView?.Visible == true) { if (SuperView is { UseContentOffset: true }) { @@ -1129,7 +1107,7 @@ private void ShowHideScrollBars (bool redraw = true) _otherScrollBarView._contentBottomRightCorner.Visible = true; } } - else if (!_showScrollIndicator) + else if (!Visible) { if (_contentBottomRightCorner is { }) { @@ -1153,16 +1131,6 @@ private void ShowHideScrollBars (bool redraw = true) { _otherScrollBarView._contentBottomRightCorner.Visible = false; } - - if (SuperView?.Visible == true && _showScrollIndicator && !Visible) - { - Visible = true; - } - - if (SuperView?.Visible == true && _otherScrollBarView?._showScrollIndicator == true && !_otherScrollBarView.Visible) - { - _otherScrollBarView.Visible = true; - } } internal class ContentBottomRightCorner : View diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index dfa92fcb82..2b4e40234d 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -122,10 +122,11 @@ public ScrollView () } SetContentOffset (_contentOffset); - _contentView.Frame = new (ContentOffset, ContentSize); + _contentView.Frame = new Rectangle (ContentOffset, ContentSize); + // PERF: How about calls to Point.Offset instead? - _vertical.ChangedPosition += delegate { ContentOffset = new (ContentOffset.X, _vertical.Position); }; - _horizontal.ChangedPosition += delegate { ContentOffset = new (_horizontal.Position, ContentOffset.Y); }; + _vertical.ChangedPosition += delegate { ContentOffset = new Point (ContentOffset.X, _vertical.Position); }; + _horizontal.ChangedPosition += delegate { ContentOffset = new Point (_horizontal.Position, ContentOffset.Y); }; }; } @@ -138,17 +139,10 @@ public bool AutoHideScrollBars if (_horizontal.AutoHideScrollBars || _vertical.AutoHideScrollBars != value) { _vertical.AutoHideScrollBars = value; - _horizontal.AutoHideScrollBars = value; - - if (Subviews.Contains (_vertical)) - { - _vertical.AutoHideScrollBars = value; - } + _vertical.Visible = _vertical.ShowScrollIndicator; - if (Subviews.Contains (_horizontal)) - { - _horizontal.AutoHideScrollBars = value; - } + _horizontal.AutoHideScrollBars = value; + _horizontal.Visible = _horizontal.ShowScrollIndicator; SetNeedsDisplay (); } @@ -185,7 +179,7 @@ public Size ContentSize if (_contentSize != value) { _contentSize = value; - _contentView.Frame = new (_contentOffset, value); + _contentView.Frame = new Rectangle (_contentOffset, value); _vertical.Size = _contentSize.Height; _horizontal.Size = _contentSize.Width; SetNeedsDisplay (); @@ -223,21 +217,22 @@ public bool ShowHorizontalScrollIndicator { _horizontal.OtherScrollBarView = _vertical; - if (!Subviews.Contains (_horizontal)) - { - base.Add (_horizontal); - } + //if (!Subviews.Contains (_horizontal)) + //{ + // base.Add (_horizontal); + //} _horizontal.ShowScrollIndicator = true; + _horizontal.Visible = true; _horizontal.AutoHideScrollBars = AutoHideScrollBars; - _horizontal.OtherScrollBarView.ShowScrollIndicator = true; _horizontal.MouseEnter += View_MouseEnter; _horizontal.MouseLeave += View_MouseLeave; } else { - base.Remove (_horizontal); + //base.Remove (_horizontal); _horizontal.ShowScrollIndicator = false; + _horizontal.Visible = false; _horizontal.MouseEnter -= View_MouseEnter; _horizontal.MouseLeave -= View_MouseLeave; } @@ -261,21 +256,22 @@ public bool ShowVerticalScrollIndicator { _vertical.OtherScrollBarView = _horizontal; - if (!Subviews.Contains (_vertical)) - { - base.Add (_vertical); - } + //if (!Subviews.Contains (_vertical)) + //{ + // base.Add (_vertical); + //} _vertical.ShowScrollIndicator = true; + _vertical.Visible = true; _vertical.AutoHideScrollBars = AutoHideScrollBars; - _vertical.OtherScrollBarView.ShowScrollIndicator = true; _vertical.MouseEnter += View_MouseEnter; _vertical.MouseLeave += View_MouseLeave; } else { - Remove (_vertical); + //Remove (_vertical); _vertical.ShowScrollIndicator = false; + _vertical.Visible = false; _vertical.MouseEnter -= View_MouseEnter; _vertical.MouseLeave -= View_MouseLeave; } @@ -560,11 +556,11 @@ private void SetContentBottomRightCornerVisibility () return; } - if (_horizontal.ShowScrollIndicator && _vertical.ShowScrollIndicator) + if (_horizontal.Visible && _vertical.Visible) { _contentBottomRightCorner.Visible = true; } - else if (_horizontal.IsAdded || _vertical.IsAdded) + else if (!_horizontal.Visible || !_vertical.Visible) { _contentBottomRightCorner.Visible = false; } @@ -573,8 +569,8 @@ private void SetContentBottomRightCornerVisibility () private void SetContentOffset (Point offset) { // INTENT: Unclear intent. How about a call to Offset? - _contentOffset = new (-Math.Abs (offset.X), -Math.Abs (offset.Y)); - _contentView.Frame = new (_contentOffset, _contentSize); + _contentOffset = new Point (-Math.Abs (offset.X), -Math.Abs (offset.Y)); + _contentView.Frame = new Rectangle (_contentOffset, _contentSize); int p = Math.Max (0, -_contentOffset.Y); if (_vertical.Position != p) @@ -609,7 +605,7 @@ private void ShowHideScrollBars () { if (ShowVerticalScrollIndicator) { - ShowVerticalScrollIndicator = false; + _vertical.Visible = false; } v = false; @@ -620,19 +616,18 @@ private void ShowHideScrollBars () } else { - if (!ShowVerticalScrollIndicator) + if (ShowVerticalScrollIndicator) { - ShowVerticalScrollIndicator = true; + _vertical.Visible = true; + v = true; } - - v = true; } if (ContentArea.Width == 0 || ContentArea.Width > _contentSize.Width) { if (ShowHorizontalScrollIndicator) { - ShowHorizontalScrollIndicator = false; + _horizontal.Visible = false; } h = false; @@ -641,14 +636,14 @@ private void ShowHideScrollBars () { if (ShowHorizontalScrollIndicator) { - ShowHorizontalScrollIndicator = false; + _horizontal.Visible = false; } h = false; if (ShowVerticalScrollIndicator) { - ShowVerticalScrollIndicator = false; + _vertical.Visible = false; } v = false; @@ -657,32 +652,30 @@ private void ShowHideScrollBars () { if (p) { - if (!ShowVerticalScrollIndicator) + if (ShowVerticalScrollIndicator) { - ShowVerticalScrollIndicator = true; + _vertical.Visible = true; + v = true; } - - v = true; } - if (!ShowHorizontalScrollIndicator) + if (ShowHorizontalScrollIndicator) { - ShowHorizontalScrollIndicator = true; + _horizontal.Visible = true; + h = true; } - - h = true; } Dim dim = Dim.Fill (h ? 1 : 0); - if (!_vertical.Height.Equals (dim)) + if (_vertical.Visible && !_vertical.Height.Equals (dim)) { _vertical.Height = dim; } dim = Dim.Fill (v ? 1 : 0); - if (!_horizontal.Width.Equals (dim)) + if (_horizontal.Visible && !_horizontal.Width.Equals (dim)) { _horizontal.Width = dim; } diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index e2a6fa1644..6b4b487069 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -20,6 +20,7 @@ public void AutoHideScrollBars_Check () AddHandlers (); _hostView.Draw (); + Assert.True (_scrollBar.AutoHideScrollBars); Assert.True (_scrollBar.ShowScrollIndicator); Assert.True (_scrollBar.Visible); Assert.Equal ("Absolute(1)", _scrollBar.Width.ToString ()); @@ -43,7 +44,7 @@ public void AutoHideScrollBars_Check () _hostView.Lines = 10; _hostView.Draw (); - Assert.False (_scrollBar.ShowScrollIndicator); + Assert.True (_scrollBar.ShowScrollIndicator); Assert.False (_scrollBar.Visible); Assert.Equal ("Absolute(1)", _scrollBar.Width.ToString ()); Assert.Equal (1, _scrollBar.ContentArea.Width); @@ -66,7 +67,7 @@ public void AutoHideScrollBars_Check () _hostView.Cols = 60; _hostView.Draw (); - Assert.False (_scrollBar.ShowScrollIndicator); + Assert.True (_scrollBar.ShowScrollIndicator); Assert.False (_scrollBar.Visible); Assert.Equal ("Absolute(1)", _scrollBar.Width.ToString ()); Assert.Equal (1, _scrollBar.ContentArea.Width); @@ -76,7 +77,7 @@ public void AutoHideScrollBars_Check () _scrollBar.Height.ToString () ); Assert.Equal (24, _scrollBar.ContentArea.Height); - Assert.False (_scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); Assert.False (_scrollBar.OtherScrollBarView.Visible); Assert.Equal ( @@ -99,7 +100,7 @@ public void AutoHideScrollBars_Check () _scrollBar.Height.ToString () ); Assert.Equal (25, _scrollBar.ContentArea.Height); - Assert.False (_scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); Assert.False (_scrollBar.OtherScrollBarView.Visible); Assert.Equal ( @@ -579,8 +580,8 @@ This is a tes▼ sbv.OtherScrollBarView.Size = 0; Assert.Equal (0, sbv.Size); Assert.Equal (0, sbv.OtherScrollBarView.Size); - Assert.False (sbv.ShowScrollIndicator); - Assert.False (sbv.OtherScrollBarView.ShowScrollIndicator); + Assert.True (sbv.ShowScrollIndicator); + Assert.True (sbv.OtherScrollBarView.ShowScrollIndicator); Assert.False (sbv.Visible); Assert.False (sbv.OtherScrollBarView.Visible); Application.Top.Draw (); @@ -652,7 +653,7 @@ This is a tes▼ sbv.Size = 0; Assert.Equal (0, sbv.Size); - Assert.False (sbv.ShowScrollIndicator); + Assert.True (sbv.ShowScrollIndicator); Assert.False (sbv.Visible); Application.Top.Draw (); @@ -759,8 +760,8 @@ public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () var scrollBar = textView.Padding.Subviews [0] as ScrollBarView; Assert.True (scrollBar.AutoHideScrollBars); - Assert.False (scrollBar.ShowScrollIndicator); - Assert.False (scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.True (scrollBar.ShowScrollIndicator); + Assert.True (scrollBar.OtherScrollBarView.ShowScrollIndicator); Assert.Equal (5, textView.Lines); // The length is one more for the cursor on the last column of the line @@ -1000,6 +1001,43 @@ public void KeepContentAlwaysInViewport_False () Assert.Equal (99, _hostView.Left); } + [Fact] + [ScrollBarAutoInitShutdown] + public void KeepContentAlwaysInViewport_False_True_With_Both_ShowScrollBars_False () + { + KeepContentAlwaysInViewport_False (); + + Assert.True (_scrollBar.ShowScrollIndicator); + Assert.True (_scrollBar.Visible); + Assert.True(_scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.True (_scrollBar.OtherScrollBarView.Visible); + Assert.False(_scrollBar.KeepContentAlwaysInViewPort); + _scrollBar.ShowScrollIndicator = false; + _scrollBar.OtherScrollBarView.ShowScrollIndicator = false; + _scrollBar.KeepContentAlwaysInViewPort = true; + + Assert.Equal (_scrollBar.Position, _scrollBar.Size - _scrollBar.ContentArea.Height - 1); + Assert.Equal (_scrollBar.Position, _hostView.Top); + Assert.Equal (5, _scrollBar.Position); + Assert.Equal (5, _hostView.Top); + Assert.False (_scrollBar.ShowScrollIndicator); + Assert.False (_scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.False (_scrollBar.Visible); + Assert.False (_scrollBar.OtherScrollBarView.Visible); + + Assert.Equal ( + _scrollBar.OtherScrollBarView.Position, + _scrollBar.OtherScrollBarView.Size - _scrollBar.OtherScrollBarView.ContentArea.Width - 1 + ); + Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); + Assert.Equal (20, _scrollBar.OtherScrollBarView.Position); + Assert.Equal (20, _hostView.Left); + Assert.False (_scrollBar.ShowScrollIndicator); + Assert.False (_scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.False (_scrollBar.Visible); + Assert.False (_scrollBar.OtherScrollBarView.Visible); + } + [Fact] [ScrollBarAutoInitShutdown] public void KeepContentAlwaysInViewport_True () @@ -1513,7 +1551,7 @@ public void ShowScrollIndicator_False_Must_Also_Set_Visible_To_False_To_Not_Resp Assert.Equal (5, sbv.Size); Assert.Null (sbv.OtherScrollBarView); - Assert.False (sbv.ShowScrollIndicator); + Assert.True (sbv.ShowScrollIndicator); Assert.False (sbv.Visible); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -1543,7 +1581,7 @@ This is a test sbv.Visible = true; Assert.Equal (5, sbv.Size); - Assert.False (sbv.ShowScrollIndicator); + Assert.True (sbv.ShowScrollIndicator); Assert.True (sbv.Visible); Application.Top.Draw (); @@ -1573,13 +1611,13 @@ This is a test Assert.Null (Application.MouseGrabView); Assert.True (clicked); Assert.Equal (5, sbv.Size); - Assert.False (sbv.ShowScrollIndicator); + Assert.True (sbv.ShowScrollIndicator); Assert.False (sbv.Visible); // It's needed to set ShowScrollIndicator to true and AutoHideScrollBars to false forcing // showing the scroll bar, otherwise AutoHideScrollBars will automatically control it Assert.True (sbv.AutoHideScrollBars); - sbv.ShowScrollIndicator = true; + Assert.True (sbv.ShowScrollIndicator); sbv.AutoHideScrollBars = false; Application.Top.Draw (); diff --git a/UnitTests/Views/ScrollViewTests.cs b/UnitTests/Views/ScrollViewTests.cs index 252e860385..29e53eaf9f 100644 --- a/UnitTests/Views/ScrollViewTests.cs +++ b/UnitTests/Views/ScrollViewTests.cs @@ -142,8 +142,10 @@ public void AutoHideScrollBars_ShowHorizontalScrollIndicator_ShowVerticalScrollI Application.Begin (Application.Top); Assert.True (sv.AutoHideScrollBars); - Assert.False (sv.ShowHorizontalScrollIndicator); - Assert.False (sv.ShowVerticalScrollIndicator); + Assert.True (sv.ShowHorizontalScrollIndicator); + Assert.False (sv.Subviews.First(sv => sv is ScrollBarView { Orientation: Orientation.Horizontal }).Visible); + Assert.True (sv.ShowVerticalScrollIndicator); + Assert.False (sv.Subviews.First(sv => sv is ScrollBarView { Orientation: Orientation.Vertical }).Visible); TestHelpers.AssertDriverContentsWithFrameAre ("", _output); sv.AutoHideScrollBars = false; From 01e5b52a28e227c0c84e5b6daba7f1f392431814 Mon Sep 17 00:00:00 2001 From: BDisp Date: Tue, 27 Feb 2024 18:52:15 +0000 Subject: [PATCH 063/130] Rename to ShowBothScrollIndicator. --- Terminal.Gui/Views/ScrollBarView.cs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index 1d668cdb20..6aac0d6938 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -179,12 +179,12 @@ public int Size } } - private bool _showBothScrollIndicator => OtherScrollBarView?._showScrollIndicator == true && _showScrollIndicator; - private int GetOtherScrollBarViewOffset => OtherScrollBarView?.Visible == true ? 1 : 0; private bool IsBuiltIn => SuperView is Adornment; + private bool ShowBothScrollIndicator => Visible && OtherScrollBarView?.Visible == true; + /// This event is raised when the position on the scrollbar has changed. public event EventHandler ChangedPosition; @@ -652,7 +652,7 @@ internal bool CanScroll (int n, out int maxToScroll, Orientation orientation = O maxToScroll = Size > barSize + newPosition ? newPosition - _position - : Size - (barSize + _position) - (barSize == 0 && _showBothScrollIndicator ? 1 : 0); + : Size - (barSize + _position) - (barSize == 0 && ShowBothScrollIndicator ? 1 : 0); return Size >= barSize + newPosition && maxToScroll != 0; } @@ -669,16 +669,16 @@ private void AdjustContentInViewport (bool refresh = true) if (KeepContentAlwaysInViewPort && _orientation == Orientation.Horizontal - && _position > Math.Max (Size - bounds.Width + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0), GetOtherScrollBarViewOffset)) + && _position > Math.Max (Size - bounds.Width + (!IsBuiltIn && ShowBothScrollIndicator ? 1 : 0), GetOtherScrollBarViewOffset)) { - pos = Math.Max (Size - bounds.Width + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0), GetOtherScrollBarViewOffset); + pos = Math.Max (Size - bounds.Width + (!IsBuiltIn && ShowBothScrollIndicator ? 1 : 0), GetOtherScrollBarViewOffset); } if (KeepContentAlwaysInViewPort && _orientation == Orientation.Vertical - && _position > Math.Max (Size - bounds.Height + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0), GetOtherScrollBarViewOffset)) + && _position > Math.Max (Size - bounds.Height + (!IsBuiltIn && ShowBothScrollIndicator ? 1 : 0), GetOtherScrollBarViewOffset)) { - pos = Math.Max (Size - bounds.Height + (!IsBuiltIn && _showBothScrollIndicator ? 1 : 0), GetOtherScrollBarViewOffset); + pos = Math.Max (Size - bounds.Height + (!IsBuiltIn && ShowBothScrollIndicator ? 1 : 0), GetOtherScrollBarViewOffset); } if (pos != 0) @@ -715,7 +715,7 @@ private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = fa scrollBarView.Visible = false; } - if (scrollBarView.OtherScrollBarView is { } && scrollBarView._showBothScrollIndicator) + if (scrollBarView.OtherScrollBarView is { } && scrollBarView.ShowBothScrollIndicator) { scrollBarView.OtherScrollBarView.Visible = false; } @@ -728,7 +728,7 @@ private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = fa { if (scrollBarView.OtherScrollBarView is { } && pending) { - if (!scrollBarView._showBothScrollIndicator && scrollBarView.OtherScrollBarView._showScrollIndicator) + if (!scrollBarView.ShowBothScrollIndicator && scrollBarView.OtherScrollBarView._showScrollIndicator) { scrollBarView.OtherScrollBarView.Visible = true; } @@ -842,9 +842,9 @@ private int GetBarSize (Orientation orientation) } return orientation == Orientation.Vertical ? KeepContentAlwaysInViewPort - ? bounds.Height - (_showBothScrollIndicator ? 1 : 0) + ? bounds.Height - (ShowBothScrollIndicator ? 1 : 0) : 0 : - KeepContentAlwaysInViewPort ? bounds.Width - (_showBothScrollIndicator ? 1 : 0) : 0; + KeepContentAlwaysInViewPort ? bounds.Width - (ShowBothScrollIndicator ? 1 : 0) : 0; } private void ManageScrollBarThickness () @@ -991,7 +991,7 @@ private void SetWidthHeight () return; } - if (_showBothScrollIndicator) + if (ShowBothScrollIndicator) { if (SuperView is { UseContentOffset: true }) { @@ -1096,7 +1096,7 @@ private void ShowHideScrollBars (bool redraw = true) OtherScrollBarView.SetRelativeLayout (SuperView?.GetVisibleContentArea () ?? Rectangle.Empty); } - if (_showBothScrollIndicator) + if (ShowBothScrollIndicator) { if (_contentBottomRightCorner is { }) { From d9ab5a9744107def7afdf3d870e2d2cee63ac1c2 Mon Sep 17 00:00:00 2001 From: BDisp Date: Tue, 27 Feb 2024 18:56:18 +0000 Subject: [PATCH 064/130] Improving scenario to manage auto-hide properly. --- UICatalog/Scenarios/Scrolling.cs | 37 +++++++++----------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/UICatalog/Scenarios/Scrolling.cs b/UICatalog/Scenarios/Scrolling.cs index 69f9298e47..56e674ecec 100644 --- a/UICatalog/Scenarios/Scrolling.cs +++ b/UICatalog/Scenarios/Scrolling.cs @@ -25,10 +25,10 @@ public override void Setup () Id = "scrollView", X = 2, Y = Pos.Bottom (label) + 1, - Width = 50, - Height = 20, + Width = Dim.Percent(60), + Height = Dim.Percent (80), ColorScheme = Colors.ColorSchemes ["TopLevel"], - ContentSize = new (200, 100), + ContentSize = new (80, 28), //ContentOffset = Point.Empty, ShowVerticalScrollIndicator = true, @@ -183,39 +183,21 @@ void Top_Loaded (object sender, EventArgs args) hCheckBox.Toggled += (s, e) => { - if (ahCheckBox.Checked == false) - { - scrollView.ShowHorizontalScrollIndicator = (bool)hCheckBox.Checked; - } - else - { - hCheckBox.Checked = true; - MessageBox.Query ("Message", "Disable Auto Hide Scrollbars first.", "Ok"); - } + scrollView.ShowHorizontalScrollIndicator = !(bool)hCheckBox.Checked; }; vCheckBox.Toggled += (s, e) => { - if (ahCheckBox.Checked == false) - { - scrollView.ShowVerticalScrollIndicator = (bool)vCheckBox.Checked; - } - else - { - vCheckBox.Checked = true; - MessageBox.Query ("Message", "Disable Auto Hide Scrollbars first.", "Ok"); - } + scrollView.ShowVerticalScrollIndicator = !(bool)vCheckBox.Checked; }; ahCheckBox.Toggled += (s, e) => { - scrollView.AutoHideScrollBars = (bool)ahCheckBox.Checked; - hCheckBox.Checked = true; - vCheckBox.Checked = true; + scrollView.AutoHideScrollBars = !(bool)ahCheckBox.Checked; }; Win.Add (ahCheckBox); - keepCheckBox.Toggled += (s, e) => scrollView.KeepContentAlwaysInViewPort = (bool)keepCheckBox.Checked; + keepCheckBox.Toggled += (s, e) => scrollView.KeepContentAlwaysInViewPort = !(bool)keepCheckBox.Checked; Win.Add (keepCheckBox); //var scrollView2 = new ScrollView (new (55, 2, 20, 8)) { @@ -247,11 +229,12 @@ void Top_Loaded (object sender, EventArgs args) X = Pos.Right (scrollView) + 1, Y = Pos.AnchorEnd (1), AutoSize = false, - Width = 50, + Width = Dim.Fill(), + Height = 1, Text = "Mouse: " }; Win.Add (mousePos); - Application.MouseEvent += (sender, a) => { mousePos.Text = $"Mouse: ({a.MouseEvent.X},{a.MouseEvent.Y}) - {a.MouseEvent.Flags} {count++}"; }; + Application.MouseEvent += (sender, a) => { mousePos.Text = $"Mouse: ({a.MouseEvent.X},{a.MouseEvent.Y}) - {a.MouseEvent.Flags} - {a.MouseEvent.View} {count++}"; }; var progress = new ProgressBar { X = Pos.Right (scrollView) + 1, Y = Pos.AnchorEnd (2), Width = 50 }; Win.Add (progress); From 32515fdcef316cc58c2cba96fd2eeb1073022e74 Mon Sep 17 00:00:00 2001 From: BDisp Date: Tue, 27 Feb 2024 18:59:05 +0000 Subject: [PATCH 065/130] Only set _ignoreEnsureSelectedCellIsVisible to false after process the select row. --- Terminal.Gui/Views/TableView/TableView.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/Views/TableView/TableView.cs b/Terminal.Gui/Views/TableView/TableView.cs index ec52bec7f8..1da9baa67b 100644 --- a/Terminal.Gui/Views/TableView/TableView.cs +++ b/Terminal.Gui/Views/TableView/TableView.cs @@ -440,8 +440,6 @@ public int SelectedRow get => _selectedRow; set { - _ignoreEnsureSelectedCellIsVisible = false; - int oldValue = _selectedRow; _selectedRow = TableIsNullOrInvisible () ? 0 : Math.Min (Table.Rows - 1, Math.Max (0, value)); @@ -458,6 +456,8 @@ public int SelectedRow ) ); } + + _ignoreEnsureSelectedCellIsVisible = false; } } From 733a918af4641181ef96a2e8996b1404cb2ce80a Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 28 Feb 2024 14:53:40 +0000 Subject: [PATCH 066/130] Fix a code style where object type name were added after the 'new' statement. --- Terminal.sln.DotSettings | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Terminal.sln.DotSettings b/Terminal.sln.DotSettings index 621952feb5..214480e63f 100644 --- a/Terminal.sln.DotSettings +++ b/Terminal.sln.DotSettings @@ -13,7 +13,9 @@ WARNING ERROR ERROR - WARNING + HINT + DO_NOT_SHOW + WARNING WARNING WARNING From 022e715d8b4b88e732a476ceb7a992713b11be0d Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 28 Feb 2024 14:54:53 +0000 Subject: [PATCH 067/130] Cleanup code. --- UICatalog/Scenarios/Scrolling.cs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/UICatalog/Scenarios/Scrolling.cs b/UICatalog/Scenarios/Scrolling.cs index 56e674ecec..5c4d2ed637 100644 --- a/UICatalog/Scenarios/Scrolling.cs +++ b/UICatalog/Scenarios/Scrolling.cs @@ -1,5 +1,4 @@ using System; -using System.Text; using Terminal.Gui; namespace UICatalog.Scenarios; @@ -25,7 +24,7 @@ public override void Setup () Id = "scrollView", X = 2, Y = Pos.Bottom (label) + 1, - Width = Dim.Percent(60), + Width = Dim.Percent (60), Height = Dim.Percent (80), ColorScheme = Colors.ColorSchemes ["TopLevel"], ContentSize = new (80, 28), @@ -68,7 +67,7 @@ void Top_Loaded (object sender, EventArgs args) { horizontalRuler.Text = rule.Repeat ((int)Math.Ceiling (horizontalRuler.ContentArea.Width / (double)rule.Length)) [ - ..horizontalRuler.ContentArea.Width] + ..horizontalRuler.ContentArea.Width] + "\n" + "| ".Repeat ( (int)Math.Ceiling (horizontalRuler.ContentArea.Width / (double)rule.Length) @@ -181,20 +180,11 @@ void Top_Loaded (object sender, EventArgs args) X = Pos.Left (scrollView), Y = Pos.Bottom (ahCheckBox), Text = k, Checked = scrollView.AutoHideScrollBars }; - hCheckBox.Toggled += (s, e) => - { - scrollView.ShowHorizontalScrollIndicator = !(bool)hCheckBox.Checked; - }; + hCheckBox.Toggled += (s, e) => { scrollView.ShowHorizontalScrollIndicator = !(bool)hCheckBox.Checked; }; - vCheckBox.Toggled += (s, e) => - { - scrollView.ShowVerticalScrollIndicator = !(bool)vCheckBox.Checked; - }; + vCheckBox.Toggled += (s, e) => { scrollView.ShowVerticalScrollIndicator = !(bool)vCheckBox.Checked; }; - ahCheckBox.Toggled += (s, e) => - { - scrollView.AutoHideScrollBars = !(bool)ahCheckBox.Checked; - }; + ahCheckBox.Toggled += (s, e) => { scrollView.AutoHideScrollBars = !(bool)ahCheckBox.Checked; }; Win.Add (ahCheckBox); keepCheckBox.Toggled += (s, e) => scrollView.KeepContentAlwaysInViewPort = !(bool)keepCheckBox.Checked; @@ -229,12 +219,16 @@ void Top_Loaded (object sender, EventArgs args) X = Pos.Right (scrollView) + 1, Y = Pos.AnchorEnd (1), AutoSize = false, - Width = Dim.Fill(), + Width = Dim.Fill (), Height = 1, Text = "Mouse: " }; Win.Add (mousePos); - Application.MouseEvent += (sender, a) => { mousePos.Text = $"Mouse: ({a.MouseEvent.X},{a.MouseEvent.Y}) - {a.MouseEvent.Flags} - {a.MouseEvent.View} {count++}"; }; + + Application.MouseEvent += (sender, a) => + { + mousePos.Text = $"Mouse: ({a.MouseEvent.X},{a.MouseEvent.Y}) - {a.MouseEvent.Flags} - {a.MouseEvent.View} {count++}"; + }; var progress = new ProgressBar { X = Pos.Right (scrollView) + 1, Y = Pos.AnchorEnd (2), Width = 50 }; Win.Add (progress); From 7c96a68b7d58eee58e0b409ed4add5045d5d9a2d Mon Sep 17 00:00:00 2001 From: BDisp Date: Wed, 6 Mar 2024 15:55:52 +0000 Subject: [PATCH 068/130] Fix window 2 name title. --- UICatalog/Scenarios/Clipping.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UICatalog/Scenarios/Clipping.cs b/UICatalog/Scenarios/Clipping.cs index 3389c3b1d4..c2b05a7927 100644 --- a/UICatalog/Scenarios/Clipping.cs +++ b/UICatalog/Scenarios/Clipping.cs @@ -45,7 +45,7 @@ public override void Setup () var embedded2 = new Window { - Title = "1", + Title = "2", X = 3, Y = 3, Width = Dim.Fill (3), From d6270558a8a9184b4a6ffb1fbd2e087e78540907 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 9 Mar 2024 19:15:10 +0000 Subject: [PATCH 069/130] Fix GetVisibleContentArea. --- Terminal.Gui/View/Adornment/Adornment.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/View/Adornment/Adornment.cs b/Terminal.Gui/View/Adornment/Adornment.cs index c1bb5beda4..c19d4def1d 100644 --- a/Terminal.Gui/View/Adornment/Adornment.cs +++ b/Terminal.Gui/View/Adornment/Adornment.cs @@ -32,7 +32,7 @@ public Adornment () /// /// Gets the rectangle that describes the area of the Adornment. The Location is always (0,0). - /// The size is the size of the Frame + /// The size is the size of the Frame /// public override Rectangle ContentArea { @@ -105,7 +105,7 @@ public override Rectangle FrameToScreen () /// public override Rectangle GetVisibleContentArea () { - return Thickness?.GetInside (new Rectangle (Point.Empty, Frame.Size)) ?? new Rectangle (Point.Empty, Frame.Size); + return new Rectangle (Point.Empty, Frame.Size); } /// Does nothing for Adornment From d8df3364e144f726dfc605b056a555c9b26dfb9d Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 9 Mar 2024 19:18:52 +0000 Subject: [PATCH 070/130] Fix Adornments sub-classes. --- Terminal.Gui/View/Adornment/Border.cs | 21 +-------------------- Terminal.Gui/View/Adornment/Padding.cs | 21 +-------------------- 2 files changed, 2 insertions(+), 40 deletions(-) diff --git a/Terminal.Gui/View/Adornment/Border.cs b/Terminal.Gui/View/Adornment/Border.cs index b77246904b..815661663b 100644 --- a/Terminal.Gui/View/Adornment/Border.cs +++ b/Terminal.Gui/View/Adornment/Border.cs @@ -100,26 +100,7 @@ public LineStyle LineStyle } /// - public override Rectangle FrameToScreen () - { - Rectangle ret = base.FrameToScreen (); - - ret.X += Parent?.Margin.Thickness.Left ?? 0; - ret.Y += Parent?.Margin.Thickness.Top ?? 0; - - return ret; - } - - /// - public override Thickness GetAdornmentsThickness () - { - int left = Parent.Margin.Thickness.Left; - int top = Parent.Margin.Thickness.Top; - int right = Parent.Margin.Thickness.Right; - int bottom = Parent.Margin.Thickness.Bottom; - - return new Thickness (left, top, right, bottom); - } + public override Thickness GetAdornmentsThickness () { return Parent.Margin.Thickness; } /// public override void OnDrawContent (Rectangle contentArea) diff --git a/Terminal.Gui/View/Adornment/Padding.cs b/Terminal.Gui/View/Adornment/Padding.cs index e5521c1b5f..ebc4f0dda5 100644 --- a/Terminal.Gui/View/Adornment/Padding.cs +++ b/Terminal.Gui/View/Adornment/Padding.cs @@ -40,24 +40,5 @@ public override ColorScheme ColorScheme } /// - public override Rectangle FrameToScreen () - { - Rectangle ret = base.FrameToScreen (); - - ret.X += Parent != null ? Parent.Margin.Thickness.Left + Parent.Border.Thickness.Left : 0; - ret.Y += Parent != null ? Parent.Margin.Thickness.Top + Parent.Border.Thickness.Top : 0; - - return ret; - } - - /// - public override Thickness GetAdornmentsThickness () - { - int left = Parent.Margin.Thickness.Left + Parent.Border.Thickness.Left; - int top = Parent.Margin.Thickness.Top + Parent.Border.Thickness.Top; - int right = Parent.Margin.Thickness.Right + Parent.Border.Thickness.Right; - int bottom = Parent.Margin.Thickness.Bottom + Parent.Border.Thickness.Bottom; - - return new Thickness (left, top, right, bottom); - } + public override Thickness GetAdornmentsThickness () { return Parent.Margin.Thickness + Parent.Border.Thickness; } } From 4ff9403927d119cc9abc12fef3528f485cba1246 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 9 Mar 2024 19:27:10 +0000 Subject: [PATCH 071/130] Fix FindDeepestView. --- Terminal.Gui/View/Layout/ViewLayout.cs | 35 ++++++++------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index de8659e52b..1a623e7653 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -598,7 +598,6 @@ public Rectangle BoundsToScreen (in Rectangle bounds) /// The superview where to look for. /// The column location in the superview. /// The row location in the superview. - /// TODO: Remove this in PR #3273 /// /// The view that was found at the and coordinates. /// if no view was found. @@ -606,42 +605,30 @@ public Rectangle BoundsToScreen (in Rectangle bounds) // CONCURRENCY: This method is not thread-safe. // Undefined behavior and likely program crashes are exposed by unsynchronized access to InternalSubviews. - public static View? FindDeepestView (View? start, int x, int y, bool findAdornments = false) + public static View? FindDeepestView (View? start, int x, int y) { if (start is null || !start.Visible) { return null; } - if (!start.Frame.Contains (x, y)) + if (start is Adornment adornment) { - return null; - } - - if (findAdornments) - { - // TODO: This is a temporary hack for PR #3273; it is not actually used anywhere but unit tests at this point. - if (start.Margin.Thickness.Contains (start.Margin.Frame, x, y)) - { - return start.Margin; - } - - if (start.Border.Thickness.Contains (start.Border.Frame, x, y)) + if (!adornment.FrameToScreen().Contains(x, y)) { - return start.Border; - } - - if (start.Padding.Thickness.Contains (start.Padding.Frame, x, y)) - { - return start.Padding; + return null; } } + else if (!start.Frame.Contains (x, y)) + { + return null; + } if (start.InternalSubviews is { Count: > 0 }) { Point boundsOffset = start.GetBoundsOffset (); - int rx = x - (start.Frame.X + boundsOffset.X); - int ry = y - (start.Frame.Y + boundsOffset.Y); + int rx = x - (start is Adornment ? start.FrameToScreen().X : start.Frame.X + boundsOffset.X); + int ry = y - (start is Adornment ? start.FrameToScreen().Y : start.Frame.Y + boundsOffset.Y); for (int i = start.InternalSubviews.Count - 1; i >= 0; i--) { @@ -649,7 +636,7 @@ public Rectangle BoundsToScreen (in Rectangle bounds) if (v.Visible && v.Frame.Contains (rx, ry)) { - View? deep = FindDeepestView (v, rx, ry, findAdornments); + View? deep = FindDeepestView (v, rx, ry); return deep ?? v; } From 06c402b7e4a3e057094ad18089b4de7f5d85f1e7 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 9 Mar 2024 19:31:01 +0000 Subject: [PATCH 072/130] Fix FrameToScreen. --- Terminal.Gui/View/Layout/ViewLayout.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 1a623e7653..74f18c7e90 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -657,6 +657,13 @@ public virtual Rectangle FrameToScreen () while (super is { }) { Point boundsOffset = super.GetBoundsOffset (); + + if (super is Adornment adornment) + { + boundsOffset = super.FrameToScreen ().Location; + Thickness thickness = adornment.GetAdornmentsThickness (); + boundsOffset.Offset (-thickness.Left, -thickness.Top); + } ret.X += super.Frame.X + boundsOffset.X; ret.Y += super.Frame.Y + boundsOffset.Y; super = super.SuperView; From 8abebd40e441229a83b274ccf32f0f13f69cb415 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 9 Mar 2024 19:31:51 +0000 Subject: [PATCH 073/130] Make GetAdornmentsThickness virtual. --- Terminal.Gui/View/Layout/ViewLayout.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 74f18c7e90..46b3f53934 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -676,7 +676,7 @@ public virtual Rectangle FrameToScreen () /// Gets the thickness describing the sum of the Adornments' thicknesses. /// /// A thickness that describes the sum of the Adornments' thicknesses. - public Thickness GetAdornmentsThickness () { return Margin.Thickness + Border.Thickness + Padding.Thickness; } + public virtual Thickness GetAdornmentsThickness () { return Margin.Thickness + Border.Thickness + Padding.Thickness; } /// /// Helper to get the X and Y offset of the Bounds from the Frame. This is the sum of the Left and Top properties From 52ef1ea43f7f35aec6c931047bd38b1413b292cc Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 9 Mar 2024 19:32:27 +0000 Subject: [PATCH 074/130] Fix format. --- Terminal.Gui/View/Layout/ViewLayout.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 46b3f53934..8b9ce350f5 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -694,7 +694,7 @@ public virtual Point GetBoundsOffset () /// /// Get the visible content area represent the View-relative rectangle used for this view. The area inside the view - /// where subviews + /// where subviews and content are presented.The Location is always (0,0). It will be mainly used for clipping a region. /// and content are presented. The Location is always (0,0). It will be mainly used for clipping a region. /// public virtual Rectangle GetVisibleContentArea () From 853fb4b730028ce09257c857921e7710164375dd Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 9 Mar 2024 19:35:00 +0000 Subject: [PATCH 075/130] Remove duplicate commentary. --- Terminal.Gui/View/Layout/ViewLayout.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 8b9ce350f5..8baba4ffc9 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -695,7 +695,6 @@ public virtual Point GetBoundsOffset () /// /// Get the visible content area represent the View-relative rectangle used for this view. The area inside the view /// where subviews and content are presented.The Location is always (0,0). It will be mainly used for clipping a region. - /// and content are presented. The Location is always (0,0). It will be mainly used for clipping a region. /// public virtual Rectangle GetVisibleContentArea () { From 054f34b64d6f4fcd583f5023e31d0f593165dd07 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 9 Mar 2024 19:38:30 +0000 Subject: [PATCH 076/130] Fix merge conflicts. --- Terminal.Gui/View/ViewDrawing.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Terminal.Gui/View/ViewDrawing.cs b/Terminal.Gui/View/ViewDrawing.cs index 728284257a..3495fbc6e4 100644 --- a/Terminal.Gui/View/ViewDrawing.cs +++ b/Terminal.Gui/View/ViewDrawing.cs @@ -97,7 +97,7 @@ public void Clear (Rectangle contentArea) Attribute prev = Driver.SetAttribute (GetNormalColor ()); // Clamp the region to the bounds of the view - contentArea = Rectangle.Intersect (contentArea, Bounds); + contentArea = Rectangle.Intersect (contentArea, ContentArea); Driver.FillRect (BoundsToScreen (contentArea)); Driver.SetAttribute (prev); } From 82ffb4f5a82668a65a14681a0b988b313a12523e Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 9 Mar 2024 19:39:56 +0000 Subject: [PATCH 077/130] Invoke DrawContentComplete in the Draw method as the DrawContent. --- Terminal.Gui/View/ViewDrawing.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/View/ViewDrawing.cs b/Terminal.Gui/View/ViewDrawing.cs index 3495fbc6e4..946a8a600b 100644 --- a/Terminal.Gui/View/ViewDrawing.cs +++ b/Terminal.Gui/View/ViewDrawing.cs @@ -183,7 +183,7 @@ public void Draw () ClearNeedsDisplay (); // Invoke DrawContentCompleteEvent - dev = new DrawEventArgs (ContentArea); + dev = new (ContentArea); DrawContentComplete?.Invoke (this, dev); if (!dev.Cancel) @@ -445,7 +445,7 @@ public virtual void OnDrawContent (Rectangle contentArea) /// This method will be called after any subviews removed with have been completed /// drawing. /// - public virtual void OnDrawContentComplete (Rectangle contentArea) { DrawContentComplete?.Invoke (this, new (contentArea)); } + public virtual void OnDrawContentComplete (Rectangle contentArea) { } // TODO: Make this cancelable /// From f8f55c148b033663f5aa588ca935b65b444036c9 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 9 Mar 2024 19:40:53 +0000 Subject: [PATCH 078/130] Fix SetNeedsDisplay on Adornments. --- Terminal.Gui/View/ViewDrawing.cs | 36 +++----------------------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/Terminal.Gui/View/ViewDrawing.cs b/Terminal.Gui/View/ViewDrawing.cs index 946a8a600b..dbf6fa0080 100644 --- a/Terminal.Gui/View/ViewDrawing.cs +++ b/Terminal.Gui/View/ViewDrawing.cs @@ -545,39 +545,9 @@ public void SetNeedsDisplay (Rectangle region) _superView?.SetSubViewNeedsDisplay (); - if (_needsDisplayRect.X < ContentArea.X - || _needsDisplayRect.Y < ContentArea.Y - || _needsDisplayRect.Width > ContentArea.Width - || _needsDisplayRect.Height > ContentArea.Height) - { - Margin?.SetNeedsDisplay (Margin.ContentArea); - Border?.SetNeedsDisplay (Border.ContentArea); - Padding?.SetNeedsDisplay (Padding.ContentArea); - - if (Margin != null) - { - for (var i = 0; i < 3; i++) - { - Adornment adornment = i switch - { - 0 => Margin, - 1 => Border, - 2 => Padding, - _ => null - }; - - if (adornment != null) - { - adornment.SetNeedsDisplay (); - - foreach (View view in adornment.Subviews) - { - view.SetNeedsDisplay (); - } - } - } - } - } + Margin?.SetNeedsDisplay (Margin.Frame); + Border?.SetNeedsDisplay (Border.Frame); + Padding?.SetNeedsDisplay (Padding.Frame); if (_subviews is null) { From fc0f25e3316d3195e07570cd76a3224324d10d24 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 9 Mar 2024 19:46:14 +0000 Subject: [PATCH 079/130] Fixes 3310. A view where CanFocus is true must be able to set focus on click. --- Terminal.Gui/View/ViewMouse.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Terminal.Gui/View/ViewMouse.cs b/Terminal.Gui/View/ViewMouse.cs index 2ab4d54bad..d302d8ab73 100644 --- a/Terminal.Gui/View/ViewMouse.cs +++ b/Terminal.Gui/View/ViewMouse.cs @@ -146,6 +146,11 @@ protected bool OnMouseClick (MouseEventEventArgs args) return true; } + if (!HasFocus && CanFocus) + { + SetFocus(); + } + return args.Handled; } } From 27600c4f8ca46620d9bbfdfeaa1d7ca425280e60 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 9 Mar 2024 19:47:12 +0000 Subject: [PATCH 080/130] Fix SetBoundsByPosition. --- Terminal.Gui/View/ViewScrollBar.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 39539eec58..cbf26a6b68 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -432,11 +432,11 @@ private void SetBoundsByPosition (ScrollBarView scrollBar) { if (scrollBar.Orientation == Orientation.Vertical) { - ContentOffset = new Point (ContentArea.X, -scrollBar.Position); + ContentOffset = ContentOffset with { Y = -scrollBar.Position }; } else { - ContentOffset = new Point (-scrollBar.Position, ContentArea.Y); + ContentOffset = ContentOffset with { X = -scrollBar.Position }; } SetTextFormatterSize (); From 26be3095ba88d71177a383c3c0c49904e2e63b4c Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 9 Mar 2024 19:57:22 +0000 Subject: [PATCH 081/130] Fix merge conflicts. --- Terminal.Gui/Views/ComboBox.cs | 4 +- Terminal.Gui/Views/Slider.cs | 2 +- UnitTests/Drawing/LineCanvasTests.cs | 2 +- UnitTests/UICatalog/ScenarioTests.cs | 2 +- UnitTests/View/Adornment/AdornmentTests.cs | 18 +-- UnitTests/View/Adornment/ToScreenTests.cs | 2 +- UnitTests/View/Layout/BoundsTests.cs | 6 +- UnitTests/View/ViewTests.cs | 127 +++++++-------------- UnitTests/Views/ButtonTests.cs | 36 ------ 9 files changed, 62 insertions(+), 137 deletions(-) diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index e683adfdb8..eb7907c5c2 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -501,7 +501,7 @@ private void HideList () _listview.Clear (_listview.IsInitialized ? _listview.ContentArea : Rectangle.Empty); _listview.TabStop = false; SuperView?.SendSubviewToBack (this); - Rectangle rect = _listview.BoundsToScreen (_listview.IsInitialized ? _listview.Bounds : Rectangle.Empty); + Rectangle rect = _listview.BoundsToScreen (_listview.IsInitialized ? _listview.ContentArea : Rectangle.Empty); SuperView?.SetNeedsDisplay (rect); OnCollapsed (); } @@ -768,7 +768,7 @@ private void SetValue (object text, bool isFromSelectedItem = false) private void ShowList () { _listview.SetSource (_searchset); - _listview.Clear (Bounds); // Ensure list shrinks in Dialog as you type + _listview.Clear (ContentArea); // Ensure list shrinks in Dialog as you type _listview.Height = CalculatetHeight (); SuperView?.BringSubviewToFront (this); } diff --git a/Terminal.Gui/Views/Slider.cs b/Terminal.Gui/Views/Slider.cs index bf3c263147..49c0aee4b2 100644 --- a/Terminal.Gui/Views/Slider.cs +++ b/Terminal.Gui/Views/Slider.cs @@ -1073,7 +1073,7 @@ private string AlignText (string text, int width, TextAlignment textAlignment) private void DrawSlider () { // TODO: be more surgical on clear - Clear (Bounds); + Clear (ContentArea); // Attributes diff --git a/UnitTests/Drawing/LineCanvasTests.cs b/UnitTests/Drawing/LineCanvasTests.cs index ff931d089b..0f5a51cfdd 100644 --- a/UnitTests/Drawing/LineCanvasTests.cs +++ b/UnitTests/Drawing/LineCanvasTests.cs @@ -1312,7 +1312,7 @@ private View GetCanvas (out LineCanvas canvas, int offsetX = 0, int offsetY = 0) v.DrawContentComplete += (s, e) => { - v.Clear (v.Bounds); + v.Clear (v.ContentArea); foreach (KeyValuePair p in canvasCopy.GetMap ()) { diff --git a/UnitTests/UICatalog/ScenarioTests.cs b/UnitTests/UICatalog/ScenarioTests.cs index 6a2b7803fa..222bf430d0 100644 --- a/UnitTests/UICatalog/ScenarioTests.cs +++ b/UnitTests/UICatalog/ScenarioTests.cs @@ -254,7 +254,7 @@ public void Run_All_Views_Tester_Scenario () _hostPane.Remove (_curView); _curView.Dispose (); _curView = null; - _hostPane.Clear (_hostPane.Bounds); + _hostPane.Clear (_hostPane.ContentArea); } _curView = CreateClass (_viewClasses.Values.ToArray () [_classListView.SelectedItem]); diff --git a/UnitTests/View/Adornment/AdornmentTests.cs b/UnitTests/View/Adornment/AdornmentTests.cs index 0ac6478900..eb6bf0bc6b 100644 --- a/UnitTests/View/Adornment/AdornmentTests.cs +++ b/UnitTests/View/Adornment/AdornmentTests.cs @@ -22,25 +22,25 @@ public void Bounds_Location_Always_Empty_Size_Correct () view.EndInit (); Assert.Equal (new (1, 2, 20, 20), view.Frame); - Assert.Equal (new (0, 0, 20, 20), view.Bounds); + Assert.Equal (new (0, 0, 20, 20), view.ContentArea); var marginThickness = 1; view.Margin.Thickness = new (marginThickness); - Assert.Equal (new (0, 0, 18, 18), view.Bounds); + Assert.Equal (new (0, 0, 18, 18), view.ContentArea); var borderThickness = 2; view.Border.Thickness = new (borderThickness); - Assert.Equal (new (0, 0, 14, 14), view.Bounds); + Assert.Equal (new (0, 0, 14, 14), view.ContentArea); var paddingThickness = 3; view.Padding.Thickness = new Thickness (paddingThickness); - Assert.Equal (new (0, 0, 8, 8), view.Bounds); + Assert.Equal (new (0, 0, 8, 8), view.ContentArea); - Assert.Equal (new (0, 0, view.Margin.Frame.Width, view.Margin.Frame.Height), view.Margin.Bounds); + Assert.Equal (new (0, 0, view.Margin.Frame.Width, view.Margin.Frame.Height), view.Margin.ContentArea); - Assert.Equal (new (0, 0, view.Border.Frame.Width, view.Border.Frame.Height), view.Border.Bounds); + Assert.Equal (new (0, 0, view.Border.Frame.Width, view.Border.Frame.Height), view.Border.ContentArea); - Assert.Equal (new (0, 0, view.Padding.Frame.Width , view.Padding.Frame.Height), view.Padding.Bounds); + Assert.Equal (new (0, 0, view.Padding.Frame.Width , view.Padding.Frame.Height), view.Padding.ContentArea); } // Test that Adornment.Bounds_get override returns Frame.Size minus Thickness @@ -88,7 +88,7 @@ public void Bounds_Width_Is_Frame_Width (int thickness, int x, int y, int w, int Assert.Equal (new Rectangle (x, y, w, h), adornment.Frame); var expectedBounds = new Rectangle (0, 0, w, h); - Assert.Equal (expectedBounds, adornment.Bounds); + Assert.Equal (expectedBounds, adornment.ContentArea); } // Test that Adornment.Bounds_get override uses Parent not SuperView @@ -347,7 +347,7 @@ public void Frames_are_Parent_SuperView_Relative () view.EndInit (); Assert.Equal (new Rectangle (1, 2, 20, 31), view.Frame); - Assert.Equal (new Rectangle (0, 0, 8, 19), view.Bounds); + Assert.Equal (new Rectangle (0, 0, 8, 19), view.ContentArea); // Margin.Frame is always the same as the view frame Assert.Equal (new Rectangle (0, 0, 20, 31), view.Margin.Frame); diff --git a/UnitTests/View/Adornment/ToScreenTests.cs b/UnitTests/View/Adornment/ToScreenTests.cs index bc45086480..86b0a18a73 100644 --- a/UnitTests/View/Adornment/ToScreenTests.cs +++ b/UnitTests/View/Adornment/ToScreenTests.cs @@ -289,7 +289,7 @@ public void BoundsToScreen_NoSuperView_WithAdornments (int frameX, int boundsX, // Total thickness is 3 (view.Bounds will be Frame.Width - 6) view.Frame = frame; - Assert.Equal(4, view.Bounds.Width); + Assert.Equal(4, view.ContentArea.Width); // Act var marginScreen = view.Margin.BoundsToScreen (new (boundsX, 0, 0, 0)); diff --git a/UnitTests/View/Layout/BoundsTests.cs b/UnitTests/View/Layout/BoundsTests.cs index 2a4c3e5c6a..5c51cdd0d7 100644 --- a/UnitTests/View/Layout/BoundsTests.cs +++ b/UnitTests/View/Layout/BoundsTests.cs @@ -28,7 +28,7 @@ public void Get_Bounds_NoSuperView_WithoutAdornments (int x, int expectedW) view.EndInit(); // Act - var bounds = view.Bounds; + var bounds = view.ContentArea; // Assert Assert.Equal(expectedW, bounds.Width); @@ -85,7 +85,7 @@ public void Get_Bounds_NestedSuperView_WithAdornments (int frameX, int borderThi superSuperView.LayoutSubviews (); // Act - var bounds = view.Bounds; + var bounds = view.ContentArea; // Assert Assert.Equal (expectedW, bounds.Width); @@ -144,7 +144,7 @@ public void Get_Bounds_NestedSuperView_WithAdornments_WithBorder (int frameX, in superSuperView.LayoutSubviews (); // Act - var bounds = view.Bounds; + var bounds = view.ContentArea; // Assert Assert.Equal (expectedW, bounds.Width); diff --git a/UnitTests/View/ViewTests.cs b/UnitTests/View/ViewTests.cs index f773eb1fe3..421b96b5ad 100644 --- a/UnitTests/View/ViewTests.cs +++ b/UnitTests/View/ViewTests.cs @@ -9,43 +9,6 @@ public class ViewTests private readonly ITestOutputHelper _output; public ViewTests (ITestOutputHelper output) { _output = output; } - [Fact] - public void Accept_Cancel_Event_OnAccept_Returns_True () - { - var view = new View (); - var acceptInvoked = false; - - view.Accept += ViewOnAccept; - - bool? ret = view.OnAccept (); - Assert.True (ret); - Assert.True (acceptInvoked); - - return; - - void ViewOnAccept (object sender, CancelEventArgs e) - { - acceptInvoked = true; - e.Cancel = true; - } - } - - [Fact] - public void Accept_Command_Invokes_Accept_Event () - { - var view = new View (); - var accepted = false; - - view.Accept += ViewOnAccept; - - view.InvokeCommand (Command.Accept); - Assert.True (accepted); - - return; - - void ViewOnAccept (object sender, CancelEventArgs e) { accepted = true; } - } - [Fact] [AutoInitShutdown] public void Clear_Bounds_Can_Use_Driver_AddRune_Or_AddStr_Methods () @@ -90,7 +53,7 @@ public void Clear_Bounds_Can_Use_Driver_AddRune_Or_AddStr_Methods () Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rectangle (0, 0, 20, 10), pos); - view.Clear (view.Bounds); + view.Clear (view.ContentArea); expected = @" ┌──────────────────┐ @@ -152,7 +115,7 @@ public void Clear_Can_Use_Driver_AddRune_Or_AddStr_Methods () Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); Assert.Equal (new Rectangle (0, 0, 20, 10), pos); - view.Clear (view.Bounds); + view.Clear (view.ContentArea); expected = @" ┌──────────────────┐ @@ -562,17 +525,6 @@ public void GetNormalColor_ColorScheme () view.Dispose (); } - [Fact] - public void HotKey_Command_SetsFocus () - { - var view = new View (); - - view.CanFocus = true; - Assert.False (view.HasFocus); - view.InvokeCommand (Command.HotKey); - Assert.True (view.HasFocus); - } - [Fact] [AutoInitShutdown] public void Incorrect_Redraw_Bounds_NeedDisplay_On_Shrink_And_Move_Down_Right_Using_Frame () @@ -770,6 +722,21 @@ public void Internal_Tests () var view = new View { Frame = rect }; } + [Fact] + [SetupFakeDriver] + public void SetText_RendersCorrectly () + { + View view; + var text = "test"; + + view = new Label { Text = text }; + view.BeginInit (); + view.EndInit (); + view.Draw (); + + TestHelpers.AssertDriverContentsWithFrameAre ( text, _output); + } + [Fact] [TestRespondersDisposed] public void New_Initializes () @@ -908,38 +875,6 @@ public void New_Methods_Return_False () // TODO: Add more } - // OnAccept/Accept tests - [Fact] - public void OnAccept_Fires_Accept () - { - var view = new View (); - var accepted = false; - - view.Accept += ViewOnAccept; - - view.OnAccept (); - Assert.True (accepted); - - return; - - void ViewOnAccept (object sender, CancelEventArgs e) { accepted = true; } - } - - [Fact] - [SetupFakeDriver] - public void SetText_RendersCorrectly () - { - View view; - var text = "test"; - - view = new Label { Text = text }; - view.BeginInit (); - view.EndInit (); - view.Draw (); - - TestHelpers.AssertDriverContentsWithFrameAre (text, _output); - } - [Fact] [AutoInitShutdown] public void Test_Nested_Views_With_Height_Equal_To_One () @@ -1269,4 +1204,30 @@ void ViewOnAccept (object sender, CancelEventArgs e) { e.Cancel = true; } } -} + + [Fact] + public void Accept_Command_Invokes_Accept_Event () + { + var view = new View (); + var accepted = false; + + view.Accept += ViewOnAccept; + + view.InvokeCommand (Command.Accept); + Assert.True (accepted); + + return; + void ViewOnAccept (object sender, CancelEventArgs e) { accepted = true; } + } + + [Fact] + public void HotKey_Command_SetsFocus () + { + var view = new View (); + + view.CanFocus = true; + Assert.False (view.HasFocus); + view.InvokeCommand (Command.HotKey); + Assert.True (view.HasFocus); + } +} \ No newline at end of file diff --git a/UnitTests/Views/ButtonTests.cs b/UnitTests/Views/ButtonTests.cs index b0b7ccfe2c..c43abf5608 100644 --- a/UnitTests/Views/ButtonTests.cs +++ b/UnitTests/Views/ButtonTests.cs @@ -8,27 +8,6 @@ public class ButtonTests private readonly ITestOutputHelper _output; public ButtonTests (ITestOutputHelper output) { _output = output; } - [Fact] - public void Accept_Cancel_Event_OnAccept_Returns_True () - { - var button = new Button (); - var acceptInvoked = false; - - button.Accept += ButtonAccept; - - bool? ret = button.OnAccept (); - Assert.True (ret); - Assert.True (acceptInvoked); - - return; - - void ButtonAccept (object sender, CancelEventArgs e) - { - acceptInvoked = true; - e.Cancel = true; - } - } - // BUGBUG: This test is NOT a unit test and needs to be broken apart into // more specific tests (e.g. it tests Checkbox as well as Button) [Fact] @@ -683,21 +662,6 @@ public void KeyBindings_Command () clicked = false; } - [Fact] - public void HotKey_Command_Accepts () - { - var button = new Button (); - var accepted = false; - - button.Accept += ButtonOnAccept; - button.InvokeCommand (Command.HotKey); - - Assert.True (accepted); - - return; - void ButtonOnAccept (object sender, CancelEventArgs e) { accepted = true; } - } - [Fact] public void Accept_Cancel_Event_OnAccept_Returns_True () { From 61740c3977a4a588cc88bb4a3f62a8732c2dd9f0 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 9 Mar 2024 20:05:11 +0000 Subject: [PATCH 082/130] Fix issues in ScrollBarView. --- Terminal.Gui/Views/ScrollBarView.cs | 496 ++++++++++++++-------------- 1 file changed, 247 insertions(+), 249 deletions(-) diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index 3fe3685944..65102b32f1 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -188,187 +188,6 @@ public int Size /// This event is raised when the position on the scrollbar has changed. public event EventHandler ChangedPosition; - /// - protected internal override bool OnMouseEvent (MouseEvent mouseEvent) - { - if (mouseEvent.Flags != MouseFlags.Button1Pressed - && mouseEvent.Flags != MouseFlags.Button1DoubleClicked - && !mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition) - && mouseEvent.Flags != MouseFlags.Button1Released - && mouseEvent.Flags != MouseFlags.WheeledDown - && mouseEvent.Flags != MouseFlags.WheeledUp - && mouseEvent.Flags != MouseFlags.WheeledRight - && mouseEvent.Flags != MouseFlags.WheeledLeft - && mouseEvent.Flags != MouseFlags.Button1TripleClicked) - { - return false; - } - - View host = SuperView is Adornment adornment ? adornment.Parent : SuperView; - - if (!host.CanFocus) - { - return true; - } - - if (host?.HasFocus == false) - { - host.SetFocus (); - } - - int location = _orientation == Orientation.Vertical ? mouseEvent.Y : mouseEvent.X; - int barsize = _orientation == Orientation.Vertical ? ContentArea.Height : ContentArea.Width; - int posTopLeftTee = _orientation == Orientation.Vertical ? _posTopTee + 1 : _posLeftTee + 1; - int posBottomRightTee = _orientation == Orientation.Vertical ? _posBottomTee + 1 : _posRightTee + 1; - barsize -= 2; - int pos = Position; - - if (mouseEvent.Flags != MouseFlags.Button1Released && (Application.MouseGrabView is null || Application.MouseGrabView != this)) - { - Application.GrabMouse (this); - } - else if (mouseEvent.Flags == MouseFlags.Button1Released && Application.MouseGrabView is { } && Application.MouseGrabView == this) - { - _lastLocation = -1; - Application.UngrabMouse (); - - return true; - } - - if (Visible - && (mouseEvent.Flags == MouseFlags.WheeledDown - || mouseEvent.Flags == MouseFlags.WheeledUp - || mouseEvent.Flags == MouseFlags.WheeledRight - || mouseEvent.Flags == MouseFlags.WheeledLeft)) - { - return Host.OnMouseEvent (mouseEvent); - } - - if (_lastLocation == -1 && mouseEvent.Flags == MouseFlags.Button1Pressed && location == 0) - { - if (pos > 0) - { - Position = pos - 1; - } - } - else if (_lastLocation == -1 && mouseEvent.Flags == MouseFlags.Button1Pressed && location == barsize + 1) - { - if (CanScroll (pos + 1, out _, _orientation)) - { - Position = pos + 1; - } - } - else if (location > 0 && location < barsize + 1) - { - //var b1 = pos * (Size > 0 ? barsize / Size : 0); - //var b2 = Size > 0 - // ? (KeepContentAlwaysInViewport ? Math.Min (((pos + barsize) * barsize / Size) + 1, barsize - 1) : (pos + barsize) * barsize / Size) - // : 0; - //if (KeepContentAlwaysInViewport && b1 == b2) { - // b1 = Math.Max (b1 - 1, 0); - //} - - if (_lastLocation > -1 - || (location >= posTopLeftTee - && location <= posBottomRightTee - && mouseEvent.Flags.HasFlag ( - MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition - ))) - { - if (_lastLocation == -1) - { - _lastLocation = location; - - _posBarOffset = _keepContentAlwaysInViewport - ? Math.Max (location - posTopLeftTee, 1) - : 0; - - return true; - } - - if (location > _lastLocation) - { - if (location == barsize) - { - Position = Size; - } - else if (location - _posBarOffset < barsize) - { - int np = (location - _posBarOffset) * Size / barsize + Size / barsize; - - if (CanScroll (np, out int nv, _orientation)) - { - Position = pos + nv; - } - } - else if (CanScroll (Size, out int nv, _orientation)) - { - Position = Math.Min (pos + nv, Size); - } - } - else if (location < _lastLocation) - { - if (location - _posBarOffset > 0) - { - int np = (location - _posBarOffset) * Size / barsize - Size / barsize; - - if (CanScroll (np, out int nv, _orientation)) - { - Position = pos + nv; - } - } - else - { - Position = 0; - } - } - else if (location == _lastLocation) - { - Position = Size; - } - else if (location - _posBarOffset >= barsize && posBottomRightTee - posTopLeftTee >= 3 && CanScroll (Size - pos, out int nv, _orientation)) - { - Position = Math.Min (pos + nv, Size); - } - else if (location - _posBarOffset >= barsize - 1 && posBottomRightTee - posTopLeftTee <= 3 && CanScroll (Size - pos, out nv, _orientation)) - { - Position = Math.Min (pos + nv, Size); - } - else if (location - _posBarOffset <= 0 && posBottomRightTee - posTopLeftTee <= 3) - { - Position = 0; - } - } - else if (location > posBottomRightTee) - { - if (CanScroll (pos + barsize, out int nv, _orientation)) - { - Position = pos + nv; - } - } - else if (location < posTopLeftTee) - { - if (CanScroll (pos - barsize, out int nv, _orientation)) - { - Position = pos + nv; - } - } - else if (location == 1 && posTopLeftTee <= 3) - { - Position = 0; - } - else if (location == barsize) - { - if (CanScroll (Size, out int nv, _orientation)) - { - Position = Math.Min (pos + nv, Size); - } - } - } - - return true; - } - /// Virtual method to invoke the action event. public virtual void OnChangedPosition () { ChangedPosition?.Invoke (this, EventArgs.Empty); } @@ -379,7 +198,7 @@ public override void OnDrawContent (Rectangle contentArea) { if ((!Visible || Size == 0) && AutoHideScrollBars && Visible) { - ShowHideScrollBars (false); + ShowHideScrollBars (); } return; @@ -613,8 +432,11 @@ public override bool OnEnter (View view) return base.OnEnter (view); } + /// Only used for a hosted view that will update and redraw the scrollbars. + public virtual void Refresh () { ShowHideScrollBars (); } + /// - public override bool OnMouseEnter (MouseEvent mouseEvent) + protected internal override bool OnMouseEnter (MouseEvent mouseEvent) { Application.GrabMouse (this); @@ -622,7 +444,188 @@ public override bool OnMouseEnter (MouseEvent mouseEvent) } /// - public override bool OnMouseLeave (MouseEvent mouseEvent) + protected internal override bool OnMouseEvent (MouseEvent mouseEvent) + { + if (mouseEvent.Flags != MouseFlags.Button1Pressed + && mouseEvent.Flags != MouseFlags.Button1DoubleClicked + && !mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition) + && mouseEvent.Flags != MouseFlags.Button1Released + && mouseEvent.Flags != MouseFlags.WheeledDown + && mouseEvent.Flags != MouseFlags.WheeledUp + && mouseEvent.Flags != MouseFlags.WheeledRight + && mouseEvent.Flags != MouseFlags.WheeledLeft + && mouseEvent.Flags != MouseFlags.Button1TripleClicked) + { + return false; + } + + View host = SuperView is Adornment adornment ? adornment.Parent : SuperView; + + if (!host.CanFocus) + { + return true; + } + + if (host?.HasFocus == false) + { + host.SetFocus (); + } + + int location = _orientation == Orientation.Vertical ? mouseEvent.Y : mouseEvent.X; + int barsize = _orientation == Orientation.Vertical ? ContentArea.Height : ContentArea.Width; + int posTopLeftTee = _orientation == Orientation.Vertical ? _posTopTee + 1 : _posLeftTee + 1; + int posBottomRightTee = _orientation == Orientation.Vertical ? _posBottomTee + 1 : _posRightTee + 1; + barsize -= 2; + int pos = Position; + + if (mouseEvent.Flags != MouseFlags.Button1Released && (Application.MouseGrabView is null || Application.MouseGrabView != this)) + { + Application.GrabMouse (this); + } + else if (mouseEvent.Flags == MouseFlags.Button1Released && Application.MouseGrabView is { } && Application.MouseGrabView == this) + { + _lastLocation = -1; + Application.UngrabMouse (); + + return true; + } + + if (Visible + && (mouseEvent.Flags == MouseFlags.WheeledDown + || mouseEvent.Flags == MouseFlags.WheeledUp + || mouseEvent.Flags == MouseFlags.WheeledRight + || mouseEvent.Flags == MouseFlags.WheeledLeft)) + { + return SuperView.OnMouseEvent (mouseEvent); + } + + if (mouseEvent.Flags == MouseFlags.Button1Pressed && location == 0) + { + if (pos > 0) + { + Position = pos - 1; + } + } + else if (mouseEvent.Flags == MouseFlags.Button1Pressed && location == barsize + 1) + { + if (CanScroll (pos + 1, out _, _orientation)) + { + Position = pos + 1; + } + } + else if (location > 0 && location < barsize + 1) + { + //var b1 = pos * (Size > 0 ? barsize / Size : 0); + //var b2 = Size > 0 + // ? (KeepContentAlwaysInViewport ? Math.Min (((pos + barsize) * barsize / Size) + 1, barsize - 1) : (pos + barsize) * barsize / Size) + // : 0; + //if (KeepContentAlwaysInViewport && b1 == b2) { + // b1 = Math.Max (b1 - 1, 0); + //} + + if (_lastLocation > -1 + || (location >= posTopLeftTee + && location <= posBottomRightTee + && mouseEvent.Flags.HasFlag ( + MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition + ))) + { + if (_lastLocation == -1) + { + _lastLocation = location; + + _posBarOffset = _keepContentAlwaysInViewport + ? Math.Max (location - posTopLeftTee, 1) + : 0; + + return true; + } + + if (location > _lastLocation) + { + if (location == barsize) + { + Position = Size; + } + else if (location - _posBarOffset < barsize) + { + int np = (location - _posBarOffset) * Size / barsize + Size / barsize; + + if (CanScroll (np, out int nv, _orientation)) + { + Position = pos + nv; + } + } + else if (CanScroll (Size, out int nv, _orientation)) + { + Position = Math.Min (pos + nv, Size); + } + } + else if (location < _lastLocation) + { + if (location - _posBarOffset > 0) + { + int np = (location - _posBarOffset) * Size / barsize - Size / barsize; + + if (CanScroll (np, out int nv, _orientation)) + { + Position = pos + nv; + } + } + else + { + Position = 0; + } + } + else if (location == _lastLocation) + { + Position = Size; + } + else if (location - _posBarOffset >= barsize && posBottomRightTee - posTopLeftTee >= 3 && CanScroll (Size - pos, out int nv, _orientation)) + { + Position = Math.Min (pos + nv, Size); + } + else if (location - _posBarOffset >= barsize - 1 && posBottomRightTee - posTopLeftTee <= 3 && CanScroll (Size - pos, out nv, _orientation)) + { + Position = Math.Min (pos + nv, Size); + } + else if (location - _posBarOffset <= 0 && posBottomRightTee - posTopLeftTee <= 3) + { + Position = 0; + } + } + else if (location > posBottomRightTee) + { + if (CanScroll (pos + barsize, out int nv, _orientation)) + { + Position = pos + nv; + } + } + else if (location < posTopLeftTee) + { + if (CanScroll (pos - barsize, out int nv, _orientation)) + { + Position = pos + nv; + } + } + else if (location == 1 && posTopLeftTee <= 3) + { + Position = 0; + } + else if (location == barsize) + { + if (CanScroll (Size, out int nv, _orientation)) + { + Position = Math.Min (pos + nv, Size); + } + } + } + + return true; + } + + /// + protected internal override bool OnMouseLeave (MouseEvent mouseEvent) { if (Application.MouseGrabView != null && Application.MouseGrabView != this) { @@ -632,13 +635,10 @@ public override bool OnMouseLeave (MouseEvent mouseEvent) return base.OnMouseLeave (mouseEvent); } - /// Only used for a hosted view that will update and redraw the scrollbars. - public virtual void Refresh () { ShowHideScrollBars (); } - // param n is the new position and the max is the positive/negative value that can be scrolled for the new position internal bool CanScroll (int n, out int maxToScroll, Orientation orientation = Orientation.Horizontal) { - Rectangle bounds = SuperView?.GetVisibleContentArea () ?? Rectangle.Empty; + Rectangle bounds = GetParentVisibleContentArea (); if (bounds.IsEmpty) { @@ -648,13 +648,14 @@ internal bool CanScroll (int n, out int maxToScroll, Orientation orientation = O } int barSize = GetBarSize (orientation); + int isBuiltInOffset = IsBuiltIn ? 1 : 0; int newPosition = Math.Max (Math.Min (Size - barSize, n), 0); - maxToScroll = Size > barSize + newPosition + maxToScroll = Size > barSize + newPosition - isBuiltInOffset ? newPosition - _position - : Size - (barSize + _position) - (barSize == 0 && ShowBothScrollIndicator ? 1 : 0); + : Size - (barSize + _position) + isBuiltInOffset - (barSize == 0 && ShowBothScrollIndicator ? 1 : 0); - return Size >= barSize + newPosition && maxToScroll != 0; + return Size >= barSize + newPosition - isBuiltInOffset && maxToScroll != 0; } private void AdjustContentInViewport (bool refresh = true) @@ -665,7 +666,7 @@ private void AdjustContentInViewport (bool refresh = true) } var pos = 0; - Rectangle bounds = SuperView?.GetVisibleContentArea () ?? Rectangle.Empty; + Rectangle bounds = GetParentVisibleContentArea (); if (KeepContentAlwaysInViewPort && _orientation == Orientation.Horizontal @@ -703,19 +704,19 @@ private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = fa if (barsize == 0 || barsize >= scrollBarView.Size) { - if (scrollBarView._showScrollIndicator) + if (scrollBarView._showScrollIndicator && scrollBarView.Visible) { scrollBarView.Visible = false; } } else if (barsize > 0 && barsize == scrollBarView.Size && scrollBarView.OtherScrollBarView is { } && pending) { - if (scrollBarView._showScrollIndicator) + if (scrollBarView._showScrollIndicator && scrollBarView.Visible) { scrollBarView.Visible = false; } - if (scrollBarView.OtherScrollBarView is { } && scrollBarView.ShowBothScrollIndicator) + if (scrollBarView.OtherScrollBarView is { } && scrollBarView.ShowBothScrollIndicator && scrollBarView.OtherScrollBarView.Visible) { scrollBarView.OtherScrollBarView.Visible = false; } @@ -728,13 +729,15 @@ private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = fa { if (scrollBarView.OtherScrollBarView is { } && pending) { - if (!scrollBarView.ShowBothScrollIndicator && scrollBarView.OtherScrollBarView._showScrollIndicator) + if (!scrollBarView.ShowBothScrollIndicator + && scrollBarView.OtherScrollBarView._showScrollIndicator + && !scrollBarView.OtherScrollBarView.Visible) { scrollBarView.OtherScrollBarView.Visible = true; } } - if (scrollBarView._showScrollIndicator) + if (scrollBarView._showScrollIndicator && !scrollBarView.Visible) { scrollBarView.Visible = true; } @@ -798,16 +801,8 @@ private void CreateBottomRightCorner (View host) _contentBottomRightCorner = new ContentBottomRightCorner { Visible = host.Visible }; host.Add (_contentBottomRightCorner); - if (IsBuiltIn) - { - _contentBottomRightCorner.X = Pos.AnchorEnd (); - _contentBottomRightCorner.Y = Pos.AnchorEnd (); - } - else - { - _contentBottomRightCorner.X = Pos.AnchorEnd (1); - _contentBottomRightCorner.Y = Pos.AnchorEnd (1); - } + _contentBottomRightCorner.X = Pos.AnchorEnd (1); + _contentBottomRightCorner.Y = Pos.AnchorEnd (1); _contentBottomRightCorner.Width = 1; _contentBottomRightCorner.Height = 1; @@ -826,7 +821,7 @@ private void CreateBottomRightCorner (View host) private int GetBarSize (Orientation orientation) { - Rectangle bounds = SuperView?.GetVisibleContentArea () ?? Rectangle.Empty; + Rectangle bounds = GetParentVisibleContentArea (); if (bounds.IsEmpty) { @@ -847,6 +842,17 @@ private int GetBarSize (Orientation orientation) KeepContentAlwaysInViewPort ? bounds.Width - (ShowBothScrollIndicator ? 1 : 0) : 0; } + // Always return the parent view visible content area or an empty rectangle. + private Rectangle GetParentVisibleContentArea () + { + if (SuperView is Adornment adornment) + { + return adornment.Parent.GetVisibleContentArea (); + } + + return SuperView?.GetVisibleContentArea () ?? Rectangle.Empty; + } + private void ManageScrollBarThickness () { if (!IsBuiltIn) @@ -856,22 +862,22 @@ private void ManageScrollBarThickness () ((Adornment)SuperView).Thickness = ((Adornment)SuperView).Parent.ScrollBarType switch { - ScrollBarType.None => new Thickness (0), - ScrollBarType.Vertical => new Thickness (0, 0, Visible ? 1 : 0, 0), - ScrollBarType.Horizontal => new Thickness (0, 0, 0, Visible ? 1 : 0), - ScrollBarType.Both => new Thickness ( - 0, - 0, - Orientation == Orientation.Vertical - ? Visible ? 1 : 0 - : OtherScrollBarView?.Orientation == Orientation.Vertical - ? OtherScrollBarView?.Visible == true ? 1 : 0 - : 0, - Orientation == Orientation.Horizontal - ? Visible ? 1 : 0 - : OtherScrollBarView?.Orientation == Orientation.Horizontal - ? OtherScrollBarView?.Visible == true ? 1 : 0 - : 0), + ScrollBarType.None => new (0), + ScrollBarType.Vertical => new (0, 0, Visible ? 1 : 0, 0), + ScrollBarType.Horizontal => new (0, 0, 0, Visible ? 1 : 0), + ScrollBarType.Both => new ( + 0, + 0, + Orientation == Orientation.Vertical + ? Visible ? 1 : 0 + : OtherScrollBarView?.Orientation == Orientation.Vertical + ? OtherScrollBarView?.Visible == true ? 1 : 0 + : 0, + Orientation == Orientation.Horizontal + ? Visible ? 1 : 0 + : OtherScrollBarView?.Orientation == Orientation.Horizontal + ? OtherScrollBarView?.Visible == true ? 1 : 0 + : 0), _ => throw new ArgumentOutOfRangeException () }; } @@ -911,16 +917,8 @@ private void Parent_VisibleChanged (object sender, EventArgs e) private void ScrollBarView_Added (object sender, SuperViewChangedEventArgs e) { - if (IsBuiltIn) - { - X = Orientation == Orientation.Vertical ? Pos.AnchorEnd () : 0; - Y = Orientation == Orientation.Vertical ? 0 : Pos.AnchorEnd (); - } - else - { - X = Orientation == Orientation.Vertical ? Pos.AnchorEnd (1) : 0; - Y = Orientation == Orientation.Vertical ? 0 : Pos.AnchorEnd (1); - } + X = Orientation == Orientation.Vertical ? Pos.AnchorEnd (1) : 0; + Y = Orientation == Orientation.Vertical ? 0 : Pos.AnchorEnd (1); if (OtherScrollBarView is { SuperView: null } && !e.Parent.Subviews.Contains (OtherScrollBarView)) { @@ -999,29 +997,29 @@ private void SetWidthHeight () X = _orientation == Orientation.Vertical ? bounds.Right - 1 : bounds.Left; Y = _orientation == Orientation.Vertical ? bounds.Top : bounds.Bottom - 1; - Width = _orientation == Orientation.Vertical ? 1 : SuperView is Adornment ? Dim.Fill () : bounds.Width - 1; - Height = _orientation == Orientation.Vertical ? SuperView is Adornment ? Dim.Fill () : bounds.Height - 1 : 1; + Width = _orientation == Orientation.Vertical ? 1 : SuperView is Adornment ? Dim.Fill (1) : bounds.Width - 1; + Height = _orientation == Orientation.Vertical ? SuperView is Adornment ? Dim.Fill (1) : bounds.Height - 1 : 1; _otherScrollBarView.X = _otherScrollBarView._orientation == Orientation.Vertical ? bounds.Right - 1 : bounds.Left; _otherScrollBarView.Y = _otherScrollBarView._orientation == Orientation.Vertical ? bounds.Top : bounds.Bottom - 1; _otherScrollBarView.Width = _otherScrollBarView._orientation == Orientation.Vertical ? 1 : - SuperView is Adornment ? Dim.Fill () : bounds.Width - 1; + SuperView is Adornment ? Dim.Fill (1) : bounds.Width - 1; _otherScrollBarView.Height = _otherScrollBarView._orientation == Orientation.Vertical - ? SuperView is Adornment ? Dim.Fill () : bounds.Height - 1 + ? SuperView is Adornment ? Dim.Fill (1) : bounds.Height - 1 : 1; } else { - Width = _orientation == Orientation.Vertical ? 1 : SuperView is Adornment ? Dim.Fill () : Dim.Fill (1); - Height = _orientation == Orientation.Vertical ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) : 1; + Width = _orientation == Orientation.Vertical ? 1 : SuperView is Adornment ? Dim.Fill (1) : Dim.Fill (1); + Height = _orientation == Orientation.Vertical ? SuperView is Adornment ? Dim.Fill (1) : Dim.Fill (1) : 1; _otherScrollBarView.Width = _otherScrollBarView._orientation == Orientation.Vertical ? 1 : - SuperView is Adornment ? Dim.Fill () : Dim.Fill (1); + SuperView is Adornment ? Dim.Fill (1) : Dim.Fill (1); _otherScrollBarView.Height = _otherScrollBarView._orientation == Orientation.Vertical - ? SuperView is Adornment ? Dim.Fill () : Dim.Fill (1) + ? SuperView is Adornment ? Dim.Fill (1) : Dim.Fill (1) : 1; } } @@ -1067,7 +1065,7 @@ private void SetWidthHeight () } } - private void ShowHideScrollBars (bool redraw = true) + private void ShowHideScrollBars () { if (!IsInitialized) { @@ -1098,22 +1096,22 @@ private void ShowHideScrollBars (bool redraw = true) if (ShowBothScrollIndicator) { - if (_contentBottomRightCorner is { }) + if (_contentBottomRightCorner is { Visible: false }) { _contentBottomRightCorner.Visible = true; } - else if (_otherScrollBarView is { } && _otherScrollBarView._contentBottomRightCorner is { }) + else if (_otherScrollBarView is { _contentBottomRightCorner.Visible: false }) { _otherScrollBarView._contentBottomRightCorner.Visible = true; } } else if (!Visible) { - if (_contentBottomRightCorner is { }) + if (_contentBottomRightCorner is { Visible: true }) { _contentBottomRightCorner.Visible = false; } - else if (_otherScrollBarView is { } && _otherScrollBarView._contentBottomRightCorner is { }) + else if (_otherScrollBarView is { _contentBottomRightCorner.Visible: true }) { _otherScrollBarView._contentBottomRightCorner.Visible = false; } @@ -1123,11 +1121,11 @@ private void ShowHideScrollBars (bool redraw = true) Application.UngrabMouse (); } } - else if (_contentBottomRightCorner is { }) + else if (_contentBottomRightCorner is { Visible: true }) { _contentBottomRightCorner.Visible = false; } - else if (_otherScrollBarView is { } && _otherScrollBarView._contentBottomRightCorner is { }) + else if (_otherScrollBarView is { _contentBottomRightCorner.Visible: true }) { _otherScrollBarView._contentBottomRightCorner.Visible = false; } From 7e9a76d82ac1049f852e3fe44ae6d746493518cc Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 9 Mar 2024 20:06:19 +0000 Subject: [PATCH 083/130] Fix merge conflicts. --- Terminal.Gui/Views/ScrollView.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index 47ca2b932d..b74921c039 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -366,7 +366,7 @@ protected internal override bool OnMouseEvent (MouseEvent me) { ScrollUp (1); } - else if (me.Flags == MouseFlags.WheeledRight && _showHorizontalScrollIndicator) + else if (me.Flags == MouseFlags.WheeledRight && ShowHorizontalScrollIndicator) { ScrollRight (1); } From fff899848f395ac9476899b850c200924938b05c Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 9 Mar 2024 20:10:24 +0000 Subject: [PATCH 084/130] Fix OnMouseEvent working with adornments. --- Terminal.Gui/Application.cs | 272 ++++++++++++++++-------------------- 1 file changed, 121 insertions(+), 151 deletions(-) diff --git a/Terminal.Gui/Application.cs b/Terminal.Gui/Application.cs index a3c11c59fd..f8a3d1b149 100644 --- a/Terminal.Gui/Application.cs +++ b/Terminal.Gui/Application.cs @@ -1403,86 +1403,44 @@ internal static void OnMouseEvent (MouseEventEventArgs a) // If the mouse is grabbed, send the event to the view that grabbed it. // The coordinates are relative to the Bounds of the view that grabbed the mouse. Point newxy; - MouseEvent nme; if (MouseGrabView.SuperView is Adornment) { - View previousView = view; - int previousScreenX = screenX; - int previousScreenY = screenY; - view = View.FindDeepestView (view?.Padding, screenX, screenY, out screenX, out screenY); - - if (view is { }) - { - nme = new MouseEvent - { - X = screenX, - Y = screenY, - Flags = a.MouseEvent.Flags, - OfX = a.MouseEvent.X - screenX, - OfY = a.MouseEvent.Y - screenY, - View = view - }; - } - else - { - view = previousView; - - nme = new MouseEvent - { - X = previousScreenX, - Y = previousScreenY, - Flags = a.MouseEvent.Flags, - OfX = a.MouseEvent.X - previousScreenX, - OfY = a.MouseEvent.Y - previousScreenY, - View = view - }; - } - - WantContinuousButtonPressedView = view is { WantContinuousButtonPressed: true } ? view : null; + newxy = MouseGrabView.FrameToScreen ().Location; + newxy = new (a.MouseEvent.X - newxy.X, a.MouseEvent.Y - newxy.Y); } else { newxy = MouseGrabView.ScreenToFrame (a.MouseEvent.X, a.MouseEvent.Y); - - nme = new MouseEvent - { - X = newxy.X, - Y = newxy.Y, - Flags = a.MouseEvent.Flags, - OfX = a.MouseEvent.X - newxy.X, - OfY = a.MouseEvent.Y - newxy.Y, - View = view - }; } - if (MouseGrabView.ContentArea.Contains (nme.X, nme.Y) is false || (view is { } && view != MouseGrabView)) + var nme = new MouseEvent + { + X = newxy.X, + Y = newxy.Y, + Flags = a.MouseEvent.Flags, + OfX = a.MouseEvent.X - newxy.X, + OfY = a.MouseEvent.Y - newxy.Y, + View = view + }; + + if (MouseGrabView.ContentArea.Contains (nme.X, nme.Y) is false) { // The mouse has moved outside the bounds of the view that // grabbed the mouse, so we tell the view that last got // OnMouseEnter the mouse is leaving // BUGBUG: That sentence makes no sense. Either I'm missing something // or this logic is flawed. - // We cannot trust the bounds because they may be the same as the bounds of - // other views, and therefore it is more accurate to trust the view itself - if (view is { }) - { - View parent = view is Adornment adornment ? adornment.Parent : view; - - if (parent.OnMouseEnter (a.MouseEvent)) - { - MouseGrabView?.OnMouseLeave (a.MouseEvent); - } - } - else - { - _mouseEnteredView?.OnMouseLeave (a.MouseEvent); - } + _mouseEnteredView?.OnMouseLeave (a.MouseEvent); } - //System.Diagnostics.Debug.WriteLine ($"{nme.Flags};{nme.X};{nme.Y};{MouseGrabView}"); if (MouseGrabView?.OnMouseEvent (nme) == true) { + if (MouseGrabView is { WantContinuousButtonPressed: true }) + { + WantContinuousButtonPressedView = MouseGrabView; + } + return; } } @@ -1502,138 +1460,150 @@ internal static void OnMouseEvent (MouseEventEventArgs a) } } - bool AdornmentHandledMouseEvent (Adornment adornment) + if (view is null) { - if (adornment?.Thickness.Contains (adornment.FrameToScreen (), a.MouseEvent.X, a.MouseEvent.Y) ?? false) - { - Point boundsPoint = adornment.ScreenToBounds (a.MouseEvent.X, a.MouseEvent.Y); + return; + } - var me = new MouseEvent - { - X = boundsPoint.X, - Y = boundsPoint.Y, - Flags = a.MouseEvent.Flags, - OfX = boundsPoint.X, - OfY = boundsPoint.Y, - View = adornment - }; - adornment.OnMouseEvent (me); + var screen = view.Padding.FrameToScreen (); - return true; + // Work inside-out (Padding, Border, Margin) + // TODO: Debate whether inside-out or outside-in is the right strategy + if (view is Padding || AdornmentHandledMouseEvent (view.Padding, a)) + { + view = View.FindDeepestView (view.Padding, a.MouseEvent.X, a.MouseEvent.Y); + + if (view is { } && AdornmentSubViewHandledMouseEvent ()) + { + return; } - return false; + return; } - if (view is { }) + screen = view.Border.FrameToScreen (); + + if (view is Border || AdornmentHandledMouseEvent (view.Border, a)) { - // Work inside-out (Padding, Border, Margin) - // TODO: Debate whether inside-out or outside-in is the right strategy - if (AdornmentHandledMouseEvent (view?.Padding)) - { - view = View.FindDeepestView (view?.Padding, screenX, screenY, out int newX, out int newY); + View previousView = view; - if (view is { } && AdornmentSubViewHandledMouseEvent (newX, newY)) - { - return; - } + view = View.FindDeepestView (view.Border, a.MouseEvent.X, a.MouseEvent.Y); + if (view is { } && view != previousView && AdornmentSubViewHandledMouseEvent ()) + { return; } - if (AdornmentHandledMouseEvent (view?.Border)) + view = previousView; + + if (view is not Toplevel) { - View previousView = view; + return; + } - view = View.FindDeepestView (view?.Border, screenX, screenY, out int newX, out int newY); + // TODO: This is a temporary hack to work around the fact that + // drag handling is handled in Toplevel (See Issue #2537) - if (view is { } && AdornmentSubViewHandledMouseEvent (newX, newY)) - { - return; - } + if (AdornmentSubViewHandledMouseEvent ()) + { + return; + } - view = previousView; + return; + } - if (previousView is Toplevel) - { - // TODO: This is a temporary hack to work around the fact that - // drag handling is handled in Toplevel (See Issue #2537) + screen = view.Margin.FrameToScreen (); - if (AdornmentSubViewHandledMouseEvent (screenX, screenY)) - { - return; - } - } + if (AdornmentHandledMouseEvent (view?.Margin, a)) + { + view = View.FindDeepestView (view.Margin, a.MouseEvent.X, a.MouseEvent.Y); + if (view is { } && AdornmentSubViewHandledMouseEvent ()) + { return; } - if (AdornmentHandledMouseEvent (view?.Margin)) + return; + } + + Rectangle bounds = view.BoundsToScreen (view.ContentArea); + + if (bounds.Contains (a.MouseEvent.X, a.MouseEvent.Y)) + { + Point boundsPoint = view.ScreenToBounds (a.MouseEvent.X, a.MouseEvent.Y); + + var me = new MouseEvent { - view = View.FindDeepestView (view?.Margin, screenX, screenY, out int newX, out int newY); + X = boundsPoint.X, + Y = boundsPoint.Y, + Flags = a.MouseEvent.Flags, + OfX = boundsPoint.X, + OfY = boundsPoint.Y, + View = view + }; - if (view is { } && AdornmentSubViewHandledMouseEvent (newX, newY)) - { - return; - } + if (_mouseEnteredView is null) + { + _mouseEnteredView = view; + view.OnMouseEnter (me); + } + else if (_mouseEnteredView != view) + { + _mouseEnteredView.OnMouseLeave (me); + view.OnMouseEnter (me); + _mouseEnteredView = view; + } + if (!view.WantMousePositionReports && a.MouseEvent.Flags == MouseFlags.ReportMousePosition) + { return; } - Rectangle bounds = view.BoundsToScreen (view.ContentArea); + WantContinuousButtonPressedView = view.WantContinuousButtonPressed ? view : null; - if (bounds.Contains (a.MouseEvent.X, a.MouseEvent.Y)) + if (view.OnMouseEvent (me)) { - Point boundsPoint = view.ScreenToBounds (a.MouseEvent.X, a.MouseEvent.Y); + // Should we bubble up the event, if it is not handled? + //return; + } - var me = new MouseEvent - { - X = boundsPoint.X, - Y = boundsPoint.Y, - Flags = a.MouseEvent.Flags, - OfX = boundsPoint.X, - OfY = boundsPoint.Y, - View = view - }; - - if (_mouseEnteredView is null) - { - _mouseEnteredView = view; - view.OnMouseEnter (me); - } - else if (_mouseEnteredView != view) - { - _mouseEnteredView.OnMouseLeave (me); - view.OnMouseEnter (me); - _mouseEnteredView = view; - } + BringOverlappedTopToFront (); + } - if (!view.WantMousePositionReports && a.MouseEvent.Flags == MouseFlags.ReportMousePosition) - { - return; - } + return; - WantContinuousButtonPressedView = view.WantContinuousButtonPressed ? view : null; + static bool AdornmentHandledMouseEvent (Adornment? frame, MouseEventEventArgs args) + { + if (frame?.Thickness.Contains (frame.FrameToScreen (), args.MouseEvent.X, args.MouseEvent.Y) is not true) + { + return false; + } - if (view.OnMouseEvent (me)) - { - // Should we bubble up the event, if it is not handled? - //return; - } + Point boundsPoint = frame.ScreenToBounds (args.MouseEvent.X, args.MouseEvent.Y); - BringOverlappedTopToFront (); - } + var me = new MouseEvent + { + X = boundsPoint.X, + Y = boundsPoint.Y, + Flags = args.MouseEvent.Flags, + OfX = boundsPoint.X, + OfY = boundsPoint.Y, + View = frame + }; + frame.OnMouseEvent (me); + + return true; } - bool AdornmentSubViewHandledMouseEvent (int x, int y) + bool AdornmentSubViewHandledMouseEvent () { var me = new MouseEvent { - X = x, - Y = y, + X = a.MouseEvent.X - screen.X, + Y = a.MouseEvent.Y - screen.Y, Flags = a.MouseEvent.Flags, - OfX = screenX - x, - OfY = screenY - y, + OfX = a.MouseEvent.X - screen.X, + OfY = a.MouseEvent.Y - screen.Y, View = view }; From 9bb6f5f3544309700b4c74b3e165b201806e35c2 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 9 Mar 2024 20:11:43 +0000 Subject: [PATCH 085/130] Change button text to alert to tab or click on the views. --- UICatalog/Scenarios/ScrollBars.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UICatalog/Scenarios/ScrollBars.cs b/UICatalog/Scenarios/ScrollBars.cs index a284fdcda5..8fed64f641 100644 --- a/UICatalog/Scenarios/ScrollBars.cs +++ b/UICatalog/Scenarios/ScrollBars.cs @@ -77,7 +77,7 @@ public override void Setup () win.Add (new Label { X = Pos.Left (viewOnBorder), Y = Pos.Top (viewOnBorder) - 2, Text = "On Border:" }); - var btn = new Button { X = Pos.Center (), Y = Pos.Bottom (viewOnContentArea) + 1, Text = "Test" }; + var btn = new Button { X = Pos.Center (), Y = Pos.Bottom (viewOnContentArea) + 1, Text = "Tab or click to select the views" }; win.Add (btn); viewOnBorder.TabIndex = 1; From e2742378b08df10d3da30851216bc1267879cff6 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 9 Mar 2024 20:12:56 +0000 Subject: [PATCH 086/130] Fix unit tests. --- UnitTests/View/Adornment/AdornmentTests.cs | 53 ++++++++++++---------- UnitTests/View/FindDeepestViewTests.cs | 40 ++++++++++------ UnitTests/Views/ScrollBarViewTests.cs | 12 ++--- UnitTests/Views/ToplevelTests.cs | 1 + 4 files changed, 62 insertions(+), 44 deletions(-) diff --git a/UnitTests/View/Adornment/AdornmentTests.cs b/UnitTests/View/Adornment/AdornmentTests.cs index eb6bf0bc6b..2443fb0497 100644 --- a/UnitTests/View/Adornment/AdornmentTests.cs +++ b/UnitTests/View/Adornment/AdornmentTests.cs @@ -106,21 +106,21 @@ public void BoundsToScreen_All_Adornments_With_Thickness () Assert.Equal (new Rectangle (1, 2, 10, 10), parent.Frame); Assert.Equal (new Rectangle (0, 0, 4, 4), parent.ContentArea); Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Margin.Frame); - Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Margin.ContentArea); + Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Margin.ContentArea); Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Border.Frame); - Assert.Equal (new Rectangle (1, 1, 6, 6), parent.Border.ContentArea); + Assert.Equal (new Rectangle (0, 0, 8, 8), parent.Border.ContentArea); Assert.Equal (new Rectangle (2, 2, 6, 6), parent.Padding.Frame); - Assert.Equal (new Rectangle (1, 1, 4, 4), parent.Padding.ContentArea); + Assert.Equal (new Rectangle (0, 0, 6, 6), parent.Padding.ContentArea); Assert.Null (parent.Margin.SuperView); Rectangle boundsAsScreen = parent.BoundsToScreen (parent.ContentArea); Assert.Equal (new Rectangle (4, 5, 4, 4), boundsAsScreen); boundsAsScreen = parent.Margin.BoundsToScreen (parent.Margin.ContentArea); - Assert.Equal (new Rectangle (2, 3, 8, 8), boundsAsScreen); + Assert.Equal (new Rectangle (1, 2, 10, 10), boundsAsScreen); boundsAsScreen = parent.Border.BoundsToScreen (parent.Border.ContentArea); - Assert.Equal (new Rectangle (2, 3, 6, 6), boundsAsScreen); + Assert.Equal (new Rectangle (2, 3, 8, 8), boundsAsScreen); boundsAsScreen = parent.Padding.BoundsToScreen (parent.Padding.ContentArea); - Assert.Equal (new Rectangle (2, 3, 4, 4), boundsAsScreen); + Assert.Equal (new Rectangle (3, 4, 6, 6), boundsAsScreen); } [Fact] @@ -195,13 +195,13 @@ public void Draw_Centered_View_With_Thickness_One_On_All_Adornments () Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Border.Frame.ToString ()); Assert.Equal ("{X=2,Y=2,Width=6,Height=5}", parent.Padding.Frame.ToString ()); Assert.Equal ("{X=5,Y=1,Width=10,Height=9}", parent.Frame.ToString ()); - Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Margin.ContentArea.ToString ()); - Assert.Equal ("{X=1,Y=1,Width=6,Height=5}", parent.Border.ContentArea.ToString ()); - Assert.Equal ("{X=1,Y=1,Width=4,Height=3}", parent.Padding.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=10,Height=9}", parent.Margin.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=8,Height=7}", parent.Border.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=6,Height=5}", parent.Padding.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=4,Height=3}", parent.ContentArea.ToString ()); - Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Margin.GetVisibleContentArea ().ToString ()); - Assert.Equal ("{X=1,Y=1,Width=6,Height=5}", parent.Border.GetVisibleContentArea ().ToString ()); - Assert.Equal ("{X=1,Y=1,Width=4,Height=3}", parent.Padding.GetVisibleContentArea ().ToString ()); + Assert.Equal ("{X=0,Y=0,Width=10,Height=9}", parent.Margin.GetVisibleContentArea ().ToString ()); + Assert.Equal ("{X=0,Y=0,Width=8,Height=7}", parent.Border.GetVisibleContentArea ().ToString ()); + Assert.Equal ("{X=0,Y=0,Width=6,Height=5}", parent.Padding.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=4,Height=3}", parent.GetVisibleContentArea ().ToString ()); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -282,13 +282,13 @@ public void Draw_Centered_View_With_Thickness_One_On_All_Adornments_Inside_Anoth Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Border.Frame.ToString ()); Assert.Equal ("{X=2,Y=2,Width=6,Height=5}", parent.Padding.Frame.ToString ()); Assert.Equal ("{X=4,Y=0,Width=10,Height=9}", parent.Frame.ToString ()); - Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Margin.ContentArea.ToString ()); - Assert.Equal ("{X=1,Y=1,Width=6,Height=5}", parent.Border.ContentArea.ToString ()); - Assert.Equal ("{X=1,Y=1,Width=4,Height=3}", parent.Padding.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=10,Height=9}", parent.Margin.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=8,Height=7}", parent.Border.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=6,Height=5}", parent.Padding.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=4,Height=3}", parent.ContentArea.ToString ()); - Assert.Equal ("{X=1,Y=1,Width=8,Height=7}", parent.Margin.GetVisibleContentArea ().ToString ()); - Assert.Equal ("{X=1,Y=1,Width=6,Height=5}", parent.Border.GetVisibleContentArea ().ToString ()); - Assert.Equal ("{X=1,Y=1,Width=4,Height=3}", parent.Padding.GetVisibleContentArea ().ToString ()); + Assert.Equal ("{X=0,Y=0,Width=10,Height=9}", parent.Margin.GetVisibleContentArea ().ToString ()); + Assert.Equal ("{X=0,Y=0,Width=8,Height=7}", parent.Border.GetVisibleContentArea ().ToString ()); + Assert.Equal ("{X=0,Y=0,Width=6,Height=5}", parent.Padding.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=4,Height=3}", parent.GetVisibleContentArea ().ToString ()); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -465,11 +465,11 @@ public void FrameToScreen_All_Adornments_With_Thickness () Assert.Equal (new Rectangle (1, 2, 10, 10), parent.Frame); Assert.Equal (new Rectangle (0, 0, 4, 4), parent.ContentArea); Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Margin.Frame); - Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Margin.ContentArea); + Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Margin.ContentArea); Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Border.Frame); - Assert.Equal (new Rectangle (1, 1, 6, 6), parent.Border.ContentArea); + Assert.Equal (new Rectangle (0, 0, 8, 8), parent.Border.ContentArea); Assert.Equal (new Rectangle (2, 2, 6, 6), parent.Padding.Frame); - Assert.Equal (new Rectangle (1, 1, 4, 4), parent.Padding.ContentArea); + Assert.Equal (new Rectangle (0, 0, 6, 6), parent.Padding.ContentArea); Assert.Null (parent.Margin.SuperView); Assert.Equal (new Rectangle (1, 2, 10, 10), parent.FrameToScreen ()); @@ -496,11 +496,11 @@ public void FrameToScreen_All_Adornments_With_Thickness_With_SuperView () Assert.Equal (new Rectangle (1, 2, 10, 10), parent.Frame); Assert.Equal (new Rectangle (0, 0, 4, 4), parent.ContentArea); Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Margin.Frame); - Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Margin.ContentArea); + Assert.Equal (new Rectangle (0, 0, 10, 10), parent.Margin.ContentArea); Assert.Equal (new Rectangle (1, 1, 8, 8), parent.Border.Frame); - Assert.Equal (new Rectangle (1, 1, 6, 6), parent.Border.ContentArea); + Assert.Equal (new Rectangle (0, 0, 8, 8), parent.Border.ContentArea); Assert.Equal (new Rectangle (2, 2, 6, 6), parent.Padding.Frame); - Assert.Equal (new Rectangle (1, 1, 4, 4), parent.Padding.ContentArea); + Assert.Equal (new Rectangle (0, 0, 6, 6), parent.Padding.ContentArea); Assert.Null (parent.Margin.SuperView); Assert.Equal (new Rectangle (0, 0, 12, 12), top.FrameToScreen ()); @@ -519,10 +519,15 @@ public void FrameToScreen_All_Adornments_With_Thickness_With_SuperView () [InlineData (1, 2, "Border", false)] [InlineData (2, 2, "Border", false)] [InlineData (2, 3, "Border", true)] + [InlineData (2, 4, "Border", true)] + [InlineData (3, 4, "Border", false)] [InlineData (1, 2, "Padding", false)] [InlineData (1, 3, "Padding", false)] [InlineData (2, 3, "Padding", false)] [InlineData (3, 4, "Padding", true)] + [InlineData (4, 5, "Padding", false)] + [InlineData (5, 4, "Padding", true)] + [InlineData (5, 6, "Padding", false)] public void FrameToScreen_Find_Adornment_By_Location (int x, int y, string adornment, bool expectedBool) { var parent = new View { X = 1, Y = 2, Width = 10, Height = 10 }; diff --git a/UnitTests/View/FindDeepestViewTests.cs b/UnitTests/View/FindDeepestViewTests.cs index 6434eaa8ce..81547d5acb 100644 --- a/UnitTests/View/FindDeepestViewTests.cs +++ b/UnitTests/View/FindDeepestViewTests.cs @@ -172,23 +172,35 @@ public void Returns_Correct_If_Start_Has_Adornments (int testX, int testY, bool }; start.Add (subview); - var found = View.FindDeepestView (start, testX, testY, true); + var found = View.FindDeepestView (start, testX, testY); Assert.Equal (expectedSubViewFound, found == subview); } [Theory] - [InlineData (0, 0, typeof(Margin))] - [InlineData (9, 9, typeof (Margin))] - - [InlineData (1, 1, typeof (Border))] - [InlineData (8, 8, typeof (Border))] - - [InlineData (2, 2, typeof (Padding))] - [InlineData (7, 7, typeof (Padding))] - - [InlineData (5, 5, typeof (View))] - public void Returns_Adornment_If_Start_Has_Adornments (int testX, int testY, Type expectedAdornmentType) + [InlineData (0, 0, typeof (View), "start")] + [InlineData (0, 1, typeof (View), "start")] + [InlineData (9, 1, typeof (View), "start")] + [InlineData (9, 9, typeof (View), "start")] + + [InlineData (1, 1, typeof (View), "start")] + [InlineData (1, 2, typeof (View), "start")] + [InlineData (8, 1, typeof (View), "start")] + [InlineData (8, 8, typeof (View), "start")] + + [InlineData (2, 2, typeof (View), "start")] + [InlineData (2, 3, typeof (View), "start")] + [InlineData (7, 2, typeof (View), "start")] + [InlineData (7, 7, typeof (View), "start")] + + [InlineData (3, 3, typeof (View), "start")] + [InlineData (3, 4, typeof (View), "start")] + [InlineData (6, 3, typeof (View), "start")] + [InlineData (6, 6, typeof (View), "start")] + [InlineData (5, 5, typeof (View), "start")] + + [InlineData (4, 4, typeof (View), "subview")] + public void Returns_Adornment_If_Start_Has_Adornments (int testX, int testY, Type expectedAdornmentType, string expectedParentName) { var start = new View () { @@ -205,8 +217,9 @@ public void Returns_Adornment_If_Start_Has_Adornments (int testX, int testY, Typ }; start.Add (subview); - var found = View.FindDeepestView (start, testX, testY, true); + var found = View.FindDeepestView (start, testX, testY); Assert.Equal(expectedAdornmentType, found.GetType()); + Assert.Equal (expectedParentName, found is Adornment ? "start" : found == start ? "start" : "subview"); } // Test that FindDeepestView works if the subview has positive Adornments @@ -221,7 +234,6 @@ public void Returns_Adornment_If_Start_Has_Adornments (int testX, int testY, Typ [InlineData (1, 2, true)] [InlineData (2, 3, true)] [InlineData (5, 6, true)] - [InlineData (2, 3, true)] public void Returns_Correct_If_SubView_Has_Adornments (int testX, int testY, bool expectedSubViewFound) { var start = new View () diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index 6b4b487069..36a92814dc 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -1216,8 +1216,8 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Padding_Thickne Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Frame.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Padding.ContentArea.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Padding.GetVisibleContentArea ().ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.Frame.ToString ()); Assert.Equal ("(Left=0,Top=0,Right=1,Bottom=1)", view.Padding.Thickness.ToString ()); Assert.Equal ("{Width=8, Height=5}", view.TextFormatter.Size.ToString ()); @@ -1259,8 +1259,8 @@ Fifth Li▼ null, attrs); - Assert.True (view.Padding.OnInvokingKeyBindings (new Key (KeyCode.End))); - Assert.True (view.Padding.OnInvokingKeyBindings (new Key (KeyCode.End | KeyCode.ShiftMask))); + Assert.True (view.Padding.OnInvokingKeyBindings (Key.End)); + Assert.True (view.Padding.OnInvokingKeyBindings (Key.End.WithShift)); top.Draw (); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -1332,8 +1332,8 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Padding_Thickne Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Frame.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Padding.ContentArea.ToString ()); - Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.Padding.GetVisibleContentArea ().ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.Frame.ToString ()); Assert.Equal ("(Left=0,Top=0,Right=1,Bottom=1)", view.Padding.Thickness.ToString ()); Assert.Equal ("{Width=8, Height=5}", view.TextFormatter.Size.ToString ()); diff --git a/UnitTests/Views/ToplevelTests.cs b/UnitTests/Views/ToplevelTests.cs index 97ee6e9c20..61d6e3ebbf 100644 --- a/UnitTests/Views/ToplevelTests.cs +++ b/UnitTests/Views/ToplevelTests.cs @@ -1504,6 +1504,7 @@ public void Toplevel_Inside_ScrollView_MouseGrabView () new MouseEvent { X = 5, Y = 5, Flags = MouseFlags.Button1Released } ) ); + // ScrollView always grab the mouse when the container's subview OnMouseEnter don't want grab the mouse Assert.Equal (scrollView, Application.MouseGrabView); Application.OnMouseEvent ( From 8bd301e29e64b39369fe19b6c7e125cac93c1d9c Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 9 Mar 2024 23:20:20 +0000 Subject: [PATCH 087/130] Remove ScrollBarType enum and replaced by the EnableScrollBars bool. --- Terminal.Gui/View/ViewScrollBar.cs | 269 +++++++------------ Terminal.Gui/Views/ComboBox.cs | 6 +- Terminal.Gui/Views/ScrollBarView.cs | 46 ++-- Terminal.Gui/Views/ScrollView.cs | 2 +- Terminal.Gui/Views/TextView.cs | 2 +- Terminal.Gui/Views/Wizard/WizardStep.cs | 2 +- UICatalog/Scenarios/CsvEditor.cs | 2 +- UICatalog/Scenarios/Editor.cs | 4 +- UICatalog/Scenarios/ListColumns.cs | 2 +- UICatalog/Scenarios/ListViewWithSelection.cs | 6 +- UICatalog/Scenarios/ListsAndCombos.cs | 4 +- UICatalog/Scenarios/ProcessTable.cs | 2 +- UICatalog/Scenarios/ScrollBars.cs | 8 +- UICatalog/Scenarios/TableEditor.cs | 2 +- UICatalog/Scenarios/TreeViewFileSystem.cs | 2 +- UICatalog/Scenarios/Wizards.cs | 2 +- UICatalog/UICatalog.cs | 4 +- UnitTests/View/ViewScrollBarTests.cs | 28 ++ UnitTests/Views/ScrollBarViewTests.cs | 35 +-- UnitTests/Views/TextViewTests.cs | 4 +- 20 files changed, 196 insertions(+), 236 deletions(-) create mode 100644 UnitTests/View/ViewScrollBarTests.cs diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index cbf26a6b68..7e951ab3f6 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -1,118 +1,129 @@ namespace Terminal.Gui; -/// -/// The scroll bar types used by this . -/// -public enum ScrollBarType -{ - /// - /// None scroll bar will be used and to avoid throwing an exception never use it in a constructor. - /// - None, - - /// - /// Only the vertical scroll bar will be shown. - /// - Vertical, - - /// - /// Only the horizontal scroll bar will be shown. - /// - Horizontal, - - /// - /// Both vertical and horizontal scroll bars will be shown. - /// - Both -} - public partial class View { + private bool _enableScrollBars; + private View _parent; private ScrollBarView _scrollBar; - private ScrollBarType _scrollBarType; /// If true the vertical/horizontal scroll bars won't be showed if it's not needed. - public bool ScrollAutoHideScrollBars + public bool AutoHideScrollBars { - get => _scrollBar.AutoHideScrollBars; - set => _scrollBar.AutoHideScrollBars = value; + get => _parent?._scrollBar?.AutoHideScrollBars is true; + set + { + if (HasVerticalScrollBar) + { + _parent._scrollBar.AutoHideScrollBars = value; + } + + if (HasHorizontalScrollBar) + { + _parent._scrollBar.OtherScrollBarView.AutoHideScrollBars = value; + } + } } /// - /// Gets or sets the used by this view. + /// Gets or sets the used by this view. /// /// The value is out of range. - public virtual ScrollBarType ScrollBarType + public virtual bool EnableScrollBars { - get => _scrollBarType; + get => _enableScrollBars; set { - View view = this is Adornment adornment ? adornment.Parent : this; + if (this is Adornment adornment) + { + _parent = adornment.Parent; + adornment.Parent._parent = _parent; + } + else + { + _parent = this; + } - if (view._scrollBar is { } && view._scrollBarType == value) + if (_parent._scrollBar is { } && _parent._enableScrollBars == value) { return; } - view._scrollBarType = value; - view.DisposeScrollBar (); + _parent._enableScrollBars = value; + DisposeScrollBar (); - switch (view._scrollBarType) + if (!value) { - case ScrollBarType.Vertical: - view._scrollBar = new ScrollBarView { Orientation = Orientation.Vertical }; - - break; - case ScrollBarType.Horizontal: - view._scrollBar = new ScrollBarView { Orientation = Orientation.Horizontal }; - - break; - case ScrollBarType.Both: - view._scrollBar = new ScrollBarView { Orientation = Orientation.Vertical }; - view._scrollBar.OtherScrollBarView = new ScrollBarView { Orientation = Orientation.Horizontal, OtherScrollBarView = view._scrollBar }; - - break; - case ScrollBarType.None: - return; - default: - throw new ArgumentOutOfRangeException (); + return; } - Add (view._scrollBar); - view.AddEventHandlersForScrollBars (view._scrollBar); - view.AddKeyBindingsForScrolling (view._scrollBar); + var vertical = new ScrollBarView { Orientation = Orientation.Vertical }; + var horizontal = new ScrollBarView { Orientation = Orientation.Horizontal }; + _parent._scrollBar = vertical; + _parent._scrollBar.OtherScrollBarView = horizontal; + + Add (_parent._scrollBar); + _parent.AddEventHandlersForScrollBars (_parent._scrollBar); + _parent.AddKeyBindingsForScrolling (_parent._scrollBar); - if (view._scrollBar.OtherScrollBarView != null) + if (_parent._scrollBar.OtherScrollBarView != null) { - view.AddKeyBindingsForScrolling (view._scrollBar.OtherScrollBarView); + _parent.AddKeyBindingsForScrolling (_parent._scrollBar.OtherScrollBarView); } - view.SetNeedsDisplay (); + _parent.SetNeedsDisplay (); } } /// Get or sets if the view-port is kept always visible in the area of this - public bool ScrollKeepContentAlwaysInViewPort + public bool KeepContentAlwaysInContentArea { - get => _scrollBar.KeepContentAlwaysInViewPort; - set => _scrollBar.KeepContentAlwaysInViewPort = value; + get => _parent?._scrollBar?.KeepContentAlwaysInViewPort is true || _parent?._scrollBar?.OtherScrollBarView.KeepContentAlwaysInViewPort is true; + set + { + if (HasVerticalScrollBar) + { + _parent._scrollBar.KeepContentAlwaysInViewPort = value; + } + + if (HasHorizontalScrollBar) + { + _parent._scrollBar.OtherScrollBarView.KeepContentAlwaysInViewPort = value; + } + } } - /// Represent a vertical or horizontal ScrollBarView other than this. - public ScrollBarView ScrollOtherScrollBarView + /// Gets or sets the visibility for the vertical or horizontal scroll bar. + /// true if show horizontal scroll bar; otherwise, false. + public virtual bool ShowHorizontalScrollBar { - get => _scrollBar.OtherScrollBarView; - set => _scrollBar.OtherScrollBarView = value; + get => _parent?._scrollBar?.OtherScrollBarView.ShowScrollIndicator is true; + set + { + if (_parent._scrollBar?.OtherScrollBarView is { }) + { + _parent._scrollBar.OtherScrollBarView.ShowScrollIndicator = value; + } + } } - /// Gets or sets the visibility for the vertical or horizontal scroll indicator. - /// true if show vertical or horizontal scroll indicator; otherwise, false. - public bool ScrollShowScrollIndicator + /// Gets or sets the visibility for the vertical or horizontal scroll bar. + /// true if show vertical scroll bar; otherwise, false. + public virtual bool ShowVerticalScrollBar { - get => _scrollBar.ShowScrollIndicator; - set => _scrollBar.ShowScrollIndicator = value; + get => _parent?._scrollBar?.ShowScrollIndicator is true; + set + { + if (_parent._scrollBar is { }) + { + _parent._scrollBar.ShowScrollIndicator = value; + } + } } + private bool HasHorizontalScrollBar => _parent is { _scrollBar.OtherScrollBarView: { } }; + + private bool HasVerticalScrollBar => _parent is { _scrollBar: { } }; + private void AddEventHandlersForScrollBars (ScrollBarView scrollBar) { if (scrollBar is null) @@ -120,11 +131,11 @@ private void AddEventHandlersForScrollBars (ScrollBarView scrollBar) return; } - scrollBar.ChangedPosition += ScrollBar_ChangedPosition; + scrollBar.ChangedPosition += VerticalScrollBar_ChangedPosition; if (_scrollBar.OtherScrollBarView != null) { - _scrollBar.OtherScrollBarView.ChangedPosition += OtherScrollBarView_ChangedPosition; + _scrollBar.OtherScrollBarView.ChangedPosition += HorizontalScrollBar_ChangedPosition; } } @@ -144,13 +155,6 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Vertical }) - { - scrollBar.OtherScrollBarView.Position++; - - return true; - } - return false; }); @@ -165,13 +169,6 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Vertical }) - { - scrollBar.OtherScrollBarView.Position--; - - return true; - } - return false; }); @@ -186,13 +183,6 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Vertical }) - { - scrollBar.OtherScrollBarView.Position = 0; - - return true; - } - return false; }); @@ -207,13 +197,6 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Vertical }) - { - scrollBar.OtherScrollBarView.Position = ContentSize.Height; - - return true; - } - return false; }); @@ -228,13 +211,6 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Vertical }) - { - scrollBar.OtherScrollBarView.Position += GetVisibleContentArea ().Height; - - return true; - } - return false; }); @@ -249,13 +225,6 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Vertical }) - { - scrollBar.OtherScrollBarView.Position -= GetVisibleContentArea ().Height; - - return true; - } - return false; }); @@ -281,13 +250,6 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Horizontal }) - { - scrollBar.OtherScrollBarView.Position--; - - return true; - } - return false; }); @@ -302,13 +264,6 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Horizontal }) - { - scrollBar.OtherScrollBarView.Position++; - - return true; - } - return false; }); @@ -323,13 +278,6 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Horizontal }) - { - scrollBar.OtherScrollBarView.Position = 0; - - return true; - } - return false; }); @@ -344,13 +292,6 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Horizontal }) - { - scrollBar.OtherScrollBarView.Position = ContentSize.Width; - - return true; - } - return false; }); @@ -365,13 +306,6 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Horizontal }) - { - scrollBar.OtherScrollBarView.Position += GetVisibleContentArea ().Width; - - return true; - } - return false; }); @@ -386,13 +320,6 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) return true; } - if (scrollBar.OtherScrollBarView is { Orientation: Orientation.Horizontal }) - { - scrollBar.OtherScrollBarView.Position -= GetVisibleContentArea ().Width; - - return true; - } - return false; }); @@ -408,25 +335,29 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) private void DisposeScrollBar () { - if (_scrollBar is null) + if (_parent._scrollBar is null) { return; } - _scrollBar.ChangedPosition -= ScrollBar_ChangedPosition; + _parent._scrollBar.ChangedPosition -= VerticalScrollBar_ChangedPosition; + _parent.Remove (_parent._scrollBar); - if (_scrollBar.OtherScrollBarView != null) + if (_parent._scrollBar.OtherScrollBarView != null) { - _scrollBar.OtherScrollBarView.ChangedPosition -= OtherScrollBarView_ChangedPosition; + _parent._scrollBar.OtherScrollBarView.ChangedPosition -= HorizontalScrollBar_ChangedPosition; + _parent.Remove (_parent._scrollBar.OtherScrollBarView); } - _scrollBar.RemoveAll (); - _scrollBar = null; - } + if (_parent.Subviews.First (v => v is ScrollBarView.ContentBottomRightCorner) is { } contentBottomRightCorner) + { + _parent.Remove (contentBottomRightCorner); + } - private void OtherScrollBarView_ChangedPosition (object sender, EventArgs e) { SetBoundsByPosition (_scrollBar.OtherScrollBarView); } + _parent._scrollBar = null; + } - private void ScrollBar_ChangedPosition (object sender, EventArgs e) { SetBoundsByPosition (_scrollBar); } + private void HorizontalScrollBar_ChangedPosition (object sender, EventArgs e) { SetBoundsByPosition (_scrollBar.OtherScrollBarView); } private void SetBoundsByPosition (ScrollBarView scrollBar) { @@ -442,4 +373,6 @@ private void SetBoundsByPosition (ScrollBarView scrollBar) SetTextFormatterSize (); SetNeedsDisplay (); } + + private void VerticalScrollBar_ChangedPosition (object sender, EventArgs e) { SetBoundsByPosition (_scrollBar); } } diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index eb7907c5c2..261630543b 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -139,10 +139,10 @@ public bool ReadOnly } /// - public override ScrollBarType ScrollBarType + public override bool EnableScrollBars { - get => _listview.Padding.ScrollBarType; - set => _listview.Padding.ScrollBarType = value; + get => _listview.Padding.EnableScrollBars; + set => _listview.Padding.EnableScrollBars = value; } /// Current search text diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index 65102b32f1..ffa02b0548 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -793,7 +793,7 @@ private void CreateBottomRightCorner (View host) && ((_contentBottomRightCorner is null && OtherScrollBarView is null) || (_contentBottomRightCorner is null && OtherScrollBarView is { } && OtherScrollBarView._contentBottomRightCorner is null))) { - if (IsBuiltIn && ((Adornment)host).Parent.ScrollBarType != ScrollBarType.Both) + if (IsBuiltIn && !((Adornment)host).Parent.EnableScrollBars) { return; } @@ -809,11 +809,7 @@ private void CreateBottomRightCorner (View host) _contentBottomRightCorner.MouseClick += ContentBottomRightCorner_MouseClick; _contentBottomRightCorner.DrawContent += ContentBottomRightCorner_DrawContent; } - else if (host != null - && _contentBottomRightCorner == null - && OtherScrollBarView != null - && OtherScrollBarView._contentBottomRightCorner != null) - + else if (host != null && _contentBottomRightCorner is null && OtherScrollBarView is { _contentBottomRightCorner: { } }) { _contentBottomRightCorner = OtherScrollBarView._contentBottomRightCorner; } @@ -860,26 +856,24 @@ private void ManageScrollBarThickness () return; } - ((Adornment)SuperView).Thickness = ((Adornment)SuperView).Parent.ScrollBarType switch - { - ScrollBarType.None => new (0), - ScrollBarType.Vertical => new (0, 0, Visible ? 1 : 0, 0), - ScrollBarType.Horizontal => new (0, 0, 0, Visible ? 1 : 0), - ScrollBarType.Both => new ( - 0, - 0, - Orientation == Orientation.Vertical - ? Visible ? 1 : 0 - : OtherScrollBarView?.Orientation == Orientation.Vertical - ? OtherScrollBarView?.Visible == true ? 1 : 0 - : 0, - Orientation == Orientation.Horizontal - ? Visible ? 1 : 0 - : OtherScrollBarView?.Orientation == Orientation.Horizontal - ? OtherScrollBarView?.Visible == true ? 1 : 0 - : 0), - _ => throw new ArgumentOutOfRangeException () - }; + var adornment = (Adornment)SuperView; + + if (Visible && OtherScrollBarView.Visible) + { + adornment.Thickness = new Thickness (0, 0, 1, 1); + } + else if ((Visible && Orientation == Orientation.Vertical) || (OtherScrollBarView.Visible && OtherScrollBarView.Orientation == Orientation.Vertical)) + { + adornment.Thickness = new Thickness (0, 0, 1, 0); + } + else if ((Visible && Orientation == Orientation.Horizontal) || (OtherScrollBarView.Visible && OtherScrollBarView.Orientation == Orientation.Horizontal)) + { + adornment.Thickness = new Thickness (0, 0, 0, 1); + } + else + { + adornment.Thickness = new Thickness (0); + } } private void Parent_DrawAdornments (object sender, DrawEventArgs e) { AdjustContentInViewport (); } diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index b74921c039..6d8b1f1c77 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -122,7 +122,7 @@ public ScrollView () } SetContentOffset (_contentOffset); - _contentView.Frame = new Rectangle (ContentOffset, ContentSize); + _contentView.Frame = new (ContentOffset, ContentSize); // PERF: How about calls to Point.Offset instead? _vertical.ChangedPosition += delegate { ContentOffset = new Point (ContentOffset.X, _vertical.Position); }; diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index a4df235abd..baf351fd52 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -6344,7 +6344,7 @@ private void SetOverwrite (bool overwrite) private void SetScrollColsRowsSize () { - if (ScrollBarType != ScrollBarType.None) + if (EnableScrollBars) { ContentSize = new Size (Maxlength, Lines); ContentOffset = new Point (-LeftColumn, -TopRow); diff --git a/Terminal.Gui/Views/Wizard/WizardStep.cs b/Terminal.Gui/Views/Wizard/WizardStep.cs index 78a6a47fb3..211eb114c7 100644 --- a/Terminal.Gui/Views/Wizard/WizardStep.cs +++ b/Terminal.Gui/Views/Wizard/WizardStep.cs @@ -50,7 +50,7 @@ public WizardStep () _helpTextView.ReadOnly = true; _helpTextView.WordWrap = true; - _helpTextView.ScrollBarType = ScrollBarType.Both; + _helpTextView.EnableScrollBars = true; base.Add (_helpTextView); ShowHide (); diff --git a/UICatalog/Scenarios/CsvEditor.cs b/UICatalog/Scenarios/CsvEditor.cs index 3c5471af7c..a10e201ce7 100644 --- a/UICatalog/Scenarios/CsvEditor.cs +++ b/UICatalog/Scenarios/CsvEditor.cs @@ -605,7 +605,7 @@ private void SetFormat () private void SetTable (DataTable dataTable) { _tableView.Table = new DataTableSource (_currentTable = dataTable); } - private void SetupScrollBar () { _tableView.Padding.ScrollBarType = ScrollBarType.Both; } + private void SetupScrollBar () { _tableView.Padding.EnableScrollBars = true; } private void Sort (bool asc) { diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index b763dd7411..7426d4379d 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -59,7 +59,7 @@ public override void Init () Width = Dim.Fill (), Height = Dim.Fill () }; - _textView.Padding.ScrollBarType = ScrollBarType.Both; + _textView.Padding.EnableScrollBars = true; CreateDemoFile (_fileName); @@ -719,7 +719,7 @@ private MenuItem [] CreateKeepChecked () item.Title = "Keep Content Always In Viewport"; item.CheckType |= MenuItemCheckStyle.Checked; item.Checked = true; - item.Action += () => _textView.ScrollKeepContentAlwaysInViewPort = (bool)(item.Checked = !item.Checked); + item.Action += () => _textView.KeepContentAlwaysInContentArea = (bool)(item.Checked = !item.Checked); return new [] { item }; } diff --git a/UICatalog/Scenarios/ListColumns.cs b/UICatalog/Scenarios/ListColumns.cs index 5c68b5c0b5..6b5d7579c4 100644 --- a/UICatalog/Scenarios/ListColumns.cs +++ b/UICatalog/Scenarios/ListColumns.cs @@ -67,7 +67,7 @@ public override void Setup () ExpandLastColumn = false } }; - _listColView.Padding.ScrollBarType = ScrollBarType.Both; + _listColView.Padding.EnableScrollBars = true; var listColStyle = new ListColumnStyle (); var menu = new MenuBar diff --git a/UICatalog/Scenarios/ListViewWithSelection.cs b/UICatalog/Scenarios/ListViewWithSelection.cs index 241a672979..6c91bc194d 100644 --- a/UICatalog/Scenarios/ListViewWithSelection.cs +++ b/UICatalog/Scenarios/ListViewWithSelection.cs @@ -51,7 +51,7 @@ public override void Setup () AllowsMarking = false, AllowsMultipleSelection = false }; - _listView.Padding.ScrollBarType = ScrollBarType.Both; + _listView.Padding.EnableScrollBars = true; _listView.RowRender += ListView_RowRender; Win.Add (_listView); @@ -61,9 +61,9 @@ public override void Setup () var keepCheckBox = new CheckBox { - X = Pos.AnchorEnd (k.Length + 3), Y = 0, Text = k, Checked = _listView.ScrollAutoHideScrollBars + X = Pos.AnchorEnd (k.Length + 3), Y = 0, Text = k, Checked = _listView.AutoHideScrollBars }; - keepCheckBox.Toggled += (s, e) => _listView.ScrollKeepContentAlwaysInViewPort = (bool)keepCheckBox.Checked; + keepCheckBox.Toggled += (s, e) => _listView.KeepContentAlwaysInContentArea = (bool)keepCheckBox.Checked; Win.Add (keepCheckBox); } diff --git a/UICatalog/Scenarios/ListsAndCombos.cs b/UICatalog/Scenarios/ListsAndCombos.cs index 30d8182994..8ef27bda15 100644 --- a/UICatalog/Scenarios/ListsAndCombos.cs +++ b/UICatalog/Scenarios/ListsAndCombos.cs @@ -49,7 +49,7 @@ public override void Setup () Width = Dim.Percent (40), Source = new ListWrapper (items) }; - listview.Padding.ScrollBarType = ScrollBarType.Both; + listview.Padding.EnableScrollBars = true; listview.SelectedItemChanged += (s, e) => lbListView.Text = items [listview.SelectedItem]; Win.Add (lbListView, listview); @@ -70,7 +70,7 @@ public override void Setup () Height = Dim.Fill (2), Width = Dim.Percent (40) }; - comboBox.ScrollBarType = ScrollBarType.Both; + comboBox.EnableScrollBars = true; comboBox.SetSource (items); comboBox.SelectedItemChanged += (s, text) => lbComboBox.Text = text.Value.ToString (); diff --git a/UICatalog/Scenarios/ProcessTable.cs b/UICatalog/Scenarios/ProcessTable.cs index 8c3b297038..4351b53f04 100644 --- a/UICatalog/Scenarios/ProcessTable.cs +++ b/UICatalog/Scenarios/ProcessTable.cs @@ -18,7 +18,7 @@ public override void Setup () Win.Height = Dim.Fill (1); // status bar tableView = new TableView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () }; - tableView.Padding.ScrollBarType = ScrollBarType.Both; + tableView.Padding.EnableScrollBars = true; // First time CreateProcessTable (); diff --git a/UICatalog/Scenarios/ScrollBars.cs b/UICatalog/Scenarios/ScrollBars.cs index 8fed64f641..cf9b437049 100644 --- a/UICatalog/Scenarios/ScrollBars.cs +++ b/UICatalog/Scenarios/ScrollBars.cs @@ -25,7 +25,7 @@ public override void Setup () Text = text, UseContentOffset = true }; - viewOnMargin.Margin.ScrollBarType = ScrollBarType.Both; + viewOnMargin.Margin.EnableScrollBars = true; SetViewProperties (viewOnMargin); win.Add (viewOnMargin); @@ -36,7 +36,7 @@ public override void Setup () X = Pos.AnchorEnd () - 15, Y = Pos.Center (), Width = 15, Height = 8, Text = text, UseContentOffset = true, - ScrollBarType = ScrollBarType.Both + EnableScrollBars = true }; viewOnContentArea.Margin.Thickness = new Thickness (1); viewOnContentArea.Margin.ColorScheme = Colors.ColorSchemes ["Dialog"]; @@ -52,7 +52,7 @@ public override void Setup () Text = text, UseContentOffset = true }; - viewOnPadding.Padding.ScrollBarType = ScrollBarType.Both; + viewOnPadding.Padding.EnableScrollBars = true; viewOnPadding.Margin.Thickness = new Thickness (1); viewOnPadding.Margin.ColorScheme = Colors.ColorSchemes ["Dialog"]; viewOnPadding.BorderStyle = LineStyle.Single; @@ -69,7 +69,7 @@ public override void Setup () UseContentOffset = true, BorderStyle = LineStyle.None }; - viewOnBorder.Border.ScrollBarType = ScrollBarType.Both; + viewOnBorder.Border.EnableScrollBars = true; viewOnBorder.Margin.Thickness = new Thickness (1); viewOnBorder.Margin.ColorScheme = Colors.ColorSchemes ["Dialog"]; SetViewProperties (viewOnBorder); diff --git a/UICatalog/Scenarios/TableEditor.cs b/UICatalog/Scenarios/TableEditor.cs index af8c4b7e30..d5f5186d34 100644 --- a/UICatalog/Scenarios/TableEditor.cs +++ b/UICatalog/Scenarios/TableEditor.cs @@ -434,7 +434,7 @@ public override void Setup () Win.Height = Dim.Fill (1); // status bar _tableView = new TableView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill (1) }; - _tableView.Padding.ScrollBarType = ScrollBarType.Both; + _tableView.Padding.EnableScrollBars = true; var menu = new MenuBar { diff --git a/UICatalog/Scenarios/TreeViewFileSystem.cs b/UICatalog/Scenarios/TreeViewFileSystem.cs index 379090a083..5e7037a73a 100644 --- a/UICatalog/Scenarios/TreeViewFileSystem.cs +++ b/UICatalog/Scenarios/TreeViewFileSystem.cs @@ -175,7 +175,7 @@ public override void Setup () Application.Top.Add (menu); _treeViewFiles = new TreeView { X = 0, Y = 0, Width = Dim.Percent (50), Height = Dim.Fill () }; - _treeViewFiles.Padding.ScrollBarType = ScrollBarType.Both; + _treeViewFiles.Padding.EnableScrollBars = true; _treeViewFiles.DrawLine += TreeViewFiles_DrawLine; _detailsFrame = new DetailsFrame (_iconProvider) diff --git a/UICatalog/Scenarios/Wizards.cs b/UICatalog/Scenarios/Wizards.cs index 4e70f831b1..9e761eb964 100644 --- a/UICatalog/Scenarios/Wizards.cs +++ b/UICatalog/Scenarios/Wizards.cs @@ -261,7 +261,7 @@ void Top_Loaded (object sender, EventArgs args) AllowsTab = false, ColorScheme = Colors.ColorSchemes ["Base"] }; - someText.Padding.ScrollBarType = ScrollBarType.Both; + someText.Padding.EnableScrollBars = true; var help = "This is helpful."; fourthStep.Add (someText); diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index 7f5fd2471e..95107e6f51 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -500,7 +500,7 @@ public UICatalogTopLevel () SuperViewRendersLineCanvas = true, Source = new ListWrapper (_categories) }; - CategoryList.Padding.ScrollBarType = ScrollBarType.Both; + CategoryList.Padding.EnableScrollBars = true; CategoryList.OpenSelectedItem += (s, a) => { ScenarioList!.SetFocus (); }; CategoryList.SelectedItemChanged += CategoryView_SelectedChanged; @@ -520,7 +520,7 @@ public UICatalogTopLevel () BorderStyle = LineStyle.Single, SuperViewRendersLineCanvas = true }; - ScenarioList.Padding.ScrollBarType = ScrollBarType.Both; + ScenarioList.Padding.EnableScrollBars = true; // TableView provides many options for table headers. For simplicity we turn all // of these off. By enabling FullRowSelect and turning off headers, TableView looks just diff --git a/UnitTests/View/ViewScrollBarTests.cs b/UnitTests/View/ViewScrollBarTests.cs new file mode 100644 index 0000000000..424a294039 --- /dev/null +++ b/UnitTests/View/ViewScrollBarTests.cs @@ -0,0 +1,28 @@ +public class ViewScrollBarTests +{ + [Fact] + public void EnableScrollBars_Defaults () + { + var view = new View (); + Assert.False (view.EnableScrollBars); + Assert.Empty (view.Subviews); + Assert.False (view.AutoHideScrollBars); + Assert.False (view.KeepContentAlwaysInContentArea); + Assert.False (view.ShowVerticalScrollBar); + Assert.False (view.ShowHorizontalScrollBar); + + view.EnableScrollBars = true; + Assert.Equal (3, view.Subviews.Count); + Assert.True (view.AutoHideScrollBars); + Assert.True (view.KeepContentAlwaysInContentArea); + Assert.True (view.ShowVerticalScrollBar); + Assert.True (view.ShowHorizontalScrollBar); + + view.EnableScrollBars = false; + Assert.Empty (view.Subviews); + Assert.False (view.AutoHideScrollBars); + Assert.False (view.KeepContentAlwaysInContentArea); + Assert.False (view.ShowVerticalScrollBar); + Assert.False (view.ShowHorizontalScrollBar); + } +} diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index 36a92814dc..a1d35c22bd 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -407,10 +407,11 @@ public void Height = Dim.Fill (), Source = new ListWrapper (source) }; - listView.Padding.ScrollBarType = ScrollBarType.Horizontal; + listView.Padding.EnableScrollBars = true; + listView.Padding.ShowVerticalScrollBar = false; win.Add (listView); - Assert.True (listView.ScrollKeepContentAlwaysInViewPort); + Assert.True (listView.KeepContentAlwaysInContentArea); var newScrollBarView = listView.Padding.Subviews [0] as ScrollBarView; @@ -749,7 +750,7 @@ public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () Text = "This is the help text for the Second Step.\n\nPress the button to see a message box.\n\nEnter name too." }; - textView.Padding.ScrollBarType = ScrollBarType.Both; + textView.Padding.EnableScrollBars = true; var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () }; win.Add (textView); @@ -1100,11 +1101,11 @@ public void OtherScrollBarView_Not_Null () public void ScrollBar_Ungrab_Mouse_If_The_Mouse_Is_On_Another_View () { var top = new Toplevel { Id = "top", Width = 10, Height = 10 }; - var viewLeft = new View { Id = "left", Width = 5, Height = 5, ScrollBarType = ScrollBarType.Vertical, ContentSize = new Size (0, 20), CanFocus = true }; + var viewLeft = new View { Id = "left", Width = 5, Height = 5, EnableScrollBars = true, ShowHorizontalScrollBar = false, ContentSize = new Size (0, 20), CanFocus = true }; var viewRight = new View { - Id = "right", X = Pos.Right (viewLeft), Width = 5, Height = 6, ScrollBarType = ScrollBarType.Vertical, ContentSize = new Size (0, 20), + Id = "right", X = Pos.Right (viewLeft), Width = 5, Height = 6, EnableScrollBars = true, ShowHorizontalScrollBar = false, ContentSize = new Size (0, 20), CanFocus = true }; top.Add (viewLeft, viewRight); @@ -1127,11 +1128,11 @@ public void ScrollBar_Ungrab_Mouse_If_The_Mouse_Is_On_Another_View () [Fact] public void ScrollBarType_IsBuiltIn_In_Padding () { - var view = new View { ScrollBarType = ScrollBarType.None }; + var view = new View (); Assert.Empty (view.Padding.Subviews); view = new View (); - view.Padding.ScrollBarType = ScrollBarType.Both; + view.Padding.EnableScrollBars = true; Assert.Equal (3, view.Padding.Subviews.Count); foreach (View sbv in view.Padding.Subviews) @@ -1147,20 +1148,24 @@ public void ScrollBarType_IsBuiltIn_In_Padding () } view = new View (); - view.Padding.ScrollBarType = ScrollBarType.Vertical; - Assert.Single (view.Padding.Subviews); + view.Padding.EnableScrollBars = true; + view.Padding.ShowHorizontalScrollBar = false; + // While EnableScrollBars is true the scroll bars aren't removed. + Assert.Equal (3, view.Padding.Subviews.Count); Assert.True (view.Padding.Subviews [0] is ScrollBarView); view = new View (); - view.Padding.ScrollBarType = ScrollBarType.Horizontal; - Assert.Single (view.Padding.Subviews); + view.Padding.EnableScrollBars = true; + view.Padding.ShowVerticalScrollBar = false; + // While EnableScrollBars is true the scroll bars aren't removed. + Assert.Equal (3, view.Padding.Subviews.Count); Assert.True (view.Padding.Subviews [0] is ScrollBarView); } [Fact] public void ScrollBarType_IsBuiltIn_In_Padding_Does_Not_Throws_If_ScrollBarType_None () { - Exception exception = Record.Exception (() => () => new View { ScrollBarType = ScrollBarType.None }); + Exception exception = Record.Exception (() => () => new View ()); Assert.Null (exception); } @@ -1178,7 +1183,7 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Padding_Thickne Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", CanFocus = true, UseContentOffset = true }; - view.Padding.ScrollBarType = ScrollBarType.Both; + view.Padding.EnableScrollBars = true; view.TextFormatter.WordWrap = false; view.TextFormatter.MultiLine = true; string [] strings = view.Text.Split ("\n").ToArray (); @@ -1290,7 +1295,7 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Padding_Thickne Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", CanFocus = true, UseContentOffset = true }; - view.Padding.ScrollBarType = ScrollBarType.Both; + view.Padding.EnableScrollBars = true; view.TextFormatter.WordWrap = false; view.TextFormatter.MultiLine = true; string [] strings = view.Text.Split ("\n").ToArray (); @@ -1410,7 +1415,7 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Parent_Inside_A { X = Pos.Center (), Y = Pos.Center (), Width = 9, Height = 6, Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", CanFocus = true, - ScrollBarType = ScrollBarType.Both, + EnableScrollBars = true, UseContentOffset = true }; view.TextFormatter.WordWrap = false; diff --git a/UnitTests/Views/TextViewTests.cs b/UnitTests/Views/TextViewTests.cs index 10a8ae3405..14e98668b9 100644 --- a/UnitTests/Views/TextViewTests.cs +++ b/UnitTests/Views/TextViewTests.cs @@ -6893,7 +6893,7 @@ public void ScrollBarType_IsBuiltIn_Always_Adjust_LeftColumn () } var tv = new TextView { Width = 10, Height = 10 }; - tv.Padding.ScrollBarType = ScrollBarType.Both; + tv.Padding.EnableScrollBars = true; tv.Text = text; tv.BeginInit (); @@ -6940,7 +6940,7 @@ public void ScrollBarType_IsBuiltIn_Always_Adjust_TopRow () } var tv = new TextView { Width = 10, Height = 10 }; - tv.Padding.ScrollBarType = ScrollBarType.Both; + tv.Padding.EnableScrollBars = true; tv.Text = text; tv.BeginInit (); From 222c213d5540bf763813c66333fb34adebf2e0e2 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 10 Mar 2024 12:44:02 +0000 Subject: [PATCH 088/130] Rename to ParentView, fix some key binding issue and add more unit tests. --- Terminal.Gui/View/Layout/ViewLayout.cs | 26 +-- Terminal.Gui/View/ViewScrollBar.cs | 215 +++++++++---------------- UnitTests/View/ViewScrollBarTests.cs | 73 +++++++++ 3 files changed, 159 insertions(+), 155 deletions(-) diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 8baba4ffc9..4d3089e8a1 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -219,32 +219,32 @@ public virtual Rectangle ContentArea /// public virtual Point ContentOffset { - get => _contentOffset; + get => ParentView._contentOffset; set { - _contentOffset = value; + ParentView._contentOffset = value; if (_scrollBar is null) { return; } - if (_scrollBar.Orientation == Orientation.Horizontal && _scrollBar.Position != -_contentOffset.X) + if (_scrollBar.Orientation == Orientation.Horizontal && _scrollBar.Position != -ContentOffset.X) { - _scrollBar.Position = -_contentOffset.X; + _scrollBar.Position = -ContentOffset.X; } - else if (_scrollBar is { OtherScrollBarView.Orientation: Orientation.Horizontal } && _scrollBar?.OtherScrollBarView.Position != -_contentOffset.X) + else if (_scrollBar is { OtherScrollBarView.Orientation: Orientation.Horizontal } && _scrollBar?.OtherScrollBarView.Position != -ContentOffset.X) { - _scrollBar!.OtherScrollBarView.Position = -_contentOffset.X; + _scrollBar!.OtherScrollBarView.Position = -ContentOffset.X; } - if (_scrollBar.Orientation == Orientation.Vertical && _scrollBar.Position != -_contentOffset.Y) + if (_scrollBar.Orientation == Orientation.Vertical && _scrollBar.Position != -ContentOffset.Y) { - _scrollBar.Position = -_contentOffset.Y; + _scrollBar.Position = -ContentOffset.Y; } - else if (_scrollBar is { OtherScrollBarView.Orientation: Orientation.Vertical } && _scrollBar?.OtherScrollBarView.Position != -_contentOffset.Y) + else if (_scrollBar is { OtherScrollBarView.Orientation: Orientation.Vertical } && _scrollBar?.OtherScrollBarView.Position != -ContentOffset.Y) { - _scrollBar!.OtherScrollBarView.Position = -_contentOffset.Y; + _scrollBar!.OtherScrollBarView.Position = -ContentOffset.Y; } } } @@ -254,12 +254,12 @@ public virtual Point ContentOffset /// public Size ContentSize { - get => _contentSize; + get => ParentView._contentSize; set { - if (_contentSize != value) + if (ParentView._contentSize != value) { - _contentSize = value; + ParentView._contentSize = value; SetNeedsDisplay (); } diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 7e951ab3f6..3c56f9a988 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -3,23 +3,22 @@ public partial class View { private bool _enableScrollBars; - private View _parent; private ScrollBarView _scrollBar; /// If true the vertical/horizontal scroll bars won't be showed if it's not needed. public bool AutoHideScrollBars { - get => _parent?._scrollBar?.AutoHideScrollBars is true; + get => ParentView?._scrollBar?.AutoHideScrollBars is true; set { if (HasVerticalScrollBar) { - _parent._scrollBar.AutoHideScrollBars = value; + ParentView._scrollBar.AutoHideScrollBars = value; } if (HasHorizontalScrollBar) { - _parent._scrollBar.OtherScrollBarView.AutoHideScrollBars = value; + ParentView._scrollBar.OtherScrollBarView.AutoHideScrollBars = value; } } } @@ -33,22 +32,12 @@ public virtual bool EnableScrollBars get => _enableScrollBars; set { - if (this is Adornment adornment) - { - _parent = adornment.Parent; - adornment.Parent._parent = _parent; - } - else - { - _parent = this; - } - - if (_parent._scrollBar is { } && _parent._enableScrollBars == value) + if (ParentView._scrollBar is { } && ParentView._enableScrollBars == value) { return; } - _parent._enableScrollBars = value; + ParentView._enableScrollBars = value; DisposeScrollBar (); if (!value) @@ -56,38 +45,38 @@ public virtual bool EnableScrollBars return; } - var vertical = new ScrollBarView { Orientation = Orientation.Vertical }; - var horizontal = new ScrollBarView { Orientation = Orientation.Horizontal }; - _parent._scrollBar = vertical; - _parent._scrollBar.OtherScrollBarView = horizontal; + var vertical = new ScrollBarView { Orientation = Orientation.Vertical, Size = ParentView.ContentSize.Height }; + var horizontal = new ScrollBarView { Orientation = Orientation.Horizontal, Size = ParentView.ContentSize.Width }; + ParentView._scrollBar = vertical; + ParentView._scrollBar.OtherScrollBarView = horizontal; - Add (_parent._scrollBar); - _parent.AddEventHandlersForScrollBars (_parent._scrollBar); - _parent.AddKeyBindingsForScrolling (_parent._scrollBar); + Add (ParentView._scrollBar); + ParentView.AddEventHandlersForScrollBars (ParentView._scrollBar); + ParentView.AddKeyBindingsForScrolling (ParentView._scrollBar); - if (_parent._scrollBar.OtherScrollBarView != null) + if (ParentView._scrollBar.OtherScrollBarView != null) { - _parent.AddKeyBindingsForScrolling (_parent._scrollBar.OtherScrollBarView); + ParentView.AddKeyBindingsForScrolling (ParentView._scrollBar.OtherScrollBarView); } - _parent.SetNeedsDisplay (); + ParentView.SetNeedsDisplay (); } } /// Get or sets if the view-port is kept always visible in the area of this public bool KeepContentAlwaysInContentArea { - get => _parent?._scrollBar?.KeepContentAlwaysInViewPort is true || _parent?._scrollBar?.OtherScrollBarView.KeepContentAlwaysInViewPort is true; + get => ParentView?._scrollBar?.KeepContentAlwaysInViewPort is true || ParentView?._scrollBar?.OtherScrollBarView.KeepContentAlwaysInViewPort is true; set { if (HasVerticalScrollBar) { - _parent._scrollBar.KeepContentAlwaysInViewPort = value; + ParentView._scrollBar.KeepContentAlwaysInViewPort = value; } if (HasHorizontalScrollBar) { - _parent._scrollBar.OtherScrollBarView.KeepContentAlwaysInViewPort = value; + ParentView._scrollBar.OtherScrollBarView.KeepContentAlwaysInViewPort = value; } } } @@ -96,12 +85,12 @@ public bool KeepContentAlwaysInContentArea /// true if show horizontal scroll bar; otherwise, false. public virtual bool ShowHorizontalScrollBar { - get => _parent?._scrollBar?.OtherScrollBarView.ShowScrollIndicator is true; + get => ParentView?._scrollBar?.OtherScrollBarView.ShowScrollIndicator is true; set { - if (_parent._scrollBar?.OtherScrollBarView is { }) + if (ParentView._scrollBar?.OtherScrollBarView is { }) { - _parent._scrollBar.OtherScrollBarView.ShowScrollIndicator = value; + ParentView._scrollBar.OtherScrollBarView.ShowScrollIndicator = value; } } } @@ -110,19 +99,21 @@ public virtual bool ShowHorizontalScrollBar /// true if show vertical scroll bar; otherwise, false. public virtual bool ShowVerticalScrollBar { - get => _parent?._scrollBar?.ShowScrollIndicator is true; + get => ParentView?._scrollBar?.ShowScrollIndicator is true; set { - if (_parent._scrollBar is { }) + if (ParentView._scrollBar is { }) { - _parent._scrollBar.ShowScrollIndicator = value; + ParentView._scrollBar.ShowScrollIndicator = value; } } } - private bool HasHorizontalScrollBar => _parent is { _scrollBar.OtherScrollBarView: { } }; + private bool HasHorizontalScrollBar => ParentView is { _scrollBar.OtherScrollBarView: { } }; - private bool HasVerticalScrollBar => _parent is { _scrollBar: { } }; + private bool HasVerticalScrollBar => ParentView is { _scrollBar: { } }; + + private View ParentView => this is Adornment adornment ? adornment.Parent : this; private void AddEventHandlersForScrollBars (ScrollBarView scrollBar) { @@ -148,93 +139,63 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) Command.ScrollDown, () => { - if (scrollBar.Orientation == Orientation.Vertical) - { - scrollBar.Position++; - - return true; - } + scrollBar.Position++; - return false; + return true; }); scrollBar.AddCommand ( Command.ScrollUp, () => { - if (scrollBar.Orientation == Orientation.Vertical) - { - scrollBar.Position--; + scrollBar.Position--; - return true; - } - - return false; + return true; }); scrollBar.AddCommand ( Command.TopHome, () => { - if (scrollBar.Orientation == Orientation.Vertical) - { - scrollBar.Position = 0; - - return true; - } + scrollBar.Position = 0; - return false; + return true; }); scrollBar.AddCommand ( Command.BottomEnd, () => { - if (scrollBar.Orientation == Orientation.Vertical) - { - scrollBar.Position = ContentSize.Height; + scrollBar.Position = ContentSize.Height; - return true; - } - - return false; + return true; }); scrollBar.AddCommand ( Command.PageDown, () => { - if (scrollBar.Orientation == Orientation.Vertical) - { - scrollBar.Position += GetVisibleContentArea ().Height; - - return true; - } + scrollBar.Position += scrollBar.GetVisibleContentArea ().Height; - return false; + return true; }); scrollBar.AddCommand ( Command.PageUp, () => { - if (scrollBar.Orientation == Orientation.Vertical) - { - scrollBar.Position -= GetVisibleContentArea ().Height; - - return true; - } + scrollBar.Position -= scrollBar.GetVisibleContentArea ().Height; - return false; + return true; }); // Default keybindings for this view - scrollBar.KeyBindings.Add (KeyCode.CursorDown, KeyBindingScope.HotKey, Command.ScrollDown); - scrollBar.KeyBindings.Add (KeyCode.CursorUp, KeyBindingScope.HotKey, Command.ScrollUp); - scrollBar.KeyBindings.Add (KeyCode.Home, KeyBindingScope.HotKey, Command.TopHome); - scrollBar.KeyBindings.Add (KeyCode.End, KeyBindingScope.HotKey, Command.BottomEnd); - scrollBar.KeyBindings.Add (KeyCode.PageDown, KeyBindingScope.HotKey, Command.PageDown); - scrollBar.KeyBindings.Add (KeyCode.PageUp, KeyBindingScope.HotKey, Command.PageUp); + scrollBar.KeyBindings.Add (Key.CursorDown, KeyBindingScope.HotKey, Command.ScrollDown); + scrollBar.KeyBindings.Add (Key.CursorUp, KeyBindingScope.HotKey, Command.ScrollUp); + scrollBar.KeyBindings.Add (Key.Home, KeyBindingScope.HotKey, Command.TopHome); + scrollBar.KeyBindings.Add (Key.End, KeyBindingScope.HotKey, Command.BottomEnd); + scrollBar.KeyBindings.Add (Key.PageDown, KeyBindingScope.HotKey, Command.PageDown); + scrollBar.KeyBindings.Add (Key.PageUp, KeyBindingScope.HotKey, Command.PageUp); } else { @@ -243,118 +204,88 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) Command.Left, () => { - if (scrollBar.Orientation == Orientation.Horizontal) - { - scrollBar.Position--; + scrollBar.Position--; - return true; - } - - return false; + return true; }); scrollBar.AddCommand ( Command.Right, () => { - if (scrollBar.Orientation == Orientation.Horizontal) - { - scrollBar.Position++; - - return true; - } + scrollBar.Position++; - return false; + return true; }); scrollBar.AddCommand ( Command.LeftHome, () => { - if (scrollBar.Orientation == Orientation.Horizontal) - { - scrollBar.Position = 0; + scrollBar.Position = 0; - return true; - } - - return false; + return true; }); scrollBar.AddCommand ( Command.RightEnd, () => { - if (scrollBar.Orientation == Orientation.Horizontal) - { - scrollBar.Position = ContentSize.Width; - - return true; - } + scrollBar.Position = ContentSize.Width; - return false; + return true; }); scrollBar.AddCommand ( Command.PageRight, () => { - if (scrollBar.Orientation == Orientation.Horizontal) - { - scrollBar.Position += GetVisibleContentArea ().Width; + scrollBar.Position += scrollBar.GetVisibleContentArea ().Width; - return true; - } - - return false; + return true; }); scrollBar.AddCommand ( Command.PageLeft, () => { - if (scrollBar.Orientation == Orientation.Horizontal) - { - scrollBar.Position -= GetVisibleContentArea ().Width; - - return true; - } + scrollBar.Position -= scrollBar.GetVisibleContentArea ().Width; - return false; + return true; }); // Default keybindings for this view - scrollBar.KeyBindings.Add (KeyCode.CursorLeft, KeyBindingScope.HotKey, Command.Left); - scrollBar.KeyBindings.Add (KeyCode.CursorRight, KeyBindingScope.HotKey, Command.Right); - scrollBar.KeyBindings.Add (KeyCode.Home | KeyCode.ShiftMask, KeyBindingScope.HotKey, Command.LeftHome); - scrollBar.KeyBindings.Add (KeyCode.End | KeyCode.ShiftMask, KeyBindingScope.HotKey, Command.RightEnd); - scrollBar.KeyBindings.Add (KeyCode.PageDown | KeyCode.ShiftMask, KeyBindingScope.HotKey, Command.PageRight); - scrollBar.KeyBindings.Add (KeyCode.PageUp | KeyCode.ShiftMask, KeyBindingScope.HotKey, Command.PageLeft); + scrollBar.KeyBindings.Add (Key.CursorLeft, KeyBindingScope.HotKey, Command.Left); + scrollBar.KeyBindings.Add (Key.CursorRight, KeyBindingScope.HotKey, Command.Right); + scrollBar.KeyBindings.Add (Key.Home.WithShift, KeyBindingScope.HotKey, Command.LeftHome); + scrollBar.KeyBindings.Add (Key.End.WithShift, KeyBindingScope.HotKey, Command.RightEnd); + scrollBar.KeyBindings.Add (Key.PageDown.WithShift, KeyBindingScope.HotKey, Command.PageRight); + scrollBar.KeyBindings.Add (Key.PageUp.WithShift, KeyBindingScope.HotKey, Command.PageLeft); } } private void DisposeScrollBar () { - if (_parent._scrollBar is null) + if (ParentView._scrollBar is null) { return; } - _parent._scrollBar.ChangedPosition -= VerticalScrollBar_ChangedPosition; - _parent.Remove (_parent._scrollBar); + ParentView._scrollBar.ChangedPosition -= VerticalScrollBar_ChangedPosition; + ParentView.Remove (ParentView._scrollBar); - if (_parent._scrollBar.OtherScrollBarView != null) + if (ParentView._scrollBar.OtherScrollBarView != null) { - _parent._scrollBar.OtherScrollBarView.ChangedPosition -= HorizontalScrollBar_ChangedPosition; - _parent.Remove (_parent._scrollBar.OtherScrollBarView); + ParentView._scrollBar.OtherScrollBarView.ChangedPosition -= HorizontalScrollBar_ChangedPosition; + ParentView.Remove (ParentView._scrollBar.OtherScrollBarView); } - if (_parent.Subviews.First (v => v is ScrollBarView.ContentBottomRightCorner) is { } contentBottomRightCorner) + if (ParentView.Subviews.First (v => v is ScrollBarView.ContentBottomRightCorner) is { } contentBottomRightCorner) { - _parent.Remove (contentBottomRightCorner); + ParentView.Remove (contentBottomRightCorner); } - _parent._scrollBar = null; + ParentView._scrollBar = null; } private void HorizontalScrollBar_ChangedPosition (object sender, EventArgs e) { SetBoundsByPosition (_scrollBar.OtherScrollBarView); } diff --git a/UnitTests/View/ViewScrollBarTests.cs b/UnitTests/View/ViewScrollBarTests.cs index 424a294039..4814a82a65 100644 --- a/UnitTests/View/ViewScrollBarTests.cs +++ b/UnitTests/View/ViewScrollBarTests.cs @@ -1,5 +1,16 @@ public class ViewScrollBarTests { + public static TheoryData ScrollBarKeyBindings => + new () + { + { Key.CursorDown, 0, -1, Key.CursorUp, 0, 0 }, + { Key.End, 0, -11, Key.Home, 0, 0 }, + { Key.PageDown, 0, -9, Key.PageUp, 0, 0 }, + { Key.CursorRight, -1, 0, Key.CursorLeft, 0, 0 }, + { Key.End.WithShift, -11, 0, Key.Home.WithShift, 0, 0 }, + { Key.PageDown.WithShift, -9, 0, Key.PageUp.WithShift, 0, 0 } + }; + [Fact] public void EnableScrollBars_Defaults () { @@ -10,6 +21,7 @@ public void EnableScrollBars_Defaults () Assert.False (view.KeepContentAlwaysInContentArea); Assert.False (view.ShowVerticalScrollBar); Assert.False (view.ShowHorizontalScrollBar); + Assert.False (view.UseContentOffset); view.EnableScrollBars = true; Assert.Equal (3, view.Subviews.Count); @@ -17,6 +29,7 @@ public void EnableScrollBars_Defaults () Assert.True (view.KeepContentAlwaysInContentArea); Assert.True (view.ShowVerticalScrollBar); Assert.True (view.ShowHorizontalScrollBar); + Assert.False (view.UseContentOffset); view.EnableScrollBars = false; Assert.Empty (view.Subviews); @@ -24,5 +37,65 @@ public void EnableScrollBars_Defaults () Assert.False (view.KeepContentAlwaysInContentArea); Assert.False (view.ShowVerticalScrollBar); Assert.False (view.ShowHorizontalScrollBar); + Assert.False (view.UseContentOffset); + } + + [Theory] + [MemberData (nameof (ScrollBarKeyBindings))] + public void KeyBindings_On_Border (Key firstKey, int expectedFirstX, int expectedFirstY, Key secondKey, int expectedSecondX, int expectedSecondY) + { + var view = new View { Width = 10, Height = 10, ContentSize = new (20, 20), UseContentOffset = true }; + view.Border.EnableScrollBars = true; + view.BeginInit (); + view.EndInit (); + + Assert.True (view.Border.OnInvokingKeyBindings (firstKey)); + Assert.Equal (new (expectedFirstX, expectedFirstY), view.ContentOffset); + Assert.True (view.Border.OnInvokingKeyBindings (secondKey)); + Assert.Equal (new (expectedSecondX, expectedSecondY), view.ContentOffset); + } + + [Theory] + [MemberData (nameof (ScrollBarKeyBindings))] + public void KeyBindings_On_ContentArea (Key firstKey, int expectedFirstX, int expectedFirstY, Key secondKey, int expectedSecondX, int expectedSecondY) + { + var view = new View { Width = 10, Height = 10, EnableScrollBars = true, ContentSize = new (20, 20), UseContentOffset = true }; + view.BeginInit (); + view.EndInit (); + + Assert.True (view.OnInvokingKeyBindings (firstKey)); + Assert.Equal (new (expectedFirstX, expectedFirstY), view.ContentOffset); + Assert.True (view.OnInvokingKeyBindings (secondKey)); + Assert.Equal (new (expectedSecondX, expectedSecondY), view.ContentOffset); + } + + [Theory] + [MemberData (nameof (ScrollBarKeyBindings))] + public void KeyBindings_On_Margin (Key firstKey, int expectedFirstX, int expectedFirstY, Key secondKey, int expectedSecondX, int expectedSecondY) + { + var view = new View { Width = 10, Height = 10, ContentSize = new (20, 20), UseContentOffset = true }; + view.Margin.EnableScrollBars = true; + view.BeginInit (); + view.EndInit (); + + Assert.True (view.Margin.OnInvokingKeyBindings (firstKey)); + Assert.Equal (new (expectedFirstX, expectedFirstY), view.ContentOffset); + Assert.True (view.Margin.OnInvokingKeyBindings (secondKey)); + Assert.Equal (new (expectedSecondX, expectedSecondY), view.ContentOffset); + } + + [Theory] + [MemberData (nameof (ScrollBarKeyBindings))] + public void KeyBindings_On_Padding (Key firstKey, int expectedFirstX, int expectedFirstY, Key secondKey, int expectedSecondX, int expectedSecondY) + { + var view = new View { Width = 10, Height = 10, ContentSize = new (20, 20), UseContentOffset = true }; + view.Padding.EnableScrollBars = true; + view.BeginInit (); + view.EndInit (); + + Assert.True (view.Padding.OnInvokingKeyBindings (firstKey)); + Assert.Equal (new (expectedFirstX, expectedFirstY), view.ContentOffset); + Assert.True (view.Padding.OnInvokingKeyBindings (secondKey)); + Assert.Equal (new (expectedSecondX, expectedSecondY), view.ContentOffset); } } From 95f60e6f0cf45e0705304f762d28660385caedc9 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 10 Mar 2024 22:50:54 +0000 Subject: [PATCH 089/130] Fix merge errors. --- UnitTests/Views/LabelTests.cs | 126 ++++++++++++---------------------- 1 file changed, 42 insertions(+), 84 deletions(-) diff --git a/UnitTests/Views/LabelTests.cs b/UnitTests/Views/LabelTests.cs index e72fa011fe..2ae0511524 100644 --- a/UnitTests/Views/LabelTests.cs +++ b/UnitTests/Views/LabelTests.cs @@ -72,6 +72,21 @@ public void MouseClick_SetsFocus_OnNextSubview () Assert.True (nextSubview.HasFocus); } + [Fact] + public void HotKey_Command_Does_Not_Accept () + { + var label = new Label (); + var accepted = false; + + label.Accept += LabelOnAccept; + label.InvokeCommand (Command.HotKey); + + Assert.False (accepted); + + return; + void LabelOnAccept (object sender, CancelEventArgs e) { accepted = true; } + } + [Fact] [AutoInitShutdown] public void AutoSize_Stays_True_AnchorEnd () @@ -234,60 +249,6 @@ public void Constructors_Defaults () Application.End (rs); } - [Fact] - [AutoInitShutdown] - public void Full_Border () - { - var label = new Label { Text = "Test", /*Width = 6, Height = 3, */BorderStyle = LineStyle.Single }; - Application.Top.Add (label); - Application.Begin (Application.Top); - - Assert.Equal (new Rectangle (0, 0, 6, 3), label.Frame); - Assert.Equal (new Rectangle (0, 0, 4, 1), label.ContentArea); - - TestHelpers.AssertDriverContentsWithFrameAre ( - @" -┌┤Te├┐ -│Test│ -└────┘", - _output - ); - } - - [Fact] - public void HotKey_Command_Does_Not_Accept () - { - var label = new Label (); - var accepted = false; - - label.Accept += LabelOnAccept; - label.InvokeCommand (Command.HotKey); - - Assert.False (accepted); - - return; - - void LabelOnAccept (object sender, CancelEventArgs e) { accepted = true; } - } - - [Fact] - public void HotKey_Command_SetsFocus_OnNextSubview () - { - var superView = new View { CanFocus = true }; - var label = new Label (); - var nextSubview = new View { CanFocus = true }; - superView.Add (label, nextSubview); - superView.BeginInit (); - superView.EndInit (); - - Assert.False (label.HasFocus); - Assert.False (nextSubview.HasFocus); - - label.InvokeCommand (Command.HotKey); - Assert.False (label.HasFocus); - Assert.True (nextSubview.HasFocus); - } - [Fact] [AutoInitShutdown] public void Label_Draw_Fill_Remaining_AutoSize_True () @@ -480,31 +441,6 @@ public void TestAssignTextToLabel () Assert.Equal ("heyb", ((Label)b).Text); } - // Test that Title and Text are the same - [Fact] - public void Text_Mirrors_Title () - { - var label = new Label (); - label.Title = "Hello"; - Assert.Equal ("Hello", label.Title); - Assert.Equal ("Hello", label.TitleTextFormatter.Text); - - Assert.Equal ("Hello", label.Text); - Assert.Equal ("Hello", label.TextFormatter.Text); - } - - [Fact] - public void Title_Mirrors_Text () - { - var label = new Label (); - label.Text = "Hello"; - Assert.Equal ("Hello", label.Text); - Assert.Equal ("Hello", label.TextFormatter.Text); - - Assert.Equal ("Hello", label.Title); - Assert.Equal ("Hello", label.TitleTextFormatter.Text); - } - [Fact] [AutoInitShutdown] public void Update_Only_On_Or_After_Initialize () @@ -566,6 +502,27 @@ public void Update_Parameterless_Only_On_Or_After_Initialize () Assert.Equal (new Rectangle (0, 0, 30, 5), pos); } + + [Fact] + [AutoInitShutdown] + public void Full_Border () + { + var label = new Label { Text = "Test", /*Width = 6, Height = 3, */BorderStyle = LineStyle.Single }; + Application.Top.Add (label); + Application.Begin (Application.Top); + + Assert.Equal (new (0, 0, 6, 3), label.Frame); + Assert.Equal (new (0, 0, 4, 1), label.ContentArea); + + TestHelpers.AssertDriverContentsWithFrameAre ( + @" +┌┤Te├┐ +│Test│ +└────┘", + _output + ); + } + [Fact] [AutoInitShutdown] public void With_Top_Margin_Without_Top_Border () @@ -576,8 +533,8 @@ public void With_Top_Margin_Without_Top_Border () Application.Top.Add (label); Application.Begin (Application.Top); - Assert.Equal (new Rectangle (0, 0, 6, 3), label.Frame); - Assert.Equal (new Rectangle (0, 0, 4, 1), label.ContentArea); + Assert.Equal (new (0, 0, 6, 3), label.Frame); + Assert.Equal (new (0, 0, 4, 1), label.ContentArea); Application.Begin (Application.Top); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -597,8 +554,8 @@ public void Without_Top_Border () Application.Top.Add (label); Application.Begin (Application.Top); - Assert.Equal (new Rectangle (0, 0, 6, 2), label.Frame); - Assert.Equal (new Rectangle (0, 0, 4, 1), label.ContentArea); + Assert.Equal (new (0, 0, 6, 2), label.Frame); + Assert.Equal (new (0, 0, 4, 1), label.ContentArea); Application.Begin (Application.Top); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -608,4 +565,5 @@ public void Without_Top_Border () _output ); } -} + +} \ No newline at end of file From e1e689ed31811a6199de64fdb6c3440d79612bb5 Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 11 Mar 2024 21:16:02 +0000 Subject: [PATCH 090/130] Enable scrolling without scroll bars. --- Terminal.Gui/View/Layout/ViewLayout.cs | 96 +--- Terminal.Gui/View/View.cs | 5 + Terminal.Gui/View/ViewScrollBar.cs | 532 +++++++++++++----- UICatalog/Scenarios/ScrollBars.cs | 10 +- .../ScrollingWithoutEnableScrollBars.cs | 96 ++++ UnitTests/View/ViewScrollBarTests.cs | 166 +++++- 6 files changed, 664 insertions(+), 241 deletions(-) create mode 100644 UICatalog/Scenarios/ScrollingWithoutEnableScrollBars.cs diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 4d3089e8a1..4c0f42d398 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -188,8 +188,8 @@ public virtual Rectangle ContentArea } Thickness totalThickness = GetAdornmentsThickness (); - int width = Math.Max (0, Frame.Size.Width - totalThickness.Horizontal- (UseContentOffset ? ContentOffset.X : 0)); - int height = Math.Max (0, Frame.Size.Height - totalThickness.Vertical- (UseContentOffset ? ContentOffset.Y : 0)); + int width = Math.Max (0, Frame.Size.Width - totalThickness.Horizontal - (UseContentOffset ? ContentOffset.X : 0)); + int height = Math.Max (0, Frame.Size.Height - totalThickness.Vertical - (UseContentOffset ? ContentOffset.Y : 0)); return new (UseContentOffset ? ContentOffset : Point.Empty, new Size (width, height)); } @@ -214,93 +214,6 @@ public virtual Rectangle ContentArea } } - /// - /// Represent the content offset if is true. - /// - public virtual Point ContentOffset - { - get => ParentView._contentOffset; - set - { - ParentView._contentOffset = value; - - if (_scrollBar is null) - { - return; - } - - if (_scrollBar.Orientation == Orientation.Horizontal && _scrollBar.Position != -ContentOffset.X) - { - _scrollBar.Position = -ContentOffset.X; - } - else if (_scrollBar is { OtherScrollBarView.Orientation: Orientation.Horizontal } && _scrollBar?.OtherScrollBarView.Position != -ContentOffset.X) - { - _scrollBar!.OtherScrollBarView.Position = -ContentOffset.X; - } - - if (_scrollBar.Orientation == Orientation.Vertical && _scrollBar.Position != -ContentOffset.Y) - { - _scrollBar.Position = -ContentOffset.Y; - } - else if (_scrollBar is { OtherScrollBarView.Orientation: Orientation.Vertical } && _scrollBar?.OtherScrollBarView.Position != -ContentOffset.Y) - { - _scrollBar!.OtherScrollBarView.Position = -ContentOffset.Y; - } - } - } - - /// - /// Represents the contents size of the data shown inside the . - /// - public Size ContentSize - { - get => ParentView._contentSize; - set - { - if (ParentView._contentSize != value) - { - ParentView._contentSize = value; - SetNeedsDisplay (); - } - - if (_scrollBar is null) - { - return; - } - - if (_scrollBar.Orientation == Orientation.Vertical) - { - if (_scrollBar.Size != ContentSize.Height) - { - _scrollBar.Size = ContentSize.Height; - } - - if (_scrollBar.OtherScrollBarView is { }) - { - if (_scrollBar.OtherScrollBarView.Size != ContentSize.Width) - { - _scrollBar.OtherScrollBarView.Size = ContentSize.Width; - } - } - } - else - { - if (_scrollBar.Size != ContentSize.Width) - { - _scrollBar.Size = ContentSize.Width; - } - - if (_scrollBar.OtherScrollBarView is { }) - { - if (_scrollBar.OtherScrollBarView.Size != ContentSize.Height) - { - _scrollBar.OtherScrollBarView.Size = ContentSize.Height; - } - } - } - } - } - /// Gets or sets the absolute location and dimension of the view. /// /// The rectangle describing absolute location and dimension of the view, in coordinates relative to the @@ -461,11 +374,6 @@ public LayoutStyle LayoutStyle /// public Padding Padding { get; private set; } - /// - /// Determines if negative bounds location is allowed for scrolling the . - /// - public bool UseContentOffset { get; set; } - /// Gets or sets whether validation of and occurs. /// /// Setting this to will enable validation of , , diff --git a/Terminal.Gui/View/View.cs b/Terminal.Gui/View/View.cs index 48571f9d88..8a1f53295f 100644 --- a/Terminal.Gui/View/View.cs +++ b/Terminal.Gui/View/View.cs @@ -462,6 +462,11 @@ public virtual void BeginInit () Border?.BeginInit (); Padding?.BeginInit (); + if (_scrollBar is null && UseContentOffset) + { + AddKeyBindingsForScrolling (); + } + if (_subviews?.Count > 0) { foreach (View view in _subviews) diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 3c56f9a988..3de09af4e2 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -4,6 +4,7 @@ public partial class View { private bool _enableScrollBars; private ScrollBarView _scrollBar; + private bool _useContentOffset; /// If true the vertical/horizontal scroll bars won't be showed if it's not needed. public bool AutoHideScrollBars @@ -23,6 +24,101 @@ public bool AutoHideScrollBars } } + /// + /// Represent the content offset if is true. + /// + public virtual Point ContentOffset + { + get => ParentView._contentOffset; + set + { + ParentView._contentOffset = value; + + if (UseContentOffset) + { + SetNeedsLayout (); + SetNeedsDisplay (); + } + + if (ParentView._scrollBar is null) + { + return; + } + + if (ParentView._scrollBar.Orientation == Orientation.Horizontal && ParentView._scrollBar.Position != -ParentView.ContentOffset.X) + { + ParentView._scrollBar.Position = -ParentView.ContentOffset.X; + } + else if (ParentView._scrollBar is { OtherScrollBarView.Orientation: Orientation.Horizontal } + && ParentView._scrollBar?.OtherScrollBarView.Position != -ParentView.ContentOffset.X) + { + ParentView._scrollBar!.OtherScrollBarView.Position = -ParentView.ContentOffset.X; + } + + if (ParentView._scrollBar.Orientation == Orientation.Vertical && ParentView._scrollBar.Position != -ParentView.ContentOffset.Y) + { + ParentView._scrollBar.Position = -ParentView.ContentOffset.Y; + } + else if (ParentView._scrollBar is { OtherScrollBarView.Orientation: Orientation.Vertical } + && ParentView._scrollBar?.OtherScrollBarView.Position != -ParentView.ContentOffset.Y) + { + ParentView._scrollBar!.OtherScrollBarView.Position = -ParentView.ContentOffset.Y; + } + } + } + + /// + /// Represents the contents size of the data shown inside the . + /// + public Size ContentSize + { + get => ParentView._contentSize; + set + { + if (ParentView._contentSize != value) + { + ParentView._contentSize = value; + SetNeedsDisplay (); + } + + if (_scrollBar is null) + { + return; + } + + if (_scrollBar.Orientation == Orientation.Vertical) + { + if (_scrollBar.Size != ContentSize.Height) + { + _scrollBar.Size = ContentSize.Height; + } + + if (_scrollBar.OtherScrollBarView is { }) + { + if (_scrollBar.OtherScrollBarView.Size != ContentSize.Width) + { + _scrollBar.OtherScrollBarView.Size = ContentSize.Width; + } + } + } + else + { + if (_scrollBar.Size != ContentSize.Width) + { + _scrollBar.Size = ContentSize.Width; + } + + if (_scrollBar.OtherScrollBarView is { }) + { + if (_scrollBar.OtherScrollBarView.Size != ContentSize.Height) + { + _scrollBar.OtherScrollBarView.Size = ContentSize.Height; + } + } + } + } + } + /// /// Gets or sets the used by this view. /// @@ -109,11 +205,22 @@ public virtual bool ShowVerticalScrollBar } } - private bool HasHorizontalScrollBar => ParentView is { _scrollBar.OtherScrollBarView: { } }; - - private bool HasVerticalScrollBar => ParentView is { _scrollBar: { } }; + /// + /// Determines if negative bounds location is allowed for scrolling the . + /// + public bool UseContentOffset + { + get => _useContentOffset; + set + { + _useContentOffset = value; - private View ParentView => this is Adornment adornment ? adornment.Parent : this; + if (IsInitialized && _useContentOffset) + { + ParentView.AddKeyBindingsForScrolling (); + } + } + } private void AddEventHandlersForScrollBars (ScrollBarView scrollBar) { @@ -130,137 +237,294 @@ private void AddEventHandlersForScrollBars (ScrollBarView scrollBar) } } - private void AddKeyBindingsForScrolling (ScrollBarView scrollBar) + private void AddKeyBindingsForScrolling (ScrollBarView scrollBar = null) { - if (scrollBar.Orientation == Orientation.Vertical) + View view = scrollBar ?? ParentView; + + if (view is ScrollBarView { Orientation: Orientation.Vertical } || (view == ParentView && view.UseContentOffset)) { - // Things this view knows how to do - scrollBar.AddCommand ( - Command.ScrollDown, - () => - { - scrollBar.Position++; - - return true; - }); - - scrollBar.AddCommand ( - Command.ScrollUp, - () => - { - scrollBar.Position--; - - return true; - }); - - scrollBar.AddCommand ( - Command.TopHome, - () => - { - scrollBar.Position = 0; - - return true; - }); - - scrollBar.AddCommand ( - Command.BottomEnd, - () => - { - scrollBar.Position = ContentSize.Height; - - return true; - }); - - scrollBar.AddCommand ( - Command.PageDown, - () => - { - scrollBar.Position += scrollBar.GetVisibleContentArea ().Height; - - return true; - }); - - scrollBar.AddCommand ( - Command.PageUp, - () => - { - scrollBar.Position -= scrollBar.GetVisibleContentArea ().Height; - - return true; - }); - - // Default keybindings for this view - scrollBar.KeyBindings.Add (Key.CursorDown, KeyBindingScope.HotKey, Command.ScrollDown); - scrollBar.KeyBindings.Add (Key.CursorUp, KeyBindingScope.HotKey, Command.ScrollUp); - scrollBar.KeyBindings.Add (Key.Home, KeyBindingScope.HotKey, Command.TopHome); - scrollBar.KeyBindings.Add (Key.End, KeyBindingScope.HotKey, Command.BottomEnd); - scrollBar.KeyBindings.Add (Key.PageDown, KeyBindingScope.HotKey, Command.PageDown); - scrollBar.KeyBindings.Add (Key.PageUp, KeyBindingScope.HotKey, Command.PageUp); + // Things this view knows how to do vertical scrolling + if (scrollBar is { Orientation: Orientation.Vertical }) + { + view.AddCommand ( + Command.ScrollDown, + () => + { + scrollBar.Position++; + + return true; + }); + + view.AddCommand ( + Command.ScrollUp, + () => + { + scrollBar.Position--; + + return true; + }); + + view.AddCommand ( + Command.TopHome, + () => + { + scrollBar.Position = 0; + + return true; + }); + + view.AddCommand ( + Command.BottomEnd, + () => + { + scrollBar.Position = ContentSize.Height; + + return true; + }); + + view.AddCommand ( + Command.PageDown, + () => + { + scrollBar.Position += scrollBar.GetVisibleContentArea ().Height; + + return true; + }); + + view.AddCommand ( + Command.PageUp, + () => + { + scrollBar.Position -= scrollBar.GetVisibleContentArea ().Height; + + return true; + }); + } + else + { + view.AddCommand ( + Command.ScrollDown, + () => + { + ParentView.ContentOffset = ParentView.ContentOffset with + { + Y = Math.Max ( + ParentView.ContentOffset.Y - 1, + -(ParentView.ContentSize.Height - ParentView.GetVisibleContentArea ().Height)) + }; + + return true; + }); + + view.AddCommand ( + Command.ScrollUp, + () => + { + ParentView.ContentOffset = ParentView.ContentOffset with { Y = Math.Min (ParentView.ContentOffset.Y + 1, 0) }; + + return true; + }); + + view.AddCommand ( + Command.TopHome, + () => + { + ParentView.ContentOffset = ParentView.ContentOffset with { Y = 0 }; + + return true; + }); + + view.AddCommand ( + Command.BottomEnd, + () => + { + ParentView.ContentOffset = ParentView.ContentOffset with + { + Y = Math.Max ( + -ParentView.ContentSize.Height, + -(ParentView.ContentSize.Height - ParentView.GetVisibleContentArea ().Height)) + }; + + return true; + }); + + view.AddCommand ( + Command.PageDown, + () => + { + ParentView.ContentOffset = ParentView.ContentOffset with + { + Y = Math.Max ( + -(ParentView.GetVisibleContentArea ().Height - ParentView.ContentOffset.Y), + ParentView.GetVisibleContentArea ().Height - ParentView.ContentSize.Height) + }; + + return true; + }); + + view.AddCommand ( + Command.PageUp, + () => + { + ParentView.ContentOffset = ParentView.ContentOffset with + { + Y = Math.Max (-(ParentView.ContentOffset.Y + ParentView.GetVisibleContentArea ().Height), 0) + }; + + return true; + }); + } + + // Default keybindings for vertical scrolling + view.KeyBindings.Add (Key.CursorDown, KeyBindingScope.HotKey, Command.ScrollDown); + view.KeyBindings.Add (Key.CursorUp, KeyBindingScope.HotKey, Command.ScrollUp); + view.KeyBindings.Add (Key.Home, KeyBindingScope.HotKey, Command.TopHome); + view.KeyBindings.Add (Key.End, KeyBindingScope.HotKey, Command.BottomEnd); + view.KeyBindings.Add (Key.PageDown, KeyBindingScope.HotKey, Command.PageDown); + view.KeyBindings.Add (Key.PageUp, KeyBindingScope.HotKey, Command.PageUp); } - else + + if (view is ScrollBarView { Orientation: Orientation.Horizontal } || (view == ParentView && view.UseContentOffset)) { - // Things this view knows how to do - scrollBar.AddCommand ( - Command.Left, - () => - { - scrollBar.Position--; - - return true; - }); - - scrollBar.AddCommand ( - Command.Right, - () => - { - scrollBar.Position++; - - return true; - }); - - scrollBar.AddCommand ( - Command.LeftHome, - () => - { - scrollBar.Position = 0; - - return true; - }); - - scrollBar.AddCommand ( - Command.RightEnd, - () => - { - scrollBar.Position = ContentSize.Width; - - return true; - }); - - scrollBar.AddCommand ( - Command.PageRight, - () => - { - scrollBar.Position += scrollBar.GetVisibleContentArea ().Width; - - return true; - }); - - scrollBar.AddCommand ( - Command.PageLeft, - () => - { - scrollBar.Position -= scrollBar.GetVisibleContentArea ().Width; - - return true; - }); - - // Default keybindings for this view - scrollBar.KeyBindings.Add (Key.CursorLeft, KeyBindingScope.HotKey, Command.Left); - scrollBar.KeyBindings.Add (Key.CursorRight, KeyBindingScope.HotKey, Command.Right); - scrollBar.KeyBindings.Add (Key.Home.WithShift, KeyBindingScope.HotKey, Command.LeftHome); - scrollBar.KeyBindings.Add (Key.End.WithShift, KeyBindingScope.HotKey, Command.RightEnd); - scrollBar.KeyBindings.Add (Key.PageDown.WithShift, KeyBindingScope.HotKey, Command.PageRight); - scrollBar.KeyBindings.Add (Key.PageUp.WithShift, KeyBindingScope.HotKey, Command.PageLeft); + if (scrollBar is { Orientation: Orientation.Horizontal }) + { + // Things this view knows how to do horizontal scrolling + view.AddCommand ( + Command.Left, + () => + { + scrollBar.Position--; + + return true; + }); + + view.AddCommand ( + Command.Right, + () => + { + scrollBar.Position++; + + return true; + }); + + view.AddCommand ( + Command.LeftHome, + () => + { + scrollBar.Position = 0; + + return true; + }); + + view.AddCommand ( + Command.RightEnd, + () => + { + scrollBar.Position = ContentSize.Width; + + return true; + }); + + view.AddCommand ( + Command.PageRight, + () => + { + scrollBar.Position += scrollBar.GetVisibleContentArea ().Width; + + return true; + }); + + view.AddCommand ( + Command.PageLeft, + () => + { + scrollBar.Position -= scrollBar.GetVisibleContentArea ().Width; + + return true; + }); + } + else + { + view.AddCommand ( + Command.Left, + () => + { + ParentView.ContentOffset = ParentView.ContentOffset with { X = Math.Min (ParentView.ContentOffset.X + 1, 0) }; + + return true; + }); + + view.AddCommand ( + Command.Right, + () => + { + ParentView.ContentOffset = ParentView.ContentOffset with + { + X = Math.Max ( + ParentView.ContentOffset.X - 1, + -(ParentView.ContentSize.Width - ParentView.GetVisibleContentArea ().Width)) + }; + + return true; + }); + + view.AddCommand ( + Command.LeftHome, + () => + { + ParentView.ContentOffset = ParentView.ContentOffset with { X = 0 }; + + return true; + }); + + view.AddCommand ( + Command.RightEnd, + () => + { + ParentView.ContentOffset = ParentView.ContentOffset with + { + X = Math.Max ( + -ParentView.ContentSize.Width, + -(ParentView.ContentSize.Width - ParentView.GetVisibleContentArea ().Width)) + }; + + return true; + }); + + view.AddCommand ( + Command.PageRight, + () => + { + ParentView.ContentOffset = ParentView.ContentOffset with + { + X = Math.Max ( + -(ParentView.GetVisibleContentArea ().Width - ParentView.ContentOffset.X), + ParentView.GetVisibleContentArea ().Width - ParentView.ContentSize.Width) + }; + + return true; + }); + + view.AddCommand ( + Command.PageLeft, + () => + { + ParentView.ContentOffset = ParentView.ContentOffset with + { + X = Math.Max (-(ParentView.ContentOffset.X + ParentView.GetVisibleContentArea ().Width), 0) + }; + + return true; + }); + } + + // Default keybindings for horizontal scrolling + view.KeyBindings.Add (Key.CursorLeft, KeyBindingScope.HotKey, Command.Left); + view.KeyBindings.Add (Key.CursorRight, KeyBindingScope.HotKey, Command.Right); + view.KeyBindings.Add (Key.Home.WithShift, KeyBindingScope.HotKey, Command.LeftHome); + view.KeyBindings.Add (Key.End.WithShift, KeyBindingScope.HotKey, Command.RightEnd); + view.KeyBindings.Add (Key.PageDown.WithShift, KeyBindingScope.HotKey, Command.PageRight); + view.KeyBindings.Add (Key.PageUp.WithShift, KeyBindingScope.HotKey, Command.PageLeft); } } @@ -288,8 +552,14 @@ private void DisposeScrollBar () ParentView._scrollBar = null; } + private bool HasHorizontalScrollBar => ParentView is { _scrollBar.OtherScrollBarView: { } }; + + private bool HasVerticalScrollBar => ParentView is { _scrollBar: { } }; + private void HorizontalScrollBar_ChangedPosition (object sender, EventArgs e) { SetBoundsByPosition (_scrollBar.OtherScrollBarView); } + private View ParentView => this is Adornment adornment ? adornment.Parent : this; + private void SetBoundsByPosition (ScrollBarView scrollBar) { if (scrollBar.Orientation == Orientation.Vertical) diff --git a/UICatalog/Scenarios/ScrollBars.cs b/UICatalog/Scenarios/ScrollBars.cs index cf9b437049..3fd134f2c3 100644 --- a/UICatalog/Scenarios/ScrollBars.cs +++ b/UICatalog/Scenarios/ScrollBars.cs @@ -3,7 +3,7 @@ namespace UICatalog.Scenarios; -[ScenarioMetadata ("ScrollBars", "Demonstrates the scroll bar built-in the Padding Adornment.")] +[ScenarioMetadata ("ScrollBars", "Demonstrates the scroll bar built-in on Adornments and view.")] [ScenarioCategory ("Controls")] public class ScrollBars : Scenario { @@ -38,7 +38,7 @@ public override void Setup () UseContentOffset = true, EnableScrollBars = true }; - viewOnContentArea.Margin.Thickness = new Thickness (1); + viewOnContentArea.Margin.Thickness = new (1); viewOnContentArea.Margin.ColorScheme = Colors.ColorSchemes ["Dialog"]; viewOnContentArea.BorderStyle = LineStyle.Single; SetViewProperties (viewOnContentArea); @@ -53,7 +53,7 @@ public override void Setup () UseContentOffset = true }; viewOnPadding.Padding.EnableScrollBars = true; - viewOnPadding.Margin.Thickness = new Thickness (1); + viewOnPadding.Margin.Thickness = new (1); viewOnPadding.Margin.ColorScheme = Colors.ColorSchemes ["Dialog"]; viewOnPadding.BorderStyle = LineStyle.Single; viewOnPadding.Padding.ColorScheme = Colors.ColorSchemes ["Menu"]; @@ -70,7 +70,7 @@ public override void Setup () BorderStyle = LineStyle.None }; viewOnBorder.Border.EnableScrollBars = true; - viewOnBorder.Margin.Thickness = new Thickness (1); + viewOnBorder.Margin.Thickness = new (1); viewOnBorder.Margin.ColorScheme = Colors.ColorSchemes ["Dialog"]; SetViewProperties (viewOnBorder); win.Add (viewOnBorder); @@ -94,6 +94,6 @@ private void SetViewProperties (View view) view.TextFormatter.FillRemaining = true; view.CanFocus = true; string [] strings = view.Text.Split ("\n").ToArray (); - view.ContentSize = new Size (strings.OrderByDescending (s => s.Length).First ().GetColumns (), strings.Length); + view.ContentSize = new (strings.OrderByDescending (s => s.Length).First ().GetColumns (), strings.Length); } } diff --git a/UICatalog/Scenarios/ScrollingWithoutEnableScrollBars.cs b/UICatalog/Scenarios/ScrollingWithoutEnableScrollBars.cs new file mode 100644 index 0000000000..0fd91b8113 --- /dev/null +++ b/UICatalog/Scenarios/ScrollingWithoutEnableScrollBars.cs @@ -0,0 +1,96 @@ +using System.Linq; +using Terminal.Gui; + +namespace UICatalog.Scenarios; + +[ScenarioMetadata ("Scrolling Without ScrollBars", "Demonstrates the scrolling without EnableScrollBars.")] +[ScenarioCategory ("Controls")] +public class ScrollingWithoutEnableScrollBars : Scenario +{ + public override void Init () + { + Application.Init (); + Application.Top.ColorScheme = Colors.ColorSchemes ["Base"]; + } + + public override void Setup () + { + var text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line"; + + var win = new Window (); + + var viewWithoutAdornments = new View + { + X = 0, Y = Pos.Center (), Width = 12, Height = 6, + Text = text, + UseContentOffset = true + }; + SetViewProperties (viewWithoutAdornments); + win.Add (viewWithoutAdornments); + + win.Add (new Label { X = 0, Y = Pos.Top (viewWithoutAdornments) - 2, Text = "No Adornments:" }); + + var viewWithMarginBorderPadding = new View + { + X = Pos.AnchorEnd () - 15, Y = Pos.Center (), Width = 15, Height = 8, + Text = text, + UseContentOffset = true + }; + viewWithMarginBorderPadding.Margin.Thickness = new (1); + viewWithMarginBorderPadding.Margin.ColorScheme = Colors.ColorSchemes ["Dialog"]; + viewWithMarginBorderPadding.BorderStyle = LineStyle.Single; + viewWithMarginBorderPadding.Padding.Thickness = new (1); + viewWithMarginBorderPadding.Padding.ColorScheme = Colors.ColorSchemes ["Menu"]; + SetViewProperties (viewWithMarginBorderPadding); + win.Add (viewWithMarginBorderPadding); + + win.Add (new Label { X = Pos.Left (viewWithMarginBorderPadding), Y = Pos.Top (viewWithMarginBorderPadding) - 2, Text = "All Adornments:" }); + + var viewWithMarginBorder = new View + { + X = Pos.Left (viewWithMarginBorderPadding) - 30, Y = Pos.Center (), Width = 15, Height = 8, + Text = text, + UseContentOffset = true + }; + viewWithMarginBorder.Margin.Thickness = new (1); + viewWithMarginBorder.Margin.ColorScheme = Colors.ColorSchemes ["Dialog"]; + viewWithMarginBorder.BorderStyle = LineStyle.Single; + SetViewProperties (viewWithMarginBorder); + win.Add (viewWithMarginBorder); + + win.Add (new Label { X = Pos.Left (viewWithMarginBorder), Y = Pos.Top (viewWithMarginBorder) - 2, Text = "With Margin/Border:" }); + + var viewWithMargin = new View + { + X = Pos.Left (viewWithMarginBorder) - 30, Y = Pos.Center (), Width = 13, Height = 8, + Text = text, + UseContentOffset = true, + BorderStyle = LineStyle.None + }; + viewWithMargin.Margin.Thickness = new (1); + viewWithMargin.Margin.ColorScheme = Colors.ColorSchemes ["Menu"]; + SetViewProperties (viewWithMargin); + win.Add (viewWithMargin); + + win.Add (new Label { X = Pos.Left (viewWithMargin), Y = Pos.Top (viewWithMargin) - 2, Text = "With Margin:" }); + + var btn = new Button { X = Pos.Center (), Y = Pos.Bottom (viewWithMarginBorderPadding) + 1, Text = "Tab or click to select the views" }; + win.Add (btn); + + viewWithMargin.TabIndex = 1; + viewWithMarginBorder.TabIndex = 2; + viewWithMarginBorderPadding.TabIndex = 3; + + Application.Top.Add (win); + } + + private void SetViewProperties (View view) + { + view.TextFormatter.WordWrap = false; + view.TextFormatter.MultiLine = true; + view.TextFormatter.FillRemaining = true; + view.CanFocus = true; + string [] strings = view.Text.Split ("\n").ToArray (); + view.ContentSize = new (strings.OrderByDescending (s => s.Length).First ().GetColumns (), strings.Length); + } +} diff --git a/UnitTests/View/ViewScrollBarTests.cs b/UnitTests/View/ViewScrollBarTests.cs index 4814a82a65..c43044c8f5 100644 --- a/UnitTests/View/ViewScrollBarTests.cs +++ b/UnitTests/View/ViewScrollBarTests.cs @@ -1,15 +1,11 @@ -public class ViewScrollBarTests +using Xunit.Abstractions; + +namespace Terminal.Gui.ViewTests; + +public class ViewScrollBarTests { - public static TheoryData ScrollBarKeyBindings => - new () - { - { Key.CursorDown, 0, -1, Key.CursorUp, 0, 0 }, - { Key.End, 0, -11, Key.Home, 0, 0 }, - { Key.PageDown, 0, -9, Key.PageUp, 0, 0 }, - { Key.CursorRight, -1, 0, Key.CursorLeft, 0, 0 }, - { Key.End.WithShift, -11, 0, Key.Home.WithShift, 0, 0 }, - { Key.PageDown.WithShift, -9, 0, Key.PageUp.WithShift, 0, 0 } - }; + public ViewScrollBarTests (ITestOutputHelper output) { _output = output; } + private readonly ITestOutputHelper _output; [Fact] public void EnableScrollBars_Defaults () @@ -98,4 +94,152 @@ public void KeyBindings_On_Padding (Key firstKey, int expectedFirstX, int expect Assert.True (view.Padding.OnInvokingKeyBindings (secondKey)); Assert.Equal (new (expectedSecondX, expectedSecondY), view.ContentOffset); } + + [Theory] + [MemberData (nameof (KeyBindingsWithoutScrollBars))] + public void KeyBindings_Without_EnableScrollBars ( + Key firstKey, + int expectedFirstX, + int expectedFirstY, + Key secondKey, + int expectedSecondX, + int expectedSecondY + ) + { + var view = new View { Width = 10, Height = 10, ContentSize = new (20, 20), UseContentOffset = true }; + view.BeginInit (); + view.EndInit (); + + Assert.True (view.OnInvokingKeyBindings (firstKey)); + Assert.Equal (new (expectedFirstX, expectedFirstY), view.ContentOffset); + Assert.True (view.OnInvokingKeyBindings (secondKey)); + Assert.Equal (new (expectedSecondX, expectedSecondY), view.ContentOffset); + } + + public static TheoryData KeyBindingsWithoutScrollBars => + new () + { + { Key.CursorDown, 0, -1, Key.CursorUp, 0, 0 }, + { Key.End, 0, -10, Key.Home, 0, 0 }, + { Key.PageDown, 0, -10, Key.PageUp, 0, 0 }, + { Key.CursorRight, -1, 0, Key.CursorLeft, 0, 0 }, + { Key.End.WithShift, -10, 0, Key.Home.WithShift, 0, 0 }, + { Key.PageDown.WithShift, -10, 0, Key.PageUp.WithShift, 0, 0 } + }; + + public static TheoryData ScrollBarKeyBindings => + new () + { + { Key.CursorDown, 0, -1, Key.CursorUp, 0, 0 }, + { Key.End, 0, -11, Key.Home, 0, 0 }, + { Key.PageDown, 0, -9, Key.PageUp, 0, 0 }, + { Key.CursorRight, -1, 0, Key.CursorLeft, 0, 0 }, + { Key.End.WithShift, -11, 0, Key.Home.WithShift, 0, 0 }, + { Key.PageDown.WithShift, -9, 0, Key.PageUp.WithShift, 0, 0 } + }; + + [Fact] + [SetupFakeDriver] + public void Scrolling_Without_ScrollBars () + { + ((FakeDriver)Application.Driver).SetBufferSize (15, 11); + + var top = new View { Width = 15, Height = 11, ColorScheme = new (Attribute.Default) }; + + var view = new View + { + X = Pos.Center (), Y = Pos.Center (), Width = 9, Height = 6, + Text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line", CanFocus = true, + UseContentOffset = true + }; + view.TextFormatter.WordWrap = false; + view.TextFormatter.MultiLine = true; + string [] strings = view.Text.Split ("\n").ToArray (); + view.ContentSize = new (strings.OrderByDescending (s => s.Length).First ().GetColumns (), strings.Length); + + view.ColorScheme = new() + { + Normal = new (Color.Green, Color.Red), + Focus = new (Color.Red, Color.Green) + }; + + var view2 = new View { X = Pos.Center (), Y = Pos.Bottom (view) + 1, Text = "Test", CanFocus = true, AutoSize = true }; + view2.ColorScheme = view.ColorScheme; + top.Add (view, view2); + top.BeginInit (); + top.EndInit (); + top.FocusFirst (); + top.LayoutSubviews (); + top.Draw (); + Assert.True (view.HasFocus); + Assert.False (view2.HasFocus); + Assert.Equal (12, view.ContentSize.Width); + Assert.Equal (7, view.ContentSize.Height); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.GetVisibleContentArea ().ToString ()); + Assert.Equal ("{X=3,Y=2,Width=9,Height=6}", view.Frame.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.GetVisibleContentArea ().ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.Frame.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.GetVisibleContentArea ().ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Border.Frame.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.GetVisibleContentArea ().ToString ()); + Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.Frame.ToString ()); + Assert.Equal ("{Width=9, Height=6}", view.TextFormatter.Size.ToString ()); + + TestHelpers.AssertDriverContentsWithFrameAre ( + @" + First Lin + Second Li + Third Lin + Fourth Li + Fifth Lin + Sixth Lin + + Test ", + _output); + + Attribute [] attrs = + [ + Attribute.Default, + new (Color.Red, Color.Green), + new (Color.Green, Color.Red), + new (Color.White, Color.DarkGray), + new (Color.Black, Color.Gray) + ]; + + TestHelpers.AssertDriverAttributesAre ( + @" +000000000000000 +000000000000000 +000111111111000 +000111111111000 +000111111111000 +000111111111000 +000111111111000 +000111111111000 +000000000000000 +000002222000000 +000000000000000", + null, + attrs); + + Assert.True (view.OnInvokingKeyBindings (Key.End)); + Assert.True (view.OnInvokingKeyBindings (Key.End.WithShift)); + top.Draw (); + + TestHelpers.AssertDriverContentsWithFrameAre ( + @" + ond Line + rd Line + rth Line + th Line + th Line + enth Line + + Test ", + _output); + } } From 933420b9867cf792f2ca6cf8378e80dd07c7c3ed Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 14 Mar 2024 14:29:19 +0000 Subject: [PATCH 091/130] Fix merge conflicts. --- Terminal.Gui/Application.cs | 2 +- Terminal.Gui/View/Adornment/Adornment.cs | 24 +++++++++--------------- Terminal.Gui/View/Adornment/Border.cs | 4 ++-- Terminal.Gui/View/Adornment/Margin.cs | 4 ++-- Terminal.Gui/View/Layout/ViewLayout.cs | 4 ++-- Terminal.Gui/View/ViewScrollBar.cs | 2 ++ Terminal.Gui/Views/TextView.cs | 7 ------- UnitTests/View/FindDeepestViewTests.cs | 2 +- 8 files changed, 19 insertions(+), 30 deletions(-) diff --git a/Terminal.Gui/Application.cs b/Terminal.Gui/Application.cs index 932a5e5606..fe59e538a1 100644 --- a/Terminal.Gui/Application.cs +++ b/Terminal.Gui/Application.cs @@ -1481,7 +1481,7 @@ internal static void OnMouseEvent (MouseEventEventArgs a) View = view }; } - else if (view.BoundsToScreen (view.Bounds).Contains (a.MouseEvent.X, a.MouseEvent.Y)) + else if (view.BoundsToScreen (view.ContentArea).Contains (a.MouseEvent.X, a.MouseEvent.Y)) { Point boundsPoint = view.ScreenToBounds (a.MouseEvent.X, a.MouseEvent.Y); diff --git a/Terminal.Gui/View/Adornment/Adornment.cs b/Terminal.Gui/View/Adornment/Adornment.cs index fe35e2f9ae..5ce2abe829 100644 --- a/Terminal.Gui/View/Adornment/Adornment.cs +++ b/Terminal.Gui/View/Adornment/Adornment.cs @@ -22,7 +22,13 @@ public Adornment () /// Constructs a new adornment for the view specified by . /// - public Adornment (View parent) { Parent = parent; } + public Adornment (View parent) + { + Application.GrabbingMouse += Application_GrabbingMouse; + Application.UnGrabbingMouse += Application_UnGrabbingMouse; + CanFocus = true; + Parent = parent; + } /// /// Gets the rectangle that describes the area of the Adornment. The Location is always (0,0). @@ -30,10 +36,8 @@ public Adornment () /// public override Rectangle ContentArea { - Application.GrabbingMouse += Application_GrabbingMouse; - Application.UnGrabbingMouse += Application_UnGrabbingMouse; - CanFocus = true; - Parent = parent; + get => Frame with { Location = Point.Empty }; + set => throw new InvalidOperationException ("It makes no sense to set ContentArea of a Thickness."); } /// The Parent of this Adornment (the View this Adornment surrounds). @@ -111,16 +115,6 @@ internal override void LayoutAdornments () /* Do nothing - Adornments do not have Adornments */ } - /// - /// Gets the rectangle that describes the area of the Adornment. The Location is always (0,0). - /// The size is the size of the . - /// - public override Rectangle Bounds - { - get => Frame with { Location = Point.Empty }; - set => throw new InvalidOperationException ("It makes no sense to set Bounds of a Thickness."); - } - /// public override Rectangle FrameToScreen () { diff --git a/Terminal.Gui/View/Adornment/Border.cs b/Terminal.Gui/View/Adornment/Border.cs index 4deb0f5f03..7f814e8eaf 100644 --- a/Terminal.Gui/View/Adornment/Border.cs +++ b/Terminal.Gui/View/Adornment/Border.cs @@ -183,8 +183,8 @@ public LineStyle LineStyle set => _lineStyle = value; } - /// - public override Thickness GetAdornmentsThickness () { return Parent.Margin.Thickness; } + ///// + //public override Thickness GetAdornmentsThickness () { return Parent.Margin.Thickness; } /// public override void OnDrawContent (Rectangle contentArea) diff --git a/Terminal.Gui/View/Adornment/Margin.cs b/Terminal.Gui/View/Adornment/Margin.cs index aa7d7ef302..d6a8eef936 100644 --- a/Terminal.Gui/View/Adornment/Margin.cs +++ b/Terminal.Gui/View/Adornment/Margin.cs @@ -39,6 +39,6 @@ public override ColorScheme ColorScheme } } - /// - public override Thickness GetAdornmentsThickness () { return Thickness.Empty; } + ///// + //public override Thickness GetAdornmentsThickness () { return Thickness.Empty; } } diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 4630d4c5c1..6ec12a0453 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -599,7 +599,7 @@ private bool ResizeBoundsToFit (Size size) if (boundsChanged) { - Bounds = new (Bounds.X, Bounds.Y, canSizeW ? rW : Bounds.Width, canSizeH ? rH : Bounds.Height); + ContentArea = new (ContentArea.X, ContentArea.Y, canSizeW ? rW : ContentArea.Width, canSizeH ? rH : ContentArea.Height); } return boundsChanged; @@ -767,7 +767,7 @@ out StatusBar statusBar else { // Use the SuperView's Bounds, not Frame - maxDimension = viewToMove.SuperView.Bounds.Width; + maxDimension = viewToMove.SuperView.ContentArea.Width; superView = viewToMove.SuperView; } diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 3de09af4e2..2513e12800 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -5,6 +5,8 @@ public partial class View private bool _enableScrollBars; private ScrollBarView _scrollBar; private bool _useContentOffset; + private Point _contentOffset; + private Size _contentSize; /// If true the vertical/horizontal scroll bars won't be showed if it's not needed. public bool AutoHideScrollBars diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index baf351fd52..fdfdd76696 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -2582,13 +2582,6 @@ public bool AllowsTab /// public IAutocomplete Autocomplete { get; protected set; } = new TextViewAutocomplete (); - /// - public override bool CanFocus - { - get => base.CanFocus; - set => base.CanFocus = value; - } - /// public override Point ContentOffset { diff --git a/UnitTests/View/FindDeepestViewTests.cs b/UnitTests/View/FindDeepestViewTests.cs index e84926e113..3e21880b32 100644 --- a/UnitTests/View/FindDeepestViewTests.cs +++ b/UnitTests/View/FindDeepestViewTests.cs @@ -400,7 +400,7 @@ public void Returns_Correct_With_NestedSubViews (int testX, int testY, int expec [InlineData (5, 5, typeof (View), "start")] [InlineData (4, 4, typeof (View), "subview")] - public void Returns_Adornment_If_Start_Has_Adornments (int testX, int testY, Type expectedAdornmentType, string expectedParentName) + public void Returns_Adornment_If_Start_Has_Adornments_New (int testX, int testY, Type expectedAdornmentType, string expectedParentName) { var start = new View () { From 7dd476021d3440c558c98b802f3f0e33cf36b69f Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 16 Mar 2024 19:36:56 +0000 Subject: [PATCH 092/130] Remove nullable check. --- Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs index 22f6c91cab..4676dcf7ad 100644 --- a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs +++ b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs @@ -57,9 +57,7 @@ public override View HostControl /// public virtual int ScrollOffset { get; set; } -#nullable enable private Point? LastPopupPos { get; set; } -#nullable restore /// public override void EnsureSelectedIdxIsValid () From f1ddca4c9f169098d7a87f0e56c1e0fe5ea52858 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 16 Mar 2024 20:22:06 +0000 Subject: [PATCH 093/130] Replacing with original code. --- Terminal.Gui/View/Adornment/Adornment.cs | 3 +++ Terminal.Gui/View/Layout/ViewLayout.cs | 2 +- Terminal.Gui/View/View.cs | 4 +--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/View/Adornment/Adornment.cs b/Terminal.Gui/View/Adornment/Adornment.cs index 5ce2abe829..ac1fed592b 100644 --- a/Terminal.Gui/View/Adornment/Adornment.cs +++ b/Terminal.Gui/View/Adornment/Adornment.cs @@ -131,6 +131,9 @@ public override Rectangle FrameToScreen () return new (new (parent.X + Frame.X, parent.Y + Frame.Y), Frame.Size); } + /// + public override Point ScreenToFrame (int x, int y) { return Parent.ScreenToFrame (x - Frame.X, y - Frame.Y); } + /// /// Gets the rectangle that describes the inner area of the Adornment. The Location is always (0,0). /// diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 6ec12a0453..f8f94c77a6 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -969,7 +969,7 @@ public virtual void LayoutSubviews () } /// Indicates that the view does not need to be laid out. - protected void ClearLayoutNeeded () + protected void ClearLayoutNeeded () { LayoutNeeded = false; } { LayoutNeeded = false; } diff --git a/Terminal.Gui/View/View.cs b/Terminal.Gui/View/View.cs index 1162df9875..55beadae83 100644 --- a/Terminal.Gui/View/View.cs +++ b/Terminal.Gui/View/View.cs @@ -50,9 +50,7 @@ namespace Terminal.Gui; /// /// /// To create a View using Absolute layout, call a constructor that takes a Rectangle parameter to specify the -/// absolute position and size or simply set ). To create a View using Computed layout use -/// a constructor that does not take a Rectangle parameter and set the X, Y, Width and Height properties on the -/// view to +/// absolute position and size or simply set ). To create a View using Computed layout use view to /// non-absolute values. Both approaches use coordinates that are relative to the of the /// the View is added to. /// From 49ee62a17efbe61ebe1a19d50b9832cddb61560c Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 16 Mar 2024 20:50:57 +0000 Subject: [PATCH 094/130] Replace with original. --- Terminal.Gui/View/Layout/ViewLayout.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index f8f94c77a6..7e8896b8e8 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -970,9 +970,6 @@ public virtual void LayoutSubviews () /// Indicates that the view does not need to be laid out. protected void ClearLayoutNeeded () { LayoutNeeded = false; } - { - LayoutNeeded = false; - } /// /// Raises the event. Called from before all sub-views From 22145a5623ea25b99dfe54aac88b244eec730263 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 16 Mar 2024 20:58:36 +0000 Subject: [PATCH 095/130] Change Bounds to ContentArea. --- Terminal.Gui/Text/TextFormatter.cs | 5 +--- Terminal.Gui/Views/Slider.cs | 48 +++++++++++++++--------------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/Terminal.Gui/Text/TextFormatter.cs b/Terminal.Gui/Text/TextFormatter.cs index f6471b0c23..3aa9a37ff7 100644 --- a/Terminal.Gui/Text/TextFormatter.cs +++ b/Terminal.Gui/Text/TextFormatter.cs @@ -30,10 +30,7 @@ public TextAlignment Alignment /// Gets or sets whether the should be automatically changed to fit the . /// - /// - /// Used by to resize the view's to fit - /// . - /// + /// Used by to resize the view's to fit . /// /// AutoSize is ignored if and /// are used. diff --git a/Terminal.Gui/Views/Slider.cs b/Terminal.Gui/Views/Slider.cs index 49c0aee4b2..0ee5b17a39 100644 --- a/Terminal.Gui/Views/Slider.cs +++ b/Terminal.Gui/Views/Slider.cs @@ -778,34 +778,34 @@ public void SetBoundsBestFit () if (_config._sliderOrientation == Orientation.Horizontal) { ContentArea = new ( - ContentArea.Location, - new ( - int.Min ( - SuperView.ContentArea.Width - GetAdornmentsThickness ().Horizontal, - CalcBestLength () - ), - int.Min ( - SuperView.ContentArea.Height - GetAdornmentsThickness ().Vertical, - CalcThickness () - ) - ) - ); + ContentArea.Location, + new ( + int.Min ( + SuperView.ContentArea.Width - adornmentsThickness.Horizontal, + CalcBestLength () + ), + int.Min ( + SuperView.ContentArea.Height - adornmentsThickness.Vertical, + CalcThickness () + ) + ) + ); } else { ContentArea = new ( - ContentArea.Location, - new ( - int.Min ( - SuperView.ContentArea.Width - GetAdornmentsThickness ().Horizontal, - CalcThickness () - ), - int.Min ( - SuperView.ContentArea.Height - GetAdornmentsThickness ().Vertical, - CalcBestLength () - ) - ) - ); + ContentArea.Location, + new ( + int.Min ( + SuperView.ContentArea.Width - adornmentsThickness.Horizontal, + CalcThickness () + ), + int.Min ( + SuperView.ContentArea.Height - adornmentsThickness.Vertical, + CalcBestLength () + ) + ) + ); } } From 3f13027d53966abafa4bf3285d8296efaa3ed541 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 17 Mar 2024 21:31:38 +0000 Subject: [PATCH 096/130] Remove unnecessary code. --- Terminal.Gui/View/Layout/ViewLayout.cs | 24 ------------------------ Terminal.Gui/View/ViewDrawing.cs | 10 ---------- Terminal.Gui/View/ViewKeyboard.cs | 22 ---------------------- 3 files changed, 56 deletions(-) diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 7e8896b8e8..de3162cf17 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -1037,30 +1037,6 @@ internal void SetNeedsLayout () view.SetNeedsLayout (); } - if (Margin != null) - { - for (var i = 0; i < 3; i++) - { - Adornment adornment = i switch - { - 0 => Margin, - 1 => Border, - 2 => Padding, - _ => null - }; - - if (adornment != null) - { - adornment.SetNeedsLayout (); - - foreach (View view in adornment.Subviews) - { - view.SetNeedsLayout (); - } - } - } - } - TextFormatter.NeedsFormat = true; SuperView?.SetNeedsLayout (); } diff --git a/Terminal.Gui/View/ViewDrawing.cs b/Terminal.Gui/View/ViewDrawing.cs index 3f211ce1ce..411e48936d 100644 --- a/Terminal.Gui/View/ViewDrawing.cs +++ b/Terminal.Gui/View/ViewDrawing.cs @@ -576,16 +576,6 @@ protected virtual void ClearNeedsDisplay () { _needsDisplayRect = Rectangle.Empty; SubViewNeedsDisplay = false; - - if (Margin is { }) - { - Margin._needsDisplayRect = Rectangle.Empty; - Margin.SubViewNeedsDisplay = false; - Border._needsDisplayRect = Rectangle.Empty; - Border.SubViewNeedsDisplay = false; - Padding._needsDisplayRect = Rectangle.Empty; - Padding.SubViewNeedsDisplay = false; - } } // INTENT: Isn't this just intersection? It isn't used anyway. diff --git a/Terminal.Gui/View/ViewKeyboard.cs b/Terminal.Gui/View/ViewKeyboard.cs index 97aadbeb18..409f7de645 100644 --- a/Terminal.Gui/View/ViewKeyboard.cs +++ b/Terminal.Gui/View/ViewKeyboard.cs @@ -403,28 +403,6 @@ public bool NewKeyDownEvent (Key keyEvent) return true; } - // Check if adornments needs to handle the key - handled = Margin?.OnInvokingKeyBindings (keyEvent); - - if (handled != null && (bool)handled) - { - return true; - } - - handled = Border?.OnInvokingKeyBindings (keyEvent); - - if (handled != null && (bool)handled) - { - return true; - } - - handled = Padding?.OnInvokingKeyBindings (keyEvent); - - if (handled != null && (bool)handled) - { - return true; - } - // TODO: The below is not right. OnXXX handlers are supposed to fire the events. // TODO: But I've moved it outside of the v-function to test something. // After (fire the cancellable event) From bce4969273856df6e21748d4a95c83612c68a368 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 17 Mar 2024 21:33:42 +0000 Subject: [PATCH 097/130] Allow scroll bars using key bindings. --- Terminal.Gui/View/View.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Terminal.Gui/View/View.cs b/Terminal.Gui/View/View.cs index 55beadae83..c0a87e3ec7 100644 --- a/Terminal.Gui/View/View.cs +++ b/Terminal.Gui/View/View.cs @@ -201,6 +201,11 @@ public virtual void BeginInit () BeginInitAdornments (); + if (_scrollBar is null && UseContentOffset) + { + AddKeyBindingsForScrolling (); + } + if (_subviews?.Count > 0) { foreach (View view in _subviews) From 1aafb642444aa181cf2ee5a1880ce9f61752f400 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 17 Mar 2024 21:35:09 +0000 Subject: [PATCH 098/130] Sometimes setting the visibility may require layout subviews. --- Terminal.Gui/View/View.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Terminal.Gui/View/View.cs b/Terminal.Gui/View/View.cs index c0a87e3ec7..fdd11d1b01 100644 --- a/Terminal.Gui/View/View.cs +++ b/Terminal.Gui/View/View.cs @@ -369,6 +369,7 @@ public virtual bool Visible } OnVisibleChanged (); + SetNeedsLayout (); SetNeedsDisplay (); } } From f7dea464c2662ddb84cd14377cddba24341011a6 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 17 Mar 2024 22:02:57 +0000 Subject: [PATCH 099/130] Fix some bugs and improving the ScrollBarView. --- Terminal.Gui/Views/ScrollBarView.cs | 33 ++++++++++++++------------- UnitTests/Views/ScrollBarViewTests.cs | 4 +++- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index ffa02b0548..8e2b52ae07 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -155,6 +155,8 @@ public bool ShowScrollIndicator Visible = false; } + SetWidthHeight (); + SetNeedsLayout (); SetNeedsDisplay (); } } @@ -702,14 +704,14 @@ private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = fa { int barsize = scrollBarView._orientation == Orientation.Vertical ? scrollBarView.ContentArea.Height : scrollBarView.ContentArea.Width; - if (barsize == 0 || barsize >= scrollBarView.Size) + if (barsize == 0 || barsize - scrollBarView.Position >= scrollBarView.Size) { if (scrollBarView._showScrollIndicator && scrollBarView.Visible) { scrollBarView.Visible = false; } } - else if (barsize > 0 && barsize == scrollBarView.Size && scrollBarView.OtherScrollBarView is { } && pending) + else if (barsize > 0 && barsize - scrollBarView.Position == scrollBarView.Size && scrollBarView.OtherScrollBarView is { } && pending) { if (scrollBarView._showScrollIndicator && scrollBarView.Visible) { @@ -721,7 +723,7 @@ private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = fa scrollBarView.OtherScrollBarView.Visible = false; } } - else if (barsize > 0 && barsize == Size && scrollBarView.OtherScrollBarView is { } && !pending) + else if (barsize > 0 && barsize - scrollBarView.Position == Size && scrollBarView.OtherScrollBarView is { } && !pending) { pending = true; } @@ -791,7 +793,7 @@ private void CreateBottomRightCorner (View host) { if (host != null && ((_contentBottomRightCorner is null && OtherScrollBarView is null) - || (_contentBottomRightCorner is null && OtherScrollBarView is { } && OtherScrollBarView._contentBottomRightCorner is null))) + || (_contentBottomRightCorner is null && OtherScrollBarView is { _contentBottomRightCorner: null }))) { if (IsBuiltIn && !((Adornment)host).Parent.EnableScrollBars) { @@ -911,9 +913,6 @@ private void Parent_VisibleChanged (object sender, EventArgs e) private void ScrollBarView_Added (object sender, SuperViewChangedEventArgs e) { - X = Orientation == Orientation.Vertical ? Pos.AnchorEnd (1) : 0; - Y = Orientation == Orientation.Vertical ? 0 : Pos.AnchorEnd (1); - if (OtherScrollBarView is { SuperView: null } && !e.Parent.Subviews.Contains (OtherScrollBarView)) { e.Parent.Add (OtherScrollBarView); @@ -921,7 +920,7 @@ private void ScrollBarView_Added (object sender, SuperViewChangedEventArgs e) CreateBottomRightCorner (e.Parent); - View parent = e.Parent is Adornment ? ((Adornment)e.Parent).Parent : e.Parent; + View parent = e.Parent is Adornment adornment ? adornment.Parent : e.Parent; //e.Parent.CanFocusChanged += Host_CanFocusChanged; parent.EnabledChanged += Parent_EnabledChanged; @@ -935,6 +934,9 @@ private void ScrollBarView_Added (object sender, SuperViewChangedEventArgs e) private void ScrollBarView_Initialized (object sender, EventArgs e) { + X = Orientation == Orientation.Vertical ? Pos.AnchorEnd (1) : 0; + Y = Orientation == Orientation.Vertical ? 0 : Pos.AnchorEnd (1); + SetWidthHeight (); ShowHideScrollBars (); @@ -1003,18 +1005,17 @@ private void SetWidthHeight () _otherScrollBarView.Height = _otherScrollBarView._orientation == Orientation.Vertical ? SuperView is Adornment ? Dim.Fill (1) : bounds.Height - 1 : 1; + + _contentBottomRightCorner.X = bounds.Right - 1; + _contentBottomRightCorner.Y = bounds.Bottom - 1; } else { - Width = _orientation == Orientation.Vertical ? 1 : SuperView is Adornment ? Dim.Fill (1) : Dim.Fill (1); - Height = _orientation == Orientation.Vertical ? SuperView is Adornment ? Dim.Fill (1) : Dim.Fill (1) : 1; - - _otherScrollBarView.Width = _otherScrollBarView._orientation == Orientation.Vertical ? 1 : - SuperView is Adornment ? Dim.Fill (1) : Dim.Fill (1); + Width = _orientation == Orientation.Vertical ? 1 : Dim.Fill (1); + Height = _orientation == Orientation.Vertical ? Dim.Fill (1) : 1; - _otherScrollBarView.Height = _otherScrollBarView._orientation == Orientation.Vertical - ? SuperView is Adornment ? Dim.Fill (1) : Dim.Fill (1) - : 1; + _otherScrollBarView.Width = _otherScrollBarView._orientation == Orientation.Vertical ? 1 : Dim.Fill (1); + _otherScrollBarView.Height = _otherScrollBarView._orientation == Orientation.Vertical ? Dim.Fill (1) : 1; } } else if (Visible) diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index a1d35c22bd..9c22880ff8 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -1017,6 +1017,7 @@ public void KeepContentAlwaysInViewport_False_True_With_Both_ShowScrollBars_Fals _scrollBar.OtherScrollBarView.ShowScrollIndicator = false; _scrollBar.KeepContentAlwaysInViewPort = true; + Assert.Equal(new (79, 0, 1, 24), _scrollBar.Frame); Assert.Equal (_scrollBar.Position, _scrollBar.Size - _scrollBar.ContentArea.Height - 1); Assert.Equal (_scrollBar.Position, _hostView.Top); Assert.Equal (5, _scrollBar.Position); @@ -1026,9 +1027,10 @@ public void KeepContentAlwaysInViewport_False_True_With_Both_ShowScrollBars_Fals Assert.False (_scrollBar.Visible); Assert.False (_scrollBar.OtherScrollBarView.Visible); + Assert.Equal(new (0, 24, 80, 1), _scrollBar.OtherScrollBarView.Frame); Assert.Equal ( _scrollBar.OtherScrollBarView.Position, - _scrollBar.OtherScrollBarView.Size - _scrollBar.OtherScrollBarView.ContentArea.Width - 1 + _scrollBar.OtherScrollBarView.Size - _scrollBar.OtherScrollBarView.ContentArea.Width ); Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); Assert.Equal (20, _scrollBar.OtherScrollBarView.Position); From 8e4efcf65b3837aea1aad91f4d6e69784a75f24d Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 17 Mar 2024 22:05:46 +0000 Subject: [PATCH 100/130] Add scroll bar to the ClassExplorer scenario. --- UICatalog/Scenarios/ClassExplorer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/UICatalog/Scenarios/ClassExplorer.cs b/UICatalog/Scenarios/ClassExplorer.cs index 389310111d..d5d545925b 100644 --- a/UICatalog/Scenarios/ClassExplorer.cs +++ b/UICatalog/Scenarios/ClassExplorer.cs @@ -58,6 +58,7 @@ public override void Setup () Application.Top.Add (menu); _treeView = new TreeView { X = 0, Y = 1, Width = Dim.Percent (50), Height = Dim.Fill () }; + _treeView.Padding.EnableScrollBars = true; var lblSearch = new Label { Text = "Search" }; var tfSearch = new TextField { Width = 20, X = Pos.Right (lblSearch) }; @@ -85,7 +86,7 @@ public override void Setup () Win.Add (_treeView); - _textView = new TextView { X = Pos.Right (_treeView), Y = 0, Width = Dim.Fill (), Height = Dim.Fill () }; + _textView = new TextView { X = Pos.Right (_treeView) + 1, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () }; Win.Add (_textView); } From 89e1bf9c779dea75ef61aaa4c59756c1ed3956bd Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 17 Mar 2024 22:07:29 +0000 Subject: [PATCH 101/130] Fix and add more unit tests. --- UnitTests/View/Adornment/AdornmentTests.cs | 6 ++--- UnitTests/View/FindDeepestViewTests.cs | 31 ++++++++++++---------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/UnitTests/View/Adornment/AdornmentTests.cs b/UnitTests/View/Adornment/AdornmentTests.cs index 7f8b132dff..bcbcad59a6 100644 --- a/UnitTests/View/Adornment/AdornmentTests.cs +++ b/UnitTests/View/Adornment/AdornmentTests.cs @@ -613,9 +613,9 @@ public void GetAdornmentsThickness_On_Adornments () view.Padding.Thickness = new Thickness (1); Assert.Equal (new Thickness (3, 3, 3, 3), view.GetAdornmentsThickness ()); - Assert.Equal (Thickness.Empty, view.Margin.GetAdornmentsThickness ()); - Assert.Equal (new Thickness (1), view.Border.GetAdornmentsThickness ()); - Assert.Equal (new Thickness (2), view.Padding.GetAdornmentsThickness ()); + Assert.Equal (new Thickness (1), view.Margin.Thickness); + Assert.Equal (new Thickness (1), view.Border.Thickness); + Assert.Equal (new Thickness (1), view.Padding.Thickness); view.Dispose (); } diff --git a/UnitTests/View/FindDeepestViewTests.cs b/UnitTests/View/FindDeepestViewTests.cs index 3e21880b32..62c84c2092 100644 --- a/UnitTests/View/FindDeepestViewTests.cs +++ b/UnitTests/View/FindDeepestViewTests.cs @@ -312,10 +312,13 @@ public void Returns_Adornment_If_Start_Has_Adornments (int testX, int testY, Typ [InlineData (7, 8, false)] [InlineData (6, 7, false)] [InlineData (1, 2, false)] + [InlineData (2, 6, false)] [InlineData (5, 6, false)] [InlineData (2, 3, true)] - [InlineData (5, 6, true)] + [InlineData (2, 4, true)] + [InlineData (2, 5, true)] + [InlineData (4, 5, true)] public void Returns_Correct_If_SubView_Has_Adornments (int testX, int testY, bool expectedSubViewFound) { var start = new View () @@ -378,20 +381,20 @@ public void Returns_Correct_With_NestedSubViews (int testX, int testY, int expec } [Theory] - [InlineData (0, 0, typeof (View), "start")] - [InlineData (0, 1, typeof (View), "start")] - [InlineData (9, 1, typeof (View), "start")] - [InlineData (9, 9, typeof (View), "start")] + [InlineData (0, 0, typeof (Margin), "start")] + [InlineData (0, 1, typeof (Margin), "start")] + [InlineData (9, 1, typeof (Margin), "start")] + [InlineData (9, 9, typeof (Margin), "start")] - [InlineData (1, 1, typeof (View), "start")] - [InlineData (1, 2, typeof (View), "start")] - [InlineData (8, 1, typeof (View), "start")] - [InlineData (8, 8, typeof (View), "start")] + [InlineData (1, 1, typeof (Border), "start")] + [InlineData (1, 2, typeof (Border), "start")] + [InlineData (8, 1, typeof (Border), "start")] + [InlineData (8, 8, typeof (Border), "start")] - [InlineData (2, 2, typeof (View), "start")] - [InlineData (2, 3, typeof (View), "start")] - [InlineData (7, 2, typeof (View), "start")] - [InlineData (7, 7, typeof (View), "start")] + [InlineData (2, 2, typeof (Padding), "start")] + [InlineData (2, 3, typeof (Padding), "start")] + [InlineData (7, 2, typeof (Padding), "start")] + [InlineData (7, 7, typeof (Padding), "start")] [InlineData (3, 3, typeof (View), "start")] [InlineData (3, 4, typeof (View), "start")] @@ -400,7 +403,7 @@ public void Returns_Correct_With_NestedSubViews (int testX, int testY, int expec [InlineData (5, 5, typeof (View), "start")] [InlineData (4, 4, typeof (View), "subview")] - public void Returns_Adornment_If_Start_Has_Adornments_New (int testX, int testY, Type expectedAdornmentType, string expectedParentName) + public void Returns_Adornment_If_Start_Has_Adornments_Using_All_Adornments (int testX, int testY, Type expectedAdornmentType, string expectedParentName) { var start = new View () { From 2e1c2cd62fde263ffa2d90c730ba3aa9fdd9b468 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 17 Mar 2024 22:14:44 +0000 Subject: [PATCH 102/130] Change the AllViewsTests unit test to handle ScrollBarView differently. --- UnitTests/Views/AllViewsTests.cs | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/UnitTests/Views/AllViewsTests.cs b/UnitTests/Views/AllViewsTests.cs index 8beb983e3a..a5dbe0ce47 100644 --- a/UnitTests/Views/AllViewsTests.cs +++ b/UnitTests/Views/AllViewsTests.cs @@ -42,17 +42,29 @@ public void AllViews_Center_Properly (View view, string viewName) int expectedX = (frame.Frame.Width - view.Frame.Width) / 2; int expectedY = (frame.Frame.Height - view.Frame.Height) / 2; - Assert.True ( - view.Frame.Left == expectedX, - $"{view} did not center horizontally. Expected: {expectedX}. Actual: {view.Frame.Left}" - ); - - Assert.True ( - view.Frame.Top == expectedY, - $"{view} did not center vertically. Expected: {expectedY}. Actual: {view.Frame.Top}" - ); - Application.Shutdown (); + if (view is ScrollBarView) + { + output.WriteLine ($"It's a {viewName} - It has its own Pos/Dim calculation"); + expectedX = frame.Frame.Width - view.Frame.Width; + expectedY = frame.Frame.Bottom - view.Frame.Height; + Assert.True (view.Frame.Left == expectedX); + Assert.True (view.Frame.Top == expectedY); + } + else + { + Assert.True ( + view.Frame.Left == expectedX, + $"{view} did not center horizontally. Expected: {expectedX}. Actual: {view.Frame.Left}" + ); + + Assert.True ( + view.Frame.Top == expectedY, + $"{view} did not center vertically. Expected: {expectedY}. Actual: {view.Frame.Top}" + ); + + } + Application.Shutdown (); } [Fact] From b7c838fbe5d868d663f9d1394501f90010f71935 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 17 Mar 2024 23:15:34 +0000 Subject: [PATCH 103/130] Replacing with original code as possible. --- .../Text/Autocomplete/PopupAutocomplete.cs | 2 ++ Terminal.Gui/View/Adornment/Border.cs | 3 --- Terminal.Gui/View/Adornment/Margin.cs | 3 --- Terminal.Gui/View/View.cs | 7 ++--- Terminal.Gui/View/ViewText.cs | 27 +++++++++---------- 5 files changed, 19 insertions(+), 23 deletions(-) diff --git a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs index 4676dcf7ad..ada8c9b0cd 100644 --- a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs +++ b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs @@ -57,7 +57,9 @@ public override View HostControl /// public virtual int ScrollOffset { get; set; } + #nullable enable private Point? LastPopupPos { get; set; } + #nullable restore /// public override void EnsureSelectedIdxIsValid () diff --git a/Terminal.Gui/View/Adornment/Border.cs b/Terminal.Gui/View/Adornment/Border.cs index 7f814e8eaf..23174acb3f 100644 --- a/Terminal.Gui/View/Adornment/Border.cs +++ b/Terminal.Gui/View/Adornment/Border.cs @@ -183,9 +183,6 @@ public LineStyle LineStyle set => _lineStyle = value; } - ///// - //public override Thickness GetAdornmentsThickness () { return Parent.Margin.Thickness; } - /// public override void OnDrawContent (Rectangle contentArea) { diff --git a/Terminal.Gui/View/Adornment/Margin.cs b/Terminal.Gui/View/Adornment/Margin.cs index d6a8eef936..ca2142fc00 100644 --- a/Terminal.Gui/View/Adornment/Margin.cs +++ b/Terminal.Gui/View/Adornment/Margin.cs @@ -38,7 +38,4 @@ public override ColorScheme ColorScheme Parent?.SetNeedsDisplay (); } } - - ///// - //public override Thickness GetAdornmentsThickness () { return Thickness.Empty; } } diff --git a/Terminal.Gui/View/View.cs b/Terminal.Gui/View/View.cs index fdd11d1b01..6e3d467546 100644 --- a/Terminal.Gui/View/View.cs +++ b/Terminal.Gui/View/View.cs @@ -45,12 +45,13 @@ namespace Terminal.Gui; /// View supports two layout styles: or . /// The style is determined by the values of , , , and /// . If any of these is set to non-absolute or object, -/// then the layout style is . Otherwise it is +/// then the layout style is . Otherwise, it is /// . /// /// -/// To create a View using Absolute layout, call a constructor that takes a Rectangle parameter to specify the -/// absolute position and size or simply set ). To create a View using Computed layout use view to +/// To create a View using Absolute layout, call a constructor that takes a Rect parameter to specify the +/// absolute position and size or simply set . To create a View using Computed layout use +/// a constructor that does not take a Rect parameter and set the X, Y, Width and Height properties on the view to /// non-absolute values. Both approaches use coordinates that are relative to the of the /// the View is added to. /// diff --git a/Terminal.Gui/View/ViewText.cs b/Terminal.Gui/View/ViewText.cs index d49caffe1c..6ab061008a 100644 --- a/Terminal.Gui/View/ViewText.cs +++ b/Terminal.Gui/View/ViewText.cs @@ -30,8 +30,7 @@ public virtual bool PreserveTrailingSpaces /// and . /// /// - /// The text will word-wrap to additional lines if it does not fit horizontally. If 's - /// height + /// The text will word-wrap to additional lines if it does not fit horizontally. If 's height /// is 1, the text will be clipped. /// /// If is true, the will be adjusted to fit the text. @@ -61,6 +60,18 @@ public virtual string Text } } + /// + /// Called when the has changed. Fires the event. + /// + /// + /// + public void OnTextChanged (string oldValue, string newValue) { TextChanged?.Invoke (this, new StateEventArgs (oldValue, newValue)); } + + /// + /// Text changed event, raised when the text has changed. + /// + public event EventHandler> TextChanged; + /// /// Gets or sets how the View's is aligned horizontally when drawn. Changing this property will /// redisplay the . @@ -191,18 +202,6 @@ public int GetHotKeySpecifierLength (bool isWidth = true) : 0; } - /// - /// Called when the has changed. Fires the event. - /// - /// - /// - public void OnTextChanged (string oldValue, string newValue) { TextChanged?.Invoke (this, new StateEventArgs (oldValue, newValue)); } - - /// - /// Text changed event, raised when the text has changed. - /// - public event EventHandler> TextChanged; - /// Can be overridden if the has different format than the default. protected virtual void UpdateTextFormatterText () { From 7e3c611fd8e1ec758fa725886e9ced583412948e Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 17 Mar 2024 23:48:38 +0000 Subject: [PATCH 104/130] Change Bounds to ContentArea. --- Terminal.Gui/Input/Mouse.cs | 6 +++--- Terminal.Gui/View/Adornment/Adornment.cs | 2 +- Terminal.Gui/View/Adornment/Padding.cs | 2 +- Terminal.Gui/View/Layout/ViewLayout.cs | 14 +++++++------- Terminal.Gui/View/ViewAdornments.cs | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Terminal.Gui/Input/Mouse.cs b/Terminal.Gui/Input/Mouse.cs index f8225c9bf2..4a7b84c9ae 100644 --- a/Terminal.Gui/Input/Mouse.cs +++ b/Terminal.Gui/Input/Mouse.cs @@ -116,10 +116,10 @@ public class MouseEvent /// The View at the location for the mouse event. public View View { get; set; } - /// The X position of the mouse in -relative coordinates. + /// The X position of the mouse in -relative coordinates. public int X { get; set; } - /// The Y position of the mouse in -relative coordinates. + /// The Y position of the mouse in -relative coordinates. public int Y { get; set; } /// @@ -133,7 +133,7 @@ public class MouseEvent /// /// /// - /// The and properties are always -relative. When the mouse is grabbed by a view, + /// The and properties are always -relative. When the mouse is grabbed by a view, /// provides the mouse position screen-relative coordinates, enabling the grabbed view to know how much the /// mouse has moved. /// diff --git a/Terminal.Gui/View/Adornment/Adornment.cs b/Terminal.Gui/View/Adornment/Adornment.cs index ac1fed592b..cecf0cc575 100644 --- a/Terminal.Gui/View/Adornment/Adornment.cs +++ b/Terminal.Gui/View/Adornment/Adornment.cs @@ -239,7 +239,7 @@ protected internal override bool OnMouseEnter (MouseEvent mouseEvent) /// Called when a mouse event occurs within the Adornment. /// /// - /// The coordinates are relative to . + /// The coordinates are relative to . /// /// /// A mouse click on the Adornment will cause the Parent to focus. diff --git a/Terminal.Gui/View/Adornment/Padding.cs b/Terminal.Gui/View/Adornment/Padding.cs index 3c2a645c12..9a04676aec 100644 --- a/Terminal.Gui/View/Adornment/Padding.cs +++ b/Terminal.Gui/View/Adornment/Padding.cs @@ -42,7 +42,7 @@ public override ColorScheme ColorScheme /// Called when a mouse event occurs within the Padding. /// /// - /// The coordinates are relative to . + /// The coordinates are relative to . /// /// /// A mouse click on the Padding will cause the Parent to focus. diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index de3162cf17..fcf3b5b2ff 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -42,10 +42,10 @@ public partial class View /// Gets or sets the absolute location and dimension of the view. /// /// The rectangle describing absolute location and dimension of the view, in coordinates relative to the - /// 's . + /// 's . /// /// - /// Frame is relative to the 's . + /// Frame is relative to the 's . /// /// Setting Frame will set , , , and to the /// values of the corresponding properties of the parameter. @@ -113,9 +113,9 @@ public virtual Rectangle FrameToScreen () /// /// Converts a screen-relative coordinate to a Frame-relative coordinate. Frame-relative means relative to the - /// View's 's . + /// View's 's . /// - /// The coordinate relative to the 's . + /// The coordinate relative to the 's . /// Screen-relative column. /// Screen-relative row. public virtual Point ScreenToFrame (int x, int y) @@ -363,7 +363,7 @@ public virtual Rectangle ContentArea } } - /// Converts a -relative rectangle to a screen-relative rectangle. + /// Converts a -relative rectangle to a screen-relative rectangle. public Rectangle BoundsToScreen (in Rectangle bounds) { // Translate bounds to Frame (our SuperView's Bounds-relative coordinates) @@ -375,7 +375,7 @@ public Rectangle BoundsToScreen (in Rectangle bounds) } /// Converts a screen-relative coordinate to a bounds-relative coordinate. - /// The coordinate relative to this view's . + /// The coordinate relative to this view's . /// Screen-relative column. /// Screen-relative row. public Point ScreenToBounds (int x, int y) @@ -401,7 +401,7 @@ public Point ScreenToBounds (int x, int y) /// /// Gets or sets a flag that determines whether the View will be automatically resized to fit the - /// within . + /// within . /// /// The default is . Set to to turn on AutoSize. If /// then and will be used if can diff --git a/Terminal.Gui/View/ViewAdornments.cs b/Terminal.Gui/View/ViewAdornments.cs index 5cf0364394..a55e1148d6 100644 --- a/Terminal.Gui/View/ViewAdornments.cs +++ b/Terminal.Gui/View/ViewAdornments.cs @@ -39,7 +39,7 @@ private void DisposeAdornments () /// /// The that enables separation of a View from other SubViews of the same - /// SuperView. The margin offsets the from the . + /// SuperView. The margin offsets the from the . /// /// /// @@ -55,7 +55,7 @@ private void DisposeAdornments () public Margin Margin { get; private set; } /// - /// The that offsets the from the . + /// The that offsets the from the . /// The Border provides the space for a visual border (drawn using /// line-drawing glyphs) and the Title. The Border expands inward; in other words if `Border.Thickness.Top == 2` the /// border and title will take up the first row and the second row will be filled with spaces. @@ -113,7 +113,7 @@ public LineStyle BorderStyle } /// - /// The inside of the view that offsets the + /// The inside of the view that offsets the /// from the . /// /// From 16214c8fb9a45b7d7c2cc5fdedee19b3ebca2bce Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 17 Mar 2024 22:46:44 +0000 Subject: [PATCH 105/130] Break the loop if the superview is found. --- Terminal.Gui/Views/ScrollView.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index 208bd57fa9..36c65b1e34 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -145,6 +145,8 @@ private void Application_UnGrabbedMouse (object sender, ViewEventArgs e) if (supView == _contentView) { Application.GrabMouse (this); + + break; } supView = supView.SuperView; From c44cf399cb61a35f9545dfab9a1ebd0e127e0d99 Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 18 Mar 2024 21:59:49 +0000 Subject: [PATCH 106/130] Set properties on both scroll bars at once. --- Terminal.Gui/Views/ScrollBarView.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index 8e2b52ae07..bb056d6998 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -57,6 +57,11 @@ public bool AutoHideScrollBars _autoHideScrollBars = value; Visible = _showScrollIndicator; SetNeedsDisplay (); + + if (OtherScrollBarView is { } && OtherScrollBarView._autoHideScrollBars != value) + { + OtherScrollBarView.AutoHideScrollBars = value; + } } } } @@ -71,6 +76,11 @@ public bool KeepContentAlwaysInViewPort { _keepContentAlwaysInViewport = value; + if (OtherScrollBarView is { } && OtherScrollBarView._keepContentAlwaysInViewport != value) + { + OtherScrollBarView.KeepContentAlwaysInViewPort = value; + } + AdjustContentInViewport (); } } From f0109bb7329cf11fc4cb7e58b1222f76349d1046 Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 18 Mar 2024 22:03:09 +0000 Subject: [PATCH 107/130] Improves ShowScrollIndicator iteration with the AutoHideScrollBars. --- Terminal.Gui/Views/ScrollBarView.cs | 47 ++++++------ Terminal.Gui/Views/ScrollView.cs | 14 ++-- UnitTests/Views/ScrollBarViewTests.cs | 102 +++++++++++++++++++++----- UnitTests/Views/ScrollViewTests.cs | 4 +- 4 files changed, 119 insertions(+), 48 deletions(-) diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index bb056d6998..b029966d32 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -146,23 +146,25 @@ public int Position } // BUGBUG: v2 - Why can't we get rid of this and just use Visible? - // We need this property to distinguish from Visible which will also affect the parent - /// Gets or sets the visibility for the vertical or horizontal scroll indicator. + // We need this property to distinguish from Visible value and the original value of this property + /// + /// Gets or sets the visibility for the vertical or horizontal scroll indicator. + /// If is true the visibility will be handled as needed, + /// no matter ShowScrollIndicator is true or false. It's a flag that indicates the original state. + /// If is false and ShowScrollIndicator is false it'll + /// be not visible, otherwise it will be always visible even it isn't needed. + /// /// true if show vertical or horizontal scroll indicator; otherwise, false. public bool ShowScrollIndicator { - get => _showScrollIndicator; + get => Visible; set { _showScrollIndicator = value; - if (value) - { - Visible = true; - } - else + if (!AutoHideScrollBars) { - Visible = false; + Visible = value; } SetWidthHeight (); @@ -712,23 +714,28 @@ private void AdjustContentInViewport (bool refresh = true) private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = false) { + if (!AutoHideScrollBars) + { + return false; + } + int barsize = scrollBarView._orientation == Orientation.Vertical ? scrollBarView.ContentArea.Height : scrollBarView.ContentArea.Width; if (barsize == 0 || barsize - scrollBarView.Position >= scrollBarView.Size) { - if (scrollBarView._showScrollIndicator && scrollBarView.Visible) + if (scrollBarView.Visible) { scrollBarView.Visible = false; } } else if (barsize > 0 && barsize - scrollBarView.Position == scrollBarView.Size && scrollBarView.OtherScrollBarView is { } && pending) { - if (scrollBarView._showScrollIndicator && scrollBarView.Visible) + if (scrollBarView.Visible) { scrollBarView.Visible = false; } - if (scrollBarView.OtherScrollBarView is { } && scrollBarView.ShowBothScrollIndicator && scrollBarView.OtherScrollBarView.Visible) + if (scrollBarView.OtherScrollBarView is { Visible: true }) { scrollBarView.OtherScrollBarView.Visible = false; } @@ -742,14 +749,13 @@ private bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = fa if (scrollBarView.OtherScrollBarView is { } && pending) { if (!scrollBarView.ShowBothScrollIndicator - && scrollBarView.OtherScrollBarView._showScrollIndicator && !scrollBarView.OtherScrollBarView.Visible) { scrollBarView.OtherScrollBarView.Visible = true; } } - if (scrollBarView._showScrollIndicator && !scrollBarView.Visible) + if (!scrollBarView.Visible) { scrollBarView.Visible = true; } @@ -1079,15 +1085,12 @@ private void ShowHideScrollBars () SetRelativeLayout (SuperView?.GetVisibleContentArea () ?? Rectangle.Empty); - if (AutoHideScrollBars) - { - bool pending = CheckBothScrollBars (this); + bool pending = CheckBothScrollBars (this); - if (_otherScrollBarView is { }) - { - _otherScrollBarView.SetRelativeLayout (SuperView?.GetVisibleContentArea () ?? Rectangle.Empty); - CheckBothScrollBars (_otherScrollBarView, pending); - } + if (_otherScrollBarView is { }) + { + _otherScrollBarView.SetRelativeLayout (SuperView?.GetVisibleContentArea () ?? Rectangle.Empty); + CheckBothScrollBars (_otherScrollBarView, pending); } SetWidthHeight (); diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index 36c65b1e34..50e09e6ccb 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -33,6 +33,8 @@ public class ScrollView : View private View _contentBottomRightCorner; private Point _contentOffset; private Size _contentSize; + private bool _showHorizontalScrollIndicator; + private bool _showVerticalScrollIndicator; /// /// Initializes a new instance of the class using @@ -229,12 +231,12 @@ public bool KeepContentAlwaysInViewPort /// true if show horizontal scroll indicator; otherwise, false. public bool ShowHorizontalScrollIndicator { - get => _horizontal.ShowScrollIndicator; + get => _horizontal.Visible; set { - if (value != _horizontal.ShowScrollIndicator) + if (value != _showHorizontalScrollIndicator) { - _horizontal.ShowScrollIndicator = value; + _showHorizontalScrollIndicator = _horizontal.ShowScrollIndicator = value; SetNeedsLayout (); if (value) @@ -268,12 +270,12 @@ public bool ShowHorizontalScrollIndicator /// true if show vertical scroll indicator; otherwise, false. public bool ShowVerticalScrollIndicator { - get => _vertical.ShowScrollIndicator; + get => _vertical.Visible; set { - if (value != _vertical.ShowScrollIndicator) + if (value != _showVerticalScrollIndicator) { - _vertical.ShowScrollIndicator = value; + _showVerticalScrollIndicator = _vertical.ShowScrollIndicator = value; SetNeedsLayout (); if (value) diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index 9c22880ff8..c749b08568 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -44,7 +44,7 @@ public void AutoHideScrollBars_Check () _hostView.Lines = 10; _hostView.Draw (); - Assert.True (_scrollBar.ShowScrollIndicator); + Assert.False (_scrollBar.ShowScrollIndicator); Assert.False (_scrollBar.Visible); Assert.Equal ("Absolute(1)", _scrollBar.Width.ToString ()); Assert.Equal (1, _scrollBar.ContentArea.Width); @@ -67,7 +67,7 @@ public void AutoHideScrollBars_Check () _hostView.Cols = 60; _hostView.Draw (); - Assert.True (_scrollBar.ShowScrollIndicator); + Assert.False (_scrollBar.ShowScrollIndicator); Assert.False (_scrollBar.Visible); Assert.Equal ("Absolute(1)", _scrollBar.Width.ToString ()); Assert.Equal (1, _scrollBar.ContentArea.Width); @@ -77,7 +77,7 @@ public void AutoHideScrollBars_Check () _scrollBar.Height.ToString () ); Assert.Equal (24, _scrollBar.ContentArea.Height); - Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.False (_scrollBar.OtherScrollBarView.ShowScrollIndicator); Assert.False (_scrollBar.OtherScrollBarView.Visible); Assert.Equal ( @@ -100,7 +100,7 @@ public void AutoHideScrollBars_Check () _scrollBar.Height.ToString () ); Assert.Equal (25, _scrollBar.ContentArea.Height); - Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.False (_scrollBar.OtherScrollBarView.ShowScrollIndicator); Assert.False (_scrollBar.OtherScrollBarView.Visible); Assert.Equal ( @@ -408,11 +408,21 @@ public void Source = new ListWrapper (source) }; listView.Padding.EnableScrollBars = true; + // Only this won't avoid the VerticalScrollBar from showing because + // AutoHideScrollBars is true and control the visibility of the VerticalScrollBar listView.Padding.ShowVerticalScrollBar = false; win.Add (listView); + Assert.True (listView.AutoHideScrollBars); + Assert.True (listView.ShowVerticalScrollBar); + Assert.True (listView.ShowHorizontalScrollBar); Assert.True (listView.KeepContentAlwaysInContentArea); + // To hide the VerticalScrollBar it's also needed to set AutoHideScrollBars to false + listView.AutoHideScrollBars = false; + Assert.False (listView.ShowVerticalScrollBar); + Assert.True (listView.ShowHorizontalScrollBar); + var newScrollBarView = listView.Padding.Subviews [0] as ScrollBarView; newScrollBarView!.ChangedPosition += (s, e) => @@ -581,8 +591,8 @@ This is a tes▼ sbv.OtherScrollBarView.Size = 0; Assert.Equal (0, sbv.Size); Assert.Equal (0, sbv.OtherScrollBarView.Size); - Assert.True (sbv.ShowScrollIndicator); - Assert.True (sbv.OtherScrollBarView.ShowScrollIndicator); + Assert.False (sbv.ShowScrollIndicator); + Assert.False (sbv.OtherScrollBarView.ShowScrollIndicator); Assert.False (sbv.Visible); Assert.False (sbv.OtherScrollBarView.Visible); Application.Top.Draw (); @@ -654,7 +664,7 @@ This is a tes▼ sbv.Size = 0; Assert.Equal (0, sbv.Size); - Assert.True (sbv.ShowScrollIndicator); + Assert.False (sbv.ShowScrollIndicator); Assert.False (sbv.Visible); Application.Top.Draw (); @@ -761,8 +771,10 @@ public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () var scrollBar = textView.Padding.Subviews [0] as ScrollBarView; Assert.True (scrollBar.AutoHideScrollBars); - Assert.True (scrollBar.ShowScrollIndicator); - Assert.True (scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.False (scrollBar.ShowScrollIndicator); + Assert.False (scrollBar.Visible); + Assert.False (scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.False (scrollBar.OtherScrollBarView.Visible); Assert.Equal (5, textView.Lines); // The length is one more for the cursor on the last column of the line @@ -1008,33 +1020,49 @@ public void KeepContentAlwaysInViewport_False_True_With_Both_ShowScrollBars_Fals { KeepContentAlwaysInViewport_False (); + Assert.True (_scrollBar.AutoHideScrollBars); Assert.True (_scrollBar.ShowScrollIndicator); Assert.True (_scrollBar.Visible); Assert.True(_scrollBar.OtherScrollBarView.ShowScrollIndicator); Assert.True (_scrollBar.OtherScrollBarView.Visible); Assert.False(_scrollBar.KeepContentAlwaysInViewPort); + // Only this won't avoid the ShowScrollIndicator from showing because + // AutoHideScrollBars is true and control their visibility _scrollBar.ShowScrollIndicator = false; _scrollBar.OtherScrollBarView.ShowScrollIndicator = false; _scrollBar.KeepContentAlwaysInViewPort = true; + Assert.True (_scrollBar.ShowScrollIndicator); + Assert.True (_scrollBar.Visible); + Assert.True(_scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.True (_scrollBar.OtherScrollBarView.Visible); + + // To hide the scroll bars it's also needed to set AutoHideScrollBars to false + _scrollBar.AutoHideScrollBars = false; + Assert.False (_scrollBar.ShowScrollIndicator); + Assert.False (_scrollBar.Visible); + Assert.False(_scrollBar.OtherScrollBarView.ShowScrollIndicator); + Assert.False (_scrollBar.OtherScrollBarView.Visible); + // The scroll bar is not visible, so the Frame is irrelevant Assert.Equal(new (79, 0, 1, 24), _scrollBar.Frame); - Assert.Equal (_scrollBar.Position, _scrollBar.Size - _scrollBar.ContentArea.Height - 1); + Assert.Equal (_scrollBar.Position, _scrollBar.Size - _scrollBar.ContentArea.Height); Assert.Equal (_scrollBar.Position, _hostView.Top); - Assert.Equal (5, _scrollBar.Position); - Assert.Equal (5, _hostView.Top); + Assert.Equal (6, _scrollBar.Position); + Assert.Equal (6, _hostView.Top); Assert.False (_scrollBar.ShowScrollIndicator); Assert.False (_scrollBar.OtherScrollBarView.ShowScrollIndicator); Assert.False (_scrollBar.Visible); Assert.False (_scrollBar.OtherScrollBarView.Visible); - Assert.Equal(new (0, 24, 80, 1), _scrollBar.OtherScrollBarView.Frame); + // The scroll bar is not visible, so the Frame is irrelevant + Assert.Equal(new (0, 24, 79, 1), _scrollBar.OtherScrollBarView.Frame); Assert.Equal ( _scrollBar.OtherScrollBarView.Position, _scrollBar.OtherScrollBarView.Size - _scrollBar.OtherScrollBarView.ContentArea.Width ); Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left); - Assert.Equal (20, _scrollBar.OtherScrollBarView.Position); - Assert.Equal (20, _hostView.Left); + Assert.Equal (21, _scrollBar.OtherScrollBarView.Position); + Assert.Equal (21, _hostView.Left); Assert.False (_scrollBar.ShowScrollIndicator); Assert.False (_scrollBar.OtherScrollBarView.ShowScrollIndicator); Assert.False (_scrollBar.Visible); @@ -1558,7 +1586,7 @@ public void ShowScrollIndicator_False_Must_Also_Set_Visible_To_False_To_Not_Resp Assert.Equal (5, sbv.Size); Assert.Null (sbv.OtherScrollBarView); - Assert.True (sbv.ShowScrollIndicator); + Assert.False (sbv.ShowScrollIndicator); Assert.False (sbv.Visible); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -1618,13 +1646,14 @@ This is a test Assert.Null (Application.MouseGrabView); Assert.True (clicked); Assert.Equal (5, sbv.Size); - Assert.True (sbv.ShowScrollIndicator); + Assert.False (sbv.ShowScrollIndicator); Assert.False (sbv.Visible); // It's needed to set ShowScrollIndicator to true and AutoHideScrollBars to false forcing // showing the scroll bar, otherwise AutoHideScrollBars will automatically control it Assert.True (sbv.AutoHideScrollBars); - Assert.True (sbv.ShowScrollIndicator); + Assert.False (sbv.ShowScrollIndicator); + Assert.False (sbv.Visible); sbv.AutoHideScrollBars = false; Application.Top.Draw (); @@ -1722,6 +1751,43 @@ public void Vertical_Default_Draws_Correctly () _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); } + [Fact] + public void Set_AutoHideScrollBars_To_False_Restore_Original_ShowScrollIndicator_Visible__Values () + { + var sbv = new ScrollBarView (); + var top = new View { Width = 10, Height = 10 }; + top.Add (sbv); + top.BeginInit (); + top.EndInit (); + + Assert.True (sbv.AutoHideScrollBars); + Assert.False (sbv.ShowScrollIndicator); + Assert.False (sbv.Visible); + + sbv.AutoHideScrollBars = false; + Assert.True (sbv.ShowScrollIndicator); + Assert.True (sbv.Visible); + } + + [Fact] + public void Set_ShowScrollIndicator_To_False_Will_Still_Be_Visible_If_Needed_When_AutoHideScrollBars_Is_True () + { + var sbv = new ScrollBarView { Size = 20 }; + var top = new View { Width = 10, Height = 10 }; + top.Add (sbv); + top.BeginInit (); + top.EndInit (); + + sbv.ShowScrollIndicator = false; + Assert.True (sbv.AutoHideScrollBars); + Assert.True (sbv.ShowScrollIndicator); + Assert.True (sbv.Visible); + + sbv.AutoHideScrollBars = false; + Assert.False (sbv.ShowScrollIndicator); + Assert.False (sbv.Visible); + } + private void _hostView_DrawContent (object sender, DrawEventArgs e) { _scrollBar.Size = _hostView.Lines; diff --git a/UnitTests/Views/ScrollViewTests.cs b/UnitTests/Views/ScrollViewTests.cs index 29e53eaf9f..402a77ee71 100644 --- a/UnitTests/Views/ScrollViewTests.cs +++ b/UnitTests/Views/ScrollViewTests.cs @@ -142,9 +142,9 @@ public void AutoHideScrollBars_ShowHorizontalScrollIndicator_ShowVerticalScrollI Application.Begin (Application.Top); Assert.True (sv.AutoHideScrollBars); - Assert.True (sv.ShowHorizontalScrollIndicator); + Assert.False (sv.ShowHorizontalScrollIndicator); Assert.False (sv.Subviews.First(sv => sv is ScrollBarView { Orientation: Orientation.Horizontal }).Visible); - Assert.True (sv.ShowVerticalScrollIndicator); + Assert.False (sv.ShowVerticalScrollIndicator); Assert.False (sv.Subviews.First(sv => sv is ScrollBarView { Orientation: Orientation.Vertical }).Visible); TestHelpers.AssertDriverContentsWithFrameAre ("", _output); From 730fa868be2420c1193d047a43112cebb235c185 Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 21 Mar 2024 12:45:33 +0000 Subject: [PATCH 108/130] Implementing mouse support for scrolling including wheeling. --- Terminal.Gui/View/ViewMouse.cs | 12 +- Terminal.Gui/View/ViewScrollBar.cs | 493 +++++++++++++++++++-------- Terminal.Gui/Views/ScrollBarView.cs | 22 +- UnitTests/View/ViewScrollBarTests.cs | 132 ++++++- 4 files changed, 503 insertions(+), 156 deletions(-) diff --git a/Terminal.Gui/View/ViewMouse.cs b/Terminal.Gui/View/ViewMouse.cs index 90422ecec6..d25d5427ee 100644 --- a/Terminal.Gui/View/ViewMouse.cs +++ b/Terminal.Gui/View/ViewMouse.cs @@ -133,7 +133,17 @@ protected internal virtual bool OnMouseEvent (MouseEvent mouseEvent) MouseEvent?.Invoke (this, args); - return args.Handled == true; + if (args.Handled) + { + return true; + } + + if (UseContentOffset) + { + return MouseHandlingForScrolling (mouseEvent); + } + + return false; } /// Invokes the MouseClick event. diff --git a/Terminal.Gui/View/ViewScrollBar.cs b/Terminal.Gui/View/ViewScrollBar.cs index 2513e12800..9bd26aca8f 100644 --- a/Terminal.Gui/View/ViewScrollBar.cs +++ b/Terminal.Gui/View/ViewScrollBar.cs @@ -252,7 +252,7 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar = null) Command.ScrollDown, () => { - scrollBar.Position++; + ScrollDownPosition (scrollBar); return true; }); @@ -261,7 +261,7 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar = null) Command.ScrollUp, () => { - scrollBar.Position--; + ScrollUpPosition (scrollBar); return true; }); @@ -270,7 +270,7 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar = null) Command.TopHome, () => { - scrollBar.Position = 0; + ScrollTopHomePosition (scrollBar); return true; }); @@ -279,7 +279,7 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar = null) Command.BottomEnd, () => { - scrollBar.Position = ContentSize.Height; + ScrollBottomEndPosition (scrollBar); return true; }); @@ -288,7 +288,7 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar = null) Command.PageDown, () => { - scrollBar.Position += scrollBar.GetVisibleContentArea ().Height; + ScrollPageDownPosition (scrollBar); return true; }); @@ -297,84 +297,24 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar = null) Command.PageUp, () => { - scrollBar.Position -= scrollBar.GetVisibleContentArea ().Height; + ScrollPageUpPosition (scrollBar); return true; }); } else { - view.AddCommand ( - Command.ScrollDown, - () => - { - ParentView.ContentOffset = ParentView.ContentOffset with - { - Y = Math.Max ( - ParentView.ContentOffset.Y - 1, - -(ParentView.ContentSize.Height - ParentView.GetVisibleContentArea ().Height)) - }; - - return true; - }); - - view.AddCommand ( - Command.ScrollUp, - () => - { - ParentView.ContentOffset = ParentView.ContentOffset with { Y = Math.Min (ParentView.ContentOffset.Y + 1, 0) }; - - return true; - }); - - view.AddCommand ( - Command.TopHome, - () => - { - ParentView.ContentOffset = ParentView.ContentOffset with { Y = 0 }; + view.AddCommand (Command.ScrollDown, ScrollDown); - return true; - }); + view.AddCommand (Command.ScrollUp, ScrollUp); - view.AddCommand ( - Command.BottomEnd, - () => - { - ParentView.ContentOffset = ParentView.ContentOffset with - { - Y = Math.Max ( - -ParentView.ContentSize.Height, - -(ParentView.ContentSize.Height - ParentView.GetVisibleContentArea ().Height)) - }; + view.AddCommand (Command.TopHome, ScrollTopHome); - return true; - }); + view.AddCommand (Command.BottomEnd, ScrollBottomEnd); - view.AddCommand ( - Command.PageDown, - () => - { - ParentView.ContentOffset = ParentView.ContentOffset with - { - Y = Math.Max ( - -(ParentView.GetVisibleContentArea ().Height - ParentView.ContentOffset.Y), - ParentView.GetVisibleContentArea ().Height - ParentView.ContentSize.Height) - }; + view.AddCommand (Command.PageDown, ScrollPageDown); - return true; - }); - - view.AddCommand ( - Command.PageUp, - () => - { - ParentView.ContentOffset = ParentView.ContentOffset with - { - Y = Math.Max (-(ParentView.ContentOffset.Y + ParentView.GetVisibleContentArea ().Height), 0) - }; - - return true; - }); + view.AddCommand (Command.PageUp, ScrollPageUp); } // Default keybindings for vertical scrolling @@ -395,7 +335,7 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar = null) Command.Left, () => { - scrollBar.Position--; + ScrollLeftPosition (scrollBar); return true; }); @@ -404,7 +344,7 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar = null) Command.Right, () => { - scrollBar.Position++; + ScrollRightPosition (scrollBar); return true; }); @@ -413,7 +353,7 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar = null) Command.LeftHome, () => { - scrollBar.Position = 0; + ScrollLeftHomePosition (scrollBar); return true; }); @@ -422,7 +362,7 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar = null) Command.RightEnd, () => { - scrollBar.Position = ContentSize.Width; + ScrollRightEndPosition (scrollBar); return true; }); @@ -431,7 +371,7 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar = null) Command.PageRight, () => { - scrollBar.Position += scrollBar.GetVisibleContentArea ().Width; + ScrollPageRightPosition (scrollBar); return true; }); @@ -440,84 +380,24 @@ private void AddKeyBindingsForScrolling (ScrollBarView scrollBar = null) Command.PageLeft, () => { - scrollBar.Position -= scrollBar.GetVisibleContentArea ().Width; + ScrollPageLeftPosition (scrollBar); return true; }); } else { - view.AddCommand ( - Command.Left, - () => - { - ParentView.ContentOffset = ParentView.ContentOffset with { X = Math.Min (ParentView.ContentOffset.X + 1, 0) }; - - return true; - }); - - view.AddCommand ( - Command.Right, - () => - { - ParentView.ContentOffset = ParentView.ContentOffset with - { - X = Math.Max ( - ParentView.ContentOffset.X - 1, - -(ParentView.ContentSize.Width - ParentView.GetVisibleContentArea ().Width)) - }; - - return true; - }); - - view.AddCommand ( - Command.LeftHome, - () => - { - ParentView.ContentOffset = ParentView.ContentOffset with { X = 0 }; - - return true; - }); - - view.AddCommand ( - Command.RightEnd, - () => - { - ParentView.ContentOffset = ParentView.ContentOffset with - { - X = Math.Max ( - -ParentView.ContentSize.Width, - -(ParentView.ContentSize.Width - ParentView.GetVisibleContentArea ().Width)) - }; + view.AddCommand (Command.Left, ScrollLeft); - return true; - }); + view.AddCommand (Command.Right, ScrollRight); - view.AddCommand ( - Command.PageRight, - () => - { - ParentView.ContentOffset = ParentView.ContentOffset with - { - X = Math.Max ( - -(ParentView.GetVisibleContentArea ().Width - ParentView.ContentOffset.X), - ParentView.GetVisibleContentArea ().Width - ParentView.ContentSize.Width) - }; + view.AddCommand (Command.LeftHome, ScrollLeftHome); - return true; - }); + view.AddCommand (Command.RightEnd, ScrollRightEnd); - view.AddCommand ( - Command.PageLeft, - () => - { - ParentView.ContentOffset = ParentView.ContentOffset with - { - X = Math.Max (-(ParentView.ContentOffset.X + ParentView.GetVisibleContentArea ().Width), 0) - }; + view.AddCommand (Command.PageRight, ScrollPageRight); - return true; - }); + view.AddCommand (Command.PageLeft, ScrollPageLeft); } // Default keybindings for horizontal scrolling @@ -554,14 +434,339 @@ private void DisposeScrollBar () ParentView._scrollBar = null; } + private void EnsureFocusWithMouse () + { + if (!HasFocus && CanFocus) + { + SetFocus (); + } + } + private bool HasHorizontalScrollBar => ParentView is { _scrollBar.OtherScrollBarView: { } }; private bool HasVerticalScrollBar => ParentView is { _scrollBar: { } }; private void HorizontalScrollBar_ChangedPosition (object sender, EventArgs e) { SetBoundsByPosition (_scrollBar.OtherScrollBarView); } + private bool MouseHandlingForScrolling (MouseEvent mouseEvent) + { + if (mouseEvent.Flags == MouseFlags.WheeledDown) + { + EnsureFocusWithMouse (); + + return ScrollDown () == true; + } + + if (mouseEvent.Flags == MouseFlags.WheeledUp) + { + EnsureFocusWithMouse (); + + return ScrollUp () == true; + } + + if (mouseEvent.Flags == MouseFlags.Button2Pressed) + { + EnsureFocusWithMouse (); + + return ScrollBottomEnd () == true; + } + + if (mouseEvent.Flags == (MouseFlags.Button2Pressed | MouseFlags.ButtonAlt)) + { + EnsureFocusWithMouse (); + + return ScrollTopHome () == true; + } + + if (mouseEvent.Flags == (MouseFlags.WheeledDown | MouseFlags.ButtonAlt)) + { + EnsureFocusWithMouse (); + + return ScrollPageDown () == true; + } + + if (mouseEvent.Flags == (MouseFlags.WheeledUp | MouseFlags.ButtonAlt)) + { + EnsureFocusWithMouse (); + + return ScrollPageUp () == true; + } + + if (mouseEvent.Flags == MouseFlags.WheeledRight) + { + EnsureFocusWithMouse (); + + return ScrollRight () == true; + } + + if (mouseEvent.Flags == MouseFlags.WheeledLeft) + { + EnsureFocusWithMouse (); + + return ScrollLeft () == true; + } + + if (mouseEvent.Flags == (MouseFlags.Button2Pressed | MouseFlags.ButtonCtrl)) + { + EnsureFocusWithMouse (); + + return ScrollRightEnd () == true; + } + + if (mouseEvent.Flags == (MouseFlags.Button2Pressed | MouseFlags.ButtonCtrl | MouseFlags.ButtonAlt)) + { + EnsureFocusWithMouse (); + + return ScrollLeftHome () == true; + } + + if (mouseEvent.Flags == (MouseFlags.WheeledRight | MouseFlags.ButtonAlt)) + { + EnsureFocusWithMouse (); + + return ScrollPageRight () == true; + } + + if (mouseEvent.Flags == (MouseFlags.WheeledLeft | MouseFlags.ButtonAlt)) + { + EnsureFocusWithMouse (); + + return ScrollPageLeft () == true; + } + + return false; + } + private View ParentView => this is Adornment adornment ? adornment.Parent : this; + private bool? ScrollBottomEnd () + { + if (HasVerticalScrollBar) + { + ScrollBottomEndPosition (_scrollBar); + } + else + { + ParentView.ContentOffset = ParentView.ContentOffset with + { + Y = Math.Max ( + -ParentView.ContentSize.Height, + -(ParentView.ContentSize.Height - ParentView.GetVisibleContentArea ().Height)) + }; + } + + return true; + } + + private void ScrollBottomEndPosition (ScrollBarView scrollBar) { scrollBar.Position = ContentSize.Height; } + + private bool? ScrollDown () + { + if (HasVerticalScrollBar) + { + ScrollDownPosition (_scrollBar); + } + else + { + ParentView.ContentOffset = ParentView.ContentOffset with + { + Y = Math.Max ( + ParentView.ContentOffset.Y - 1, + -(ParentView.ContentSize.Height - ParentView.GetVisibleContentArea ().Height)) + }; + } + + return true; + } + + private static void ScrollDownPosition (ScrollBarView scrollBar) { scrollBar.Position++; } + + private bool? ScrollLeft () + { + if (HasHorizontalScrollBar) + { + ScrollLeftPosition (_scrollBar.OtherScrollBarView); + } + else + { + ParentView.ContentOffset = ParentView.ContentOffset with { X = Math.Min (ParentView.ContentOffset.X + 1, 0) }; + } + + return true; + } + + private bool? ScrollLeftHome () + { + if (HasHorizontalScrollBar) + { + ScrollLeftHomePosition (_scrollBar.OtherScrollBarView); + } + else + { + ParentView.ContentOffset = ParentView.ContentOffset with { X = 0 }; + } + + return true; + } + + private static void ScrollLeftHomePosition (ScrollBarView scrollBar) { scrollBar.Position = 0; } + + private static void ScrollLeftPosition (ScrollBarView scrollBar) { scrollBar.Position--; } + + private bool? ScrollPageDown () + { + if (HasVerticalScrollBar) + { + ScrollPageDownPosition (_scrollBar); + } + else + { + ParentView.ContentOffset = ParentView.ContentOffset with + { + Y = Math.Max ( + -(ParentView.GetVisibleContentArea ().Height - ParentView.ContentOffset.Y), + ParentView.GetVisibleContentArea ().Height - ParentView.ContentSize.Height) + }; + } + + return true; + } + + private static void ScrollPageDownPosition (ScrollBarView scrollBar) { scrollBar.Position += scrollBar.GetVisibleContentArea ().Height; } + + private bool? ScrollPageLeft () + { + if (HasHorizontalScrollBar) + { + ScrollPageLeftPosition (_scrollBar.OtherScrollBarView); + } + else + { + ParentView.ContentOffset = ParentView.ContentOffset with + { + X = Math.Min (Math.Max (-(ParentView.ContentOffset.X + ParentView.GetVisibleContentArea ().Width), 0), 0) + }; + } + + return true; + } + + private static void ScrollPageLeftPosition (ScrollBarView scrollBar) { scrollBar.Position -= scrollBar.GetVisibleContentArea ().Width; } + + private bool? ScrollPageRight () + { + if (HasHorizontalScrollBar) + { + ScrollPageRightPosition (_scrollBar.OtherScrollBarView); + } + else + { + ParentView.ContentOffset = ParentView.ContentOffset with + { + X = Math.Max ( + -(ParentView.GetVisibleContentArea ().Width - ParentView.ContentOffset.X), + ParentView.GetVisibleContentArea ().Width - ParentView.ContentSize.Width) + }; + } + + return true; + } + + private static void ScrollPageRightPosition (ScrollBarView scrollBar) { scrollBar.Position += scrollBar.GetVisibleContentArea ().Width; } + + private bool? ScrollPageUp () + { + if (HasVerticalScrollBar) + { + ScrollPageUpPosition (_scrollBar); + } + else + { + ParentView.ContentOffset = ParentView.ContentOffset with + { + Y = Math.Min (Math.Max (-(ParentView.ContentOffset.Y + ParentView.GetVisibleContentArea ().Height), 0), 0) + }; + } + + return true; + } + + private static void ScrollPageUpPosition (ScrollBarView scrollBar) { scrollBar.Position -= scrollBar.GetVisibleContentArea ().Height; } + + private bool? ScrollRight () + { + if (HasHorizontalScrollBar) + { + ScrollRightPosition (_scrollBar.OtherScrollBarView); + } + else + { + ParentView.ContentOffset = ParentView.ContentOffset with + { + X = Math.Max ( + ParentView.ContentOffset.X - 1, + -(ParentView.ContentSize.Width - ParentView.GetVisibleContentArea ().Width)) + }; + } + + return true; + } + + private bool? ScrollRightEnd () + { + if (HasHorizontalScrollBar) + { + ScrollRightEndPosition (_scrollBar.OtherScrollBarView); + } + else + { + ParentView.ContentOffset = ParentView.ContentOffset with + { + X = Math.Max ( + -ParentView.ContentSize.Width, + -(ParentView.ContentSize.Width - ParentView.GetVisibleContentArea ().Width)) + }; + } + + return true; + } + + private void ScrollRightEndPosition (ScrollBarView scrollBar) { scrollBar.Position = ContentSize.Width; } + + private static void ScrollRightPosition (ScrollBarView scrollBar) { scrollBar.Position++; } + + private bool? ScrollTopHome () + { + if (HasVerticalScrollBar) + { + ScrollTopHomePosition (_scrollBar); + } + else + { + ParentView.ContentOffset = ParentView.ContentOffset with { Y = 0 }; + } + + return true; + } + + private static void ScrollTopHomePosition (ScrollBarView scrollBar) { scrollBar.Position = 0; } + + private bool? ScrollUp () + { + if (HasVerticalScrollBar) + { + ScrollUpPosition (_scrollBar); + } + else + { + ParentView.ContentOffset = ParentView.ContentOffset with { Y = Math.Min (ParentView.ContentOffset.Y + 1, 0) }; + } + + return true; + } + + private static void ScrollUpPosition (ScrollBarView scrollBar) { scrollBar.Position--; } + private void SetBoundsByPosition (ScrollBarView scrollBar) { if (scrollBar.Orientation == Orientation.Vertical) diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index b029966d32..a37ffa44c8 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -464,11 +464,12 @@ protected internal override bool OnMouseEvent (MouseEvent mouseEvent) && mouseEvent.Flags != MouseFlags.Button1DoubleClicked && !mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition) && mouseEvent.Flags != MouseFlags.Button1Released - && mouseEvent.Flags != MouseFlags.WheeledDown - && mouseEvent.Flags != MouseFlags.WheeledUp - && mouseEvent.Flags != MouseFlags.WheeledRight - && mouseEvent.Flags != MouseFlags.WheeledLeft - && mouseEvent.Flags != MouseFlags.Button1TripleClicked) + && mouseEvent.Flags != MouseFlags.Button1TripleClicked + && (mouseEvent.Flags & MouseFlags.WheeledDown) == 0 + && (mouseEvent.Flags & MouseFlags.WheeledUp) == 0 + && (mouseEvent.Flags & MouseFlags.WheeledRight) == 0 + && (mouseEvent.Flags & MouseFlags.WheeledLeft) == 0 + && (mouseEvent.Flags & MouseFlags.Button2Pressed) == 0) { return false; } @@ -505,12 +506,13 @@ protected internal override bool OnMouseEvent (MouseEvent mouseEvent) } if (Visible - && (mouseEvent.Flags == MouseFlags.WheeledDown - || mouseEvent.Flags == MouseFlags.WheeledUp - || mouseEvent.Flags == MouseFlags.WheeledRight - || mouseEvent.Flags == MouseFlags.WheeledLeft)) + && ((mouseEvent.Flags & MouseFlags.WheeledDown) != 0 + || (mouseEvent.Flags & MouseFlags.WheeledUp) != 0 + || (mouseEvent.Flags & MouseFlags.WheeledRight) != 0 + || (mouseEvent.Flags & MouseFlags.WheeledLeft) != 0) + || (mouseEvent.Flags & MouseFlags.Button2Pressed) != 0) { - return SuperView.OnMouseEvent (mouseEvent); + return host!.OnMouseEvent (mouseEvent); } if (mouseEvent.Flags == MouseFlags.Button1Pressed && location == 0) diff --git a/UnitTests/View/ViewScrollBarTests.cs b/UnitTests/View/ViewScrollBarTests.cs index c43044c8f5..d67ed66427 100644 --- a/UnitTests/View/ViewScrollBarTests.cs +++ b/UnitTests/View/ViewScrollBarTests.cs @@ -127,6 +127,125 @@ int expectedSecondY { Key.PageDown.WithShift, -10, 0, Key.PageUp.WithShift, 0, 0 } }; + [Theory] + [MemberData (nameof (ScrollMouseHandling))] + public void Mouse_Handling_On_Border ( + MouseFlags firstMouse, + int expectedFirstX, + int expectedFirstY, + MouseFlags secondMouse, + int expectedSecondX, + int expectedSecondY + ) + { + var view = new View { Width = 10, Height = 10, ContentSize = new (20, 20), UseContentOffset = true }; + view.Border.EnableScrollBars = true; + view.BeginInit (); + view.EndInit (); + + Assert.True (view.OnMouseEvent (new () { Flags = firstMouse })); + Assert.Equal (new (expectedFirstX, expectedFirstY), view.ContentOffset); + Assert.True (view.OnMouseEvent (new () { Flags = secondMouse })); + Assert.Equal (new (expectedSecondX, expectedSecondY), view.ContentOffset); + } + + [Theory] + [MemberData (nameof (ScrollMouseHandling))] + public void Mouse_Handling_On_ContentArea ( + MouseFlags firstMouse, + int expectedFirstX, + int expectedFirstY, + MouseFlags secondMouse, + int expectedSecondX, + int expectedSecondY + ) + { + var view = new View { Width = 10, Height = 10, EnableScrollBars = true, ContentSize = new (20, 20), UseContentOffset = true }; + view.BeginInit (); + view.EndInit (); + + Assert.True (view.OnMouseEvent (new () { Flags = firstMouse })); + Assert.Equal (new (expectedFirstX, expectedFirstY), view.ContentOffset); + Assert.True (view.OnMouseEvent (new () { Flags = secondMouse })); + Assert.Equal (new (expectedSecondX, expectedSecondY), view.ContentOffset); + } + + [Theory] + [MemberData (nameof (ScrollMouseHandling))] + public void Mouse_Handling_On_Margin ( + MouseFlags firstMouse, + int expectedFirstX, + int expectedFirstY, + MouseFlags secondMouse, + int expectedSecondX, + int expectedSecondY + ) + { + var view = new View { Width = 10, Height = 10, ContentSize = new (20, 20), UseContentOffset = true }; + view.Margin.EnableScrollBars = true; + view.BeginInit (); + view.EndInit (); + + Assert.True (view.OnMouseEvent (new () { Flags = firstMouse })); + Assert.Equal (new (expectedFirstX, expectedFirstY), view.ContentOffset); + Assert.True (view.OnMouseEvent (new () { Flags = secondMouse })); + Assert.Equal (new (expectedSecondX, expectedSecondY), view.ContentOffset); + } + + [Theory] + [MemberData (nameof (ScrollMouseHandling))] + public void Mouse_Handling_On_Padding ( + MouseFlags firstMouse, + int expectedFirstX, + int expectedFirstY, + MouseFlags secondMouse, + int expectedSecondX, + int expectedSecondY + ) + { + var view = new View { Width = 10, Height = 10, ContentSize = new (20, 20), UseContentOffset = true }; + view.Padding.EnableScrollBars = true; + view.BeginInit (); + view.EndInit (); + + Assert.True (view.OnMouseEvent (new () { Flags = firstMouse })); + Assert.Equal (new (expectedFirstX, expectedFirstY), view.ContentOffset); + Assert.True (view.OnMouseEvent (new () { Flags = secondMouse })); + Assert.Equal (new (expectedSecondX, expectedSecondY), view.ContentOffset); + } + + [Theory] + [MemberData (nameof (MouseHandlingWithoutScrollBars))] + public void Mouse_Handling_Without_EnableScrollBars ( + MouseFlags firstMouse, + int expectedFirstX, + int expectedFirstY, + MouseFlags secondMouse, + int expectedSecondX, + int expectedSecondY + ) + { + var view = new View { Width = 10, Height = 10, ContentSize = new (20, 20), UseContentOffset = true }; + view.BeginInit (); + view.EndInit (); + + Assert.True (view.OnMouseEvent (new () { Flags = firstMouse })); + Assert.Equal (new (expectedFirstX, expectedFirstY), view.ContentOffset); + Assert.True (view.OnMouseEvent (new () { Flags = secondMouse })); + Assert.Equal (new (expectedSecondX, expectedSecondY), view.ContentOffset); + } + + public static TheoryData MouseHandlingWithoutScrollBars => + new () + { + { MouseFlags.WheeledDown, 0, -1, MouseFlags.WheeledUp, 0, 0 }, + { MouseFlags.Button2Pressed, 0, -10, MouseFlags.Button2Pressed | MouseFlags.ButtonAlt, 0, 0 }, + { MouseFlags.WheeledDown | MouseFlags.ButtonAlt, 0, -10, MouseFlags.WheeledUp | MouseFlags.ButtonAlt, 0, 0 }, + { MouseFlags.WheeledRight, -1, 0, MouseFlags.WheeledLeft, 0, 0 }, + { MouseFlags.Button2Pressed | MouseFlags.ButtonCtrl, -10, 0, MouseFlags.Button2Pressed | MouseFlags.ButtonCtrl | MouseFlags.ButtonAlt, 0, 0 }, + { MouseFlags.WheeledRight | MouseFlags.ButtonAlt, -10, 0, MouseFlags.WheeledLeft | MouseFlags.ButtonAlt, 0, 0 } + }; + public static TheoryData ScrollBarKeyBindings => new () { @@ -157,7 +276,7 @@ public void Scrolling_Without_ScrollBars () string [] strings = view.Text.Split ("\n").ToArray (); view.ContentSize = new (strings.OrderByDescending (s => s.Length).First ().GetColumns (), strings.Length); - view.ColorScheme = new() + view.ColorScheme = new () { Normal = new (Color.Green, Color.Red), Focus = new (Color.Red, Color.Green) @@ -242,4 +361,15 @@ enth Line Test ", _output); } + + public static TheoryData ScrollMouseHandling => + new () + { + { MouseFlags.WheeledDown, 0, -1, MouseFlags.WheeledUp, 0, 0 }, + { MouseFlags.Button2Pressed, 0, -11, MouseFlags.Button2Pressed | MouseFlags.ButtonAlt, 0, 0 }, + { MouseFlags.WheeledDown | MouseFlags.ButtonAlt, 0, -9, MouseFlags.WheeledUp | MouseFlags.ButtonAlt, 0, 0 }, + { MouseFlags.WheeledRight, -1, 0, MouseFlags.WheeledLeft, 0, 0 }, + { MouseFlags.Button2Pressed | MouseFlags.ButtonCtrl, -11, 0, MouseFlags.Button2Pressed | MouseFlags.ButtonCtrl | MouseFlags.ButtonAlt, 0, 0 }, + { MouseFlags.WheeledRight | MouseFlags.ButtonAlt, -9, 0, MouseFlags.WheeledLeft | MouseFlags.ButtonAlt, 0, 0 } + }; } From 85e1e6c5e2947d42c0eae84fc20296a8a11bd0fc Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 28 Mar 2024 18:51:00 +0000 Subject: [PATCH 109/130] Fixes #3356. SetupFakeDriver isn't disposing Application.Top if Application.Begin was called. --- UnitTests/Application/ApplicationTests.cs | 44 +++++++++++++++++++++++ UnitTests/TestHelpers.cs | 3 ++ 2 files changed, 47 insertions(+) diff --git a/UnitTests/Application/ApplicationTests.cs b/UnitTests/Application/ApplicationTests.cs index 2dbad7cccf..42614cf45c 100644 --- a/UnitTests/Application/ApplicationTests.cs +++ b/UnitTests/Application/ApplicationTests.cs @@ -1088,4 +1088,48 @@ public void Shutdown_Resets_SyncContext () } #endregion + + [Fact] + [AutoInitShutdown] + public void AutoInitShutdown_Dispose_Application_Top () + { + // This unit test is for test the SetupFakeDriver_Also_Dispose_Application_Top + // unit test. Right-click ApplicationTests on the TestExplorer and Run or Debug + // Commenting Application.Top?.Dispose (); on the SetupFakeDriverAttribute some + // of ApplicationTests unit tests will fail + var view = new View (); + var top = new Toplevel (); + top.Add (view); + Application.Begin (top); + + Assert.NotNull (Application.Top); +#if DEBUG_IDISPOSABLE + Assert.False (Application.Top.WasDisposed); +#endif + } + + [Fact] + [SetupFakeDriver] + public void SetupFakeDriver_Also_Dispose_Application_Top () + { + // This unit test is for test the SetupFakeDriver_Also_Dispose_Application_Top + // unit test. Right-click ApplicationTests on the TestExplorer and Run or Debug + // Commenting Application.Top?.Dispose (); on the SetupFakeDriverAttribute some + // of ApplicationTests unit tests will fail + var exception = Record.Exception ( + () => + { + var view = new View (); + var top = new Toplevel (); + top.Add (view); + Application.Begin (top); + + Assert.NotNull (Application.Top); +#if DEBUG_IDISPOSABLE + Assert.False (Application.Top.WasDisposed); +#endif + }); + + Assert.Null (exception); + } } diff --git a/UnitTests/TestHelpers.cs b/UnitTests/TestHelpers.cs index 88d7ec9785..bea0ea3318 100644 --- a/UnitTests/TestHelpers.cs +++ b/UnitTests/TestHelpers.cs @@ -154,6 +154,9 @@ public override void After (MethodInfo methodUnderTest) // Turn off diagnostic flags in case some test left them on View.Diagnostics = ViewDiagnosticFlags.Off; + // Dispose Application.Top if Application.Begin was called + Application.Top?.Dispose (); + Application.Driver = null; } From 84c5f8613e2d046216619ce7340d753314d1d707 Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 28 Mar 2024 19:05:23 +0000 Subject: [PATCH 110/130] Fix merge errors. --- Terminal.Gui/Views/TableView/TableView.cs | 2 +- UICatalog/Scenarios/ScrollBars.cs | 28 ++++++------------- .../ScrollingWithoutEnableScrollBars.cs | 28 ++++++------------- UnitTests/Views/ScrollBarViewTests.cs | 10 ++----- 4 files changed, 22 insertions(+), 46 deletions(-) diff --git a/Terminal.Gui/Views/TableView/TableView.cs b/Terminal.Gui/Views/TableView/TableView.cs index 438e27abd2..1b000e2028 100644 --- a/Terminal.Gui/Views/TableView/TableView.cs +++ b/Terminal.Gui/Views/TableView/TableView.cs @@ -2172,7 +2172,7 @@ out int idx ) { // if the column index provided is out of bounds - if (table is null || columnIndex < 0 || columnIndex >= table.Columns) + if (_table is null || columnIndex < 0 || columnIndex >= _table.Columns) { idx = columnIndex; diff --git a/UICatalog/Scenarios/ScrollBars.cs b/UICatalog/Scenarios/ScrollBars.cs index 3fd134f2c3..ff35e6c68f 100644 --- a/UICatalog/Scenarios/ScrollBars.cs +++ b/UICatalog/Scenarios/ScrollBars.cs @@ -7,18 +7,10 @@ namespace UICatalog.Scenarios; [ScenarioCategory ("Controls")] public class ScrollBars : Scenario { - public override void Init () - { - Application.Init (); - Application.Top.ColorScheme = Colors.ColorSchemes ["Base"]; - } - public override void Setup () { var text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line"; - var win = new Window (); - var viewOnMargin = new View { X = 0, Y = Pos.Center (), Width = 12, Height = 6, @@ -27,9 +19,9 @@ public override void Setup () }; viewOnMargin.Margin.EnableScrollBars = true; SetViewProperties (viewOnMargin); - win.Add (viewOnMargin); + Win.Add (viewOnMargin); - win.Add (new Label { X = 0, Y = Pos.Top (viewOnMargin) - 2, Text = "On Margin:" }); + Win.Add (new Label { X = 0, Y = Pos.Top (viewOnMargin) - 2, Text = "On Margin:" }); var viewOnContentArea = new View { @@ -42,9 +34,9 @@ public override void Setup () viewOnContentArea.Margin.ColorScheme = Colors.ColorSchemes ["Dialog"]; viewOnContentArea.BorderStyle = LineStyle.Single; SetViewProperties (viewOnContentArea); - win.Add (viewOnContentArea); + Win.Add (viewOnContentArea); - win.Add (new Label { X = Pos.Left (viewOnContentArea), Y = Pos.Top (viewOnContentArea) - 2, Text = "On ContentArea:" }); + Win.Add (new Label { X = Pos.Left (viewOnContentArea), Y = Pos.Top (viewOnContentArea) - 2, Text = "On ContentArea:" }); var viewOnPadding = new View { @@ -58,9 +50,9 @@ public override void Setup () viewOnPadding.BorderStyle = LineStyle.Single; viewOnPadding.Padding.ColorScheme = Colors.ColorSchemes ["Menu"]; SetViewProperties (viewOnPadding); - win.Add (viewOnPadding); + Win.Add (viewOnPadding); - win.Add (new Label { X = Pos.Left (viewOnPadding), Y = Pos.Top (viewOnPadding) - 2, Text = "On Padding:" }); + Win.Add (new Label { X = Pos.Left (viewOnPadding), Y = Pos.Top (viewOnPadding) - 2, Text = "On Padding:" }); var viewOnBorder = new View { @@ -73,18 +65,16 @@ public override void Setup () viewOnBorder.Margin.Thickness = new (1); viewOnBorder.Margin.ColorScheme = Colors.ColorSchemes ["Dialog"]; SetViewProperties (viewOnBorder); - win.Add (viewOnBorder); + Win.Add (viewOnBorder); - win.Add (new Label { X = Pos.Left (viewOnBorder), Y = Pos.Top (viewOnBorder) - 2, Text = "On Border:" }); + Win.Add (new Label { X = Pos.Left (viewOnBorder), Y = Pos.Top (viewOnBorder) - 2, Text = "On Border:" }); var btn = new Button { X = Pos.Center (), Y = Pos.Bottom (viewOnContentArea) + 1, Text = "Tab or click to select the views" }; - win.Add (btn); + Win.Add (btn); viewOnBorder.TabIndex = 1; viewOnPadding.TabIndex = 2; viewOnContentArea.TabIndex = 3; - - Application.Top.Add (win); } private void SetViewProperties (View view) diff --git a/UICatalog/Scenarios/ScrollingWithoutEnableScrollBars.cs b/UICatalog/Scenarios/ScrollingWithoutEnableScrollBars.cs index 0fd91b8113..a97f2fbf34 100644 --- a/UICatalog/Scenarios/ScrollingWithoutEnableScrollBars.cs +++ b/UICatalog/Scenarios/ScrollingWithoutEnableScrollBars.cs @@ -7,18 +7,10 @@ namespace UICatalog.Scenarios; [ScenarioCategory ("Controls")] public class ScrollingWithoutEnableScrollBars : Scenario { - public override void Init () - { - Application.Init (); - Application.Top.ColorScheme = Colors.ColorSchemes ["Base"]; - } - public override void Setup () { var text = "First Line\nSecond Line\nThird Line\nFourth Line\nFifth Line\nSixth Line\nSeventh Line"; - var win = new Window (); - var viewWithoutAdornments = new View { X = 0, Y = Pos.Center (), Width = 12, Height = 6, @@ -26,9 +18,9 @@ public override void Setup () UseContentOffset = true }; SetViewProperties (viewWithoutAdornments); - win.Add (viewWithoutAdornments); + Win.Add (viewWithoutAdornments); - win.Add (new Label { X = 0, Y = Pos.Top (viewWithoutAdornments) - 2, Text = "No Adornments:" }); + Win.Add (new Label { X = 0, Y = Pos.Top (viewWithoutAdornments) - 2, Text = "No Adornments:" }); var viewWithMarginBorderPadding = new View { @@ -42,9 +34,9 @@ public override void Setup () viewWithMarginBorderPadding.Padding.Thickness = new (1); viewWithMarginBorderPadding.Padding.ColorScheme = Colors.ColorSchemes ["Menu"]; SetViewProperties (viewWithMarginBorderPadding); - win.Add (viewWithMarginBorderPadding); + Win.Add (viewWithMarginBorderPadding); - win.Add (new Label { X = Pos.Left (viewWithMarginBorderPadding), Y = Pos.Top (viewWithMarginBorderPadding) - 2, Text = "All Adornments:" }); + Win.Add (new Label { X = Pos.Left (viewWithMarginBorderPadding), Y = Pos.Top (viewWithMarginBorderPadding) - 2, Text = "All Adornments:" }); var viewWithMarginBorder = new View { @@ -56,9 +48,9 @@ public override void Setup () viewWithMarginBorder.Margin.ColorScheme = Colors.ColorSchemes ["Dialog"]; viewWithMarginBorder.BorderStyle = LineStyle.Single; SetViewProperties (viewWithMarginBorder); - win.Add (viewWithMarginBorder); + Win.Add (viewWithMarginBorder); - win.Add (new Label { X = Pos.Left (viewWithMarginBorder), Y = Pos.Top (viewWithMarginBorder) - 2, Text = "With Margin/Border:" }); + Win.Add (new Label { X = Pos.Left (viewWithMarginBorder), Y = Pos.Top (viewWithMarginBorder) - 2, Text = "With Margin/Border:" }); var viewWithMargin = new View { @@ -70,18 +62,16 @@ public override void Setup () viewWithMargin.Margin.Thickness = new (1); viewWithMargin.Margin.ColorScheme = Colors.ColorSchemes ["Menu"]; SetViewProperties (viewWithMargin); - win.Add (viewWithMargin); + Win.Add (viewWithMargin); - win.Add (new Label { X = Pos.Left (viewWithMargin), Y = Pos.Top (viewWithMargin) - 2, Text = "With Margin:" }); + Win.Add (new Label { X = Pos.Left (viewWithMargin), Y = Pos.Top (viewWithMargin) - 2, Text = "With Margin:" }); var btn = new Button { X = Pos.Center (), Y = Pos.Bottom (viewWithMarginBorderPadding) + 1, Text = "Tab or click to select the views" }; - win.Add (btn); + Win.Add (btn); viewWithMargin.TabIndex = 1; viewWithMarginBorder.TabIndex = 2; viewWithMarginBorderPadding.TabIndex = 3; - - Application.Top.Add (win); } private void SetViewProperties (View view) diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index 0ca38fe52e..1e09b4ab12 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -324,7 +324,7 @@ This is a tes▼ sbv.Visible = false; sbv.ShowScrollIndicator = false; sbv.AutoHideScrollBars = false; - Application.Top.Draw (); + top.Draw (); Assert.False (sbv.Visible); Assert.False (sbv.ShowScrollIndicator); @@ -922,7 +922,6 @@ public void Hosting_ShowBothScrollIndicator_Invisible_WordWrap_ReadOnly () } [Fact] - [ScrollBarAutoInitShutdown] public void Hosting_Two_Horizontal_ScrollBarView_Throws_ArgumentException () { var top = new Toplevel (); @@ -936,7 +935,6 @@ public void Hosting_Two_Horizontal_ScrollBarView_Throws_ArgumentException () } [Fact] - [ScrollBarAutoInitShutdown] public void Hosting_Two_Vertical_ScrollBarView_Throws_ArgumentException () { var top = new Toplevel (); @@ -1558,7 +1556,6 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Parent_Inside_A } [Fact] - [ScrollBarAutoInitShutdown] public void Scrolling_With_Default_Constructor_Do_Not_Scroll () { var sbv = new ScrollBarView { Position = 1 }; @@ -1592,8 +1589,7 @@ public void ShowScrollIndicator_False_Must_Also_Set_Visible_To_False_To_Not_Resp var sbv = new ScrollBarView { Orientation = Orientation.Vertical, Size = 5 }; label.Add (sbv); - Application.Top.Add (label, btn); - Application.Begin (Application.Top); + Application.Begin (top); Assert.Equal (5, sbv.Size); Assert.Null (sbv.OtherScrollBarView); @@ -1666,7 +1662,7 @@ This is a test Assert.False (sbv.ShowScrollIndicator); Assert.False (sbv.Visible); sbv.AutoHideScrollBars = false; - Application.Top.Draw (); + top.Draw (); TestHelpers.AssertDriverContentsWithFrameAre ( @$" From efb0799b6904a607df1710dd54dcbf8ab116565d Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 30 Mar 2024 16:15:26 +0000 Subject: [PATCH 111/130] Fixes #3362. SetRelativeLayout doesn't handled with positive/negative location offset. --- Terminal.Gui/View/Layout/ViewLayout.cs | 23 ++-- .../View/Layout/SetRelativeLayoutTests.cs | 127 ++++++++++++++++++ 2 files changed, 139 insertions(+), 11 deletions(-) diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index af1e417a95..7fcb4b1c8e 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -925,7 +925,7 @@ public virtual void LayoutSubviews () foreach (View v in ordered) { - LayoutSubview (v, new (GetBoundsOffset (), Bounds.Size)); + LayoutSubview (v, new (Point.Empty, Bounds.Size)); } // If the 'to' is rooted to 'from' and the layoutstyle is Computed it's a special-case. @@ -1116,6 +1116,7 @@ int GetNewDimension (Dim d, int location, int dimension, int autosize) int newDimension, newLocation; int superviewDimension = width ? superviewBounds.Width : superviewBounds.Height; + int superviewLocation = width ? superviewBounds.X : superviewBounds.Y; // Determine new location switch (pos) @@ -1124,7 +1125,7 @@ int GetNewDimension (Dim d, int location, int dimension, int autosize) // For Center, the dimension is dependent on location, but we need to force getting the dimension first // using a location of 0 newDimension = Math.Max (GetNewDimension (dim, 0, superviewDimension, autosizeDimension), 0); - newLocation = posCenter.Anchor (superviewDimension - newDimension); + newLocation = posCenter.Anchor (superviewDimension - newDimension) + superviewLocation; newDimension = Math.Max ( GetNewDimension (dim, newLocation, superviewDimension, autosizeDimension), @@ -1175,7 +1176,7 @@ int GetNewDimension (Dim d, int location, int dimension, int autosize) case Pos.PosFunc: case Pos.PosView: default: - newLocation = pos?.Anchor (superviewDimension) ?? 0; + newLocation = (pos?.Anchor (superviewDimension) ?? 0) + superviewLocation; newDimension = Math.Max ( GetNewDimension (dim, newLocation, superviewDimension, autosizeDimension), @@ -1202,15 +1203,15 @@ int GetNewDimension (Dim d, int location, int dimension, int autosize) // the view LayoutStyle.Absolute. _frame = r; - if (_x is Pos.PosAbsolute) - { - _x = Frame.X; - } + //if (_x is Pos.PosAbsolute) + //{ + // _x = Frame.X; + //} - if (_y is Pos.PosAbsolute) - { - _y = Frame.Y; - } + //if (_y is Pos.PosAbsolute) + //{ + // _y = Frame.Y; + //} if (_width is Dim.DimAbsolute) { diff --git a/UnitTests/View/Layout/SetRelativeLayoutTests.cs b/UnitTests/View/Layout/SetRelativeLayoutTests.cs index cfd0288208..93f4a0c76e 100644 --- a/UnitTests/View/Layout/SetRelativeLayoutTests.cs +++ b/UnitTests/View/Layout/SetRelativeLayoutTests.cs @@ -430,4 +430,131 @@ public void PosDimFunction () Assert.Equal (26, tf.Frame.Width); Assert.Equal (1, tf.Frame.Height); } + + [Theory] + [InlineData (0, 0, 10, 10)] + [InlineData (-1, -1, 9, 9)] + [InlineData (1, 1, 11, 11)] + public void AnchorEnd_X_Same_As_Y (int x, int y, int expectedX, int expectedY) + { + var screen = new Rectangle (x, y, 10, 10); + var view = new View { X = Pos.AnchorEnd (), Y = Pos.AnchorEnd (), Width = 3, Height = 3 }; + view.BeginInit (); + view.EndInit (); + view.SetRelativeLayout (screen); + + Assert.Equal (expectedX, view.Frame.X); + Assert.Equal (expectedY, view.Frame.Y); + Assert.Equal (3, view.Frame.Width); + Assert.Equal (3, view.Frame.Height); + } + + [Theory] + [InlineData (0, 0, 3, 3)] + [InlineData (-1, -1, 2, 2)] + [InlineData (1, 1, 4, 4)] + public void Center_X_Same_As_Y (int x, int y, int expectedX, int expectedY) + { + var screen = new Rectangle (x, y, 10, 10); + var view = new View { X = Pos.Center (), Y = Pos.Center (), Width = 3, Height = 3 }; + view.BeginInit (); + view.EndInit (); + view.SetRelativeLayout (screen); + + Assert.Equal (expectedX, view.Frame.X); + Assert.Equal (expectedY, view.Frame.Y); + Assert.Equal (3, view.Frame.Width); + Assert.Equal (3, view.Frame.Height); + } + + [Theory] + [InlineData (0, 0, 4, 4)] + [InlineData (-1, -1, 2, 2)] + [InlineData (1, 1, 6, 6)] + public void Combine_X_Same_As_Y (int x, int y, int expectedX, int expectedY) + { + var screen = new Rectangle (x, y, 10, 10); + var view = new View { X = Pos.Center () + 1, Y = Pos.Center () + 1, Width = 3, Height = 3 }; + view.BeginInit (); + view.EndInit (); + view.SetRelativeLayout (screen); + + Assert.Equal (expectedX, view.Frame.X); + Assert.Equal (expectedY, view.Frame.Y); + Assert.Equal (3, view.Frame.Width); + Assert.Equal (3, view.Frame.Height); + } + + [Theory] + [InlineData (0, 0, 3, 3)] + [InlineData (-1, -1, 2, 2)] + [InlineData (1, 1, 4, 4)] + public void Absolute_X_Same_As_Y (int x, int y, int expectedX, int expectedY) + { + var screen = new Rectangle (x, y, 10, 10); + var view = new View { X = 3, Y = 3, Width = 3, Height = 3 }; + view.BeginInit (); + view.EndInit (); + view.SetRelativeLayout (screen); + + Assert.Equal (expectedX, view.Frame.X); + Assert.Equal (expectedY, view.Frame.Y); + Assert.Equal (3, view.Frame.Width); + Assert.Equal (3, view.Frame.Height); + } + + [Theory] + [InlineData (0, 0, 5, 5)] + [InlineData (-1, -1, 4, 4)] + [InlineData (1, 1, 6, 6)] + public void Factor_X_Same_As_Y (int x, int y, int expectedX, int expectedY) + { + var screen = new Rectangle (x, y, 10, 10); + var view = new View { X = Pos.Percent (50), Y = Pos.Percent (50), Width = 3, Height = 3 }; + view.BeginInit (); + view.EndInit (); + view.SetRelativeLayout (screen); + + Assert.Equal (expectedX, view.Frame.X); + Assert.Equal (expectedY, view.Frame.Y); + Assert.Equal (3, view.Frame.Width); + Assert.Equal (3, view.Frame.Height); + } + + [Theory] + [InlineData (0, 0, 4, 4)] + [InlineData (-1, -1, 3, 3)] + [InlineData (1, 1, 5, 5)] + public void PosView_X_Same_As_Y (int x, int y, int expectedX, int expectedY) + { + var screen = new Rectangle (x, y, 10, 10); + var view1 = new View { X = 3, Y = 3, Width = 1, Height = 1 }; + var view2 = new View { X = Pos.Right (view1), Y = Pos.Bottom (view1), Width = 3, Height = 3 }; + view2.BeginInit (); + view2.EndInit (); + view2.SetRelativeLayout (screen); + + Assert.Equal (expectedX, view2.Frame.X); + Assert.Equal (expectedY, view2.Frame.Y); + Assert.Equal (3, view2.Frame.Width); + Assert.Equal (3, view2.Frame.Height); + } + + [Theory] + [InlineData (0, 0, 4, 4)] + [InlineData (-1, -1, 3, 3)] + [InlineData (1, 1, 5, 5)] + public void PosFunc_X_Same_As_Y (int x, int y, int expectedX, int expectedY) + { + var screen = new Rectangle (x, y, 10, 10); + var view = new View { X = Pos.Function (() => 4), Y = Pos.Function (() => 4), Width = 3, Height = 3 }; + view.BeginInit (); + view.EndInit (); + view.SetRelativeLayout (screen); + + Assert.Equal (expectedX, view.Frame.X); + Assert.Equal (expectedY, view.Frame.Y); + Assert.Equal (3, view.Frame.Width); + Assert.Equal (3, view.Frame.Height); + } } From 12ff0160f68066c005f41c92f3518fa9bbc1731c Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 30 Mar 2024 17:30:39 +0000 Subject: [PATCH 112/130] Allowing location offset in the LayoutSubviews. --- Terminal.Gui/View/Layout/ViewLayout.cs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 4ff50c2163..eec0b7563e 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -335,8 +335,19 @@ public virtual Rectangle ContentArea } Thickness totalThickness = GetAdornmentsThickness (); - int width = Math.Max (0, Frame.Size.Width - totalThickness.Horizontal - (UseContentOffset ? ContentOffset.X : 0)); - int height = Math.Max (0, Frame.Size.Height - totalThickness.Vertical - (UseContentOffset ? ContentOffset.Y : 0)); + int width; + int height; + + if (UseContentOffset) + { + width = Math.Max (GetVisibleContentArea ().Width, ContentSize.Width); + height = Math.Max (GetVisibleContentArea ().Height, ContentSize.Height); + } + else + { + width = Math.Max (0, Frame.Size.Width - totalThickness.Horizontal); + height = Math.Max (0, Frame.Size.Height - totalThickness.Vertical); + } return new (UseContentOffset ? ContentOffset : Point.Empty, new Size (width, height)); } @@ -948,9 +959,16 @@ public virtual void LayoutSubviews () CollectAll (this, ref nodes, ref edges); List ordered = TopologicalSort (SuperView, nodes, edges); + Point boundsOffset = Point.Empty; + + if (UseContentOffset) + { + boundsOffset.Offset (ContentOffset.X, ContentOffset.Y); + } + foreach (View v in ordered) { - LayoutSubview (v, new (Point.Empty, ContentArea.Size)); + LayoutSubview (v, new (boundsOffset, ContentArea.Size)); } // If the 'to' is rooted to 'from' and the layoutstyle is Computed it's a special-case. From c3aa8593e8c0e6697b711b09c97e7f7a24de6152 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 30 Mar 2024 17:33:44 +0000 Subject: [PATCH 113/130] Fix some bugs and adjust unit tests. --- Terminal.Gui/Views/ScrollBarView.cs | 100 +++++++++++++++++++------- UnitTests/View/ViewScrollBarTests.cs | 4 +- UnitTests/Views/ScrollBarViewTests.cs | 12 ++-- 3 files changed, 83 insertions(+), 33 deletions(-) diff --git a/Terminal.Gui/Views/ScrollBarView.cs b/Terminal.Gui/Views/ScrollBarView.cs index a37ffa44c8..8e6546f6fd 100644 --- a/Terminal.Gui/Views/ScrollBarView.cs +++ b/Terminal.Gui/Views/ScrollBarView.cs @@ -30,6 +30,7 @@ public class ScrollBarView : View private int _posTopTee; private bool _showScrollIndicator; private int _size, _position; + private Thickness _parentThickness; /// /// Initializes a new instance of the class using @@ -669,7 +670,7 @@ internal bool CanScroll (int n, out int maxToScroll, Orientation orientation = O maxToScroll = Size > barSize + newPosition - isBuiltInOffset ? newPosition - _position - : Size - (barSize + _position) + isBuiltInOffset - (barSize == 0 && ShowBothScrollIndicator ? 1 : 0); + : Size - (barSize + _position) + isBuiltInOffset - (barSize == 0 && OtherScrollBarView is { ShowScrollIndicator: true } ? 1 : 0); return Size >= barSize + newPosition - isBuiltInOffset && maxToScroll != 0; } @@ -686,16 +687,16 @@ private void AdjustContentInViewport (bool refresh = true) if (KeepContentAlwaysInViewPort && _orientation == Orientation.Horizontal - && _position > Math.Max (Size - bounds.Width + (!IsBuiltIn && ShowBothScrollIndicator ? 1 : 0), GetOtherScrollBarViewOffset)) + && _position > Math.Max (Size - bounds.Width + (!IsBuiltIn && OtherScrollBarView is { ShowScrollIndicator: true } ? 1 : 0), GetOtherScrollBarViewOffset)) { - pos = Math.Max (Size - bounds.Width + (!IsBuiltIn && ShowBothScrollIndicator ? 1 : 0), GetOtherScrollBarViewOffset); + pos = Math.Max (Size - bounds.Width + (!IsBuiltIn && OtherScrollBarView is { ShowScrollIndicator: true } ? 1 : 0), GetOtherScrollBarViewOffset); } if (KeepContentAlwaysInViewPort && _orientation == Orientation.Vertical - && _position > Math.Max (Size - bounds.Height + (!IsBuiltIn && ShowBothScrollIndicator ? 1 : 0), GetOtherScrollBarViewOffset)) + && _position > Math.Max (Size - bounds.Height + (!IsBuiltIn && OtherScrollBarView is { ShowScrollIndicator: true } ? 1 : 0), GetOtherScrollBarViewOffset)) { - pos = Math.Max (Size - bounds.Height + (!IsBuiltIn && ShowBothScrollIndicator ? 1 : 0), GetOtherScrollBarViewOffset); + pos = Math.Max (Size - bounds.Height + (!IsBuiltIn && OtherScrollBarView is { ShowScrollIndicator: true } ? 1 : 0), GetOtherScrollBarViewOffset); } if (pos != 0) @@ -853,9 +854,9 @@ private int GetBarSize (Orientation orientation) } return orientation == Orientation.Vertical ? KeepContentAlwaysInViewPort - ? bounds.Height - (ShowBothScrollIndicator ? 1 : 0) + ? bounds.Height - (OtherScrollBarView is { ShowScrollIndicator: true } ? 1 : 0) : 0 : - KeepContentAlwaysInViewPort ? bounds.Width - (ShowBothScrollIndicator ? 1 : 0) : 0; + KeepContentAlwaysInViewPort ? bounds.Width - (OtherScrollBarView is { ShowScrollIndicator: true } ? 1 : 0) : 0; } // Always return the parent view visible content area or an empty rectangle. @@ -880,19 +881,19 @@ private void ManageScrollBarThickness () if (Visible && OtherScrollBarView.Visible) { - adornment.Thickness = new Thickness (0, 0, 1, 1); + adornment.Thickness = new Thickness (_parentThickness.Left, _parentThickness.Top, _parentThickness.Right + 1, _parentThickness.Bottom + 1); } else if ((Visible && Orientation == Orientation.Vertical) || (OtherScrollBarView.Visible && OtherScrollBarView.Orientation == Orientation.Vertical)) { - adornment.Thickness = new Thickness (0, 0, 1, 0); + adornment.Thickness = new Thickness (_parentThickness.Left, _parentThickness.Top, _parentThickness.Right + 1, _parentThickness.Bottom); } else if ((Visible && Orientation == Orientation.Horizontal) || (OtherScrollBarView.Visible && OtherScrollBarView.Orientation == Orientation.Horizontal)) { - adornment.Thickness = new Thickness (0, 0, 0, 1); + adornment.Thickness = new Thickness (_parentThickness.Left, _parentThickness.Top, _parentThickness.Right, _parentThickness.Bottom + 1); } else { - adornment.Thickness = new Thickness (0); + adornment.Thickness = _parentThickness; } } @@ -944,17 +945,27 @@ private void ScrollBarView_Added (object sender, SuperViewChangedEventArgs e) parent.EnabledChanged += Parent_EnabledChanged; parent.VisibleChanged += Parent_VisibleChanged; parent.DrawAdornments += Parent_DrawAdornments; + parent.LayoutComplete += Parent_LayoutComplete; parent.MouseEnter += (s, e) => OnMouseEnter (e.MouseEvent); parent.MouseLeave += (s, e) => OnMouseLeave (e.MouseEvent); - - ManageScrollBarThickness (); } + private void Parent_LayoutComplete (object sender, LayoutEventArgs e) { AdjustContentInViewport (); } + private void ScrollBarView_Initialized (object sender, EventArgs e) { X = Orientation == Orientation.Vertical ? Pos.AnchorEnd (1) : 0; Y = Orientation == Orientation.Vertical ? 0 : Pos.AnchorEnd (1); + if (OtherScrollBarView is { _parentThickness: { } }) + { + _parentThickness = OtherScrollBarView._parentThickness; + } + else + { + _parentThickness = SuperView is Adornment adornmentThickness ? adornmentThickness.Thickness : Thickness.Empty; + } + SetWidthHeight (); ShowHideScrollBars (); @@ -1009,23 +1020,40 @@ private void SetWidthHeight () { Rectangle bounds = SuperView?.GetVisibleContentArea () ?? Rectangle.Empty; - X = _orientation == Orientation.Vertical ? bounds.Right - 1 : bounds.Left; - Y = _orientation == Orientation.Vertical ? bounds.Top : bounds.Bottom - 1; + if (IsBuiltIn) + { + X = _orientation == Orientation.Vertical ? bounds.Right - 1 : bounds.Left; + Y = _orientation == Orientation.Vertical ? bounds.Top : bounds.Bottom - 1; + + _otherScrollBarView.X = _otherScrollBarView._orientation == Orientation.Vertical ? bounds.Right - 1 : bounds.Left; + _otherScrollBarView.Y = _otherScrollBarView._orientation == Orientation.Vertical ? bounds.Top : bounds.Bottom - 1; + + _contentBottomRightCorner.X = bounds.Right - 1; + _contentBottomRightCorner.Y = bounds.Bottom - 1; + } + else + { + Point contentOffset = SuperView.ContentOffset; + + X = _orientation == Orientation.Vertical ? bounds.Right - 1 + -contentOffset.X : bounds.Left; + Y = _orientation == Orientation.Vertical ? bounds.Top + -contentOffset.Y : bounds.Bottom - 1; + + _otherScrollBarView.X = _otherScrollBarView._orientation == Orientation.Vertical ? bounds.Right - 1 + -contentOffset.X : bounds.Left; + _otherScrollBarView.Y = _otherScrollBarView._orientation == Orientation.Vertical ? bounds.Top + -contentOffset.Y : bounds.Bottom - 1; + + _contentBottomRightCorner.X = bounds.Right - 1 + -contentOffset.X; + _contentBottomRightCorner.Y = bounds.Bottom - 1 + -contentOffset.Y; + } + Width = _orientation == Orientation.Vertical ? 1 : SuperView is Adornment ? Dim.Fill (1) : bounds.Width - 1; Height = _orientation == Orientation.Vertical ? SuperView is Adornment ? Dim.Fill (1) : bounds.Height - 1 : 1; - _otherScrollBarView.X = _otherScrollBarView._orientation == Orientation.Vertical ? bounds.Right - 1 : bounds.Left; - _otherScrollBarView.Y = _otherScrollBarView._orientation == Orientation.Vertical ? bounds.Top : bounds.Bottom - 1; - _otherScrollBarView.Width = _otherScrollBarView._orientation == Orientation.Vertical ? 1 : SuperView is Adornment ? Dim.Fill (1) : bounds.Width - 1; _otherScrollBarView.Height = _otherScrollBarView._orientation == Orientation.Vertical ? SuperView is Adornment ? Dim.Fill (1) : bounds.Height - 1 : 1; - - _contentBottomRightCorner.X = bounds.Right - 1; - _contentBottomRightCorner.Y = bounds.Bottom - 1; } else { @@ -1042,8 +1070,19 @@ private void SetWidthHeight () { Rectangle bounds = SuperView?.GetVisibleContentArea () ?? Rectangle.Empty; - X = _orientation == Orientation.Vertical ? bounds.Right - 1 : bounds.Left; - Y = _orientation == Orientation.Vertical ? bounds.Top : bounds.Bottom - 1; + if (IsBuiltIn) + { + X = _orientation == Orientation.Vertical ? bounds.Right - 1 : bounds.Left; + Y = _orientation == Orientation.Vertical ? bounds.Top : bounds.Bottom - 1; + } + else + { + Point contentOffset = SuperView.ContentOffset; + + X = _orientation == Orientation.Vertical ? bounds.Right - 1 + -contentOffset.X : bounds.Left; + Y = _orientation == Orientation.Vertical ? bounds.Top + -contentOffset.Y : bounds.Bottom - 1; + } + Width = _orientation == Orientation.Vertical ? 1 : bounds.Width; Height = _orientation == Orientation.Vertical ? bounds.Height : 1; } @@ -1059,8 +1098,19 @@ private void SetWidthHeight () { Rectangle bounds = SuperView?.GetVisibleContentArea () ?? Rectangle.Empty; - _otherScrollBarView.X = _otherScrollBarView._orientation == Orientation.Vertical ? bounds.Right - 1 : bounds.Left; - _otherScrollBarView.Y = _otherScrollBarView._orientation == Orientation.Vertical ? bounds.Top : bounds.Bottom - 1; + if (IsBuiltIn) + { + _otherScrollBarView.X = _otherScrollBarView._orientation == Orientation.Vertical ? bounds.Right - 1 : bounds.Left; + _otherScrollBarView.Y = _otherScrollBarView._orientation == Orientation.Vertical ? bounds.Top : bounds.Bottom - 1; + } + else + { + Point contentOffset = SuperView.ContentOffset; + + _otherScrollBarView.X = _otherScrollBarView._orientation == Orientation.Vertical ? bounds.Right - 1 + -contentOffset.X : bounds.Left; + _otherScrollBarView.Y = _otherScrollBarView._orientation == Orientation.Vertical ? bounds.Top + -contentOffset.Y : bounds.Bottom - 1; + } + _otherScrollBarView.Width = _otherScrollBarView._orientation == Orientation.Vertical ? 1 : bounds.Width; _otherScrollBarView.Height = _otherScrollBarView._orientation == Orientation.Vertical ? bounds.Height : 1; } diff --git a/UnitTests/View/ViewScrollBarTests.cs b/UnitTests/View/ViewScrollBarTests.cs index d67ed66427..4e44a98a03 100644 --- a/UnitTests/View/ViewScrollBarTests.cs +++ b/UnitTests/View/ViewScrollBarTests.cs @@ -294,7 +294,7 @@ public void Scrolling_Without_ScrollBars () Assert.False (view2.HasFocus); Assert.Equal (12, view.ContentSize.Width); Assert.Equal (7, view.ContentSize.Height); - Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=12,Height=7}", view.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=3,Y=2,Width=9,Height=6}", view.Frame.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.ContentArea.ToString ()); @@ -306,7 +306,7 @@ public void Scrolling_Without_ScrollBars () Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.Frame.ToString ()); - Assert.Equal ("{Width=9, Height=6}", view.TextFormatter.Size.ToString ()); + Assert.Equal ("{Width=12, Height=7}", view.TextFormatter.Size.ToString ()); TestHelpers.AssertDriverContentsWithFrameAre ( @" diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index 1e09b4ab12..09beda7360 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -1249,7 +1249,7 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Padding_Thickne Assert.False (view2.HasFocus); Assert.Equal (12, view.ContentSize.Width); Assert.Equal (7, view.ContentSize.Height); - Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=12,Height=7}", view.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=3,Y=2,Width=9,Height=6}", view.Frame.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.ContentArea.ToString ()); @@ -1262,7 +1262,7 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Padding_Thickne Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.Frame.ToString ()); Assert.Equal ("(Left=0,Top=0,Right=1,Bottom=1)", view.Padding.Thickness.ToString ()); - Assert.Equal ("{Width=8, Height=5}", view.TextFormatter.Size.ToString ()); + Assert.Equal ("{Width=12, Height=7}", view.TextFormatter.Size.ToString ()); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -1365,7 +1365,7 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Padding_Thickne Assert.False (view2.HasFocus); Assert.Equal (12, view.ContentSize.Width); Assert.Equal (7, view.ContentSize.Height); - Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=12,Height=7}", view.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=8,Height=5}", view.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=2,Y=1,Width=9,Height=6}", view.Frame.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.ContentArea.ToString ()); @@ -1378,7 +1378,7 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Padding_Thickne Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.Frame.ToString ()); Assert.Equal ("(Left=0,Top=0,Right=1,Bottom=1)", view.Padding.Thickness.ToString ()); - Assert.Equal ("{Width=8, Height=5}", view.TextFormatter.Size.ToString ()); + Assert.Equal ("{Width=12, Height=7}", view.TextFormatter.Size.ToString ()); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -1482,7 +1482,7 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Parent_Inside_A Assert.False (view2.HasFocus); Assert.Equal (12, view.ContentSize.Width); Assert.Equal (7, view.ContentSize.Height); - Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.ContentArea.ToString ()); + Assert.Equal ("{X=0,Y=0,Width=12,Height=7}", view.ContentArea.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=2,Y=1,Width=9,Height=6}", view.Frame.ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Margin.ContentArea.ToString ()); @@ -1495,7 +1495,7 @@ public void ScrollBarType_IsBuiltIn_UseNegativeBoundsLocation_In_Parent_Inside_A Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.GetVisibleContentArea ().ToString ()); Assert.Equal ("{X=0,Y=0,Width=9,Height=6}", view.Padding.Frame.ToString ()); Assert.Equal ("(Left=0,Top=0,Right=0,Bottom=0)", view.Padding.Thickness.ToString ()); - Assert.Equal ("{Width=9, Height=6}", view.TextFormatter.Size.ToString ()); + Assert.Equal ("{Width=12, Height=7}", view.TextFormatter.Size.ToString ()); TestHelpers.AssertDriverContentsWithFrameAre ( @" From 3c18344743eddaef683dffde3365319bc0c91c4b Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 30 Mar 2024 17:35:14 +0000 Subject: [PATCH 114/130] Add horizontal, vertical, auto-hide and keep contents on the ScrollBars scenario. --- UICatalog/Scenarios/ScrollBars.cs | 64 +++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/UICatalog/Scenarios/ScrollBars.cs b/UICatalog/Scenarios/ScrollBars.cs index ff35e6c68f..37961eb261 100644 --- a/UICatalog/Scenarios/ScrollBars.cs +++ b/UICatalog/Scenarios/ScrollBars.cs @@ -75,6 +75,70 @@ public override void Setup () viewOnBorder.TabIndex = 1; viewOnPadding.TabIndex = 2; viewOnContentArea.TabIndex = 3; + + var hCheckBox = new CheckBox + { + X = 0, + Y = 0, + Text = "Horizontal Scrollbar", + Checked = true + }; + hCheckBox.Toggled += (s, e) => + { + viewOnMargin.ShowHorizontalScrollBar = !(bool)hCheckBox.Checked; + viewOnBorder.ShowHorizontalScrollBar = !(bool)hCheckBox.Checked; + viewOnPadding.ShowHorizontalScrollBar = !(bool)hCheckBox.Checked; + viewOnContentArea.ShowHorizontalScrollBar = !(bool)hCheckBox.Checked; + }; + Win.Add (hCheckBox); + + var vCheckBox = new CheckBox + { + X = Pos.Right (hCheckBox) + 3, + Y = 0, + Text = "Vertical Scrollbar", + Checked = true + }; + vCheckBox.Toggled += (s, e) => + { + viewOnMargin.ShowVerticalScrollBar = !(bool)vCheckBox.Checked; + viewOnBorder.ShowVerticalScrollBar = !(bool)vCheckBox.Checked; + viewOnPadding.ShowVerticalScrollBar = !(bool)vCheckBox.Checked; + viewOnContentArea.ShowVerticalScrollBar = !(bool)vCheckBox.Checked; + }; + Win.Add (vCheckBox); + + var ahCheckBox = new CheckBox + { + X = 0, + Y = Pos.Bottom (hCheckBox), + Text = "Auto Hide Scrollbars", + Checked = true + }; + ahCheckBox.Toggled += (s, e) => + { + viewOnMargin.AutoHideScrollBars = !(bool)ahCheckBox.Checked; + viewOnBorder.AutoHideScrollBars = !(bool)ahCheckBox.Checked; + viewOnPadding.AutoHideScrollBars = !(bool)ahCheckBox.Checked; + viewOnContentArea.AutoHideScrollBars = !(bool)ahCheckBox.Checked; + }; + Win.Add (ahCheckBox); + + var keepCheckBox = new CheckBox + { + X = 0, + Y = Pos.Bottom (ahCheckBox), + Text = "Keep Content Always In Viewport", + Checked = true + }; + keepCheckBox.Toggled += (s, e) => + { + viewOnMargin.KeepContentAlwaysInContentArea = !(bool)keepCheckBox.Checked; + viewOnBorder.KeepContentAlwaysInContentArea = !(bool)keepCheckBox.Checked; + viewOnPadding.KeepContentAlwaysInContentArea = !(bool)keepCheckBox.Checked; + viewOnContentArea.KeepContentAlwaysInContentArea = !(bool)keepCheckBox.Checked; + }; + Win.Add (keepCheckBox); } private void SetViewProperties (View view) From 238fdcfa85cb891b70638067ee4a9429a4f6d20e Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 30 Mar 2024 17:35:45 +0000 Subject: [PATCH 115/130] Apply @tig changes. --- UICatalog/Scenarios/Adornments.cs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/UICatalog/Scenarios/Adornments.cs b/UICatalog/Scenarios/Adornments.cs index 91c40f5a41..b60d09ceee 100644 --- a/UICatalog/Scenarios/Adornments.cs +++ b/UICatalog/Scenarios/Adornments.cs @@ -82,8 +82,6 @@ public override void Init () //BorderStyle = LineStyle.None, }; - view.X = 36; - view.Y = 0; view.Width = Dim.Percent (60); view.Height = Dim.Percent (80); @@ -91,7 +89,7 @@ public override void Init () view.Initialized += (s, e) => { - var labelInPadding = new Label () { X = 1, Y = 0, Title = "_Text:" }; + var labelInPadding = new Label () { X = 1, Y = 0, Title = "_Text:" }; view.Padding.Add (labelInPadding); var textFieldInPadding = new TextField () { X = Pos.Right (labelInPadding) + 1, Y = Pos.Top (labelInPadding), Width = 15, Text = "some text" }; @@ -101,7 +99,7 @@ public override void Init () var btnButtonInPadding = new Button { X = Pos.Center (), Y = 0, Text = "_Button in Padding" }; btnButtonInPadding.Accept += (s, e) => MessageBox.Query (20, 7, "Hi", "Button in Padding Pressed!", "Ok"); btnButtonInPadding.BorderStyle = LineStyle.Dashed; - btnButtonInPadding.Border.Thickness = new (1,1,1,1); + btnButtonInPadding.Border.Thickness = new (1, 1, 1, 1); view.Padding.Add (btnButtonInPadding); #if SUBVIEW_BASED_BORDER @@ -183,7 +181,7 @@ public Thickness Thickness } _thickness = value; - ThicknessChanged?.Invoke (this, new() { Thickness = Thickness }); + ThicknessChanged?.Invoke (this, new () { Thickness = Thickness }); if (IsInitialized) { @@ -221,12 +219,12 @@ private void AdornmentEditor_Initialized (object sender, EventArgs e) { var editWidth = 3; - _topEdit = new() { X = Pos.Center (), Y = 0, Width = editWidth }; + _topEdit = new () { X = Pos.Center (), Y = 0, Width = editWidth }; _topEdit.Accept += Edit_Accept; Add (_topEdit); - _leftEdit = new() + _leftEdit = new () { X = Pos.Left (_topEdit) - editWidth, Y = Pos.Bottom (_topEdit), Width = editWidth }; @@ -234,12 +232,12 @@ private void AdornmentEditor_Initialized (object sender, EventArgs e) _leftEdit.Accept += Edit_Accept; Add (_leftEdit); - _rightEdit = new() { X = Pos.Right (_topEdit), Y = Pos.Bottom (_topEdit), Width = editWidth }; + _rightEdit = new () { X = Pos.Right (_topEdit), Y = Pos.Bottom (_topEdit), Width = editWidth }; _rightEdit.Accept += Edit_Accept; Add (_rightEdit); - _bottomEdit = new() { X = Pos.Center (), Y = Pos.Bottom (_leftEdit), Width = editWidth }; + _bottomEdit = new () { X = Pos.Center (), Y = Pos.Bottom (_leftEdit), Width = editWidth }; _bottomEdit.Accept += Edit_Accept; Add (_bottomEdit); @@ -328,7 +326,7 @@ public View ViewToEdit _origTitle = value.Title; _viewToEdit = value; - _marginEditor = new() + _marginEditor = new () { X = 0, Y = 0, @@ -341,7 +339,7 @@ public View ViewToEdit _marginEditor.AttributeChanged += Editor_AttributeChanged; Add (_marginEditor); - _borderEditor = new() + _borderEditor = new () { X = Pos.Left (_marginEditor), Y = Pos.Bottom (_marginEditor), @@ -411,7 +409,7 @@ public View ViewToEdit { if (ckbTitle.Checked == true) { - _viewToEdit.Title = _origTitle; + //_viewToEdit.Title = _origTitle; } else { @@ -420,7 +418,7 @@ public View ViewToEdit }; Add (ckbTitle); - _paddingEditor = new() + _paddingEditor = new () { X = Pos.Left (_borderEditor), Y = Pos.Bottom (rbBorderStyle), @@ -450,6 +448,8 @@ public View ViewToEdit }; Add (_diagCheckBox); + _viewToEdit.X = Pos.Right (rbBorderStyle); + _viewToEdit.Y = 0; Add (_viewToEdit); _viewToEdit.LayoutComplete += (s, e) => From d24de8a177132228dc735fefc3a3035609590732 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 30 Mar 2024 17:37:17 +0000 Subject: [PATCH 116/130] Apply a changed @tig VirtualScrolling scenario. --- .../Scenarios/VirtualContentScrolling.cs | 179 ++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 UICatalog/Scenarios/VirtualContentScrolling.cs diff --git a/UICatalog/Scenarios/VirtualContentScrolling.cs b/UICatalog/Scenarios/VirtualContentScrolling.cs new file mode 100644 index 0000000000..30b19f6447 --- /dev/null +++ b/UICatalog/Scenarios/VirtualContentScrolling.cs @@ -0,0 +1,179 @@ +using System.Linq; +using Terminal.Gui; + +namespace UICatalog.Scenarios; + +[ScenarioMetadata ("_Virtual Content Scrolling Demo", "Demonstrates scrolling built-into View")] +[ScenarioCategory ("Layout")] +public class VirtualScrolling : Scenario +{ + private ViewDiagnosticFlags _diagnosticFlags; + + public class VirtualDemoView : View + { + public VirtualDemoView () + { + Text = "Virtual Demo View Text. This is long text.\nThe second line.\n3\n4\n5th line."; + CanFocus = true; + Arrangement = ViewArrangement.Movable; + ColorScheme = Colors.ColorSchemes ["Toplevel"]; + BorderStyle = LineStyle.Rounded; + + // TODO: Add a way to set the scroll settings in the Scenario + ContentSize = new Size (100, 60); + ////ScrollSettings = ScrollSettings.NoRestrict; + + //// Things this view knows how to do + //AddCommand (Command.ScrollDown, () => ScrollVertical (1)); + //AddCommand (Command.ScrollUp, () => ScrollVertical (-1)); + + //AddCommand (Command.ScrollRight, () => ScrollHorizontal (1)); + //AddCommand (Command.ScrollLeft, () => ScrollHorizontal (-1)); + + ////AddCommand (Command.PageUp, () => PageUp ()); + ////AddCommand (Command.PageDown, () => PageDown ()); + ////AddCommand (Command.TopHome, () => Home ()); + ////AddCommand (Command.BottomEnd, () => End ()); + + //// Default keybindings for all ListViews + //KeyBindings.Add (Key.CursorUp, Command.ScrollUp); + //KeyBindings.Add (Key.CursorDown, Command.ScrollDown); + //KeyBindings.Add (Key.CursorLeft, Command.ScrollLeft); + //KeyBindings.Add (Key.CursorRight, Command.ScrollRight); + + ////KeyBindings.Add (Key.PageUp, Command.PageUp); + ////KeyBindings.Add (Key.PageDown, Command.PageDown); + ////KeyBindings.Add (Key.Home, Command.TopHome); + ////KeyBindings.Add (Key.End, Command.BottomEnd); + + Border.Add (new Label () { X = 23 }); + LayoutComplete += VirtualDemoView_LayoutComplete; + + //MouseEvent += VirtualDemoView_MouseEvent; + } + + //private void VirtualDemoView_MouseEvent (object sender, MouseEventEventArgs e) + //{ + // if (e.MouseEvent.Flags == MouseFlags.WheeledDown) + // { + // ScrollVertical (1); + // return; + // } + // if (e.MouseEvent.Flags == MouseFlags.WheeledUp) + // { + // ScrollVertical (-1); + + // return; + // } + + // if (e.MouseEvent.Flags == MouseFlags.WheeledRight) + // { + // ScrollHorizontal (1); + // return; + // } + // if (e.MouseEvent.Flags == MouseFlags.WheeledLeft) + // { + // ScrollHorizontal (-1); + + // return; + // } + + //} + + private void VirtualDemoView_LayoutComplete (object sender, LayoutEventArgs e) + { + var status = Border.Subviews.OfType