Tig 1 year ago
parent
commit
ee3c48ae50

+ 0 - 4
Terminal.Gui/Application/Application.Keyboard.cs

@@ -301,7 +301,6 @@ public static partial class Application // Keyboard handling
                     Command.NextView,
                     Command.NextView,
                     () =>
                     () =>
                     {
                     {
-                        // TODO: Move this method to Application.Navigation.cs
                         ApplicationNavigation.MoveNextView ();
                         ApplicationNavigation.MoveNextView ();
 
 
                         return true;
                         return true;
@@ -312,7 +311,6 @@ public static partial class Application // Keyboard handling
                     Command.PreviousView,
                     Command.PreviousView,
                     () =>
                     () =>
                     {
                     {
-                        // TODO: Move this method to Application.Navigation.cs
                         ApplicationNavigation.MovePreviousView ();
                         ApplicationNavigation.MovePreviousView ();
 
 
                         return true;
                         return true;
@@ -323,7 +321,6 @@ public static partial class Application // Keyboard handling
                     Command.NextViewOrTop,
                     Command.NextViewOrTop,
                     () =>
                     () =>
                     {
                     {
-                        // TODO: Move this method to Application.Navigation.cs
                         ApplicationNavigation.MoveNextViewOrTop ();
                         ApplicationNavigation.MoveNextViewOrTop ();
 
 
                         return true;
                         return true;
@@ -334,7 +331,6 @@ public static partial class Application // Keyboard handling
                     Command.PreviousViewOrTop,
                     Command.PreviousViewOrTop,
                     () =>
                     () =>
                     {
                     {
-                        // TODO: Move this method to Application.Navigation.cs
                         ApplicationNavigation.MovePreviousViewOrTop ();
                         ApplicationNavigation.MovePreviousViewOrTop ();
 
 
                         return true;
                         return true;

+ 4 - 4
Terminal.Gui/Application/Application.Navigation.cs

@@ -67,9 +67,9 @@ internal static class ApplicationNavigation
         {
         {
             Toplevel? top = Application.Current!.Modal ? Application.Current : Application.Top;
             Toplevel? top = Application.Current!.Modal ? Application.Current : Application.Top;
 
 
-            if (!Application.Current.AdvanceFocus (NavigationDirection.Forward))
+            if (!Application.Current.AdvanceFocus (NavigationDirection.Forward, true))
             {
             {
-                Application.Current.AdvanceFocus (NavigationDirection.Forward);
+                Application.Current.AdvanceFocus (NavigationDirection.Forward, true);
             }
             }
 
 
             if (top != Application.Current.Focused && top != Application.Current.Focused?.Focused)
             if (top != Application.Current.Focused && top != Application.Current.Focused?.Focused)
@@ -129,11 +129,11 @@ internal static class ApplicationNavigation
         if (ApplicationOverlapped.OverlappedTop is null)
         if (ApplicationOverlapped.OverlappedTop is null)
         {
         {
             Toplevel? top = Application.Current!.Modal ? Application.Current : Application.Top;
             Toplevel? top = Application.Current!.Modal ? Application.Current : Application.Top;
-            top!.AdvanceFocus (NavigationDirection.Backward);
+            top!.AdvanceFocus (NavigationDirection.Backward, true);
 
 
             if (top.Focused is null)
             if (top.Focused is null)
             {
             {
-                top.AdvanceFocus (NavigationDirection.Backward);
+                top.AdvanceFocus (NavigationDirection.Backward, true);
             }
             }
 
 
             top.SetNeedsDisplay ();
             top.SetNeedsDisplay ();

+ 28 - 10
Terminal.Gui/View/View.Navigation.cs

@@ -523,11 +523,12 @@ public partial class View // Focus and cross-view navigation management (TabStop
     ///     </para>
     ///     </para>
     /// </remarks>
     /// </remarks>
     /// <param name="direction"></param>
     /// <param name="direction"></param>
+    /// <param name="acrossGroupOrOverlapped">If <see langword="true"/> will advance into ...</param>
     /// <returns>
     /// <returns>
     ///     <see langword="true"/> if focus was changed to another subview (or stayed on this one), <see langword="false"/>
     ///     <see langword="true"/> if focus was changed to another subview (or stayed on this one), <see langword="false"/>
     ///     otherwise.
     ///     otherwise.
     /// </returns>
     /// </returns>
-    public bool AdvanceFocus (NavigationDirection direction)
+    public bool AdvanceFocus (NavigationDirection direction, bool acrossGroupOrOverlapped = false)
     {
     {
         if (!CanBeVisible (this))
         if (!CanBeVisible (this))
         {
         {
@@ -569,14 +570,30 @@ public partial class View // Focus and cross-view navigation management (TabStop
             if (w.HasFocus)
             if (w.HasFocus)
             {
             {
                 // A subview has focus, tell *it* to FocusNext
                 // A subview has focus, tell *it* to FocusNext
-                if (w.AdvanceFocus (direction))
+                if (w.AdvanceFocus (direction, acrossGroupOrOverlapped))
                 {
                 {
                     // The subview changed which of it's subviews had focus
                     // The subview changed which of it's subviews had focus
                     return true;
                     return true;
                 }
                 }
+                else
+                {
+                    if (acrossGroupOrOverlapped && Arrangement.HasFlag (ViewArrangement.Overlapped))
+                    {
+                        return false;
+                    }
+                }
 
 
                 Debug.Assert (w.HasFocus);
                 Debug.Assert (w.HasFocus);
 
 
+                if (w.Focused is null)
+                {
+                    // No next focusable view was found. 
+                    if (w.Arrangement.HasFlag (ViewArrangement.Overlapped))
+                    {
+                        // Keep focus w/in w
+                        return false;
+                    }
+                }
                 // The subview has no subviews that can be next. Cache that we found a focused subview.
                 // The subview has no subviews that can be next. Cache that we found a focused subview.
                 focusedFound = true;
                 focusedFound = true;
 
 
@@ -589,17 +606,17 @@ public partial class View // Focus and cross-view navigation management (TabStop
                 // Make Focused Leave
                 // Make Focused Leave
                 Focused.SetHasFocus (false, w);
                 Focused.SetHasFocus (false, w);
 
 
-                //// If the focused view is overlapped don't focus on the next if it's not overlapped.
-                //if (Focused.Arrangement.HasFlag (ViewArrangement.Overlapped)/* && !w.Arrangement.HasFlag (ViewArrangement.Overlapped)*/)
+                // If the focused view is overlapped don't focus on the next if it's not overlapped.
+                //if (acrossGroupOrOverlapped && Focused.Arrangement.HasFlag (ViewArrangement.Overlapped)/* && !w.Arrangement.HasFlag (ViewArrangement.Overlapped)*/)
                 //{
                 //{
                 //    return false;
                 //    return false;
                 //}
                 //}
 
 
-                //// If the focused view is not overlapped and the next is, skip it
-                //if (!Focused.Arrangement.HasFlag (ViewArrangement.Overlapped) && w.Arrangement.HasFlag (ViewArrangement.Overlapped))
-                //{
-                //    continue;
-                //}
+                // If the focused view is not overlapped and the next is, skip it
+                if (!acrossGroupOrOverlapped && !Focused.Arrangement.HasFlag (ViewArrangement.Overlapped) && w.Arrangement.HasFlag (ViewArrangement.Overlapped))
+                {
+                    continue;
+                }
 
 
                 switch (direction)
                 switch (direction)
                 {
                 {
@@ -766,7 +783,8 @@ public partial class View // Focus and cross-view navigation management (TabStop
             {
             {
                 return;
                 return;
             }
             }
-
+            
+            // BUGBUG: TabStop and CanFocus should be decoupled.
             _tabStop = CanFocus && value;
             _tabStop = CanFocus && value;
         }
         }
     }
     }

+ 1 - 1
Terminal.Gui/View/ViewArrangement.cs

@@ -67,5 +67,5 @@ public enum ViewArrangement
     ///         Use Ctrl-Tab (Ctrl-PageDown) / Ctrl-Shift-Tab (Ctrl-PageUp) to move between overlapped views.
     ///         Use Ctrl-Tab (Ctrl-PageDown) / Ctrl-Shift-Tab (Ctrl-PageUp) to move between overlapped views.
     ///     </para>
     ///     </para>
     /// </remarks>
     /// </remarks>
-    Overlapped = 32
+    Overlapped = 32,
 }
 }

+ 3 - 0
UICatalog/Scenarios/AdornmentEditor.cs

@@ -90,6 +90,9 @@ public class AdornmentEditor : View
 
 
         BorderStyle = LineStyle.Dashed;
         BorderStyle = LineStyle.Dashed;
         Initialized += AdornmentEditor_Initialized;
         Initialized += AdornmentEditor_Initialized;
+
+        //Arrangement = ViewArrangement.Group;
+
     }
     }
 
 
     private void AdornmentEditor_Initialized (object sender, EventArgs e)
     private void AdornmentEditor_Initialized (object sender, EventArgs e)

+ 17 - 8
UICatalog/Scenarios/ViewExperiments.cs

@@ -18,6 +18,7 @@ public class ViewExperiments : Scenario
             Title = GetQuitKeyAndName ()
             Title = GetQuitKeyAndName ()
         };
         };
 
 
+
         var view = new View
         var view = new View
         {
         {
             X = 2,
             X = 2,
@@ -81,21 +82,29 @@ public class ViewExperiments : Scenario
 
 
         view2.Add (button);
         view2.Add (button);
 
 
-        button = new ()
-        {
-            X = Pos.AnchorEnd (),
-            Y = Pos.AnchorEnd (),
-            Title = "Button_5",
-        };
-
         var editor = new AdornmentsEditor
         var editor = new AdornmentsEditor
         {
         {
             X = 0,
             X = 0,
             Y = 0,
             Y = 0,
             AutoSelectViewToEdit = true
             AutoSelectViewToEdit = true
         };
         };
-
         app.Add (editor);
         app.Add (editor);
+
+        button = new ()
+        {
+            Y = 0,
+            X = Pos.X (view),
+            Title = "Button_0",
+        };
+        app.Add (button);
+
+        button = new ()
+        {
+            X = Pos.AnchorEnd (),
+            Y = Pos.AnchorEnd (),
+            Title = "Button_5",
+        };
+
         view.X = 34;
         view.X = 34;
         view.Y = 4;
         view.Y = 4;
         app.Add (view);
         app.Add (view);