Kaynağa Gözat

Prototype scrollbuttons in Padding for CharMap

Tig 1 yıl önce
ebeveyn
işleme
08d2716cc9

+ 19 - 2
Terminal.Gui/View/ViewSubViews.cs

@@ -31,8 +31,14 @@ public partial class View
 
     /// <summary>Adds a subview (child) to this view.</summary>
     /// <remarks>
+    /// <para>
     ///     The Views that have been added to this view can be retrieved via the <see cref="Subviews"/> property. See also
     ///     <seealso cref="Remove(View)"/> <seealso cref="RemoveAll"/>
+    /// </para>
+    /// <para>
+    ///     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.
+    /// </para>
     /// </remarks>
     public virtual void Add (View view)
     {
@@ -92,8 +98,14 @@ public partial class View
     /// <summary>Adds the specified views (children) to the view.</summary>
     /// <param name="views">Array of one or more views (can be optional parameter).</param>
     /// <remarks>
+    /// <para>
     ///     The Views that have been added to this view can be retrieved via the <see cref="Subviews"/> property. See also
-    ///     <seealso cref="Remove(View)"/> <seealso cref="RemoveAll"/>
+    ///     <seealso cref="Remove(View)"/> and <seealso cref="RemoveAll"/>.
+    /// </para>
+    /// <para>
+    ///     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.
+    /// </para>
     /// </remarks>
     public void Add (params View [] views)
     {
@@ -185,7 +197,12 @@ public partial class View
     }
 
     /// <summary>Removes a subview added via <see cref="Add(View)"/> or <see cref="Add(View[])"/> from this View.</summary>
-    /// <remarks></remarks>
+    /// <remarks>
+    /// <para>
+    ///     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 <see cref="Dispose"/>.
+    /// </para>
+    /// </remarks>
     public virtual void Remove (View view)
     {
         if (view is null || _subviews is null)

+ 46 - 1
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;
+        }
+    }
+
+    /// <inheritdoc />
+    public override bool OnLeave (View view)
+    {
+        //Application.UngrabMouse();
+        return base.OnLeave (view);
     }
 
     private void Button_MouseClick (object sender, MouseEventEventArgs e)

+ 19 - 0
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)

+ 81 - 1
UICatalog/Scenarios/CharacterMap.cs

@@ -461,8 +461,88 @@ internal class CharMap : View
         KeyBindings.Add (Key.End, Command.BottomEnd);
 
         MouseClick += Handle_MouseClick;
-
         MouseEvent += Handle_MouseEvent;
+
+        // Prototype scrollbars
+        Padding.Thickness = new Thickness (0, 0, 1, 1);
+        var up = new Button ()
+        {
+            AutoSize = false,
+            X = Pos.AnchorEnd(1),
+            Y = 0,
+            Height = 1,
+            Width = 1,
+            NoPadding = true,
+            NoDecorations = true,
+            Title = CM.Glyphs.UpArrow.ToString (),
+            WantContinuousButtonPressed = true,
+            CanFocus = false,
+
+        };
+        up.Accept += (sender, args) =>
+                     {
+                         args.Cancel = ScrollVertical (-1) == true;
+                     };
+
+        var down = new Button ()
+        {
+            AutoSize = false,
+            X = Pos.AnchorEnd (1),
+            Y = Pos.AnchorEnd (2),
+            Height = 1,
+            Width = 1,
+            NoPadding = true,
+            NoDecorations = true,
+            Title = CM.Glyphs.DownArrow.ToString (),
+            WantContinuousButtonPressed = true,
+            CanFocus = false,
+
+        };
+        down.Accept += (sender, args) =>
+                     {
+                         ScrollVertical (1);
+                     };
+
+        var left = new Button ()
+        {
+            AutoSize = false,
+            X = 0,
+            Y = Pos.AnchorEnd (1),
+            Height = 1,
+            Width = 1,
+            NoPadding = true,
+            NoDecorations = true,
+            Title = CM.Glyphs.LeftArrow.ToString (),
+            WantContinuousButtonPressed = true,
+            CanFocus = false,
+
+        };
+        left.Accept += (sender, args) =>
+                     {
+                         ScrollHorizontal (-1);
+                     };
+
+        var right = new Button ()
+        {
+            AutoSize = false,
+            X = Pos.AnchorEnd (2),
+            Y = Pos.AnchorEnd (1),
+            Height = 1,
+            Width = 1,
+            NoPadding = true,
+            NoDecorations = true,
+            Title = CM.Glyphs.RightArrow.ToString (),
+            WantContinuousButtonPressed = true,
+            CanFocus = false,
+
+        };
+        right.Accept += (sender, args) =>
+                     {
+                         ScrollHorizontal (1);
+                     };
+
+
+        Padding.Add (up, down, left, right);
     }
 
     private void Handle_MouseEvent (object sender, MouseEventEventArgs e)