From 895b3894f57b7152ec6f975c0bbf927a71271cc0 Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 9 Feb 2023 18:43:04 +0000 Subject: [PATCH 1/2] Fixes #2331. ScrollView may not be honoring clip region; CustomButton shows outside --- Terminal.Gui/Views/ScrollView.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index 23bfedbce..12aab7cc0 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -329,10 +329,11 @@ namespace Terminal.Gui { //Clear (); var savedClip = ClipToBounds (); - OnDrawContent (new Rect (ContentOffset, + var rect = new Rect (new Point (-contentView.Frame.X, -contentView.Frame.Y), new Size (Math.Max (Bounds.Width - (ShowVerticalScrollIndicator ? 1 : 0), 0), - Math.Max (Bounds.Height - (ShowHorizontalScrollIndicator ? 1 : 0), 0)))); - contentView.Redraw (contentView.Frame); + Math.Max (Bounds.Height - (ShowHorizontalScrollIndicator ? 1 : 0), 0))); + OnDrawContent (rect); + contentView.Redraw (rect); Driver.Clip = savedClip; if (autoHideScrollBars) { @@ -508,7 +509,7 @@ namespace Terminal.Gui { { if (me.Flags != MouseFlags.WheeledDown && me.Flags != MouseFlags.WheeledUp && me.Flags != MouseFlags.WheeledRight && me.Flags != MouseFlags.WheeledLeft && -// me.Flags != MouseFlags.Button1Pressed && me.Flags != MouseFlags.Button1Clicked && + // me.Flags != MouseFlags.Button1Pressed && me.Flags != MouseFlags.Button1Clicked && !me.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition)) { return false; } From 51c64babc7170e8abcbb87fb94aa2441ec9efc95 Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 9 Feb 2023 23:41:27 +0000 Subject: [PATCH 2/2] More appropriate solution for the issue #2331. --- Terminal.Gui/Core/View.cs | 14 ++++++++++++-- Terminal.Gui/Views/ScrollView.cs | 9 ++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index 8034047af..96f58b217 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -1575,8 +1575,18 @@ namespace Terminal.Gui { var driverClip = Driver == null ? Rect.Empty : Driver.Clip; containerBounds.X = Math.Max (containerBounds.X, driverClip.X); containerBounds.Y = Math.Max (containerBounds.Y, driverClip.Y); - containerBounds.Width = Math.Min (containerBounds.Width, driverClip.Width); - containerBounds.Height = Math.Min (containerBounds.Height, driverClip.Height); + var lenOffset = (driverClip.X + driverClip.Width) - (containerBounds.X + containerBounds.Width); + if (containerBounds.X + containerBounds.Width > driverClip.X + driverClip.Width) { + containerBounds.Width = Math.Max (containerBounds.Width + lenOffset, 0); + } else { + containerBounds.Width = Math.Min (containerBounds.Width, driverClip.Width); + } + lenOffset = (driverClip.Y + driverClip.Height) - (containerBounds.Y + containerBounds.Height); + if (containerBounds.Y + containerBounds.Height > driverClip.Y + driverClip.Height) { + containerBounds.Height = Math.Max (containerBounds.Height + lenOffset, 0); + } else { + containerBounds.Height = Math.Min (containerBounds.Height, driverClip.Height); + } return containerBounds; } diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index 12aab7cc0..23bfedbce 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -329,11 +329,10 @@ namespace Terminal.Gui { //Clear (); var savedClip = ClipToBounds (); - var rect = new Rect (new Point (-contentView.Frame.X, -contentView.Frame.Y), + OnDrawContent (new Rect (ContentOffset, new Size (Math.Max (Bounds.Width - (ShowVerticalScrollIndicator ? 1 : 0), 0), - Math.Max (Bounds.Height - (ShowHorizontalScrollIndicator ? 1 : 0), 0))); - OnDrawContent (rect); - contentView.Redraw (rect); + Math.Max (Bounds.Height - (ShowHorizontalScrollIndicator ? 1 : 0), 0)))); + contentView.Redraw (contentView.Frame); Driver.Clip = savedClip; if (autoHideScrollBars) { @@ -509,7 +508,7 @@ namespace Terminal.Gui { { if (me.Flags != MouseFlags.WheeledDown && me.Flags != MouseFlags.WheeledUp && me.Flags != MouseFlags.WheeledRight && me.Flags != MouseFlags.WheeledLeft && - // me.Flags != MouseFlags.Button1Pressed && me.Flags != MouseFlags.Button1Clicked && +// me.Flags != MouseFlags.Button1Pressed && me.Flags != MouseFlags.Button1Clicked && !me.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition)) { return false; }