From f65c49a8583a8da604d765e2cba449d072a371d7 Mon Sep 17 00:00:00 2001 From: Tig Date: Sun, 31 Mar 2024 22:13:48 -0600 Subject: [PATCH] More Prototype scrollbuttons in Padding for CharMap --- Terminal.Gui/View/ViewDrawing.cs | 11 +++++++++-- Terminal.Gui/Views/Button.cs | 27 +++++++++++++-------------- UICatalog/Scenarios/Buttons.cs | 2 +- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/Terminal.Gui/View/ViewDrawing.cs b/Terminal.Gui/View/ViewDrawing.cs index 2d8d31918..37094bbae 100644 --- a/Terminal.Gui/View/ViewDrawing.cs +++ b/Terminal.Gui/View/ViewDrawing.cs @@ -524,12 +524,12 @@ public partial class View _needsDisplayRect = new (x, y, w, h); } - SuperView?.SetSubViewNeedsDisplay (); - Margin?.SetNeedsDisplay (); Border?.SetNeedsDisplay (); Padding?.SetNeedsDisplay (); + SuperView?.SetSubViewNeedsDisplay (); + foreach (View subview in Subviews) { if (subview.Frame.IntersectsWith (region)) @@ -550,6 +550,13 @@ public partial class View if (SuperView is { SubViewNeedsDisplay: false }) { SuperView.SetSubViewNeedsDisplay (); + + return; + } + + if (this is Adornment adornment) + { + adornment.Parent?.SetSubViewNeedsDisplay (); } } diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index 43b9837e8..32cef242c 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -62,7 +62,8 @@ public class Button : View //MouseClick += Button_MouseClick; } - private Attribute _originalNormal; + [CanBeNull] + private ColorScheme _savedColorScheme; private void Button_MouseEvent (object sender, MouseEventEventArgs e) { @@ -71,31 +72,29 @@ public class Button : View if (Application.MouseGrabView == this) { e.Handled = InvokeCommand (Command.HotKey) == true; - return; } + + SetFocus(); Application.GrabMouse(this); - _originalNormal = ColorScheme.Normal; - var cs = new ColorScheme (ColorScheme) - { - Normal = ColorScheme.HotFocus - }; + _savedColorScheme = ColorScheme; + var cs = new ColorScheme (new Attribute (ColorScheme.Normal.Background, ColorScheme.Normal.Foreground)); ColorScheme = cs; } - if (e.MouseEvent.Flags == MouseFlags.Button1Released) + if (e.MouseEvent.Flags.HasFlag(MouseFlags.Button1Released)) { Application.UngrabMouse (); - var cs = new ColorScheme (ColorScheme) - { - Normal = _originalNormal - }; - ColorScheme = cs; e.Handled = InvokeCommand (Command.HotKey) == true; - return; + if (_savedColorScheme is { }) + { + ColorScheme = _savedColorScheme; + } + + _savedColorScheme = null; } } diff --git a/UICatalog/Scenarios/Buttons.cs b/UICatalog/Scenarios/Buttons.cs index 2702568eb..798771148 100644 --- a/UICatalog/Scenarios/Buttons.cs +++ b/UICatalog/Scenarios/Buttons.cs @@ -301,7 +301,7 @@ public class Buttons : Scenario Width = 1, NoPadding = true, NoDecorations = true, - Title = CM.Glyphs.UpArrow.ToString(), + Title = $"{CM.Glyphs.UpArrow}", }; Win.Add (label, oneByOne);