From a7079edf779d3f526bda8e329cfbf8136a032a7e Mon Sep 17 00:00:00 2001 From: Tig Date: Sun, 31 Mar 2024 21:29:46 -0600 Subject: [PATCH] Prototype scrollbuttons in Padding for CharMap --- Terminal.Gui/View/ViewSubViews.cs | 21 +++++++++++-- Terminal.Gui/Views/Button.cs | 47 ++++++++++++++++++++++++++++- UICatalog/Scenarios/Buttons.cs | 19 ++++++++++++ UICatalog/Scenarios/CharacterMap.cs | 2 +- 4 files changed, 85 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/View/ViewSubViews.cs b/Terminal.Gui/View/ViewSubViews.cs index b9cacc711..27570da2c 100644 --- a/Terminal.Gui/View/ViewSubViews.cs +++ b/Terminal.Gui/View/ViewSubViews.cs @@ -31,8 +31,14 @@ public partial class View /// Adds a subview (child) to this view. /// + /// /// The Views that have been added to this view can be retrieved via the property. See also /// + /// + /// + /// Subviews will be disposed when this View is disposed. In other-words, calling this method causes + /// the lifecycle of the subviews to be transferred to this View. + /// /// public virtual void Add (View view) { @@ -92,8 +98,14 @@ public partial class View /// Adds the specified views (children) to the view. /// Array of one or more views (can be optional parameter). /// + /// /// The Views that have been added to this view can be retrieved via the property. See also - /// + /// and . + /// + /// + /// Subviews will be disposed when this View is disposed. In other-words, calling this method causes + /// the lifecycle of the subviews to be transferred to this View. + /// /// public void Add (params View [] views) { @@ -185,7 +197,12 @@ public partial class View } /// Removes a subview added via or from this View. - /// + /// + /// + /// Normally Subviews will be disposed when this View is disposed. Removing a Subview causes ownership of the Subview's + /// lifecycle to be transferred to the caller; the caller muse call . + /// + /// public virtual void Remove (View view) { if (view is null || _subviews is null) diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index f74c3de0e..43b9837e8 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -58,7 +58,52 @@ public class Button : View KeyBindings.Add (Key.Enter, Command.HotKey); TitleChanged += Button_TitleChanged; - MouseClick += Button_MouseClick; + MouseEvent += Button_MouseEvent; + //MouseClick += Button_MouseClick; + } + + private Attribute _originalNormal; + + private void Button_MouseEvent (object sender, MouseEventEventArgs e) + { + if (e.MouseEvent.Flags == MouseFlags.Button1Pressed) + { + if (Application.MouseGrabView == this) + { + e.Handled = InvokeCommand (Command.HotKey) == true; + + return; + } + Application.GrabMouse(this); + + _originalNormal = ColorScheme.Normal; + var cs = new ColorScheme (ColorScheme) + { + Normal = ColorScheme.HotFocus + }; + ColorScheme = cs; + } + + if (e.MouseEvent.Flags == MouseFlags.Button1Released) + { + Application.UngrabMouse (); + var cs = new ColorScheme (ColorScheme) + { + Normal = _originalNormal + }; + ColorScheme = cs; + + e.Handled = InvokeCommand (Command.HotKey) == true; + + return; + } + } + + /// + public override bool OnLeave (View view) + { + //Application.UngrabMouse(); + return base.OnLeave (view); } private void Button_MouseClick (object sender, MouseEventEventArgs e) diff --git a/UICatalog/Scenarios/Buttons.cs b/UICatalog/Scenarios/Buttons.cs index 78787e83c..2702568eb 100644 --- a/UICatalog/Scenarios/Buttons.cs +++ b/UICatalog/Scenarios/Buttons.cs @@ -286,6 +286,25 @@ public class Buttons : Scenario moveUnicodeHotKeyBtn.Accept += (s, e) => { moveUnicodeHotKeyBtn.Text = MoveHotkey (moveUnicodeHotKeyBtn.Text); }; Win.Add (moveUnicodeHotKeyBtn); + label = new Label () + { + X = 0, + Y = Pos.Bottom (moveUnicodeHotKeyBtn) + 1, + Title = "_1x1 Button:", + }; + var oneByOne = new Button () + { + AutoSize = false, + X = Pos.Right(label)+1, + Y = Pos.Top (label), + Height = 1, + Width = 1, + NoPadding = true, + NoDecorations = true, + Title = CM.Glyphs.UpArrow.ToString(), + }; + Win.Add (label, oneByOne); + radioGroup.SelectedItemChanged += (s, args) => { switch (args.SelectedItem) diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index bcac93b9b..c8ba61100 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -1,4 +1,4 @@ -#define DRAW_CONTENT +#define DRAW_CONTENT //#define BASE_DRAW_CONTENT using System;